Chapter 5 DBRecovery
Chapter 5 DBRecovery
Database Recovery ?
Types of failure ?
Basic Steps in recovery ?
Recovery facilities .
Recovery Techniques .
Focusing on Recovery
All database reads/writes are within a transaction
Transactions have the “ACID” properties
Atomicity - all or nothing
Consistency - preserves database integrity
Isolation - execute as if they were run alone
Durability - results aren’t lost by a failure
Recovery subsystem guarantees A & D
Concurrency control guarantees I
Application program guarantees C
Database Recovery
• What is Recovery?
– the process of getting back something lost(dictionary
definition)
• What is Database Recovery?
– is the process of restoring the database to the most
recent consistent state that existed just before the
failure.
Why Database Recovery?
To bring the database into the last consistent state
which existed prior to the failure.
To preserve transaction properties (Atomicity,
Consistency, Isolation and Durability).
Example:
If the system crashes before a fund transfer
transaction completes its execution, then either one
or both accounts may have incorrect value.
Thus, the database must be restored to the state
before the transaction modified any of the
accounts.
Types of failure
• The database may become inconsistent or unavailable for
use due to various types of failure:
• Transaction failure: Transactions may fail because
of incorrect input, deadlock, incorrect
synchronization.
• System failure: System may fail because of
addressing error, application error, operating system
fault, RAM failure, etc.
• Media failure: Disk head crash, power disruption,
etc.
• How to control this failures?
Recovery Concept (Sample log)
1 A=A+200
2 B=B-100
3 C=C-200
Failure
4 A=A+200
5 B=B+700
6 C=C+600
Cont…
Recovery Facilities
Backup mechanism: that makes periodic
backup copies of database.
Logging facility: that keeps track of current
state of transactions and database changes.
Checkpoint facility: that enables updates to
database in progress to be made permanent.
Recovery manger : which allows DBMS to
restore the database to a consistent state
following a failure.
Such kind of information is stored in a system log
or transaction log file.
Log File
Log File
Contains information about all updates to
database:
Transaction records.
Checkpoint records.
Log file example
Recovery Techniques
Damage to the database could be either physical
and relate which will result in the loss of the data
stored or just inconsistency of the database state
after the failure. For each we can have a recover
mechanism:
Cont…
If database has been damaged:
Need to restore last backup copy of database
and reapply updates of committed transactions
using log file.
Extensive damage/catastrophic failure: physical
media failure; is restored by using the backup
copy and by re executing the committed
transactions from the log up to the time of
failure.
Cont…
If database is only inconsistent:
No physical damage/only inconsistent: the restoring is
done by reversing the changes made on the database
by consulting the transaction log.
Need to undo changes that caused inconsistency. May
also need to redo some transactions to ensure updates
reach secondary storage.
Do not need backup, but can restore database using
before- and after-images in the log file.
Recovery Techniques
Three main recovery techniques:
Deferred Update
Immediate Update
Shadow Paging
Deferred Update
Updates are not written to the database until after a
transaction has reached its commit point.
If transaction fails before commit, it will not have
modified database and so no undoing of changes
required.
May be necessary to redo updates of committed
transactions as their effect may not have reached
database.
NO-UNDO/REDO Algorithm
Immediate Update/ Update-In-Place
Updates are applied to database as they occur.
Need to redo updates of committed transactions following
a failure.
May need to undo effects of transactions that had not
committed at time of failure.
Essential that log records are written before write to
database. Write-ahead log protocol.
If no "transaction commit" record in log, then that
transaction was active at failure and must be undone.
UNDO/REDO Algorithm.
Shadow Paging
Maintain two page tables during life of a transaction:
current page and shadow page table.
When transaction starts, two pages are the same.
Shadow page table is never changed thereafter and is
used to restore database in event of failure.
During transaction, current page table records all updates
to database.
When transaction completes, current page table becomes
shadow page table.