Part 15 / Topic 3 of 7
The write-ahead log
Part 12 promised durability; the WAL delivers it. Every change is written first as a log record to the write-ahead log, and COMMIT returns only once that record is safely flushed. The data pages themselves are updated lazily, in memory, and reach disk later at a checkpoint.
Crash mid-flight? On restart, Postgres replays the WAL from the last checkpoint — committed work is reconstructed, uncommitted work never happened. The WAL's position is a byte offset you can watch advance:
SELECT pg_current_wal_lsn() AS wal_position; -- output varies per run
wal_position
--------------
0/1D41898
(1 row)
The same stream of records has a second life: ship it to another server and replay it there — that is replication (Stage 5C's world), which is why "WAL archiving" and "backups you can roll forward" are the same technology. And now Part 10's UNLOGGED tables explain themselves: skipping these records is exactly where their speed — and their crash-amnesia — comes from.
🧪 Quick quiz — answer from memory, then check.
- What exactly does COMMIT wait for?
- Why are unlogged tables faster, and what do they give up?
Show the answers
- The WAL record of the transaction reaching durable storage — not the data pages.
- They skip WAL writes — and so can't be recovered after a crash or replicated.
Done here? The practice set for Part 15 — 5 exercises with solutions — is on the part page.