Recovery: Shadow Paging
Shadow paging avoids a log by never overwriting the live page table. It switches pointers atomically and keeps the old version as a shadow.
In plain English
Write the new version on a fresh page, then switch the bookmark.
The one idea
Shadow paging writes changed pages to new locations and atomically switches the page-table root, so the old state survives a crash.
It is an elegant alternative to undo logging: if the switch did not happen, the old database is still intact.
By the end
- 01Explain current and shadow page tables.
- 02Describe the atomic commit switch.
- 03Know the cost of garbage collection.
- 04Compare shadow paging with logging.
Current and shadow pages
The database keeps a current page table and a shadow page table. Updates are written to new pages, not the live pages. The current table points to the new pages; the shadow table still points to the old consistent state.
Atomic commit
At commit, the DBMS writes the updated page table to disk and atomically switches the root pointer to it. Before the switch, the shadow table is the consistent state; after the switch, the new table is. A crash during the switch leaves either the old or the new state, never a mixture.
before commit:
shadow -> old pages (consistent)
current -> new pages (uncommitted)
commit:
write current page table
atomic switch root -> currentCosts and comparison
Shadow paging avoids undo/redo logging for page writes, but it fragments the disk because updated pages are written elsewhere. It also needs garbage collection for old pages and can be expensive for large transactions. Logging is more common in modern systems because it handles large updates and recovery more flexibly.
Switch the page table, not the page
The current page table points page 3 to disk block 30. A transaction updates page 3.
Copy page 3 to a new block, 41, and modify the copy.
The old block 30 remains untouched.
Force the new page and a new page table to disk.
The old root still points to block 30; the new root points to block 41.
Atomically update the root pointer.
A crash before the switch leaves the old state; after the switch, the new state is durable.
ConclusionShadow paging replaces undo with copy-on-write and a pointer swap. It avoids undo logs, but it fragments pages and complicates reclamation.
The trade-off
No free correctness.
Gain
No undo log and a simple crash-recovery story.
Cost
Copy-on-write overhead, page-table growth, and garbage collection of old pages.
Verdict
Conceptually important and used in some systems, but most large databases prefer WAL.
Recap
What to keep.
Takeaways
- +Shadow paging writes updates to new pages.
- +The shadow page table preserves the last consistent state.
- +Commit switches the root pointer atomically.
- +Old pages require garbage collection.
- +Logging is generally more flexible for large transactions.
Traps
- !Thinking shadow paging never writes to disk.
- !Forgetting that old pages consume space until collected.
- !Assuming the atomic switch is free.
Focus
- →Explain the current and shadow tables.
- →Trace a commit and a crash before/after the switch.
- →Compare shadow paging with WAL.
Check yourself
Before you turn the page.
What does the shadow page table represent?
What is a cost of shadow paging?