10 Database Recovery Techniques

Database Management System · Unit 10 · 3 hrs

Database Recovery Techniques

Exam-focused notes for Database Recovery Techniques (Database Management System, CSC265): what the TU syllabus asks and how it has actually been tested, with 5 solved past questions from this unit.

Database Recovery Techniques in short

This unit covers how a DBMS restores the database to a consistent state after a failure: the general recovery machinery every technique relies on, the two classical families of recovery algorithm (deferred update and immediate update), the shadow paging alternative, and backup strategy for failures too severe for the log alone to fix.

Database Recovery Techniques: full notes

Recovery Concepts

Recovery restores the database to the most recent consistent state that existed before a failure, using information about every applied change that the system has kept, typically in the log described in the transaction processing unit. Two broad situations call for different strategies. If a catastrophic failure, a disk crash, destroys a large portion of the database, recovery must restore a past backup copy of the database, since the log itself may reside on the same damaged disk. If the database on disk is intact but a non-catastrophic failure (a system crash, a failed transaction) has left it in an inconsistent state, recovery instead identifies exactly which changes need to be undone or redone using the log, without needing to touch a backup at all.

Recovery algorithms share four categories of underlying mechanism.

  • Caching (buffering) of disk blocks. Pages that hold items being updated are brought into main-memory buffers, collectively the DBMS cache, and updated there before eventually being flushed back to disk; a directory tracks which items are in which buffer, and a dirty bit per buffer records whether it has been modified since being read in.
  • Write-ahead logging (WAL). Because the log and the data buffers can both be lost together in a crash, WAL requires that an item's old value never be overwritten in the log-recorded sense until the corresponding undo information has been written to disk first, and that, before a transaction commits, both the redo and undo portions of its log entries must already be permanently on disk. This is what makes the log a reliable enough record to drive recovery at all.
  • Steal/no-steal and force/no-force. These name the rules for when a modified buffer page may be written to disk relative to the transaction that modified it. A no-steal policy never writes an updated page to disk before its transaction commits; a steal policy allows it to be written earlier, which is more flexible but means an uncommitted change can reach disk and later need to be undone. A force policy writes every page a transaction modified to disk immediately at commit time; a no-force policy defers some of those writes, trusting the log to redo them later if needed.
  • Checkpoints and fuzzy checkpointing. A checkpoint is a log entry marking a point before which the DBMS is known to have been fully consistent, all transactions committed and all changes safely on disk; taking one means briefly suspending transaction execution, force-writing every modified buffer to disk, writing a [checkpoint] record to the log, and only then resuming transactions. Since suspending the whole system is costly, fuzzy checkpointing allows transaction execution to continue while buffers are being flushed, avoiding the pause at some added bookkeeping complexity during recovery.

Transaction rollback and cascading rollback. If a transaction fails after having already modified the database but before committing, it must be rolled back: any values it changed on disk are restored to their prior (before-image) values, using the undo-type entries in the log. If some other transaction had, in the meantime, read a value written by the transaction being rolled back, that reading transaction must be rolled back too, and so on transitively; this chain reaction is a cascading rollback, and it can only arise under a recovery protocol that permits recoverable-but-not-cascadeless schedules, which is exactly why strict or cascadeless protocols are preferred whenever the added restriction on concurrency is acceptable.

NO-UNDO/REDO Recovery Based on Deferred Update

Deferred update postpones every actual write to the database on disk until a transaction has reached its commit point; while the transaction is still active, its writes are only reflected in the log and in its own private workspace, never applied to the stored database itself. Because no update ever reaches the disk before commit, a transaction that fails before committing requires no undo at all, since the database on disk was never touched by it in the first place. Only redo-type log entries, recording the new (after-image) value written by each operation, are needed, since undoing is never required; a transaction's changes are simply applied to the database, and its redo entries flushed, once its commit record is safely on disk. The chief drawback is reduced concurrency: every item a transaction has written must remain write-locked until that transaction commits, since another transaction reading it early could see a value the first transaction might still roll back internally, and the system may also need considerable buffer space to hold every update of a long transaction until it finally commits.

Recovery Technique Based on Immediate Update

Immediate update techniques allow a transaction's writes to reach the database on disk before the transaction commits, so provisions must exist for undoing a failed transaction's already-applied changes. Two variants follow depending on exactly when writes are forced to disk.

  • UNDO/NO-REDO. If the recovery protocol guarantees that every one of a transaction's updates is written to disk before that transaction commits, then a committed transaction's effects are already permanently recorded, and redo is never required, only undo (for transactions that fail before committing). This variant necessarily uses a steal/force buffer strategy, since forcing every write to disk before commit is exactly what the "force" policy means.
  • UNDO/REDO. The more general case allows a transaction to commit even while some of its updates are still only in memory, not yet flushed to disk. Both undo (for transactions that fail) and redo (to make sure every committed transaction's effects genuinely reach disk, even after a crash) are needed here, and this variant corresponds to a steal/no-force buffer strategy, the combination that gives the DBMS the most flexibility over when buffers are actually written back.

Shadow Paging

Shadow paging takes an entirely different approach to recovery, avoiding a log for the data itself. The database is treated as $n$ fixed-size disk pages, tracked by a page directory with one entry per page, the $i$-th entry pointing to the current on-disk location of page $i$; the directory itself is kept in main memory if it is small enough. When a transaction begins, its current directory is copied to form a shadow directory, which is then written to disk and never modified again for the lifetime of the transaction, while the transaction works against the (mutable) current directory. Whenever the transaction writes to a page, a brand-new copy of that page is written to a previously unused disk location, and the current directory's entry for that page is updated to point at the new copy; the old copy, still referenced by the shadow directory, is left completely untouched. If the transaction commits, the current directory (now pointing at every updated page) simply becomes the new authoritative directory, and the old shadow directory and the pages it alone still references can be discarded; if the transaction fails, the current directory is simply discarded and the untouched shadow directory, still pointing at every original page, remains the valid state, so no undo logging of individual writes is ever needed. This makes shadow paging attractively simple for recovery, though it fragments the physical layout of the database over time (updated pages scatter to new disk locations) and complicates supporting concurrent transactions cleanly, which is why write-ahead logging remains the dominant technique in mainstream DBMSs despite shadow paging's conceptual elegance.

Database Backup and Recovery from Catastrophic Failures

None of the log-based or shadow-paging techniques above can help if the disk holding the database (and, potentially, the log) is physically destroyed; this is what a database backup guards against. The entire database, and its log, are periodically copied to a separate, typically cheaper storage medium, historically magnetic tape, more commonly today a physically or geographically separate disk or cloud store. After a catastrophic failure, the most recent backup is reloaded onto working storage and the system restarted from it. Because a full database backup is comparatively expensive and infrequent, the system log is typically backed up separately and far more often, so that after restoring the last full backup, the transactions recorded in the more frequently backed-up log segments since that backup can still be redone, minimizing how much committed work is actually lost. Applications where data loss is especially costly, banking, insurance, and stock market systems among them, treat this backup discipline, full database backups at longer intervals and log backups at short, frequent intervals, as a baseline operational requirement rather than an optional safeguard.

What this unit covers

  • Recovery Concepts
  • NO-UNDO/REDO Recovery Based on Deferred Update
  • Recovery Technique Based on Immediate Update
  • Shadow Paging
  • Database Backup and Recovery from Catastrophic Failures

Recovery Technique Based on Immediate Update

2080 · 5 marks

Why database recovery is essential? Explain recovery technique based on immediate update. [5]

Database recovery is essential due to the following reasons: - System Crashes and Failures: Hardware or software failures can occur in the middle of a transaction, leaving the database in an inconsistent state. - Transaction Errors: Incorrect command execution, logic errors, or runtime errors in ...

Open this answer on its own page →

2080.1 · 5 marks

Why database recovery is essential? Explain recovery technique based on immediate update. [5]

Database recovery is essential due to the following reasons: - System Crashes and Failures: Hardware or software failures can occur in the middle of a transaction, leaving the database in an inconsistent state. - Transaction Errors: Incorrect command execution, logic errors, or runtime errors in ...

Open this answer on its own page →

Recovery Concepts

2079 · 5 marks

What is Buffer Management in DBMS? Explain. [5]

Show solved answer

Buffer Management in DBMS

Definition

Buffer Management refers to the process by which the DBMS manages a collection of in-memory buffers (called the DBMS cache) that temporarily hold disk pages (blocks) containing data items needed for processing. Since disk I/O is slow, the DBMS brings data into main memory buffers, performs operations there, and then writes the modified data back to disk at an appropriate time.


How Buffer Management Works

When a transaction needs to read or update a data item, the DBMS follows these steps:

  1. Check the buffer directory to see if the required disk page is already in the DBMS cache (buffer pool).
  2. If not present, the page is fetched from disk into a free buffer slot.
  3. The data item is updated in memory (not directly on disk).
  4. A dirty bit is associated with each buffer:
    • Dirty bit = 0: the buffer has not been modified.
    • Dirty bit = 1: the buffer has been modified and needs to be written back to disk.
  5. Eventually, the modified buffer is written back to disk based on the recovery policy in use.

Key Policies in Buffer Management

Buffer management is closely tied to recovery algorithms. Two important policy pairs govern when modified pages are written to disk:

1. Steal / No-Steal Policy

PolicyDescription
No-StealA buffer page updated by a transaction cannot be written to disk before the transaction commits.
StealThe protocol allows writing an updated buffer to disk before the transaction commits.

2. Force / No-Force Policy

PolicyDescription
ForceAll pages updated by a transaction are immediately written to disk before the transaction commits.
No-ForceUpdated pages are not necessarily written to disk at commit time; they may be written later.

Role of the DBMS Cache Directory

  • A directory is maintained to track which database pages are currently held in the buffer pool.
  • This avoids redundant disk reads if the same page is needed again.
  • The DBMS recovery subsystem uses this information to manage undo and redo operations during crash recovery.

Importance of Buffer Management

  • Reduces the number of expensive disk I/O operations.
  • Ensures data consistency by controlling when dirty pages are flushed to disk.
  • Supports transaction recovery by coordinating with logging mechanisms (undo/redo logs).
  • Works together with checkpointing, where all modified buffers are force-written to disk to establish a consistent recovery point.

Summary

Buffer management is the mechanism by which the DBMS controls a pool of main memory buffers (DBMS cache) to hold disk pages temporarily, tracks modifications using dirty bits and a directory, and applies steal/no-steal and force/no-force policies to decide when to write data back to disk, thereby balancing performance and recoverability.

Open this answer on its own page →

2078 · 5 marks

What is Checkpoints in database recovery? How does it help in database recovery? Explain. [5]

A checkpoint is a special type of entry written to the transaction log that acts as a bookmark or synchronization point in the database system. It is a mechanism where all previous log records are permanently stored to disk, and the DBMS declares a point before which all transactions were committ...

Open this answer on its own page →

2076 · 5 marks

What are the different approaches of Database recover? What should log file maintain in log-based recovery? [5]

Database recovery techniques are methods used to restore the database to a correct consistent state after failures such as system crashes, transaction errors, viruses, or incorrect command execution. The main approaches are: --- A log (also called journal) is maintained to record all transaction ...

Open this answer on its own page →