Write-Ahead Log
The write-ahead log (WAL) persists modifications to an append-only log before applying them to data pages, guaranteeing redo recovery after crashes.
Purpose
To be the cornerstone of transaction durability and crash recovery; the core mechanism of all relational databases.
Mechanism
A transaction writes the log first (LSN + change content) and fsyncs, then modifies in-memory pages. After a crash, replay the log to redo committed transactions (redo) and roll back uncommitted ones (undo). Checkpoints truncate old log.
Use cases
- Crash recovery design
- Transaction durability
- Database internals