Chapter - 5-Database Recovery Techniques
Chapter - 5-Database Recovery Techniques
Chapter Five:
Database Recovery
Techniques
Prepared by:
Misganaw Abeje
University of Gondar
College Of Informatics
Department of computer science
[email protected]
1
Outline
Introduction
Purpose of Database Recovery
Types of failures
Transaction Log
Data Update
Data Caching
Write-Ahead Logging
Check pointing
Recovery Scheme/techniques
– Deferred Update (No Undo/Redo)
4
BY: MA
2. Types of failures
1. Transaction failure
Erroneous parameter values
Logical programming error
System error like integer overflow, division by zero
Local error like “data not found”
User interrupt
Concurrency control enforcement
2. System crash
A hardware, software, or network error (also media failure)
3. Disk failure, and Catastrophe
5
BY: MA
Strategy for recovery may be summarized as :
Recovery from catastrophic
– If there is extensive damage to the wide portion of the database
– This method restore a past copy of the database from the backup
storage and reconstructs operation of a committed transaction
from the back up log up to the time of failure
Recovery from non-catastrophic failure
– When the database is not physically damaged but has be come
inconsistent.
– The strategy uses undoing and redoing some operations in order
to restore to a consistent state and by keeping information about the
6 change in the system log.
BY: MA
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 (appended file) called Transaction log
These log files becomes very useful in brining back the
system to a stable state after a system crash.
A sample log is given below. Back P and Next P point to the
previous and next log records of the same transaction.
T ID Back P Next P Operation Data item BFIM AFIM
T1 0 1 Begin
T1 1 4 Write X X = 100 X = 200
T2 0 8 Begin
T1 2 5 W Y Y = 50 Y = 100
T1 4 7 R M M = 200 M = 200
7
7 T3 0 9 R N N = 400 N = 400
BY: MA T1 5 nil End
4 Data Update Strategy
There are different types of data update
1. Immediate Update: 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.
– These update are first recorded on the log and on the disk by force
writing, before the database is updated
– If a transaction fails after recording some change to the database but
before reaching its commit point , the effect of its operations on the
database must be undone; that is, the transaction must be rolled back.
– In the general case of immediate update, both undo and redo may be
required during recovery. This technique, known as the
UNDO/REDO algorithm,
8
BY: MA
2. Deferred Update: 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.
– During commit the updates are first recorded on the log
and then on the database.
– If a transaction fails before reaching its commit point
undo is not needed because it didn’t change the
database yet, Hence, deferred update is also known as
the NO-UNDO/REDO algorithm.
9
BY: MA
3. Shadow update:
The modified version of a data item does not overwrite its
disk copy but is written at a separate disk location.
Multiple version of the same data item can be maintained.
Thus the old value ( before image BFIM) and the new
value (AFIM) are kept in the disk
No need of Log for recovery
4. In-place update: The disk version of the data item is
overwritten by the cache version.
10
BY: MA
5. Data Caching
15
BY: MA
7. Check pointing
Log file is used to recover failed DB but we may not know how
far back in the log to search. Thus Checkpoint is a Point of
synchronization between database and log file.
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
16 appearing after [checkpoint] record.
BY: MA
17
BY: MA
8. Recovery Scheme/techniques
19
BY: MA
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.
Two tables are required for implementing this protocol:
Active table: All active transactions are entered in this table.
Commit table: Transactions to be committed are entered in this table.
During recovery, all transactions of the commit table are redone 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 redone 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
20 AFIM
BY: MA
2. Recovery Techniques Based on Immediate Update
21
BY: MA
2.2. Undo/Redo Algorithm (Single-user
environment)
22
BY: MA
2.3. Undo/Redo Algorithm (Concurrent execution)
25
BY: MA
3. The ARIES Recovery Algorithm
Stands for “Algorithm for Recovery and Isolation Exploiting
Semantics.”
It is designed to work with a steal , no- force/undo/redo approach, which
is based on the following three principles
1. WAL (Write Ahead Logging)
Any change to the database object is first recorded in the log
The record on the log must first be save on the disk and then
The database object is written to disk
27
BY: MA
i. The Log and Log Sequence Number (LSN)
– The log is a history of actions executed by the DBMS in
terms of a file of records stored in disk for recovery purpose
– A unique LSN is associated with every log record
LSN 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.
28
BY: MA
A log record is written for each of the following actions:
– updating a page: After modifying the page , an update record is
appended to the log tail. The page LSN of the page is then set to
the LSN of the update log record
– commit- when a transaction decides to commit , it force writes a
commit type log record containing the transaction id
– Abort- when a transaction is aborted , an abort type log containing
the transaction id is appended to the log
– End-when a transaction is aborted or committed , an end type log
record containing transaction id is appended to the log
– undo update- when transaction is roll back its updates are undone
29
BY: MA
A log record stores
– The previous LSN of that transaction
– The transaction ID
– The type of log record.
– For a write operation the following additional
information is logged:
Page ID for the page that includes the item
Length of the updated item
Its offset from the beginning of the page
BFIM of the item
30
BY: MA
ii. The Transaction table and the Dirty Page table
– 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( in progresses, committed or aborted)
and the LSN of the most recent log record for the
transaction.
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.
31
BY: MA
A check pointing does the following:
– Writes a begin checkpoint record in the log
– Writes an end checkpoint record in the log. With this
record the contents of transaction table and dirty page
table are appended to the end of the log.
– 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 check-pointing and allow the system
to continue to execute transactions, ARIES uses “fuzzy
32 check-pointing”.
BY: MA
The ARIES recovery algorithm consists of three steps:
1. 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 phase: Starts from the point in the log up to where all
dirty pages have been flushed, and move forward to the end
of the log. Any change that appears in the dirty page table is
redone.
3. Undo phase: Starts from the end of the log and proceeds
backward while performing appropriate undo.
33 The recovery completes at the end of undo phase.
BY: MA
Example of recovery in ARIES
34
BY: MA
Thank you?
35