Professional Documents
Culture Documents
DB CH 3
DB CH 3
By Ashenafi Wubshet 1
Chapter Three
Databases Recovery
1. Recovery Concepts
I. Types of Failure
II. Purpose of Data Recovery
III. Transaction Log
IV. Data Updates
V. Data Caching
VI. Write-Ahead Logging
VII. Check pointing
2. Recovery Scheme
I. Deferred Update (No Undo/Redo)
II. Recovery Techniques Based on Immediate Update
III. Shadow Paging
By Ashenafi Wubshet 2
▪ Transaction Manager : Accepts transaction commands from an application, which
tell the transaction manager when transactions begin and end,
as well as information about the expectations of the
application.
The transaction processor performs the following tasks:
Transaction Request ✓ Logging: In order to assure
durability, every change in the
Query Transaction Log database is logged separately on
Processor Manager Manager disk.
By Ashenafi Wubshet 12
VII. Checkpointing
▪ 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.
▪ When failure occurs, redo all transactions that committed since the
checkpoint and undo all transactions active at time of crash.
▪ In previous example ,Figure 2, on slide 6 , with checkpoint at time tc,
changes made by T2 and T3 have been written to secondary storage.
Thus: only redo T4 and T5, undo transactions T1 and T6.
▪ At what interval to take a check pointing may be measured :
▪ In terms of time , say m minutes after the last check point
▪ The # t of committed transaction since the last check point
▪ The following steps defines a checkpoint operation:
i. Suspend execution of transactions temporarily.
ii. Force write modified buffer data to disk.
iii. Write a [checkpoint] record to the log, save the log to disk.
iv. Resume normal transaction
By Ashenafiexecution.
Wubshet 13
2. Recovery Scheme
i. Deferred Update (No Undo/Redo)
– The data update goes as follows:
▪ A set of transactions records their updates in the log.
▪ At commit point under WAL scheme these updates are saved on
database disk.
▪ No undo is required because no AFIM is flushed to the disk before a
transaction commits.
▪ After reboot from a failure the log is used to redo all the transactions
affected by this failure.
– Limitation: out of buffer space may be happened because transaction
changes must be held in the cache buffer until the commit point
– Type of deferred updated recovery environment
▪ Single User and Multiple user environment
a) Deferred Update in a single-user system
▪ There is no concurrent data sharing in a single user system.
▪ The data update goes as follows:
▪ A set of transactions records their updates in the log.
▪ At commit point under WAL scheme these updates are saved on
By Ashenafi Wubshet 14
database disk.
b) 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.
▪T4 and T5 are ignored because they didn’t reach their commit points
▪T2 and T3 are redone because their commit point is after the last
checkpoint
By Ashenafi Wubshet 15
▪ 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 AFIM.
By Ashenafi Wubshet 16
ii. Recovery Techniques Based on Immediate Update
▪ Undo/No-redo Algorithm
– In this algorithm AFIMs of a transaction are flushed to the
database disk under WAL before it commits.
– For this reason the recovery manager undoes all transactions
during recovery.
– No transaction is redone.
– It is possible that a transaction might have completed execution
and ready to commit but this transaction is also undone.
By Ashenafi Wubshet 17
iii. Shadow Paging
▪ Maintain two page tables during life of a transaction: current page
and shadow page table.
▪ When transaction starts, two pages are the same.
▪ Shadow page table is never changed thereafter and is used to restore
database in event of failure.
▪ During transaction, current page table records all updates to
database.
▪ When transaction completes, current page table becomes shadow
page table.
X Y
X' Y'
Database