Replaying the Log Elsewhere
A replica keeps a copy of the primary by consuming its write ahead log stream. The same records that protect the primary against crashes are shipped to replicas, which replay them to reproduce every change in order.
Physical Versus Logical
- Physical replication ships raw page level WAL records, producing an exact byte copy. It is efficient but the replica must match the primary version and layout.
- Logical replication decodes the log into row level change events, which can target a different schema or version and feed selective tables.
Lag and Synchronous Modes
Replays trail the primary by some replication lag. In asynchronous mode the primary commits without waiting, risking a small window of loss on failover. In synchronous mode the primary waits for a replica to confirm the log record is durable before acknowledging commit, trading latency for stronger guarantees.
Key idea
Replicas consume the primary WAL stream and replay it, with physical replication copying pages and logical replication decoding row events, while synchronous mode waits for replica confirmation to reduce data loss.