Database Recovery Concepts
Database Recovery Concepts
1. Introduction
Database recovery refers to the process of restoring the database to a consistent state after a failure such as system crashes, transaction errors, or disk failures.
The main objectives of recovery are:
-
Atomicity – Incomplete transactions must be undone.
-
Durability – Committed transactions must remain permanent.
To support recovery, the DBMS maintains a system log that records all updates performed by transactions.
2. Types of Failures
Database failures are classified into two types:
1. Catastrophic Failure
These failures cause physical damage to the database.
Examples:
-
Disk crash
-
Hardware failure
Recovery method:
-
Restore database from backup
-
Redo committed transactions using the log.
2. Non-Catastrophic Failure
These failures do not damage the database physically.
Examples:
-
System crash
-
Transaction abort
-
Software errors
Recovery is done using log records.
3. Recovery Algorithms
There are two main recovery techniques.
| Technique | Description |
|---|---|
| Deferred Update | Database updated only after transaction commits |
| Immediate Update | Database updated before commit |
4. Deferred Update (NO-UNDO / REDO)
In deferred update, the database is not updated until the transaction commits.
-
Updates are stored in buffers or logs.
-
If transaction fails → no undo required.
-
If system crashes after commit → redo operations are required.
Thus it is called:
5. Immediate Update
In immediate update, the database may be updated before the transaction commits.
If a transaction fails:
-
Changes already written to disk must be undone.
Recovery may require:
-
Undo of uncommitted transactions
-
Redo of committed transactions
Two variations exist:
| Algorithm | Description |
|---|---|
| UNDO/REDO | Both undo and redo required |
| UNDO/NO-REDO | Only undo required |
6. Write-Ahead Logging (WAL)
Write-Ahead Logging ensures that log records are written to disk before database updates.
Rules of WAL:
-
Before a data item is updated, its before image must be written to the log.
-
A transaction cannot commit until all its log records are written to disk.
This guarantees correct recovery.
7. Buffer Management
DBMS uses main memory buffers (cache) to store disk pages temporarily.
Important components:
Dirty Bit
-
Indicates whether a page has been modified.
| Value | Meaning |
|---|---|
| 0 | Not modified |
| 1 | Modified |
Pin/Unpin Bit
-
Determines whether a page can be written back to disk.
8. Steal / No-Steal and Force / No-Force Policies
Steal / No-Steal
| Policy | Meaning |
|---|---|
| No-Steal | Updated pages cannot be written before commit |
| Steal | Updated pages may be written before commit |
Force / No-Force
| Policy | Meaning |
|---|---|
| Force | All updates written to disk before commit |
| No-Force | Updates may remain in memory |
Most DBMS use:
Which requires UNDO and REDO operations.
9. Checkpoints
A checkpoint is a special log record that indicates that all modified buffers have been written to disk.
Format:
Purpose:
-
Reduces recovery time
-
During crash recovery, the system only examines log records after the last checkpoint.
10. Fuzzy Checkpointing
Normal checkpointing pauses transaction processing.
To avoid delays, fuzzy checkpointing is used.
Steps:
-
Write begin_checkpoint record
-
Continue transaction execution
-
Flush buffers gradually
-
Write end_checkpoint
11. Transaction Rollback
If a transaction fails before commit, the system performs rollback.
Rollback process:
-
Use log records
-
Restore before images (BFIM) of data items
-
Undo all write operations.
12. Cascading Rollback
Cascading rollback occurs when one transaction depends on another.
Example:
-
T1 writes a value
-
T2 reads that value
-
If T1 aborts → T2 must also abort.
To avoid cascading rollback, DBMS uses strict or cascadeless schedules.
Conclusion
-
Log files
-
Write-Ahead Logging
-
Checkpoints
-
Undo and Redo operations
Modern DBMS typically use steal/no-force strategy with WAL, which supports efficient recovery.
Comments
Post a Comment