BIT202 ยท 0 ยท 5 marks
What is shadow paging? How it is used for database recovery?
What is shadow paging? How it is used for database recovery? [5]
Quick answer
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...
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.
Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.