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.
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 answerHide 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 Table | Description |
|---|---|
| Current Page Table | Points to the most recent (active) pages being modified by the current transaction. |
| Shadow Page Table | Points 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):
- All modified pages are written to disk.
- 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).
- The old shadow pages that were replaced are freed.
- The database is now in a new consistent state.
On ABORT / Failure (Transaction Failure):
- The current page table is simply discarded.
- The shadow page table (which still points to the old consistent pages) is restored as the current page table.
- 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.
Shadow paging technique
2080 · 5 marks
What is shadow paging? How it is used for database recovery? [5]
Show solved answerHide 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
| Advantages | Disadvantages |
|---|---|
| No log file is needed, so no undo or redo pass | Data pages are scattered on disk, which destroys locality |
| Recovery is instantaneous after a crash | Copying pages creates fragmentation and needs garbage collection of old pages |
| Commit is a single atomic pointer switch | Hard 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.
0 · 5 marks
What is shadow paging? How it is used for database recovery? [5]
Show solved answerHide 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:
- A shadow page table is created as an exact copy of the current page table.
- Both tables initially point to the same physical disk pages.
During Transaction Execution
When a transaction wants to modify a page:
- A new copy of that page is created on disk (copy-on-write).
- The current page table is updated to point to the new (modified) page.
- 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)
- All modified pages in the current page table are written to disk.
- The current page table replaces the shadow page table (shadow is discarded).
- The old pages (pointed to by the shadow) are freed/reclaimed.
- The database is now in the new consistent state.
On Abort / System Crash (Unsuccessful Transaction)
- The current page table is simply discarded.
- The shadow page table is restored as the current page table.
- All newly written (modified) pages are discarded.
- The database automatically returns to the last consistent state -- no undo/redo logs are needed.
Advantages of Shadow Paging
| Feature | Benefit |
|---|---|
| No redo logs needed | Committed data is already on disk |
| No undo logs needed | Recovery is done by restoring shadow table |
| Simple recovery | Just switch back to shadow page table |
| No cascading rollback | Each 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.
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]
Types of failures
2079 · 5 marks
Discuss the different types of failures. What is meant by catastrophic failure? [5]
Make Unit 9 stick
Practice BIT202 with flashcards & quizzes