6.7Log-based recovery and checkpoints
The idea
Log-based recovery uses a write-ahead log. After a crash, committed transactions are redone and uncommitted ones undone. A checkpoint limits how far back to look.
Think of it like this: A diary of every change: after a power cut you redo what was finished and cross out what was not.
Why it exists
GATE gives a log and asks which transactions are redone or undone.
How it works
- Log record before data page (write-ahead).
- Transaction with a commit record: redo (unless it committed before the last checkpoint).
- Transaction without a commit record: undo, newest change first.
- A checkpoint means everything before it is already on disk.
Worked example: T1 commits before the checkpoint, T2 commits after it, T3 never commits.
T1: nothing to do. T2: redo. T3: undo.
Now play with it
- →Select each example log and read the three result boxes.
- →Edit the log to add a commit for T3.
Redo, in log order: B = 6 (T2)
Undo, backwards: C = 7 (undo T3)
Write-ahead logging: the log record goes to disk before the data page. At a checkpoint all earlier committed work is on disk, so recovery only scans from the checkpoint. A transaction that committed before the checkpoint needs no redo.
Check yourself
After a crash, a transaction with no commit record in the log is
Exam notes (the dense version)
The log records <T start>, <T, X, old, new>, <T commit>. Write-ahead logging: the log record reaches disk before the data. After a crash: redo the committed transactions, undo the uncommitted ones (in reverse order). A checkpoint flushes data to disk, so work committed before it needs no redo; recovery starts at the last checkpoint and looks at the transactions active at that time. Deferred update logs only new values (no undo); immediate update logs old and new values.
Previous year questions: Transactions & Concurrency Control (15)
PYQs are grouped by topic, so this is the full set for Transactions & Concurrency Control; try the ones that match this subtopic. Open all 15 on the topic page.