#streaming-replication
How does streaming replication work? What is sent between nodes?
What to say
Streaming (physical) replication sends the WAL stream. On the primary a walsender process ships WAL records as they appear, and on the replica a walreceiver process accepts them and applies them, replaying the same page changes. A replica is a byte-for-byte copy of the cluster: the same files, the same LSNs. A standby can be a hot standby, accepting read-only queries while it keeps applying WAL. Application follows the same redo rules as crash recovery, so a replica always "catches up" the WAL to the position it managed to receive. The gap between the primary's position and the replica's is the lag.
What they want to hear
A senior should: - name what is sent: the WAL stream, and the walsender/walreceiver processes - say that a physical replica is a binary copy of the whole cluster at the page level - tie application on the replica to the redo mechanism and LSN - distinguish the roles: a hot standby accepts reads, a plain standby only catches up
Pitfalls
- ✗ Thinking a physical replica copies tables selectively. It is the whole cluster at the WAL level
- ✗ Assuming you can write on a physical replica. It is read-only
- ✗ Confusing the WAL stream with logical row changes. Physical replication works in pages
Follow-up
- ? How does walsender differ from walreceiver?
- ? Why can't you run an INSERT on a physical replica?
- ? How does a replica know up to which position it applied the WAL?
Depth in knowledge base