PostgreSQL Replication

Logical Replication

Understand PostgreSQL logical replication, where it fits best, and the tradeoffs teams should plan for in production.

Definition

A method of replicating data changes based on their logical representation rather than physical storage.

What Logical Replication Enables

Logical replication streams table-level changes using publications and subscriptions, enabling selective synchronization.

Unlike physical streaming replication, it supports partial data movement and version-flexible migration workflows.

  • Replicate selected tables instead of full cluster state
  • Enable gradual migration and cutover strategies
  • Support specialized downstream consumers

Best-Fit Use Cases

  • Near-zero downtime migrations
  • Selective table distribution
  • Data fan-out for specialized consumers
  • Cross-region read patterns for selected workloads

Tradeoffs To Plan For

Operational complexity rises with schema evolution, DDL coordination, and conflict handling. Runbooks and observability are required.

Teams should test schema-change rollout and rollback paths before production cutovers.

Operational Design Checklist

  • Define publication scope and ownership boundaries
  • Plan schema-change compatibility between producer/subscriber
  • Monitor replication lag and apply errors continuously
  • Rehearse cutover and fallback before migration windows

Logical vs Physical Replication

Logical replication is flexible and selective; physical replication is simpler for full-cluster HA/read replicas.

Many teams use both: physical for HA and logical for migration or selective integration use cases.

Frequently Asked Questions

What is logical replication in PostgreSQL?
It replicates logical row changes for selected tables, enabling selective sync and migration scenarios.
How is logical replication different from streaming replication?
Streaming replication copies physical WAL at cluster level. Logical replication operates at table/change level with selective scope.
When should teams use logical replication?
Use it for low-downtime migrations, selective data sharing, and controlled cross-environment synchronization.
What are common logical replication risks?
Schema drift, apply errors, conflict handling complexity, and insufficient observability are common failure points.
Is logical replication enough for full disaster recovery?
No. Disaster recovery still needs full backup and restore strategy with WAL-based recovery controls.