A physical copy
Streaming replication keeps one or more standby servers as exact physical copies of a primary. The primary streams its write ahead log records to standbys as they are generated, and each standby replays them to stay current.
How it stays in sync
- The standby starts from a base backup of the primary.
- It then connects and continuously receives WAL over the replication connection.
- It replays each record, so its data files become byte for byte identical to the primary.
Standbys can serve read only queries, spreading read load while the primary handles writes. This is called a hot standby.
Synchronous or asynchronous
- Asynchronous replication is the default. The primary commits without waiting, so a standby may lag slightly and a crash could lose the last few transactions.
- Synchronous replication makes the primary wait until a standby confirms the commit, trading latency for zero data loss on failover.
If the primary fails, a standby is promoted to become the new primary.
Key idea
Streaming replication ships the write ahead log from a primary to physical standbys that replay it, offering read scaling and fast failover, with a synchronous mode that trades latency for no lost commits.