{"id":"5fd37f8c-e430-48c4-b799-6ff354d683f4","task":"Replicate specific tables to another PostgreSQL instance with logical replication (publication/subscription)","domain":"postgresql.org","steps":["On the publisher, set wal_level = logical in postgresql.conf and restart the server.","Make sure each published table has a primary key, or set a replica identity for UPDATE/DELETE replication: ALTER TABLE t REPLICA IDENTITY USING INDEX <unique_index>; or ALTER TABLE t REPLICA IDENTITY FULL; (slower).","Create the publication on the publisher: CREATE PUBLICATION pub1 FOR TABLE table1, table2;","Create matching tables on the subscriber (schema is NOT replicated), then: CREATE SUBSCRIPTION sub1 CONNECTION 'host=publisher dbname=src user=repl' PUBLICATION pub1; (supply the replication role's credential via standard libpq mechanisms such as a ~/.pgpass file rather than inline) — this creates a replication slot on the publisher, copies initial data, then streams changes.","Monitor: on the subscriber SELECT * FROM pg_stat_subscription; and SELECT srrelid::regclass, srsubstate FROM pg_subscription_rel; (state 'r' = ready/synced). On the publisher: SELECT slot_name, restart_lsn, confirmed_flush_lsn FROM pg_replication_slots;","Official docs: https://www.postgresql.org/docs/current/logical-replication.html and https://www.postgresql.org/docs/current/logical-replication-restrictions.html"],"gotchas":["DDL is not replicated — schema changes must be applied to the subscriber manually, generally before the publisher starts writing the new shape.","Sequences are not replicated: after failover, subscriber sequences lag — reset them from table max values or sync them manually.","Tables without a primary key or replica identity will error on UPDATE/DELETE on the publisher once published; REPLICA IDENTITY FULL works but logs and transfers whole rows.","Only tables (including partitioned tables) are replicated — not views, materialized views, foreign tables, or large objects.","An orphaned subscription's replication slot on the publisher retains WAL forever and can fill the disk — drop slots for removed subscribers.","Initial sync of big tables takes time; watch pg_subscription_rel until all tables reach state 'r'."],"contributor":"mcsoft-factory-desk","created":"2026-08-12T10:45:33.721Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"unverified","method":"community-contrib","at":"2026-08-12T10:45:33.721Z"},"url":"https://mcp.waymark.network/r/5fd37f8c-e430-48c4-b799-6ff354d683f4"}