Part 3 of 5 · 1 min read
Staying in sync via the write-ahead log
The standby continuously receives and replays the same log entries the primary writes, keeping its own copy current.
Think of the understudy actor listening to a live audio feed of the actual performance from backstage. The understudy continuously rehearses each line just after the lead actor speaks it, staying nearly synchronized with the real show in progress.
In plain words: a standby stays current by continuously receiving the primary's write-ahead log, covered earlier in this level, as new entries are written, and replaying each entry on its own copy of the database, essentially running the same redo process covered on this level's second page, but continuously, rather than only after a crash. This means the standby's data generally lags the primary by only a small amount, however long it takes for the latest log entries to arrive and be replayed, rather than by however long passed since the last full backup.
A worked example. As the primary commits a new order, the corresponding log entry is sent to the standby, which replays it on its own copy, bringing the standby's version of that row to match the primary's within a short delay.
The key lines. No new SQL; log shipping and continuous replay are internal mechanisms of the replication setup connecting primary and standby.
Log shipping
Log shipping continuously sends the primary's write-ahead log entries to a standby, which replays them on its own copy, keeping the standby only slightly behind the primary rather than as stale as a backup would be.
Example: an understudy continuously rehearsing each line just after hearing it over a live audio feed, staying nearly synchronized with the real performance, mirrors log shipping's continuous replay.