DataBase Recovery Techniques
DataBase Recovery Techniques
DataBase Recovery Techniques
Types of failures
Recovery concepts Recovery techniques
Database recovery
Pre-condition: At any given point in time the
database is in a consistent state. Condition: Some kind of system failure occurs Post-condition --- Restore the database to the consistent state that existed before the failure
Database recovery is the process of restoring the
database to the most recent consistent state that existed just before the failure.
TRANSACTION FAILURE
INCORRECT INPUT
DEADLOCK INCORRECT SYNCHRONIZATION
SYSTEM FAILURE
MEDIA FAILURE
SYSTEM HEAD CRASH POWER DISRUPTION
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.
cache is written either after a transaction ends its execution or after a fixed number of transactions have completed their execution.
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
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
AFIMs). Redo: Restore all AFIMs on to disk. Database recovery is achieved either by performing only Undos or only Redos or by a combination of the two. These operations are recorded in the log as they happen.
following three transactions T1, and T2 and T3. 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)
12
Roll-back: One execute Roll-back: One execution of T1, T2 and T3 as recorded in the log. ion of T1, T2 and T3 as recorded in the log.
then log is necessary for recovery and it must be available to recovery manager. This is achieved by Write-Ahead Logging (WAL) protocol.
database disk (overwriting the BFIM) its BFIM must be written to the log and the log must be saved on a stable store (log disk).
commit operation,all its AFIMs must be written to the log and the log must be saved on a stable store
disk - 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.
1. A set of transactions records their updates in the log. 2. At commit point under WAL scheme these updates are saved on database disk.
After reboot from a failure the log is used to redo all the transactions affected by this failure. No undo is required because no AFIM is flushed to the disk before a transaction commits.
-Shadow Paging
-ARIES recovery
maintained under WAL. At any time there will be one transaction in the system. Either in the commit table or in the active table.
The recovery manager performs: 1. Undo of a transaction if it is in the active table. 2. Redo of a transaction if it is in the commit table.
control is required and log is maintained under WAL. Commit table records transactions to be committed and active table records active transactions. To minimize the work of the recovery manager check pointing is used. The recovery performs: 1. Undo of a transaction if it is in the active table. 2. Redo of a transaction if it is in the commit table.
Provides atomicity and durability Copy on-write technique used for avoiding in place
updates.
The AFIM does not overwrite its BFIM but recorded at
(Shadow copy of the data item) at two different places on the disk.
modified liberally.
When the page is ready to become durable, all pages
that referred to the original are updated to refer to the new replacement page instead.
similar to the old master-new master batch
25
1. WAL (Write Ahead Logging) 2. Repeating history during redo: ARIES will retrace all actions of the database system prior to the crash to reconstruct the database state when the crash occurred. 3. Logging changes during undo: It will prevent ARIES from repeating the completed undo operations if a failure occurs during recovery, which causes a restart of the recovery process.
Analysis: step identifies the dirty (updated) pages in the buffer and the set of transactions active at the time of crash. The appropriate point in the log where redo is to start is also determined.
2. Redo: necessary redo operations are applied. 3. Undo: log is scanned backwards and the operations of transactions active at the time of crash are undone in reverse order.
(a) data update (b) transaction commit (c) transaction abort (d) Undo (e) transaction end. In the case of undo a compensating log record is written.
increases monotonically and indicates the disk address of the log record it is associated with. In addition, each data page stores the LSN of the latest log record corresponding to a change for that page.
A log record stores (a) the previous LSN of that
transaction, (b) the transaction ID, and (c) the type of log record.
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 a write operation the following additional information is logged: 4. Page ID for the page that includes the item 5. Length of the updated item 6. Its offset from the beginning of the page 7. BFIM of the item 8. AFIM of the item
For efficient recovery following tables are also stored in the log during check pointing:
Transaction table: Contains an entry for each
active transaction, with information such as transaction ID, transaction status and the LSN of the most recent log record for the transaction.
page in the buffer, which includes the page ID and the LSN corresponding to the earliest update to that page.
1. Writes a begin_checkpoint record in the log 2. Writes an end_checkpoint record in the log.
3. Writes the LSN of the begin_checkpoint record to a special file.This special file is accessed during recovery to locate the last checkpoint information. To reduce the cost of checkpointing and allow the system to continue to execute transactions, ARIES uses fuzzy checkpointing.
36
Phase 2
If all participants OK, the transaction is successful and the