postgres

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2026 License: Apache-2.0 Imports: 41 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	URI      string
	ConnCfg  *connect.Config // resolved from nested config (nil when using URI)
	DB       *sql.DB
	SlotName string
	Tables   []source.TableRef
	Logger   *slog.Logger
	// RetryCount is the transient-error reconnect budget for the
	// replication stream (#166). 0 disables reconnect.
	RetryCount int
	// InitialWait bounds how long the reader waits for the first WAL message
	// before failing with a non-retryable error (#154). Zero uses the
	// default (300s).
	InitialWait time.Duration
	// Plugin is the logical decoding plugin: "pgoutput" (default) or
	// "wal2json".
	Plugin string
	// ReplicaIdentity is "full" (default) or "keep" (issue #571): FULL is set
	// only when the table is not already, and keep leaves the table's
	// identity untouched.
	ReplicaIdentity string
	// Filters and Columns are the per-source read projection (#162/#163),
	// keyed by "schema.table". The reader compiles the filter with the
	// introspected column types, so numeric columns compare numerically.
	Filters map[string]*spec.Filter
	Columns map[string][]string
	// UpsertTargets marks the target tables that maintain keyed state. An
	// UPDATE that changes the primary key emits a delete of the old key only
	// for these; append targets keep the old row.
	UpsertTargets map[string]bool
	// Schemas is each target table's canonical (projected) schema, the shape
	// the direct encoder builds. The engine's SetSourceSchemas replaces
	// KindUnknown with the cast-resolved type before Start (#455).
	Schemas map[string]core.Schema
	// OnTruncate is "ignore" (default) or "fail": whether a TRUNCATE on a
	// replicated table ends the stream (#671).
	OnTruncate string
	// OnDestructiveDDL, when non-nil, is called for every TRUNCATE seen on the
	// stream so the engine can record a metric and a run event (#671).
	OnDestructiveDDL func(source.DestructiveDDL)
}

Config dials one PostgreSQL instance. One replication connection per source — the invariant the whole design stands on. DB is the query connection used for introspection and position reads.

type Projection added in v0.3.0

type Projection struct {
	// contains filtered or unexported fields
}

Projection is a table's source-side read filter: the compiled filter a row must satisfy. The emitted column set is the canonical schema (the adapter filters it), so the live path appends the projected columns straight into Arrow; only the filter needs named access, and it reads a minimal map of just the columns it references.

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

Reader wraps one logical-decoding connection and decodes pgoutput/wal2json row changes straight into Arrow wire batches (emitted on batchOut at commit), positioned at their commit LSN.

func New

func New(ctx context.Context, cfg Config, batchOut chan<- *dataplane.Batch) (*Reader, error)

New introspects the tables, performs the server-side setup (replica identity, publication, slot), and opens the replication connection — but does not start streaming.

func (*Reader) ClearWindow

func (r *Reader) ClearWindow()

ClearWindow is part of the SourceReader contract; see OpenWindow.

func (*Reader) Close

func (r *Reader) Close()

Close stops the reader and its replication connection. It cancels the replication loop first and waits for it to exit pgx, so the conn close never races an in-flight receive.

func (*Reader) Master

func (r *Reader) Master(ctx context.Context) (position.Position, error)

Master reports the server's current WAL write position (the caught-up target for the DBLog window).

func (*Reader) OpenWindow

func (r *Reader) OpenWindow(_ context.Context, _ uint32)

OpenWindow is part of the SourceReader contract. The DBLog window tag is applied by the coordinator's gate to the batches it holds (WindowTag on the wire) — not by the source — so the reader keeps no window state.

func (*Reader) SetConfirmed

func (r *Reader) SetConfirmed(f func() position.Position)

SetConfirmed installs the confirmed-position callback.

func (*Reader) SetResume added in v0.5.0

func (r *Reader) SetResume(pos string)

SetResume records the position the stream resumes from: the safe position a partial piece of the first transaction carries.

func (*Reader) SetSourceSchemas added in v0.5.0

func (r *Reader) SetSourceSchemas(resolved map[string]core.Schema)

SetSourceSchemas installs the cast-resolved canonical schemas before Start. The direct encoder must see the resolved kinds.

func (*Reader) StartFromLSN

func (r *Reader) StartFromLSN(ctx context.Context, at *position.LSN) error

StartFromLSN begins streaming from the given LSN, blocking until the stream ends or ctx is cancelled. Call in a goroutine. An LSN of 0/0 starts at the slot's confirmed point.

A transient stream failure (network blip, 08xxx/53xxx, admin shutdown) is retried: the replication connection is re-dialed and the stream resumes from the last position committed to the sink, up to r.retries times (#166). A permanent failure is returned immediately.

func (*Reader) Synced

func (r *Reader) Synced() position.Position

Synced reports the end LSN of the last committed transaction.

type Source

type Source struct {
	// contains filtered or unexported fields
}

Source adapts the Postgres pgoutput reader to the source contract. It is the self-contained driver entry point; init() registers the kind.

func (Source) CloseQuery

func (a Source) CloseQuery() error

CloseQuery releases the query connection and tears down the SSH tunnel.

func (Source) Discover added in v0.3.0

func (a Source) Discover(ctx context.Context, schemas []string) ([]source.TableRef, error)

Discover implements source.Discoverer (#152): every table the connected user may SELECT, limited to schemas when non-empty. It returns base tables

  • matviews ('m') and foreign tables ('f') are excluded because EnsureSetup runs REPLICA IDENTITY FULL and CREATE PUBLICATION on every discovered table, and both fail on those relkinds;
  • leaf partitions are excluded (relispartition) because the parent already covers their rows — replicating parent and leaves doubles every row, and syncPublication's pg_publication_rel model expects the parent.

func (Source) Incremental added in v0.3.0

func (a Source) Incremental(ctx context.Context, t source.TableRef, cursor, after string) (string, []map[string]any, bool, error)

func (Source) IncrementalBatch added in v0.5.0

func (a Source) IncrementalBatch(ctx context.Context, t source.TableRef, cursor, after string, schema core.Schema) (string, *dataplane.Batch, bool, error)

IncrementalBatch implements source.BatchIncrementalSource (#733): the columnar sibling of Incremental. It runs the SAME cursor-bounded page query (incrementalQuery), but encodes every row straight into the Arrow builders of a transport.RowEncoder built from schema, with no per-row map[string]any in between. schema is the engine's canonical wire schema for the target table (the shape it installs on the worker), so the returned batch lands exactly what the map path's RecordFromChanges would have produced.

The returned batch carries the page's rows, every one stamped with the page's resume position (as the map path stamps every change with next), and Watermark = []byte(next). A page with no rows returns (next, nil, false, nil), which the engine treats as the end of the drain.

func (Source) InitialPosition

func (a Source) InitialPosition(ctx context.Context) (position.Position, error)

InitialPosition returns the slot's confirmed LSN: a first boot starts streaming from the slot's consistency point — everything after it flows through the stream, everything before it belongs to the snapshot.

func (Source) Introspect

func (a Source) Introspect(ctx context.Context, t spec.Table) (core.TableRef, core.Schema, []core.Warning, error)

Introspect resolves one spec table into its ref and canonical schema.

func (Source) NewChunker

func (a Source) NewChunker(source, pk string, chunkSize int) (source.ChunkSource, error)

NewChunker builds the chunk SELECT source for one table. The concurrent normalization pool (#161) and the snapshot-query retry budget (#166) come from the resolved connection config; the column projection (#162), the filter (#163), and the chunk column / CTID target bytes (#151) come from the spec.

func (Source) Open

func (a Source) Open(ctx context.Context, refs []source.TableRef) (source.Reader, error)

Open builds the replication reader over the pipeline's tables.

func (Source) ParsePosition

func (a Source) ParsePosition(s string) (position.Position, error)

ParsePosition decodes a stored cdc.position as an LSN.

Directories

Path Synopsis
Package source.postgres implements the PostgreSQL replication source: a single logical-decoding reader (pgoutput) that decodes row changes into rowchange.Change, positions them at their commit LSN, and exposes the synced and confirmed positions for the DBLog watermark logic.
Package source.postgres implements the PostgreSQL replication source: a single logical-decoding reader (pgoutput) that decodes row changes into rowchange.Change, positions them at their commit LSN, and exposes the synced and confirmed positions for the DBLog watermark logic.
Package chunk reads a PostgreSQL table through SQL for the snapshot: it picks a strategy for the table (CTID ranges, a typed key domain, or key batches), splits it into chunks and scans them, as row maps or straight into Arrow.
Package chunk reads a PostgreSQL table through SQL for the snapshot: it picks a strategy for the table (CTID ranges, a typed key domain, or key batches), splits it into chunks and scans them, as row maps or straight into Arrow.
Package connect resolves the source's connection settings, from a URI or from the nested spec, into one pgx config that the query pool and the replication connection share, including TLS and the SSH tunnel.
Package connect resolves the source's connection settings, from a URI or from the nested spec, into one pgx config that the query pool and the replication connection share, including TLS and the SSH tunnel.
Package replication manages what logical replication needs on the server before the stream starts: the slot, the publication and each table's replica identity.
Package replication manages what logical replication needs on the server before the stream starts: the slot, the publication and each table's replica identity.
Package retry classifies PostgreSQL errors as transient or permanent and retries the transient ones with a capped backoff.
Package retry classifies PostgreSQL errors as transient or permanent and retries the transient ones with a capped backoff.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL