PostgreSQLXIV · Replication, Slots and Read ReplicasReplication
Physical streaming replication end to end
What you'll learn
- Describe the path a change takes from primary commit to standby visibility
- Name the processes involved on each side
- Explain why physical replication is all-or-nothing
- State what physical replication can and cannot be used for
Prerequisites
Verified against PostgreSQL 18.x · PostgreSQL (comparison targets) 17.11, 16.15 · PostgreSQL (support calendar) 18, 17, 16, 15, 14 supported · pgBackRest 2.59.1 · PgBouncer 1.25.2 · Patroni 4.1.5 · Ubuntu (host baseline) 26.04 LTS · 2026-08-27
Part XII established that WAL is the record of every change, and that crash recovery is replaying it. Replication is the same replay, on a different machine, that never stops.
The path a change takes
- A backend on the primary modifies a page and writes a WAL record.
COMMITflushes WAL to disk on the primary. The commit is now durable locally and, by default, returns to the client here.- The walsender reads that WAL and sends it over a replication connection.
- The walreceiver on the standby receives it and writes it.
- The walreceiver flushes it to the standby’s disk.
- The startup process on the standby replays it into the standby’s pages.
- The change becomes visible to queries on the standby.
Steps 3 to 7 happen after the client was told the commit succeeded, unless you configure otherwise. That gap is the subject of lessons XIV-04 and XIV-05.
The processes
$ ps -eo pid,args | grep postgres: 71 postgres: checkpointer
72 postgres: background writer
74 postgres: walwriter
75 postgres: autovacuum launcher
76 postgres: logical replication launcher
124 postgres: walsender repl 172.26.0.3(46864) streaming 0/5000060$ ps -eo pid,args | grep postgres: 31 postgres: startup recovering 000000010000000000000005
32 postgres: walreceiver streaming 0/5000060Two processes carry the mechanism. One walsender per connected standby, one walreceiver per standby.
What “physical” means
Physical replication ships byte-level changes to pages. Record 47 says “on relation 16384, block 219, at offset 44, write these bytes.”
Three consequences follow directly, and they are the shape of everything in this part:
It is all or nothing. You cannot replicate one database, one schema or one table. A physical standby is a byte-for-byte copy of the entire cluster.
The standby is read-only. It cannot have its own tables, its own indexes, or different data.
$ INSERT INTO t DEFAULT VALUES;ERROR: cannot execute INSERT in a read-only transactionBoth sides must be the same major version, architecture and page layout. A byte offset means nothing otherwise. Physical replication cannot be used to upgrade across major versions, which is why Part XVII covers upgrades separately.
In exchange it is cheap, complete and simple. Everything is replicated — DDL, sequences, large objects, extensions, permissions — because everything goes through WAL.
Streaming or archive
A standby has two ways to obtain WAL, and it can use both:
Streaming, over a replication connection, is the low-latency path and the normal one.
Archive, via restore_command, is the same mechanism as recovery in
Part XIII. A standby falls back to it when streaming is interrupted, and
it is what allows a standby to catch up after being down longer than the
primary retained WAL.
Configuring both is the robust arrangement: streaming for latency, the archive as the safety net. Lesson XIV-06 shows what happens when the safety net is a replication slot instead, and the slot is the only thing holding the WAL.
What replication is for, and what it is not for
| Goal | Physical replication |
|---|---|
| Survive a primary host failure | Yes, with a promotion mechanism (Part XV) |
| Offload read traffic | Yes, with caveats (lesson XIV-08) |
| Reduce read latency in another region | Yes |
Recover from DROP TABLE | No. The drop replicates in milliseconds |
| Recover from application corruption | No. Same reason |
| Cross major-version upgrade | No. Byte-level |
| Replicate one table | No. Cluster-wide |
The first three are what it does. The rest is what backups are for, and lesson XIII-01 made that argument with the failure that proves it.
What to take from this
- Replication is crash recovery that never finishes, driven by WAL arriving over a connection.
- One walsender per standby, one walreceiver per standby, one startup process doing the replay.
- Physical means byte-level: whole cluster, read-only, same major version and architecture.
- Streaming for latency, archive as the fallback; configure both.
- A standby is a complete cluster and fails independently of the primary, silently.
- Replication is not a backup. A
DROP TABLEreplicates in milliseconds.
Cross-course references
- Linux for Production Sysadmins — Part LII (High availability fundamentals) covers where replication sits in an availability argument, and what it does not supply on its own.
- Observability for Production Sysadmins — Part LIX (Database observability) covers exporting replication state per standby rather than as a single cluster-level number.
Quiz
Knowledge check · 6 questions
Q1. Why can physical streaming replication not be used to replicate a single table to another server?
Q2. A standby's process list shows 'postgres: startup recovering 000000010000000000000005'. What is that process?
Q3. A team relies on a streaming standby as their protection against data loss. Someone runs DROP TABLE orders on the primary. What does the standby provide?
Q4. Which are true of a physical standby? Select all that apply.
Q5. A physical standby can be given an extra index that the primary does not have, since its planner is independent.
Q6. Trace a committed change from the primary to visibility on a standby, and say where the client's COMMIT returns by default.
Passing score: 75%. Answers are checked in this browser.