The Core Rule
A write ahead log, or WAL, enforces one rule: record a change in a sequential log and flush it to disk before applying it to the data pages. The log is the source of truth for recovery.
Why It Works
- Appending to a log is a fast sequential disk write.
- The actual table pages can be updated later and in batches.
- If the system crashes, recovery replays committed log records to rebuild state.
Commit and Recovery
- A transaction is durable once its commit record is safely in the log.
- On restart, recovery redoes committed changes and undoes uncommitted ones.
- A checkpoint periodically flushes dirty pages so recovery has less log to replay.
Why It Matters
The WAL is how databases get durability without paying a random page write on every commit. It also underpins replication, since replicas can apply the same log stream.
Key idea
A write ahead log records changes durably before applying them, enabling crash recovery and feeding replication from one log stream.