Unit 6
Database Recovery Techniques
Recovery Concept:
• Database recovery techniques are used in database management
systems (DBMS) to restore a database to a consistent state after a
failure or error has occurred. The main goal of recovery techniques is
to ensure data integrity and consistency and prevent data loss.
• Recovery from failure state refers to the method by which system
restore its most recent consistent state just before the time of failure.
There are several methods by which you can recover database from
failure state:
There are mainly two types of recovery techniques
used in DBMS:
• Log Based Recovery : In log based recovery system, a log is
maintained, in which all the modifications of the database are kept. A
log consists of log records. For each activity of database, separate log
record is made. Log records are maintained in a serial manner in
which different activities are happened. There are various log records.
A typical update log record must contain following fields:
a)Transaction identifier b) Data-item identifier c) Date and Time d) Old
value e) New value.
There are two types of log based recovery techniques and they are:
i) Recovery based on deferred update(No-UNDO/REDO)
ii) Recovery based on immediate update( UNDO/REDO)
No-UNDO/REDO Recovery Based on Deferred
Update:
• It is a technique for the maintenance of the transaction log files of the
DBMS. It is also called NO-UNDO/REDO technique. It is used for the
recovery of transaction failures that occur due to power, memory, or
OS failures. Whenever any transaction is executed, the updates are
not made immediately to the database. They are first recorded on the
log file and then those changes are applied once the commit is done.
This is called the “Re-doing” process. Once the rollback is done none
of the changes are applied to the database and the changes in the log
file are also discarded. If the commit is done before crashing the
system, then after restarting the system the changes that have been
recorded in the log file are thus applied to the database.
Feature Deferred Update
• Update timing: Updates occur after instruction execution .
• Processor speed: May be faster which update occurs after instruction
execution, allowing for multiple updates to be performed at once .
• Complexity : More complex that requires additional instructions or
mechanisms to handle updates after instruction execution .
• Consistency: May result in temporary inconsistency between data in
registers and memory .
• Flexibility: May be more flexible that allows for more complex data
manipulations and algorithms.
Recovery Technique Based on Immediate
update:
• It is a technique for the maintenance of the transaction log files of the
DBMS. It is also called UNDO/REDO technique. It is used for the
recovery of transaction failures that occur due to power, memory, or
OS failures. Whenever any transaction is executed, the updates are
made directly to the database and the log file is also maintained
which contains both old and new values. Once the commit is done, all
the changes get stored permanently in the database, and records in
the log file are thus discarded. Once rollback is done the old values
get restored in the database and all the changes made to the
database are also discarded. This is called the “Un-doing” process. If
the commit is done before crashing the system, then after restarting
the system the changes are stored permanently in the database.
Feature of Immediate update:
• Update timing: Updates occur during instruction execution.
• Processor speed: May be slower then update occurs during instruction
execution, potentially causing the processor to stall.
• Complexity : Less complex to updates occur immediately during
instruction execution.
• Consistency: Data in registers and memory are always consistent
• Flexibility: Less flexible then immediate updates can limit the range
of data manipulations and algorithms that can be performed
Difference between Deferred update and Immediate
update:
Deferred Update Immediate Update
In a deferred update, the changes are not applied immediately to the
In an immediate update, the changes are applied directly to the database.
database.
The log file contains all the changes that are to be applied to the database. The log file contains both old as well as new values.
In this method once rollback is done all the records of log file are discarded In this method once rollback is done the old values are restored to the
and no changes are applied to the database. database using the records of the log file.
Concepts of buffering and caching are used in deferred update method. Concept of shadow paging is used in immediate update method.
The major disadvantage of this method is that it requires a lot of time for The major disadvantage of this method is that there are frequent I/O
recovery in case of system failure. operations while the transaction is active.
In this method of recovery, firstly the changes carried out by a transaction on
In this method of recovery, the database gets directly updated after the
the data are done in the log file and then applied to the database on commit.
changes made by the transaction and the log file keeps the old and new
Here, the maintained record gets discarded on rollback and thus, not applied
values. In the case of rollback, these records are used to restore old values.
to the database.
Shadow Paging:
• Shadow Paging is an alternative technique for recovery to overcome the
disadvantages of log-based recovery techniques. The main idea behind the
shadow paging is to keep two page tables in database, one is used for
current operations and other is used in case of recovery.
• Database is partitioned into fixed length blocks called pages. For memory
management, adopt any paging technique.
• Shadow page table must be stored in non-volatile or stable storage
because it is used at the time of recovery. Suppose the system crashed and
you have to recover it. After every successful completion of transaction,
current page table is converted into shadow page table. So, shadow page
table has to be searched.To make the searching simple, stores shadow page
table on fixed location of stable storage. No redo operations need to be
invoked. Shadow page table and current page table are shown in figure:
Advantages
The advantages of shadow paging are as follows −
• No need for log records.
• No undo/ Redo algorithm.
• Recovery is faster.
Disadvantages
The disadvantages of shadow paging are as follows −
• Data is fragmented or scattered.
• Garbage collection problem. Database pages containing old versions
of modified data need to be garbage collected after every transaction.
• Hard to extend algorithm to allow transaction to run concurrently.
Database Backup and Recovery from
Catastrophic Failures:
• So far, all the techniques we have discussed apply to noncatastrophic
failures. A key assumption has been that the system log is maintained on
the disk and is not lost as a result of the failure. Similarly, the shadow
directory must be stored on disk to allow recovery when shadow paging is
used. The recovery techniques we have discussed use the entries in the
system log or the shadow directory to recover from failure by bringing the
database back to a consistent state.
• The recovery manager of a DBMS must also be equipped to handle more
catastrophic failures such as disk crashes. The main technique used to
handle such crashes is a database backup, in which the whole database and
the log are periodically copied onto a cheap storage medium such as
magnetic tapes or other large capacity offline storage devices. In case of a
catastrophic system failure, the latest backup copy can be reloaded from
the tape to the disk, and the system can be restarted.
• Data from critical application such as banking, insurance, stock
market, and other database is periodically backed up in its entirety
and moved to physically separate safe locations.
• To avoid losing all the effects of transactions that have been executed
since t he last backup, it is customary to back up the system log at
more frequent intervals than full database backup by periodically
copying it to magnetic tape. The system log is usually substantially
smaller than the database itself and hence can be backed up more
frequently. Therefore, users do not lose all transactions they have
performed since the last database backup. Hence, to recover from
disk failure, the database is first recreated on disk from its latest
backup copy on tape.