A table allowlist between independent clusters
Setup supplies 20 products on the publisher. Create a publication there, initialise an independent subscriber, then create its matching database and table before subscribing.
CREATE SUBSCRIPTION returns before every row is necessarily synchronised. The apply-worker PID proves a process exists; the deterministic ID, SKU, name and price check proves the initial contents. The later SKU-NEW read proves ongoing delivery.
Logical replication carries supported table changes, not DDL or sequence state. Physical replication includes the entire cluster; this publication selects one table. Both servers can use database name beer_db without referring to the same database.
Normal DROP SUBSCRIPTION contacts the reachable publisher and removes the owned slot; verify both subscription and slot disappearance. Table rows remain. An unreachable publisher requires a separate cleanup procedure.
Reference-only cutover: fence source writes, wait for a known final transaction to apply, repair destination sequences, validate application behaviour, and redirect traffic. LSN receipt and equal counts alone are insufficient evidence of safe migration. This lab neither redirects an application nor demonstrates sequence repair.
Did you know? The rows from serial can arrive while its sequence stays at the beginning: the counter and its generated IDs are separate objects. Logical replication restrictions.
Key concepts
Publication
A named, table-level allowlist of what a source database is willing to logically replicate. Unlike physical replication, which always ships everything, a publication can cover a single table, several specific tables, or every table in a schema — giving fine-grained control over exactly what leaves the source.
What Logical Replication Does Not Replicate
DDL (schema changes like CREATE TABLE or ALTER TABLE), sequence values (a subscriber's sequences advance independently based on its own inserts), and unlogged tables (which generate no WAL to decode in the first place) are all outside what logical replication carries. A migration plan has to account for all three explicitly — this lab's target table was created by hand for exactly this reason.