Database Recovery Techniques
Database Recovery Techniques
Database Recovery
Techniques
2 Types of Failure
The database may become unavailable for use due to
• 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.
Database Recovery
3 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. A sample log is given below. Back P and Next P
point to the previous and next log records of the same transaction.
T1 T2 T3
read_item (A) read_item (B) read_item (C)
read_item (D) write_item (B) write_item (B)
write_item (D) read_item (D) read_item (A)
write_item (A) write_item (A)
Database Recovery
Roll-back: One execution of T1, T2 and T3 as recorded in the log.
A B C D
30 15 40 20
[start_transaction, T3]
[read_item, T3, C]
* [write_item, T3, B, 15, 12] 12
[start_transaction,T2]
[read_item, T2, B]
** [write_item, T2, B, 12, 18] 18
[start_transaction,T1]
[read_item, T1, A]
[read_item, T1, D]
[write_item, T1, D, 20, 25] 25
[read_item, T2, D]
[write_item, T2, D, 25, 26] 26
[read_item, T3, A]
---- T3 failed system crash ----
* T3 is rolled back because it did not reach its commit point.
** T2 is rolled back because it reads the value of item B written by T3.
Database Recovery
Roll-back: One execution of T1, T2 and T3 as recorded in the log.
7 Checkpointing
Time to time (randomly or under some criteria) the database
flushes its buffer to database disk to minimize the task of
recovery. The following steps defines a checkpoint
operation:
1. Suspend execution of transactions temporarily.
2. Force write modified buffer data to disk.
3. Write a [checkpoint] record to the log, save the log to
disk.
4. Resume normal transaction execution.
During recovery redo or undo is required to transactions
appearing after [checkpoint] record.
Database Recovery
Deferred Update with concurrent users
This environment requires some concurrency control mechanism to
guarantee isolation property of transactions. In a system recovery
transactions which were recorded in the log after the last checkpoint were
redone. The recovery manager may scan some of the transactions
recorded before the checkpoint to get the AFIMs.
T1
T2
T3
T4
T5
t1 Time t2
checkpoint system crash
T1
T2
T3
T4
T5
t1 Time t2
checkpoint system crash
T2 and T3 are ignored because they did not reach their commit points.
T4 is redo because its commit point is after the last checkpoint.
Database Recovery
Deferred Update with concurrent users
Two tables are required for implementing this protocol:
During recovery, all transactions of the commit table are redo and all
transactions of active tables are ignored since none of their AFIMs
reached the database. It is possible that a commit table transaction may
be redo twice but this does not create any inconsistency because of a
redone is “idempotent”, that is, one redone for an AFIM is equivalent to
multiple redone for the same AFIM.
Database Recovery
Recovery Techniques Based on Immediate Update
Undo/No-redo Algorithm
Recovery schemes of this category apply undo and also redo for
recovery. In a single-user environment no concurrency control is
required but a log is maintained under WAL. Note that at any time there
will be one transaction in the system and it will be either in the commit
table or in the active table. The recovery manager performs:
X Y
X' Y'
Database
A log record stores (a) the previous LSN of that transaction, (b) the
transaction ID, and (c) the type of log record.
Database Recovery
The ARIES Recovery Algorithm
The Log and Log Sequence Number (LSN)
A log record stores:
1. Previous LSN of that transaction: It links the log record of each
transaction. It is like a back pointer points to the previous
record of the same transaction.
2. Transaction ID
3. Type of log record.
For efficient recovery following tables are also stored in the log during
checkpointing:
Dirty Page table: Contains an entry for each dirty page in the buffer,
which includes the page ID and the LSN corresponding to the earliest
update to that page.
Database Recovery
The ARIES Recovery Algorithm
Checkpointing
A checkpointing does the following: