DATABASE MANAGEMENT SYSTEM

SHADOW PAGING IN DBMS

Shadow paging is a technique used in database management systems (DBMS) to ensure data consistency and atomicity, especially during transaction processing. It is a method of implementing a recovery mechanism that guarantees the ACID (Atomicity, Consistency, Isolation, Durability) properties of transactions. 

  1. Page Table:
    • The DBMS maintains a page table where each entry corresponds to a data page in the database.
    • Each entry in the page table contains a pointer to the physical location of the data page on disk.
  2. Shadow Page Table:
    • When a transaction begins, a shadow copy of the current page table is created. This is called the shadow page table.
    • The shadow page table remains unchanged throughout the transaction and acts as a backup.
  3. Transaction Processing:
    • During the transaction, changes are made to the data pages and the current page table.
    • The shadow page table is not updated; it remains as it was before the transaction started.
    • If a data page is modified, a new copy of that page is created, and the current page table is updated to point to this new copy. The original page remains unchanged, preserving its state.
  4. Commit Operation:
    • When the transaction commits, the shadow page table is replaced with the current page table.
    • This ensures that all changes made during the transaction are now permanent and visible to other transactions.
  5. Rollback Operation:
    • If the transaction needs to be aborted, the current page table is discarded, and the shadow page table is used to restore the database to its previous consistent state.
    • Since the shadow page table was not changed during the transaction, it reflects the state of the database before the transaction began.

Advantages of Shadow Paging

  • Simplicity: The mechanism is straightforward and easy to implement.
  • Immediate Recovery: Since the shadow page table provides a snapshot of the database before the transaction, recovery is quick and does not require complex log analysis or undo operations.
  • Atomicity and Durability: Shadow paging ensures that changes are either fully applied or not applied at all, providing strong guarantees for atomicity and durability.

Disadvantages of Shadow Paging

  • Overhead: Creating copies of pages and maintaining two page tables can be resource-intensive in terms of memory and disk space.
  • Concurrency Control: Managing concurrent transactions can be challenging, as each transaction would require its own shadow page table, leading to potential performance bottlenecks.
  • Fragmentation: Frequent copying of pages can lead to fragmentation, requiring periodic reorganization of the database to maintain performance.

Example Workflow

  1. Start Transaction:
    • Current page table: [P1, P2, P3]
    • Shadow page table: [P1, P2, P3]
  2. Modify Data Page:
    • Modify P2, creating a new version P2'.
    • Update current page table: [P1, P2', P3]
    • Shadow page table remains unchanged: [P1, P2, P3]
  3. Commit Transaction:
    • Replace shadow page table with current page table.
    • New shadow page table: [P1, P2', P3]