Course contentsShow
← Databases & SQL
Lesson 569 of 1,9536. Query Performance and IndexingFree lesson

Shadow Paging Mechanisms

Understand atomic page updates using dual-buffer pointer manipulation.

Understanding Shadow Paging Mechanisms

In this lesson, you will learn how to achieve atomic database updates without a traditional transaction log by using a "dual-buffer" pointer strategy known as shadow paging.

The Problem: Atomicity without Logs

In our previous look at the "Role of the Transaction Log," we learned that most systems write changes to a log before committing them to the disk to ensure data integrity. Shadow paging offers an alternative approach: instead of overwriting existing data, we create a copy.

The Dual-Buffer Mechanism

At any given time, the database maintains a Current Page Table that points to the physical locations of data on the disk. When a transaction needs to modify a page, the database performs these three steps:

  1. Shadow Creation: The system copies the target page to a new, empty location on the disk.
  2. Local Modification: All updates are applied only to this new "shadow" page, leaving the original data untouched and consistent.
  3. Pointer Swap: Once the modification is complete, the database updates the Current Page Table to point to the new shadow page.

If the system crashes during the process, the Current Page Table still points to the original, unmodified data. The transaction never "officially" happened, and no recovery is needed because the original state was never overwritten.

-- Conceptual View
Current Page Table: [Page A -> Disk Block 1]

-- Transaction begins:
1. Copy Block 1 to Block 2 (The Shadow).
2. Modify Block 2.
3. Update Table: [Page A -> Disk Block 2]

Why it Matters

This mechanism ensures that an update is truly atomic—it either happens entirely (the pointer swap succeeds) or it doesn't happen at all. Because we never overwrite the "live" version of a page until the very last second, we eliminate the need for the complex undo/redo logs we discussed earlier. However, the trade-off is high overhead: copying pages and managing constant pointer updates can lead to significant disk fragmentation and require more frequent garbage collection to clean up orphaned blocks.

Key Takeaway: Shadow paging provides atomicity by writing changes to a new disk block and performing an instantaneous pointer swap, ensuring that the database always points to either the old state or the new, completed state—never a corrupted mix of both.