Crash Recovery and Write-Ahead Logging
Durability is achieved by writing the intention to a log before touching the data pages. After a crash the system replays committed work and undoes the rest, which is how a commit can be trusted the moment it returns.
What a learner can do afterwards
- Order the log write, the commit record and the page write, and say why
- Walk through redo and undo for a log that ends mid-transaction
- Explain what a checkpoint saves during recovery
1 · Read
Durability is achieved by writing the intention to a log before touching the data pages. The order is strict: the log record first, then the change to the page, and the commit record only after every change of the transaction sits safely in the log. A commit can be trusted the moment it returns, because everything promised is already in the log.
Picture a log with two transactions: one finished with a commit record, one cut off mid stream with none. Recovery replays the committed work step by step until the pages match what was promised, which is called redo. The unfinished work gets rolled back and its partial changes removed, which is called undo. When recovery ends, every committed transaction is present and no unfinished one left a trace.
The log goes first because pages can be lost in a crash while the log survives on safe storage. If the intention is in the log, the work can be rebuilt. If it is not in the log, the work never happened, and nothing is owed to anyone.
Replaying a huge log takes time, so the system takes checkpoints. At a checkpoint it writes all pending changes into the data pages and notes the spot in the log. Recovery then starts from the last checkpoint instead of from the beginning, replaying only what came after.
Write the log before the pages, redo the committed, undo the rest, and checkpoint so recovery starts late.
2 · Watch
Take it off screen
Where it sits
8 questions wait behind this lesson, each with its answer explained. Every answer feeds the sky: stars light as they are learned, and dim when it is time to come back.