Recovery
Wikipedia · Write-ahead logging · CC BY-SA 4.0
Recovery restores the database to a consistent state after a crash. The key mechanism is write-ahead logging (WAL): before any data page is modified on disk, the change is first recorded in a log. On crash recovery, the log replays committed changes (redo) and undoes uncommitted ones (undo).
Write-ahead logging (WAL)
The WAL protocol: (1) before modifying a data page, write the log record to stable storage. (2) Before committing, flush all log records for that transaction. This guarantees that if the database crashes, the log contains enough information to reconstruct the committed state and undo uncommitted changes.
Checkpoints
A checkpoint flushes all dirty pages to disk and records which transactions are active. On recovery, the system only needs to scan the log from the last checkpoint, not from the beginning. This bounds recovery time.
ARIES algorithm
ARIES (Algorithms for Recovery and Isolation Exploiting Semantics) is the industry-standard recovery algorithm. Three phases: (1) Analysis: scan the log to determine which transactions were active at crash time. (2) Redo: replay all logged actions from the last checkpoint. (3) Undo: reverse actions of uncommitted transactions, working backward. ARIES uses LSNs (Log Sequence Numbers) to avoid redundant work.