Snapshot coverage and resume

Copy Markdown View Source

This guide explains which rows and columns reach a sink during backfill. Read it when choosing a start mode or implementing snapshot callbacks.

Start modes

Use snapshot: true to capture a point-in-time snapshot from an exported snapshot and stream from its consistent point. Implement Replicant.Sink.handle_snapshot/2 and Replicant.Sink.handle_snapshot_complete/1. Clear the sink's table when first_for_table? is true to make a retried start safe. Persist the handoff checkpoint in the completion callback.

Use snapshot: [mode: :incremental, chunk_rows: 1000] to backfill while streaming. The same handle_snapshot/2 callback receives chunks and the final completion notification. Writes arriving during a chunk window take precedence over stale snapshot values. A keyed chunk or a whole-table window halts with :snapshot_table_contended after three discarded attempts. Reconnects preserve durable progress and carry a fresh reader retry budget.

A sink-owned backfill persists the opaque ctx.progress token atomically with each chunk and returns it from Replicant.Sink.snapshot_progress/0. Return {:ok, :backfill_pending} after durably arming the backfill and before persisting the first token. On restart in that state, Replicant resumes discovery from the live slot origin. In library-owned mode Replicant stores the token for the sink.

Progress tokens contain primary-key bounds (row data) and row_filter text (publication configuration that can include literal constants). Persist the token and keep its contents out of logs, errors and telemetry.

Use go_forward_only: true to start with changes from a new slot's consistent point. Resume an existing pipeline against its durable checkpoint. The snapshot options and go-forward intent are mutually exclusive.

Replication origins

Either snapshot mode works with either origin: setting. Exported and incremental snapshots seed the current table state, which can include rows written by a replication origin. With origin: :none, the filter applies only to the change stream. PostgreSQL documents the same limit for a subscription with copy_data = true and origin = NONE.

Published columns and rows

Both snapshot paths select the stream's projection in physical column order. For example, this publication delivers id, item and qty for qualifying rows. The sink receives neither internal_note nor rows outside the filter.

CREATE TABLE orders (id int PRIMARY KEY, item text, qty int, internal_note text);
CREATE PUBLICATION orders_pub FOR TABLE orders (id, item, qty) WHERE (qty > 0);
  • Column lists. pgoutput uses the effective publication column list. pglogical uses the local replication sets' set_att_list. When two lists for one table differ, including an unrestricted list alongside a partial list, discovery halts with :snapshot_column_list_conflict before reading rows.
  • Row filters. A pgoutput snapshot is INSERT-equivalent. Predicates from publications that publish INSERT combine with OR. An unfiltered INSERT publication admits every row, and without an INSERT publication there are no snapshot rows. pglogical combines non-NULL set predicates with AND, including when an unfiltered set participates. Predicate text comes from the server catalog and is parenthesized before composition.
  • Generated columns. PostgreSQL 15 excludes them in pgoutput and snapshots. From PostgreSQL 16, discovery uses the effective publication column list, including the opt-in publish_generated_columns = stored on PostgreSQL 18 and later.
  • Keys. Replicant adds no unpublished key columns. PostgreSQL rejects UPDATE and DELETE when the publication omits required identity columns. An INSERT-only projection can omit a key. Incremental backfill then uses a whole-table window when the complete primary key is unavailable.
  • Empty projections. A table with live columns and an empty published projection halts with :snapshot_no_publishable_columns and the table name. A zero-column or all-dropped table still produces an empty reset.

On PostgreSQL 15, an explicit list of every live column and an implicit list can pass discovery yet fail in the stream if the table has dropped attributes. ADR-0002 explains the server-side comparison.