Logical Replication Patterns
Postgres logical decoding.
Overview
Postgres logical replication exposes database changes at the row level rather than the byte level. Logical decoding turns the WAL into a change stream that downstream systems can subscribe to: CDC pipelines, zero-downtime version upgrades, selective table replication. The pattern is fundamentally different from physical replication and unlocks integrations that physical replication cannot.
- Logical decoding. Per-row change stream from the WAL. Foundation for everything else in this list.
- CDC integration. Debezium and Kafka Connect consume the stream and emit per-table topics. Event-driven architectures hook in here.
- Version-skewed replication. Source on Postgres 14, target on Postgres 16. Enables zero-downtime major-version upgrades.
- Selective replication plus replication slots. Per-table or per-row filtering for compliance and partitioned data; persistent slots survive consumer disconnects without losing changes.
The approach
Three habits make logical replication production-grade: logical slots managed deliberately, slot lag monitored as a standing signal, and REPLICA IDENTITY set per table to match consumer needs.
- Logical slots for CDC.
pg_create_logical_replication_slot. Each consumer gets a named slot with persistent position. - Debezium for change capture. Industry-standard CDC consumer. Per-table Kafka topics emerge naturally.
- Slot-lag monitoring. Slow or dropped consumers fill the WAL. Alert on slot lag before disk fills.
- Per-table
REPLICA IDENTITYplus integration docs. Identity strategy tuned to the consumer’s needs; per-stream the consumer documented next to the schema.
Why this compounds
Each integrated stream extends the team’s event-driven surface. CDC fluency grows; new integrations follow the same pattern; major-version upgrades stop being multi-hour outages.
- Modern integration. CDC produces real-time event flow into downstream systems. Polling-based ETL retires.
- Zero-downtime upgrades. Version-skewed replication makes major-version Postgres upgrades practical.
- Selective replication for compliance. Per-table or per-row filtering supports residency and access-control requirements.
- Year-one investment, year-two habit. First slot is heavy lift. By the third integration, the operational template is settled.