Database Recovery Techniques
Database Recovery Techniques
In this chapter, we discuss some of the techniques that can be used for database recovery in case
of system failure.
In Section 20.1.4 we discussed the different causes of failure, such as system crashes and
transaction errors. In Section 20.2, we introduced some of the concepts that are used by recovery
processes, such as the system log and commit points.
This chapter explains important concepts related to database recovery and gives an overview of
different recovery methods.
In Section 22.1, we begin with a basic outline of how recovery usually works and introduce
the main types of recovery algorithms. We also explain key ideas like write-ahead logging,
the difference between in-place and shadow updates, and how a system undoes the effects of
a failed or incomplete transaction.
Section 22.2 covers deferred update recovery, also called the NO-UNDO/REDO method.
Here, changes are not made to the database until the transaction is successfully completed.
In Section 22.3, we look at immediate update recovery, where changes can be written to the
database even before a transaction is complete. This section includes UNDO/REDO and
UNDO/NO-REDO techniques.
Section 22.4 discusses a method called shadow paging (or shadowing), which fits into the
NO-UNDO/NO-REDO category, as it avoids both undo and redo operations.
Section 22.5 presents a widely used and practical recovery system called ARIES.
In Section 22.6, we briefly look at how recovery works in multidatabase systems (systems
with more than one database).
Section 22.7 explains how to recover from catastrophic failures, such as hardware crashes.
Finally, Section 22.8 gives a summary of the chapter. While recovery and concurrency
control are closely related, this chapter focuses only on recovery, without going into
concurrency control. For details on how recovery is implemented in specific database
systems, you can refer to the user manuals or additional reading suggested at the end of the
chapter.
22.1 Recovery Concepts – Simplified Notes
22.1.1 Overview of Recovery and Algorithm Types
Recovery Goal: Restore the database to its last consistent state after a failure.
Key Component: The System Log, which tracks all changes made by transactions.
Two Main Failure Scenarios:
1. Catastrophic Failure (e.g., disk crash):
o Restore from a backup.
o Use the log to redo committed transactions.
2. Non-catastrophic Failure (e.g., system crash or power failure):
o Use the log to:
Undo uncommitted transactions.
Redo committed transactions not yet written to disk.
Recovery Techniques:
1. Deferred Update (NO-UNDO/REDO):
o No changes are made to the database until a transaction commits.
o Only REDO is needed if system crashes after commit.
2. Immediate Update (UNDO/REDO):
o Changes are made before commit, but only after being logged.
o Both UNDO (for uncommitted changes) and REDO (for committed but unwritten
changes) may be needed.
3. UNDO/NO-REDO:
o All changes written before commit.
o Only UNDO is needed if the transaction fails before committing.
✅ UNDO and REDO must be idempotent – repeating them doesn't change the outcome.
This simplified explanation covers the core concepts of database recovery, focusing on clarity
and ease of understanding while retaining essential details. Let me know if you need further
clarification or examples!
🧠 Key Points:
Only REDO is needed (for committed transactions).
UNDO is not needed — failed transactions haven’t touched the disk.
Useful for simple/short transactions, since changes stay in memory until commit (can use
up buffer space).
⚠️Drawbacks:
More memory needed (buffers stay pinned).
Lower concurrency (locked items stay locked until commit).
💡 Main Advantages
1. No need to UNDO anything.
2. No cascading rollbacks.
3. Simple recovery: just REDO committed transactions.
Let me know if you’d like a diagram, a flowchart, or practice questions to make it even clearer!
I prefer this response
22.2 NO-UNDO/REDO Recovery Based on Deferred Update (Simplified)
What is Deferred Update?
Deferred update is a recovery method where a transaction’s changes are not written to the
database on disk until the transaction successfully completes (reaches its commit point). Until
then, changes are stored in the system log and cache buffers in memory.
Key Idea:
If a transaction fails before committing, no changes are made to the database on disk, so
there’s no need to undo anything.
Only REDO is needed to reapply changes from committed transactions if they weren’t
fully written to the database before a system crash.
Why REDO Only?
The log records only the new values (after images, AFIMs) of data items, as no undo is
needed.
If the system crashes after a transaction commits but before its changes are written to
disk, the log’s REDO entries are used to apply those changes.
Limitations:
This method works best for short transactions that modify few items.
For longer or larger transactions, it can use up a lot of memory because all changes must
stay in cache buffers until the transaction commits, and these buffers are pinned (can’t be
replaced).
Optimization
To make recovery faster:
If an item (e.g., X) was updated multiple times by committed transactions since the last
checkpoint, only redo the last update from the log.
Track redone items in a list to avoid repeating earlier updates, as the last update
overwrites them.
Drawbacks
1. Limited Concurrency: Items stay locked until the transaction commits, which can slow
down other transactions.
2. High Memory Usage: All changes must stay in pinned cache buffers until commit, which
can strain memory for large transactions.
This simplified explanation captures the essence of the NO-UNDO/REDO recovery method using
deferred update, making it easy to understand while covering the key points. Let me know if you
need further details or clarification!
🧠 Key Concepts:
Since changes can be written before commit, we need a way to undo the effects of a
failed transaction.
For this, the system must log the old value of any data item that is updated (called BFIM
– Before Image).
The log must contain both:
o UNDO information (old value),
o REDO information (new value), if commit happens before all updates are
written to disk.
🔁 UNDO Procedure:
For each [write_item, T, X, old_value, new_value]:
o Set X = old_value in the database.
🔁 REDO Procedure:
For each [write_item, T, X, new_value]:
o Set X = new_value in the database.
🚀 Optimizing Recovery:
To improve performance:
For REDO: Only apply the last change to each item (scan log backwards).
For UNDO: Only undo each item once (scan log forwards, and skip items already
undone).
⚠️Important Note:
Because updates happen before commit, recovery must undo failed transaction effects.
This makes UNDO/REDO more complex, but it's the most flexible and widely used
method.
22.3 Recovery Techniques Based on Immediate Update (Simplified)
What is Immediate Update?
In immediate update recovery, a transaction’s changes can be written to the database on disk
before the transaction reaches its commit point. This is different from deferred update, where
changes wait until commit.
Key Idea:
Changes are written to the database immediately but must also be logged to allow
recovery.
If a transaction fails before committing, its changes must be undone (rolled back) using
the before image (BFIM) from the log.
If a transaction commits but some changes aren’t on disk, they may need to be redone
using the after image (AFIM) from the log.
Why Undo?
Since changes can be written to disk before a transaction commits, a failed transaction’s
changes must be reversed to restore the database to its previous state.
This uses a steal strategy, where modified cache buffers can be written to disk before
commit to free up memory.
Optimization
To make recovery faster:
For Redo: Start from the end of the log and redo only the last update for each item.
Track redone items in a list to avoid repeating.
For Undo: Start from the beginning of the log and apply the earliest undo for each item.
Track undone items to avoid repeating.
This simplified explanation covers the core of immediate update recovery, focusing on clarity
and ease of understanding. Let me know if you need further details or examples!
🧱 How It Works
1. Database is split into fixed-size pages (e.g., Page 1, Page 2, ..., Page n).
2. A directory keeps track of where each page is located on disk.
o The directory maps page numbers to physical disk blocks.
o All reads and writes go through this directory.
3. When a transaction starts:
o The current directory is copied and saved as the shadow directory.
o The shadow directory stays unchanged during the transaction.
o The current directory is used for any updates.
✅ Committing a Transaction
When a transaction commits:
o The shadow directory is discarded.
o The current directory becomes the new shadow directory.
o Now, the new pages are officially part of the database.
🧩 Advantages
Simple and clean: just switch directories for commit or recovery.
No need to undo or redo any operations.
⚠️Disadvantages
1. Page movement: Updated pages are written to new locations, so pages can become
scattered on disk.
o Makes it hard to keep related data together for performance.
2. Large directories: If the directory is big, saving it to disk every time a transaction
commits can be slow.
3. Garbage collection needed:
o After commit, old pages (no longer in use) must be freed and added back to the
free space list.
4. Atomic switch:
o Switching from the shadow to the current directory must be done as one atomic
step to avoid inconsistency.
🤝 Multiuser Systems
In multiuser systems, you still need:
o Logging and checkpointing for concurrency control.
o So shadow paging is mainly practical for single-user or simple environments.
Let me know if you’d like a visual diagram or a simple example to help make this even clearer!
22.4 Shadow Paging (Simplified)
What is Shadow Paging?
Shadow paging is a recovery method that doesn’t require a log in a single-user environment. In
a multiuser environment, a log may still be needed for concurrency control. It treats the
database as a collection of fixed-size disk pages (or blocks) and uses a directory to manage
them.
Recovery Process
If a transaction fails:
o Discard the modified pages and the current directory.
o Restore the shadow directory, which points to the database’s state before the
transaction started.
o This returns the database to its original state without needing to undo or redo
changes.
If a transaction commits:
o Discard the shadow directory, making the current directory the new official
directory.
Result: Shadow paging is a NO-UNDO/NO-REDO method because it neither reverses
nor reapplies changes during recovery.
Shadow Paging in Multiuser Environments
In a multiuser system with concurrent transactions, shadow paging needs logs and
checkpoints to work with concurrency control methods (e.g., locking).
This ensures transactions don’t interfere with each other.
This simplified explanation covers the essentials of shadow paging, making it easy to understand
while retaining key details. Let me know if you need further clarification or examples!