Purpose of Database Recovery :-
1. To bring the database into the last consistent state, which
existed prior to the failure.
2. To preserve transaction properties Atomicity, Consistency,
Isolation and Durability.
3. Thus recovery ensures high availability of the database for
transaction purpose.
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 :-
There are three types of failures that occur commonly
1. Transaction failure: Transactions may fail because of
incorrect input, deadlock, incorrect synchronization.
2. System failure: System may fail because of addressing
error, application error, operating system fault, RAM
failure, etc.
3. Media failure: Disk head crash, power disruption, etc.
Transaction Log :-
For recovery from any type of failure data values prior to
modification (BFIM - BeFore Image) and the new value
after modification (AFIM – AFter Image) are required.
These values and other information is stored in a
sequential file called Transaction log.
2. Log is the most commonly used structure for recording
the modifications that as to be made in the actual
database. Hence during the recovery procedure a log file
is maintainted.
The log record maintains four types of operations.
1. <start> represented as <T,start>
2. <Update>
3. <Commit> represented as <T,Commit>
4. <Abort> represented as <T,Abort>
Example:-
Data Update :-
Immediate Update:-
As soon as a data item is modified in cache, the disk copy is
updated.
Deferred Update: All modified data items in the cache is written
either after a transaction ends its execution or after a fixed
number of transactions have completed their execution.
Shadow update: The modified version of a data item does not
overwrite its disk copy but is written at a separate disk location.
In-place update: The disk version of the data item is overwritten
by the cache version
Data Caching :-
Data items to be modified are first stored into database cache
by the Cache Manager (CM) and after modification they are
flushed (written) to the disk.
The flushing is controlled by Modified and Pin-Unpin bits.
Pin-Unpin: Instructs the operating system not to flush the data
item.
Modified: Indicates the AFIM of the data item.