DBMS NotesPYQs

Chapter 8

Crash Recovery

Chapter Notes

Block-based notes with markdown, diagrams, code, and math.

Chapter 8 — Crash Recovery

8.1 Failure Classification

TypeCauseRecovery
Transaction failureLogical error (divide by zero, constraint violation) or deadlockRollback single transaction
System crashPower failure, OS bug, hardware faultRecover from log using checkpoint
Disk failureHead crash, corrupt sectorRestore from backup + replay log

Stable storage: storage that survives all failures (achieved by writing to multiple physically independent disk copies before acknowledging a write).


8.2 Log-Based Recovery

The Write-Ahead Log (WAL) rule: before a data page is written to disk, its log record must reach stable storage.

Log Record Types

RecordMeaning
<Ti, start>Transaction Ti has started
<Ti, Xj, old_val, new_val>Ti updated attribute Xj from old to new
<Ti, commit>Ti has committed
<Ti, abort>Ti has aborted
<checkpoint, [active list]>Checkpoint taken with listed active transactions

Immediate vs Deferred Modification

Immediate ModificationDeferred Modification
When data written to diskAs soon as operation executes (before commit)Only after commit
Recovery needsBoth UNDO and REDOREDO only
PerformanceBetter concurrencySimpler recovery

Recovery Algorithm (with checkpointing)

Phase 1 — Redo phase (forward scan from last checkpoint):

  • Redo ALL updates found in log (even aborted ones — simpler to redo everything then undo).
  • Build undo-list: transactions that appear in log but have no <Ti, commit> record.

Phase 2 — Undo phase (backward scan from end):

  • For each transaction in undo-list: apply UNDO (restore old_val) and write <Ti, abort> to log.
  • Continue until all undo-list transactions are undone.

Checkpointing

Periodically write a checkpoint to reduce recovery time:

  1. Write <checkpoint, active_list> to log.
  2. Flush all dirty (modified) buffer pages to disk.
  3. Flush log to stable storage.

Recovery shortcut: during recovery, only scan from the most recent checkpoint — no need to redo transactions committed before that checkpoint.

Worked example — Checkpoint recovery:

Log:
  <T0, start>
  <T0, A, 1000, 900>
  <T1, start>
  <checkpoint, {T0, T1}>       ← last checkpoint
  <T1, B, 2000, 2100>
  <T1, commit>
  <T2, start>
  <T2, C, 500, 600>
  ** CRASH **

Recovery:
  Start scanning from checkpoint.
  Redo-list  = {T1 committed after checkpoint → REDO T1}
  Undo-list  = {T0 started before checkpoint, no commit → UNDO T0}
               {T2 started, no commit → UNDO T2}

  Redo phase (forward):
    REDO <T1, B, 2000, 2100>: set B=2100
    REDO <T2, C, 500, 600>:   set C=600  (even though we'll undo T2 next)

  Undo phase (backward):
    UNDO T2: <T2, C, 600, 500>: set C=500  → write <T2, abort>
    UNDO T0: <T0, A, 900, 1000>: set A=1000 → write <T0, abort>

  Final state: A=1000, B=2100, C=500  ✓

8.3 Shadow Paging

Mechanism:

  • Maintain two page tables: shadow (stable, from last commit) and current (in-progress).
  • All writes go to new disk pages; shadow page table is never modified during a transaction.
  • Commit: atomically switch the shadow page table pointer to point to the current page table.
  • Abort/crash: discard current page table; shadow table still intact.

How atomicity is ensured: if crash before commit, shadow table is untouched → rollback to last committed state. If crash after commit, shadow table now points to new pages → state persists.

Shadow PagingLog-Based Recovery
Undo loggingNot neededRequired
ConcurrencyPoor (difficult to support)Excellent
Storage fragmentationYes (data spreads across pages)No
Practical useLimited (old systems)Universal

8.4 Remote Backup (High Availability)

Standby TypeSyncFailover timeData loss risk
Hot standbySynchronous replicationNear-zeroNear-zero
Warm standbySemi-synchronousMinutesSeconds–minutes
Cold standbyPeriodic log shippingHoursMinutes–hours

Transfer of control: when primary fails, the backup site takes over, applying any remaining log records before accepting client connections.

Exam Quick-Reference

  • WAL rule: log must reach stable storage BEFORE data page is written.
  • Log record format: <Ti, Xj, old, new> for update; <Ti, commit> for commit.
  • Immediate modification: needs both UNDO and REDO. Deferred: REDO only.
  • Checkpoint shortcut: only scan log from last checkpoint during recovery.
  • Shadow paging: commit = atomically switch shadow pointer. No undo log needed.

Full Syllabus Outline

Every topic from the syllabus data is preserved here.

Solved PYQs

A few past questions with short answers.

Chapter 86 marksasked 1x2082 Kartik B

What is a stable storage? What are checkpoints in Log based recovery Mechanism? How is data recovered using checkpoints?

Solution

Stable storage keeps log and checkpoint data safe even if normal disk writes fail.

  • Implemented by writing to two or more independent disk copies before acknowledging a write.
  • Checkpointing shortens recovery by recording a recovery point — no need to replay from the beginning.
  • During recovery, scan from the most recent checkpoint.
Chapter 86 marksasked 1x2081 Chaitra R

What are logs in DBMS? How do you recover from a crash using log-based recovery? Explain briefly.

Solution

Three types of failures: transaction failure, system crash, and disk failure.

  • Transaction failure: logical error or system error (deadlock) in one transaction; rollback that transaction.
  • System crash: power failure, OS bug — volatile memory lost; stable storage intact; recover from log.
  • Disk failure: head crash or corruption; restore from backup + replay log.
Chapter 86 marksasked 1x2081 Ashwin B

Define stable storage. Explain log-based recovery technique with example.

Solution

Log-based recovery writes operations to a write-ahead log before applying them to the database.

  • WAL rule: log record must reach stable storage before the data page is written.
  • Log records: <Ti,start>, <Ti,Xj,old,new>, <Ti,commit>, <Ti,abort>, <checkpoint>.
  • Recovery: redo committed transactions; undo uncommitted ones.

More PYQs

Additional practice from this chapter.