Shadow Paging
Shadow Paging is a recovery technique used in database systems to maintain atomicity and durability without using a traditional write-ahead log (WAL). It is based on the idea of never modifying the original database pages directly. Instead, changes are made to a copy (shadow) of the data pages, which becomes permanent only if the transaction commits successfully.
Basic Idea of Shadow Paging
The central structure in Shadow Paging is a page table (also called a page directory or map), which keeps track of the location of all pages in the database.
Â
- At the beginning of a transaction, the current page table is called the shadow page table.
- A new page table is created for the current transaction, initially pointing to the same pages as the shadow page table.
- When a page is modified during the transaction, the database writes the changes to a new page on disk and updates the new page table to point to this new page.
- The original data remains untouched, so it can be used to roll back if necessary.
Commit and Abort in Shadow Paging
On Commit:
The new page table replaces the shadow page table atomically. This means the system now starts using the updated data pages.
Â
On Abort or Crash:
The system simply discards the new page table and continues using the old shadow page table. Since the original data was never overwritten, rollback is immediate and simple.
Â
This method avoids the need to keep an undo/redo log because the data is not changed in place.
Example Illustration
Let’s say we have the following pages and a page table:
Page Table Entry | Page ID |
---|---|
0 | A |
1 | B |
2 | C |
At the start of a transaction, this becomes the shadow page table.
A new page table is created as a copy.
Suppose page B is modified → A new page B’ is written to disk.
The new page table is updated: entry 1 → B’.
Original shadow page table remains unchanged until commit.
Advantages of Shadow Paging
- No need for undo/redo logging, as the original data is never overwritten.
- Recovery is fast, since you just use the shadow page table on failure.
- The technique is simple and conceptually easy to understand.
Disadvantages of Shadow Paging
- High overhead of copying page tables for every transaction.
- If pages are large or many pages are changed, disk I/O increases significantly.
- Not suitable for concurrent transactions, unless additional complex mechanisms are used.
- Fragmentation can occur due to creating new pages frequently.
When is Shadow Paging Used?
Shadow Paging is mainly of academic or theoretical interest today and is not commonly used in large-scale commercial databases. Most modern DBMSs prefer Write-Ahead Logging (WAL) with redo/undo logs because it supports concurrent transactions, fine-grained updates, and better performance.
Â
However, Shadow Paging still provides a foundational concept that helps students understand recovery logic without the complexity of logging.