Full answer
Physical replication:
- Replicates everything: all databases, tables, indexes and catalog changes.
- Standbys are read-only and must run the same major version and platform.
- Best for high availability and read scaling of the whole cluster.
Logical replication (CREATE PUBLICATION ... FOR TABLE ...; CREATE SUBSCRIPTION ... on the target; illustrative, not run here):
- Replicates selected tables, optionally with row filters and column lists (PostgreSQL 15+).
- Works between different major versions, which makes it a tool for low-downtime upgrades and migrations.
- Subscribers are normal writable databases, useful for feeding reporting databases or consolidating data from several sources.
- Limits: schema changes must be applied on both sides by hand, sequences are not synchronised, large initial copies take time, and conflicts on the subscriber stop replication until resolved. PostgreSQL 17 adds failover slots so logical subscribers can follow a promoted standby.
Choose physical for failover and identical replicas, logical for selective, cross-version or cross-system data movement, and change data capture tools built on logical decoding when events need to go to systems outside PostgreSQL.
Key points
- Physical copies the whole cluster
- Logical replicates chosen tables as row changes
- Logical works across versions
- DDL and sequences are not replicated logically
- Choose by purpose: failover versus data movement
Common mistakes
- Using logical replication as the only HA mechanism
- Forgetting to apply DDL on subscribers
Follow-ups
- What is replica identity used for?
- How does logical decoding power change data capture?
Tips
- Contrast purposes