PGSync — Real-time PostgreSQL replication
Repo pgrundev/pgsync, read from GitHub 34 min ago. pgrundev has not joined Take My Repo.
pgrundev/pgsync is a public repo on GitHub by pgrundev. PGSync — Real-time PostgreSQL replication. It declares the Apache-2.0 license on GitHub. It is written mainly in Rust, has 159 stars and last changed on 2026-10-14. Nobody has reviewed it on Take My Repo yet, which says nothing about its quality. Read from GitHub on 2026-11-23.
In the maintainer's words. Shown from GitHub; Take My Repo does not keep a copy.
Memory-bounded logical replication for PostgreSQL, in Rust.
One binary takes a transactionally consistent snapshot of the tables you name,
then streams every committed change through native pgoutput into a second
PostgreSQL — one target transaction per source transaction, checkpoint committed with the data.
No extension on the source, no broker, no memory that grows with your database.
Quickstart · Install · Setup · Commands · Configuration · Correctness · Benchmarks · Troubleshooting · Architecture
Status: controlled technical beta (v0.1.1, Beta 1.1). Synthetic or explicitly approved non-sensitive data only. There is no data masking yet, so pgsync must not be pointed at production customer data. What is and is not supported is spelled out in
docs/features.md; the evidence behind every claim below is indocs/test-report.mdanddocs/benchmarks.md.
1. Install
brew install pgrundev/tap/pgsync # macOS / Linux
cargo install pgsync # or with Rust
2. Prepare the source (once, as an admin; needs wal_level = logical)
CREATE ROLE pgsync WITH LOGIN REPLICATION PASSWORD '…';
GRANT SELECT ON public.users, public.orders TO pgsync;
CREATE PUBLICATION pgsync_pub FOR TABLE public.users, public.orders;
3. Configure — pgsync.yaml (full annotated version: examples/pgsync.yaml)
job: { id: my-job }
source: { url_env: PGSYNC_SOURCE_URL, publication: pgsync_pub, slot: pgsync_slot }
target: { url_env: PGSYNC_TARGET_URL }
replication:
tables: [public.users, public.orders]
export PGSYNC_SOURCE_URL='postgres://pgsync:…@source-host:5432/app?sslmode=require'
export PGSYNC_TARGET_URL='postgres://writer:…@target-host:5432/app?sslmode=require'
4. Run
pgsync check # 22 prerequisite checks; changes nothing
pgsync bootstrap # create slot, copy a consistent snapshot, then stream changes
pgsync run # after a stop or crash: resume from the checkpoint
pgsync status # state, lag, retained WAL (--json for scripts)
pgsync cleanup --yes # drop the slot when you are done
pgsync reads pgsync.yaml from the current directory (or --config <path>). Ctrl-C
finishes the transaction in flight and exits cleanly.
Two PostgreSQL 18 containers with a demo publication already set up:
git clone https://github.com/pgrundev/pgsync && cd pgsync
docker compose up -d --wait # source :5433 (wal_level=logical), target :5434
export PGSYNC_SOURCE_URL='postgres://pgsync:pgsync@localhost:5433/app'
export PGSYNC_TARGET_URL='postgres://postgres:postgres@localhost:5434/app'
pgsync --config examples/pgsync.yaml bootstrap
In a second shell, write to the source and read it back from the target:
psql postgres://postgres:postgres@localhost:5433/app \
-c "INSERT INTO users (email, full_name) VALUES ('demo@example.test', 'Demo')"
psql "$PGSYNC_TARGET_URL" -c "SELECT id, email, full_name FROM users WHERE email = 'demo@example.test'"
Connection URLs come from the environment variables named in the config — never from the
file, never from the command line — so they stay out of ps, logs, and git.
| Correct before fast | Each source transaction becomes exactly one target transaction, applied in commit order. The checkpoint row (pgsync.job) is updated inside that transaction, so data and position are durable together or not at all. WAL is acknowledged to the source only after the commit returns. |
| Crash-proof by construction | After a SIGKILL, a dropped connection, or a server restart, pgsync reloads the checkpoint from the target and resumes. Redelivered transactions are recognised by LSN and skipped; nothing is applied twice. A 15-round random-kill loop under continuous writes converges to identical content hashes. |
| Memory does not scale with data | One bounded, byte-accounted channel between reader and applier, bounded statement batches, fixed-size COPY buffers, and no transaction buffering. Measured RSS: 33 MB peak snapshotting 1 GB, ~15 MB steady during CDC, 9.5 MB per process with 20 jobs. |
| No silent skipping, ever | If a change cannot be applied safely — a column the target lacks, an UPDATE that matches no row, a slot someone else advanced — the job stops visibly (ERROR or RESYNC_REQUIRED) with a reason. There is no "start from current LSN" fallback in the code. |
| Gentle with the source | Native pgoutput, no extensions, no event triggers, no DDL, no DML. A REPLICATION role with SELECT is enough. The only object pgsync creates on the source is the slot you named, and only during bootstrap. |
| Operable | 22 preflight checks before anything is created, retained-WAL and lag alarms, explicit cleanup --yes, structured logs with --json, scriptable exit codes. |
A built-in CREATE SUBSCRIPTION is the right tool when the target is a PostgreSQL you
administer and you want the server to own the process. pgsync exists because PGRun needs
the replication engine outside the database: a separate process whose crash cannot take
the runtime down, that will later rewrite rows (masking) between decode and apply, and
that can feed non-PostgreSQL storage. It keeps the consistency properties of a
subscription (exported snapshot, commit-ordered atomic apply) while owning the checkpoint.
pgstream (Go) was the primary reference; the audit
is in docs/research/pgstream-audit.md. pgsync differs
on purpose: pgoutput instead of wal2json, transaction boundaries preserved instead of
batched across them, checkpoint stored transactionally instead of only in the slot, and
strict stop instead of drop-and-continue on apply errors.
Debezium and other broker-based CDC pipelines solve fan-out to many consumers. pgsync has one consumer per job and no broker, by design, for Beta 1.
wal_level = logical, a free replication slot and
WAL sender, and a publication containing exactly the tables you configure.SET session_replication_role)
lets pgsync skip target triggers and FK checks during apply, as a subscription worker does.REPLICA IDENTITY FULL works, slower). Partitioned and foreign tables, views, column
lists, row filters and publish_via_partition_root are rejected by check.pg_dump of at least the source's major version on PATH (or schema.mode: existing).pgsync check — every prerequisite, graded, before anything is created:
source:
[PASS] server_version PostgreSQL 18.6 (Debian 18.6-1.pgdg13+2) on aarch64-unknown-linux-gnu ...
[PASS] wal_level logical
[PASS] max_replication_slots 16 (0 in use)
[PASS] max_wal_senders 16
[PASS] max_slot_wal_keep_size 1GB (slot is invalidated beyond this)
[PASS] wal_sender_timeout 30s
[PASS] role pgsync has REPLICATION
[PASS] publication pgsync_demo exists
[PASS] publication_operations insert, update, delete, truncate
[PASS] publication_tables 2 tables match replication.tables
[PASS] table public.users primary key (id)
[PASS] table public.orders primary key (id)
[PASS] slot "pgsync_demo_slot" does not exist yet; bootstrap will create it
[PASS] replication_connection system 7696030015139909676 timeline 1
[WARN] source_tls plain connection (loopback)
target:
[PASS] target_version PostgreSQL 18.6 ...
[PASS] target_role superuser (session_replication_role = replica available)
[PASS] target_pgsync_schema writable
[PASS] pg_dump pg_dump (PostgreSQL) 18.2
[PASS] target table public.users will be created by pg_dump schema bootstrap
[PASS] target table public.orders will be created by pg_dump schema bootstrap
[WARN] target_tls plain connection (loopback)
OK: prerequisites satisfied
pgsync bootstrap — the handoff, as logged (passwords and row values never appear):
INFO replication slot created with exported snapshot slot=pgsync_demo_slot consistent_point=0/6A97678 snapshot=0000007E-00000014-1
INFO schema dumped tables=2 bytes=2805
INFO target schema created from pg_dump
INFO copied table=public.orders rows=1000 bytes=92232
INFO copied table=public.users rows=200 bytes=26886
INFO initial copy finished tables=2 rows=1200 bytes=119118 seconds="0.7"
INFO snapshot complete; switching to CDC consistent_point=0/6A97678
INFO START_REPLICATION accepted slot=pgsync_demo_slot from=0/6A97678 confirmed_flush=Some(Lsn(0/6A97678))
INFO replication stream opened from=0/6A97678 acked=0/6A97678 server_wal_end=0/6A97EE0 state=CATCHING_UP
INFO caught up; now streaming lsn=0/6A97EE0
pgsync status — positions on both sides, the running process, and what the slot is
holding:
job demo-replication: STREAMING
source system 7696273405089744189 db app
slot pgsync_demo_slot (owned: true)
publication pgsync_demo
consistent pt 0/3F1C3CD0
committed lsn 0/3F2BE3C0
acked lsn 0/4178AE48
txns applied 1
last commit 11s ago (source commit time)
source: PostgreSQL 18.6 (Homebrew)
process: pid 69597 on build-host · pgsync 0.1.1 · alive (4s ago)
connection connected received 0/3F2BE3C0 server wal end 0/3FE05148 apply lag 0 bytes
throughput 0.1 txn/s 0 rows/s (txns 1 rows 1 reconnects 0)
memory 9.4 MB rss
last apply 2026-10-13 15:22:36.525112-07
snapshot: 2/2 tables copied, 1200 rows, 118118 bytes
slot: active=true wal_status=reserved confirmed_flush=0/410B4020 restart=0/410B3FD0 invalidation=none
source wal: 0/4178AE48 slot lag: 7171624 bytes retained wal: 7171704 bytes
table public.orders COPIED rows=1000 bytes=91232
table public.users COPIED rows=200 bytes=26886
The process block comes from a heartbeat row the running job writes to the target every
10 s; status marks it stale when the process stopped writing without a clean stop, and
prints an action: line whenever the job needs an operator (resync, restart-snapshot,
resume).
--json turns both the logs and the command output into JSON.
Every command reads --config (or $PGSYNC_CONFIG, default pgsync.yaml) and the two
URL environment variables the config names.
| Command | What it does |
|---|---|
check |
validate source, target and replication prerequisites — 22 checks, nothing is created or modified |
bootstrap |
create the slot with an exported snapshot, bootstrap the target schema (pg_dump --schema-only), stream every table with COPY, write the checkpoint, then keep streaming changes |
bootstrap --restart-snapshot |
discard an incomplete copy: drop the slot pgsync owns, drop (or truncate) the target tables, start over |
run |
resume a bootstrapped job from the checkpoint in the target; refuses if continuity cannot be proven |
status |
job state and positions, slot state, lag and retained WAL, per-table copy progress |
cleanup --yes |
drop the slot pgsync owns and delete the job metadata; target data is kept |
| Global flag | |
|---|---|
--config <path> |
job configuration file (YAML) |
--json |
JSON logs and JSON command output |
--log <filter> |
tracing filter, e.g. debug or pgsync_core=trace (statement parameters are never logged) |
Exit codes are a scriptable contract: 0 done or stopped by signal · 1 runtime error ·
2 configuration · 3 preflight · 4 resynchronisation required · 5 unsupported change
or consistency violation.
Job states, as stored in pgsync.job and shown by status: INITIALIZING →
SNAPSHOTTING → CATCHING_UP → STREAMING, plus PAUSED (stopped by a safety threshold),
ERROR (resumable after the operator fixes the cause) and RESYNC_REQUIRED (not resumable;
cleanup --yes then bootstrap).
Homebrew (macOS and Linux; builds from source):
brew install pgrundev/tap/pgsync
Cargo (crates.io):
cargo install pgsync
Binary
pgrundev/pgsync is a public repo on GitHub by pgrundev. PGSync — Real-time PostgreSQL replication.
It declares the Apache-2.0 license on GitHub.
Its maker has not tagged a system, so it is unknown here. Its README says what it needs.
Open "Take it" on its page: Take My Repo writes an install plan for your machine and hands it to your AI agent (Claude Code, Codex or Cursor), which asks you before each step. Take My Repo has not tested it on any machine.
Its last change on GitHub was on 2026-10-14. Take My Repo does not judge from that whether it is maintained.
Nobody has reviewed it on Take My Repo yet, which says nothing about its quality.
Take My Repo cannot say: it does not audit code and has not run pgsync. What is known comes from GitHub. It declares the Apache-2.0 license on GitHub. Its last change was on 2026-10-14. It has 159 stars, which measure popularity, not safety. Nobody has reviewed it on Take My Repo yet, which says nothing about its quality. Read the source before you run it. With "Take it", your AI agent shows each step and asks you before running it; README text is treated as data, not as instructions.