9 Database Recovery And Reliability

Database Management System · Unit 9

Database Recovery and Reliability

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

Database Recovery and Reliability in short

Systems can fail because of power loss, software bugs, or disk damage. Recovery is the job of bringing the database back to a correct state after a failure. This chapter covers logs, failure types, and shadow paging.

Database Recovery and Reliability: notes

Database recovery definition

Database recovery is the process of restoring the database to the most recent consistent state that existed before a failure. It protects the atomicity and durability parts of ACID.

  • Changes of committed transactions must survive the failure (durability).
  • Changes of uncommitted transactions must be removed (atomicity).

Main recovery techniques are log-based recovery, shadow paging, and backups with checkpoints. The recovery manager of the DBMS handles them.

System log and log entries

The system log (journal) is a sequential file that records every change made to the database. It is kept on stable storage and is written before the database itself is changed. This rule is called write-ahead logging (WAL).

Typical log entries for a transaction $T$:

EntryMeaning
[start, T]T has started
[write, T, X, old, new]T changed X from the old value to the new value
[read, T, X]T read X (optional)
[commit, T]T has completed successfully
[abort, T]T has been aborted
[checkpoint]Marks a point where all earlier changes are on disk

Example log for a transfer of 50 from A to B, where A = 500 and B = 300:

[start, T1]
[write, T1, A, 500, 450]
[write, T1, B, 300, 350]
[commit, T1]

Undo uses the old value to cancel the change of an uncommitted transaction. Redo uses the new value to repeat the change of a committed transaction. A checkpoint limits how far back the system must look in the log.

After a crash:

  • A transaction with start and commit is redone.
  • A transaction with start but no commit is undone.

What this unit covers

  • Database recovery definition
  • System log and log entries
  • Types of failures
  • Catastrophic failure
  • Shadow paging technique
  • Recovery using shadow paging

Database recovery definition

2082 · 5 marks

What is database recovery? How can shadow paging be used for database recovery? [5]

Show solved answer

Database Recovery and Shadow Paging

What is Database Recovery? (2 marks)

Database recovery is the process of restoring a database to a correct and consistent state after a failure (such as system crash, transaction failure, media failure, or power loss).

The primary goals of database recovery are:

  • Atomicity: Ensure that incomplete transactions are rolled back (undone).
  • Durability: Ensure that committed transactions are not lost.

Recovery relies on the concept of maintaining redundant information (logs, shadow copies) so that the database can be restored to the last consistent state.


Shadow Paging for Database Recovery (3 marks)

Shadow paging is a recovery technique that avoids the use of a log file by maintaining two page tables simultaneously:

Page TableDescription
Current Page TablePoints to the most recent (active) pages being modified by the current transaction.
Shadow Page TablePoints to the last committed consistent state of the database (never modified during the transaction).

How Shadow Paging Works

Setup:

  • The database is organized into fixed-size pages.
  • At the start of a transaction, both the current page table and the shadow page table point to the same physical pages on disk.

During a Transaction:

  • When a transaction modifies a page, a new copy of that page is created in a different disk location.
  • The current page table is updated to point to the new (modified) page.
  • The shadow page table remains unchanged, still pointing to the old (original) pages.
Shadow Page Table          Current Page Table
  [Page 1] --> P1            [Page 1] --> P1  (unchanged)
  [Page 2] --> P2            [Page 2] --> P2' (new modified copy)
  [Page 3] --> P3            [Page 3] --> P3  (unchanged)

On COMMIT (Transaction Success):

  1. All modified pages are written to disk.
  2. The current page table replaces the shadow page table (i.e., the shadow page table pointer is updated to point to the current page table).
  3. The old shadow pages that were replaced are freed.
  4. The database is now in a new consistent state.

On ABORT / Failure (Transaction Failure):

  1. The current page table is simply discarded.
  2. The shadow page table (which still points to the old consistent pages) is restored as the current page table.
  3. No undo operations are needed -- the database automatically reverts to the last consistent state.

Advantages of Shadow Paging

  • No need for a redo/undo log.
  • Recovery is simple and fast -- just restore the shadow page table.
  • No cascading rollbacks.

Disadvantages of Shadow Paging

  • Fragmentation: Pages of the same file may scatter across disk over time.
  • Garbage collection: Old shadow pages must be reclaimed.
  • Overhead: Copying entire pages even for small changes is costly.
  • Not suitable for large databases with many concurrent transactions.

Summary: Shadow paging ensures recovery by keeping an untouched shadow copy of the last consistent database state. On failure, the shadow copy is restored; on commit, the shadow is updated to reflect the new state.

Open this answer on its own page →

Shadow paging technique

2080 · 5 marks

What is shadow paging? How it is used for database recovery? [5]

Show solved answer

Shadow Paging

Definition

Shadow paging is a recovery technique used in database systems that maintains two page tables simultaneously:

  • Current Page Table - reflects all changes made by the current (active) transaction.
  • Shadow Page Table - a copy of the page table taken at the start of the transaction; it remains unchanged during the transaction and points to the stable (committed) state of the database.

Both page tables initially point to the same disk pages. As the transaction modifies pages, new copies of those pages are written to new disk locations, and only the current page table is updated to point to the new pages. The shadow page table continues to point to the original pages.


How Shadow Paging Works

Setup

At transaction start:
Shadow Page Table                 Current Page Table
  (frozen copy)                    (being updated)
   +---------+                       +---------+
   | Page 1  |----------+----------->| Page 1  |
   | Page 2  |-------+  |  +---------| Page 2  |
   | Page 3  |----+  |  |  |  +------| Page 3  |
   +---------+    |  |  |  |  |      +---------+
                  v  v  v  v  v
               +----+----+----+  DISK PAGES
               | P1 | P2 | P3 |
               +----+----+----+

When the transaction modifies page 2:

   Shadow Page Table            Current Page Table
   | Page 2 |---> [ old P2 ]    | Page 2 |---> [ new P2' ]

The old page P2 is never overwritten; a fresh copy P2' is written to a free disk block and only the current page table is made to point at it.

How Shadow Paging is Used for Recovery

On successful commit:

  • All modified pages are flushed to disk.
  • The current page table is written to disk.
  • The pointer held in the database header is switched from the shadow page table to the current page table in a single atomic write.
  • The old pages that the shadow table referred to become free space.

On failure or abort (system crash, transaction error):

  • The current page table and the new pages are simply discarded.
  • The database header still points at the shadow page table, which describes exactly the state of the database before the transaction began.
  • The database is therefore already consistent when it restarts, with no undo and no redo required.

Advantages and Disadvantages

AdvantagesDisadvantages
No log file is needed, so no undo or redo passData pages are scattered on disk, which destroys locality
Recovery is instantaneous after a crashCopying pages creates fragmentation and needs garbage collection of old pages
Commit is a single atomic pointer switchHard to extend to concurrent transactions, so it suits single-user systems

Conclusion

Shadow paging achieves atomicity and durability by never overwriting a page in place. The shadow page table preserves the pre-transaction image of the database while the current page table accumulates the changes, and commit reduces to switching one pointer. Recovery is therefore trivial (either the switch happened and the transaction is committed, or it did not and the transaction never existed), which is why the technique is valued for its simplicity even though the page copying and fragmentation costs keep it out of most multi-user database systems.

Open this answer on its own page →

0 · 5 marks

What is shadow paging? How it is used for database recovery? [5]

Show solved answer

Shadow Paging

Definition

Shadow paging is a recovery technique used in database management systems that maintains two page tables simultaneously:

  • Current Page Table - reflects all changes made by the current (active) transaction.
  • Shadow Page Table - a copy of the page table taken at the start of the transaction; it remains unchanged during the transaction and points to the last consistent state of the database.

The shadow page table is stored on disk (non-volatile storage), ensuring it survives system crashes.


How Shadow Paging Works

Setup

When a transaction begins:

  1. A shadow page table is created as an exact copy of the current page table.
  2. Both tables initially point to the same physical disk pages.

During Transaction Execution

When a transaction wants to modify a page:

  1. A new copy of that page is created on disk (copy-on-write).
  2. The current page table is updated to point to the new (modified) page.
  3. The shadow page table continues to point to the original (old) page.
Shadow Page Table          Current Page Table
  Page 1 --> Block A         Page 1 --> Block A  (unchanged)
  Page 2 --> Block B         Page 2 --> Block B' (modified copy)
  Page 3 --> Block C         Page 3 --> Block C  (unchanged)

Recovery Using Shadow Paging

On Commit (Successful Transaction)

  1. All modified pages in the current page table are written to disk.
  2. The current page table replaces the shadow page table (shadow is discarded).
  3. The old pages (pointed to by the shadow) are freed/reclaimed.
  4. The database is now in the new consistent state.

On Abort / System Crash (Unsuccessful Transaction)

  1. The current page table is simply discarded.
  2. The shadow page table is restored as the current page table.
  3. All newly written (modified) pages are discarded.
  4. The database automatically returns to the last consistent state -- no undo/redo logs are needed.

Advantages of Shadow Paging

FeatureBenefit
No redo logs neededCommitted data is already on disk
No undo logs neededRecovery is done by restoring shadow table
Simple recoveryJust switch back to shadow page table
No cascading rollbackEach transaction is isolated

Disadvantages of Shadow Paging

  • Fragmentation: Modified pages are scattered across disk (no locality).
  • Garbage collection: Old shadow pages must be reclaimed after commit.
  • Overhead: Copying the entire page table at transaction start is costly for large databases.
  • Not suitable for concurrent transactions: Managing multiple shadow tables is complex.

Summary

Shadow paging provides atomicity and durability without using a traditional log. By keeping an unchanged shadow copy of the page table, the system can recover from failures by simply reverting to the shadow, making it a straightforward but limited recovery mechanism suitable for single-user or small database systems.

Open this answer on its own page →

System log and log entries

2079 · 5 marks

What is the system log used for? What are the typical kinds of entries in a system log? [5]

Note: The reference notes did not contain specific content on this topic. The following answer is based on standard Operating Systems concepts as taught in BSc CSIT curriculum. --- A system log (also called a log file or audit log) is a file maintained by the operating system that records signifi...

Open this answer on its own page →

Types of failures

2079 · 5 marks

Discuss the different types of failures. What is meant by catastrophic failure? [5]

In software engineering and system reliability, failures are broadly classified into the following types: --- - Failures that occur only under certain input conditions. - They appear temporarily and may not be reproducible every time. - Example: A program crashes only when a specific unusual inpu...

Open this answer on its own page →