Your Page Title
🔍

    Shadow paging

    n a Database Management System (DBMS), ensuring reliability and consistency is one of the most important tasks. Whenever a transaction takes place, the database must guarantee that either all changes of the transaction are applied (commit) or none at all (rollback). To achieve this, DBMS uses various recovery techniques.

    One such technique is Shadow Paging.


    Meaning of Shadow Paging

    Shadow Paging is a recovery technique in DBMS that maintains two copies (or versions) of the database pages during a transaction:

    1. Shadow Pages – These are the original, unchanged pages. They act as a backup and never get modified during the transaction.
    2. Current Pages – These are the pages where all updates of the transaction are applied.

    The idea is simple:

    • If the transaction commits, the updated pages replace the old ones.
    • If the transaction fails, the system discards the current pages and uses the shadow pages (original copy) to restore the database.

    This method ensures that the database is always consistent, even if a failure occurs.


    How Shadow Paging Works

    The shadow paging mechanism works through a page table.

    • A Page Table is a data structure that maps logical database pages to physical storage pages on disk.
    • Shadow paging keeps two page tables:
      • Shadow Page Table → Points to the original, consistent database pages.
      • Current Page Table → Used for the transaction and may point to modified pages.

    Steps:

    1. Initialization
      • At the start of a transaction, the shadow page table is created.
      • A copy of this page table is made → known as the current page table.
    2. Update Operation
      • When a page is updated, the system does not overwrite the existing page.
      • Instead, a new page is allocated on disk.
      • The current page table entry is modified to point to this new page.
      • The shadow page table remains unchanged.
    3. Commit Operation
      • If the transaction commits successfully, the current page table is written to disk.
      • The shadow page table is replaced with the current one.
      • This makes the updated version permanent.
    4. Rollback Operation
      • If the transaction fails or aborts, the current page table is discarded.
      • The shadow page table is still intact and is used to restore the database.
      • Hence, no recovery or undo operations are needed.

    Example of Shadow Paging

    Let’s assume we have a database with three pages: P1, P2, and P3.

    • Before Transaction:
      • Shadow Page Table → [P1, P2, P3]
      • Current Page Table → [P1, P2, P3]
    • Transaction Updates P2:
      • A new page P2’ is created.
      • Current Page Table → [P1, P2’, P3]
      • Shadow Page Table → [P1, P2, P3] (unchanged)
    • If Transaction Commits:
      • Shadow Page Table is replaced with Current Page Table.
      • Database → [P1, P2’, P3]
    • If Transaction Fails:
      • Current Page Table is discarded.
      • Database → [P1, P2, P3] (restored to original state)

    Advantages of Shadow Paging

    1. No Redo or Undo needed
      • Unlike log-based recovery, shadow paging does not require redo or undo operations.
      • Simply keeping or discarding the current page table ensures recovery.
    2. Simple Rollback Mechanism
      • If a transaction fails, rollback is instant because the shadow pages are untouched.
    3. Atomicity and Durability Guaranteed
      • Ensures the ACID properties of transactions (specifically atomicity and durability).

    Disadvantages of Shadow Paging

    1. Page Table Overhead
      • Maintaining two page tables (shadow and current) increases memory usage.
    2. Copying Costs
      • Copying and updating page tables after every transaction can be expensive, especially in large databases.
    3. Poor Data Clustering
      • Since updated pages are stored in new locations, related data may get scattered on disk, leading to slower access.
    4. Not Suitable for Large Databases
      • Works well for small systems but becomes inefficient in large-scale databases with high transaction volumes.

    Applications of Shadow Paging

    • Mostly used in early DBMS systems before logging became popular.
    • Still useful in:
      • File systems (e.g., some versions of NTFS use similar concepts).
      • Embedded databases where recovery logging may be too costly.
      • Simple transactional systems with smaller datasets.

    Shadow Paging vs. Log-Based Recovery

    FeatureShadow PagingLog-Based Recovery
    Rollback MechanismDiscards current page tableUses undo operations
    Commit MechanismReplace shadow page tableWrite commit log
    Storage RequirementRequires duplicate pagesRequires log files
    EfficiencySimple for small DBsMore scalable for large DBs
    Clustering of DataPoor (data gets scattered)Better clustering

    Conclusion

    Shadow Paging in DBMS is a recovery technique that ensures database consistency by maintaining two versions of pages: shadow (original) and current (updated). It simplifies rollback and guarantees atomicity, but it suffers from performance and storage overhead issues.

    While it is not widely used in modern large-scale systems (which prefer log-based recovery methods like Write-Ahead Logging), shadow paging is still an important concept in database recovery and is useful in smaller or embedded database systems.