🛠️ Recovery Techniques in Database Systems
🔰 What is Recovery?
Recovery in DBMS refers to the process of restoring the database to a correct state after a failure such as:
- System crash
- Transaction failure
- Media failure (disk crash)
- Power failure
The aim is to ensure data integrity and durability by preserving the effects of committed transactions and undoing uncommitted ones.
🔑 Important Concepts
✅ Key Recovery Techniques
1. Deferred Update (No-Force, Steal Policy)
- Changes made by a transaction are kept in memory and written to disk only after the transaction commits.
- No updates are written to disk before commit.
- If failure occurs before commit, no undo is required because changes are not saved.
Advantages:
- Simple recovery (only redo needed).
- Avoids unnecessary disk writes.
Disadvantages:
- Recovery time can be long because all updates since last checkpoint must be redone.
2. Immediate Update (Force, No-Steal Policy)
- Updates can be written to disk before transaction commits.
- If a transaction fails, DBMS must undo its changes from the disk.
Advantages:
- Changes are on disk quickly, improving durability.
Disadvantages:
- Recovery requires both undo and redo operations.
- Requires a robust logging mechanism.
3. Write-Ahead Logging (WAL) Protocol
A fundamental technique used by most DBMSs for recovery.
- Before any data item is written to disk, its before-image and after-image must be recorded in the log.
- The log is stored on stable storage.
Types of Log Records:
- Update record: Contains before and after values of a data item.
- Commit record: Marks transaction commit.
- Abort record: Marks transaction abort.
Properties:
- Guarantees atomicity and durability.
- Supports undo and redo operations.
4. Checkpointing
- Periodic process of writing the current state of the database and log to stable storage.
- Reduces recovery time by limiting how far back the system needs to scan the log.
Types:
- Fuzzy Checkpoint: Database continues processing transactions during checkpoint.
- Consistent Checkpoint: All transactions paused during checkpoint.
5. Undo and Redo Operations
| Operation |
Purpose |
| Undo |
Revert changes of uncommitted transactions to maintain atomicity. |
| Redo |
Reapply changes of committed transactions that might not have been written to disk. |
6. Shadow Paging
- The database keeps two page tables: current and shadow.
- All updates are made to the current page table.
- When transaction commits, current page table replaces shadow page table.
- On failure, shadow page table is used to restore the database.
Advantages:
- Simple recovery (just discard current page table on failure).
Disadvantages:
- Inefficient for high update workloads.
- Requires large memory for page tables.
📝 Recovery Algorithm Example: ARIES (Algorithms for Recovery and Isolation Exploiting Semantics)
ARIES is a widely used recovery method based on:
- Write-Ahead Logging (WAL)
- Repeating History during redo
- Logging logical undo operations
Phases:
- Analysis: Identify dirty pages and active transactions.
- Redo: Reapply all changes from the log.
- Undo: Rollback incomplete transactions.
🛡️ Summary Table of Recovery Techniques
| Technique |
Description |
Undo Required |
Redo Required |
Disk Writes Timing |
| Deferred Update |
Updates written after commit |
No |
Yes |
After commit |
| Immediate Update |
Updates can be written anytime |
Yes |
Yes |
Before or after commit |
| Write-Ahead Logging |
Log before data write |
Yes |
Yes |
Before data write |
| Checkpointing |
Periodic saving of DB state |
N/A |
N/A |
N/A |
| Shadow Paging |
Keep shadow copies of data pages |
No |
No |
At commit |
💡 Why Recovery Techniques Matter?
- Ensure database consistency and durability despite failures.
- Provide support for transaction atomicity.
- Minimize system downtime and data loss.
- Crucial for mission-critical applications (banking, airline reservation).