Set up PostgreSQL logical replication with publications and subscriptions

domain: postgresql · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. On the publisher, set wal_level=logical in postgresql.conf and reload; confirm with SHOW wal_level
  2. Create a publication: CREATE PUBLICATION my_pub FOR TABLE orders, customers; (or FOR ALL TABLES)
  3. On the subscriber, create the subscription using a DSN that stores credentials in .pgpass or PGPASSFILE rather than inline: CREATE SUBSCRIPTION my_sub CONNECTION 'host=primary dbname=app user=replicator' PUBLICATION my_pub
  4. Monitor replication lag with: SELECT slot_name, confirmed_flush_lsn, pg_wal_lsn_diff(pg_current_wal_lsn(), confirmed_flush_lsn) AS lag_bytes FROM pg_replication_slots
  5. Set max_slot_wal_keep_size (defaults to -1, unlimited) to cap WAL retained by inactive slots so disk does not fill up
  6. Drop unused slots promptly with SELECT pg_drop_replication_slot('slot_name') to prevent unbounded WAL accumulation

Known gotchas

Related routes

Configure quorum-based synchronous replication in PostgreSQL with synchronous_standby_names ANY
postgresql.org · 5 steps · unrated
Set up cascading PostgreSQL streaming replication where a standby relays WAL to downstream standbys
postgresql.org · 5 steps · unrated
Use PostgreSQL logical replication to perform a zero-downtime major-version upgrade
postgresql.org · 5 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans