← Lessons

quiz vs the machine

Gold1400

Databases

Streaming Replication

Byte for byte physical replicas kept current by shipping the write ahead log as it is written.

5 min read · core · beat Gold to climb

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.

Check yourself

Answer to earn rating on the learn ladder.

1. What does a standby replay to stay current?

2. What does synchronous replication guarantee at the cost of latency?