RECOVERY & FAILURES IN DATABASE SYSTEMS
(Logging, Checkpoints, Crash Recovery Techniques)
1. Introduction to Database Recovery
Definition
Database recovery refers to the process of restoring a database to a correct and
consistent state after a failure.
Why Recovery is Important
• Prevents data loss
• Maintains data integrity and consistency
• Ensures reliability of transactions
• Supports ACID properties, especially:
o Atomicity – all or nothing
o Durability – committed data persists
2. Types of Failures in DBMS
Understanding failure types helps determine the appropriate recovery technique.
2.1 Transaction Failures
Occurs when a transaction cannot complete.
Causes:
• Logical errors (invalid input, constraint violation)
• System errors (deadlock, timeout)
Example:
A transfer transaction fails midway due to insufficient balance.
2.2 System Failures (Crash)
Occurs due to:
• Power failure
• OS crash
• Hardware malfunction
Effect:
• Volatile memory (RAM) is lost
• Disk data remains intact
2.3 Media Failures
• Disk crash
• Data corruption
• Physical damage
Effect:
• Permanent loss of stored data
3. Concepts of Transaction States
A transaction goes through several states:
1. Active – executing operations
2. Partially Committed – last statement executed
3. Committed – changes saved permanently
4. Failed – error occurred
5. Aborted – rolled back
4. Database Recovery Techniques Overview
Recovery techniques ensure:
• Undo incomplete transactions
• Redo completed transactions
Main techniques:
1. Logging (Write-Ahead Logging)
2. Checkpointing
3. Shadow Paging (less common, briefly mention)
5. LOGGING IN DATABASE RECOVERY
5.1 What is Logging?
Logging is the process of recording all database operations in a log file before they
are executed.
Purpose
• Track changes made by transactions
• Enable undo/redo operations during recovery
5.2 Types of Log Records
Each log entry typically contains:
• Transaction ID (TID)
• Data item affected
• Old value (before change)
• New value (after change)
Example Log Entry
<T1, A, 1000, 800>
Meaning:
Transaction T1 changed A from 1000 to 800
5.3 Write-Ahead Logging (WAL)
Definition
A technique where:
Log records must be written to disk BEFORE the actual database changes
Rules
1. Log must be written before data update
2. Commit record must be written before transaction is considered committed
Importance
• Guarantees recoverability
• Ensures durability
5.4 Types of Logging Techniques
1. Undo Logging
• Only old values are stored
• Used to rollback incomplete transactions
2. Redo Logging
• Only new values are stored
• Used to reapply committed transactions
3. Undo/Redo Logging (Most Common)
• Stores both old and new values
• Supports both rollback and roll-forward
6. CHECKPOINTING
6.1 What is a Checkpoint?
A checkpoint is a mechanism that:
Saves the current state of the database and log to disk at a specific point in time.
6.2 Purpose of Checkpointing
• Reduces recovery time
• Limits how far back the system must scan logs
6.3 How Checkpointing Works
Steps:
1. Temporarily pause new transactions
2. Flush all log records to disk
3. Write all modified buffers (dirty pages) to disk
4. Record checkpoint in log:
5. <checkpoint>
6. Resume transactions
6.4 Types of Checkpoints
1. Sharp Checkpoint
• Stops all transactions
• Ensures full consistency
• Slower but simpler
2. Fuzzy Checkpoint
• Allows transactions to continue
• More efficient
• Used in modern DBMS
7. CRASH RECOVERY TECHNIQUES
7.1 Recovery Using Log Files
After a crash:
• DBMS examines the log file
• Identifies:
o Committed transactions
o Uncommitted transactions
7.2 Undo Operation
Reverses incomplete transactions
Example
<T1, A, 1000, 800>
Undo restores A → 1000
7.3 Redo Operation
Reapplies committed transactions
Example
Redo ensures A → 800
7.4 Recovery Algorithm Steps
Step 1: Identify Transactions
• From log:
o Committed
o Active (uncommitted)
Step 2: Undo Phase
• Rollback all uncommitted transactions
Step 3: Redo Phase
• Reapply committed transactions
7.5 Immediate vs Deferred Update
1. Immediate Update
• Updates written before commit
• Requires:
o Undo + Redo
2. Deferred Update
• Updates written only after commit
• Requires:
o Redo only
8. SHADOW PAGING (Brief Overview)
Definition
A technique where:
• Changes are made on a copy of the database (shadow)
• Original data remains unchanged until commit
Advantages
• No need for logs
• Simple recovery
Disadvantages
• High overhead
• Not suitable for large systems
9. ARIES RECOVERY ALGORITHM
Full Meaning
Algorithm for Recovery and Isolation Exploiting Semantics
Phases
1. Analysis Phase
o Identify active transactions at crash
2. Redo Phase
o Repeat history (redo all necessary actions)
3. Undo Phase
o Rollback incomplete transactions
10. Practical Example of Recovery
Log File
<T1 start>
<T1, A, 100, 200>
<T2 start>
<T2, B, 300, 400>
<T1 commit>
--- CRASH ---
Recovery Actions
• Redo T1 (committed)
• Undo T2 (not committed)
11. Summary
Students should remember:
• Difference between undo and redo
• Importance of Write-Ahead Logging
• Role of checkpoints
• Types of failures
• Steps in crash recovery
• Immediate vs deferred update
12. Short Review Questions
1. Define database recovery and explain its importance.
2. Differentiate between transaction failure and system failure.
3. Explain Write-Ahead Logging (WAL).
4. What is a checkpoint and why is it used?
5. Distinguish between undo and redo operations.
6. Explain the steps involved in crash recovery.
7. Compare immediate update and deferred update techniques.