Shadow Paging Recovery Technique

 

Shadow Paging Recovery Technique 

Shadow Paging is a database recovery technique that does not require a log in a single-user environment. Instead of recording changes in logs, it maintains two page directories to protect the database from failures.

This technique ensures that if a system crash occurs, the database can be restored simply by switching to the shadow directory, without performing UNDO or REDO operations.


1. Basic Idea of Shadow Paging

Shadow paging treats the database as a collection of fixed-size disk pages (blocks).

Example:

Database = n pages P1, P2, P3, ... , Pn

To manage these pages, the system maintains a page directory.

The directory contains n entries, where:

Directory[i] → pointer to page i on disk

Every read or write operation accesses pages through this directory.


2. Directories Used in Shadow Paging

When a transaction begins, two directories exist.

DirectoryDescription
Current Directory        Used by the running transaction
Shadow Directory        Backup copy of the database state

Step when transaction starts

  1. Current directory exists (points to latest pages).

  2. It is copied to create a shadow directory.

  3. The shadow directory is stored safely on disk.

  4. The current directory is used by the transaction.

Important rule:

The shadow directory is never modified during transaction execution.


3. How Updates Work

When a transaction updates a page, shadow paging does not overwrite the original page.

Instead it follows this process.

Step-by-step update

  1. Transaction wants to update page Pi

  2. A new page copy is created.

  3. The update is written to the new page.

  4. The current directory entry is changed to point to the new page.

  5. The shadow directory continues to point to the old page.

Thus two versions of the page exist:

VersionUsed by
Old Page        Shadow Directory
New Page        Current Directory

4. Example of Shadow Paging

Suppose a database has 6 pages:

P1 P2 P3 P4 P5 P6

Initial directories:

Current Directory → P1 P2 P3 P4 P5 P6 Shadow Directory → P1 P2 P3 P4 P5 P6

Transaction updates Page 2 and Page 5.

New pages are created:

P2' (new version) P5' (new version)

Directories now look like this:

Page    Shadow Directory        Current Directory
1        P1        P1
2    P2        P2'
3    P3        P3
4    P4        P4
5    P5        P5'
6        P6        P6

So:

  • Old pages remain unchanged

  • New pages contain updates





5. Recovery After System Crash

If the system crashes during transaction execution, recovery is very simple.

Recovery Steps

  1. Discard the current directory

  2. Discard newly modified pages

  3. Restore the shadow directory

Since the shadow directory points to the original pages, the database returns to the state before the transaction began.

No:

  • UNDO

  • REDO

  • Log scanning

is required.


6. Commit Operation in Shadow Paging

When a transaction commits successfully, the system:

  1. Replaces the shadow directory with the current directory

  2. Deletes the old shadow directory

This means the updated pages become the official database pages.

Important requirement:

Switching directories must be done as an atomic operation (cannot be interrupted).


7. Why It Is Called NO-UNDO / NO-REDO

Shadow paging is classified as:

NO-UNDO / NO-REDO recovery technique

Because:

OperationNeeded?
UndoNo
RedoNo

Reasons:

  • Old data is preserved in the shadow directory

  • New updates are stored separately

So recovery only requires directory switching.


8. Shadow Paging in Multiuser Systems

In multiuser environments, shadow paging alone is not enough.

Additional mechanisms are needed:

  • Concurrency control

  • Logging

  • Checkpoints

These are required because multiple transactions may update pages simultaneously.


9. Advantages of Shadow Paging

1. No logging required

No need to maintain complex log records.

2. Fast recovery

Recovery only requires switching directories.

3. No UNDO or REDO

This simplifies recovery operations.

4. Simple crash handling

Restoring the shadow directory restores the database.


10. Disadvantages of Shadow Paging

1. Page fragmentation

Updated pages are written to new disk locations, causing scattered pages.

This reduces disk performance.


2. Directory overhead

Large databases require large page directories, which must be copied and stored.


3. Garbage collection problem

Old pages that are no longer used must be identified and freed.

This process is called garbage collection.


4. Difficult storage management

Maintaining related pages close together on disk becomes difficult.


5. Atomic directory switching required

If the system crashes while switching directories, database consistency may be affected.


11. Comparison with Log-Based Recovery

FeatureShadow Paging    Log-Based Recovery
Uses Log    No        Yes
Undo Needed    No        Yes
Redo Needed    No        Yes
Recovery Speed    Very Fast        Moderate
Disk Fragmentation    High        Low
Used in Modern DBMS    Rare        Very Common

12. Summary

Shadow paging is a recovery technique that maintains two page directories:

  • Shadow Directory → old stable database

  • Current Directory → modified database

If a crash occurs:

  • The system restores the shadow directory.

If a transaction commits:

  • The current directory becomes the new shadow directory.

Thus shadow paging provides simple and fast recovery without using logs.



Shadow paging is a recovery technique that maintains two page directories—shadow and current. Updates are written to new pages without overwriting old pages. If a crash occurs, the shadow directory is used to restore the database, making it a NO-UNDO/NO-REDO recovery method.

Comments

Popular posts from this blog

Database Management Systems DBMS PCCST402 Semester 4 KTU CS 2024 Scheme

Data Models, Schemas and Instances

Introduction to Database Management System -DBMS