Current section
Files
Jump to
Current section
Files
documentation/how-to/reference-deployment.md
<!--
SPDX-FileCopyrightText: © 2026 BaseLabs Holdings LLC
SPDX-License-Identifier: MIT
-->
# Run a reference replication pipeline
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](https://github.com/baselabs/replicant) and run:
```bash
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](../topics/delivery/snapshot-coverage.md#start-modes).
Wait for the slot to report `active = t` before writing an example row.
```bash
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.
```bash
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](https://github.com/baselabs/replicant/blob/main/examples/replication_pipeline/lib/replication_pipeline/sink.ex)
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](../topics/about/compatibility.md) 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.