Use the reference stack to see a PostgreSQL-to-PostgreSQL state mirror with a durable checkpoint. It runs a source database, the Replicant OTP application and a separate destination database in Docker Compose.
Start the stack
Clone the repository and run:
cd examples/replication_pipeline
export REPLICANT_POSTGRES_IMAGE="$(cat ../../.github/postgres.ref)"
docker pull "$REPLICANT_POSTGRES_IMAGE"
docker compose up -d --build
Both databases use the pinned engine image and disposable scratch storage. Host ports bind to loopback (15432 for the source and 15433 for the destination). Use the stack's throwaway credentials only with this demo. The pipeline reads the connection credentials from its environment.
The default decoder is pgoutput. The stack uses the example_pub
publication and starts in go-forward mode.
Wait for the slot to report active = t before writing an example row.
docker compose exec source-pg psql -h /tmp -U postgres -d example_src \
-c "SELECT slot_name, active FROM pg_replication_slots"
docker compose exec source-pg psql -h /tmp -U postgres -d example_src \
-c "INSERT INTO orders (id, note) VALUES (1, 'hello')"
docker compose exec dest-pg psql -h /tmp -U postgres -d example_dst \
-c "SELECT * FROM orders; SELECT commit_lsn FROM pipeline_checkpoint"
Verify resume
Record the destination receipt count. Restart only the pipeline, write a new row and check that the count increases by one.
docker compose exec dest-pg psql -h /tmp -U postgres -d example_dst \
-c "SELECT count(*) FROM cdc_receipts"
docker compose restart pipeline
docker compose exec source-pg psql -h /tmp -U postgres -d example_src \
-c "INSERT INTO orders (id, note) VALUES (3, 'after restart')"
docker compose exec dest-pg psql -h /tmp -U postgres -d example_dst \
-c "SELECT id, note FROM orders ORDER BY id" \
-c "SELECT count(*) FROM cdc_receipts"
The sink implementation commits the mirror, checkpoint and a structure-only receipt in one transaction. It binds the checkpoint to the source's system identifier and database. Its upsert omits unchanged TOAST columns from the assignments.
Use a pglogical source
With a compatible pglogical build installed
on the source, add the source tables to a replication set. In the Compose
file, set REPLICANT_DECODER: pglogical in the pipeline service's environment.
Set REPLICANT_REPLICATION_SETS there to a comma-separated list of set names.
The application uses default if you omit the list.
Remove the stack
From examples/replication_pipeline, run docker compose down -v to
discard the demo containers and their data.