Professional Documents
Culture Documents
Database Recovery Techniques
Database Recovery Techniques
Database Recovery Techniques
SONA V
2021239022
MSc INTEGRATED COMPUTER SCIENCE
RECOVERY AND ATOMICITY
⮚ Consider transaction Ti that transfers $50 from account A to account B with initial values of A
and B being $1000 and $2000 respectively.
⮚ Suppose the system crash has occurred and when the system restarts, the value of A would be
$950, while B would be $2000 which is inconsistent.
⮚ To ensure atomicity despite failures, we first output information describing the modifications
without modifying the database.
RECOVERY TECHNIQUES
i. Log Based Recovery
a. Deferred Recovery
b. Immediate Recovery
iii. Checkpoints
⮚ Log is a sequence of log records, recording all update activities in the database.
⮚ It has 4 parts
• Transaction identifier
• Data-item identifier
• Old value
• New value
UPDATE LOG RECORD
⮚ It is the location of the disk of the data item, consisting of the block identifier of the
⮚ It is the value that the data item will have after write.
UPDATE LOG RECORD
⮚ We represent an update log record as <Ti,Xi,Vi,Vj> indicating the transaction Ti has performed a
write on data item Xj.
⮚ Xj had value V1 before the write and has value V2 after write.
⮚ Other special log records exist
▪ <Ti start> Transaction Ti has started.
▪ <Ti commit> Transaction Ti has committed.
▪ <Ti abort> Transaction Ti has aborted.
DATABASE MODIFICATION
⮚ We know that, a transaction creates a log record prior to modifying the database.
⮚ The log records allow the system to undo changes made by a transaction in the event that the
⮚ It allows the system to redo changes made by a transaction if the transaction has committed.
DEFERRED DATABASE MODIFICATION
⮚ The deferred modification technique occurs if the transaction does not modify the database until
it has committed.
⮚ All the logs are created and stored in the stable storage, and the database
⮚ The Immediate modification technique occurs if database modification occurs while the
⮚ In this technique, the database is modified immediately after every operation. It follows an actual
database modification.
USING LOG TO REDO AND UNDO TRANSACTION
⮚ Consider a banking system. Let T0 be the transaction that transfers $50 from account A to
account B and T1 be the transaction that transfers $100 from account C.
T0 T1
read(A); read(C);
A:=A-50; C:=C-100;
write(A); write(C).
read(B);
B:=B+50;
write(B).
Log Database
<T0 start>
<T0 , A , 1000 , 950>
<T0 , B , 2000 , 2050>
A=950
B=2050
<T0 commit>
<T1 start>
<T1 , C , 700 , 600>
C=600
<T1 commit>
(a) (b)
(c)
(a)
⮚ Assume that the system crash has occurred after the log record for the step
write(B)
of transaction T0 has been written to the stable storage.
⮚ When the system comes back up, it finds the record <T0 start> in the log but no <T0 commit>
or <T0 abort> record.
⮚ Therefore, the Transaction T0 has to be undone (ie) undo(T0).
⮚ As a result, the values of A and B in the disk buffer are restored to $1000 and $2000
respectively.
(b)
⮚ Assume that the system crash has occurred after the log record for the step
write(C)
of transaction T1 has been written to the stable storage.
⮚ When the system comes back up, it finds the record <T0 start> in the log and the record <T0
commit>.
⮚ Therefore the transaction T0 has to perform the operation redo(T0) and the transaction T1 has to be
undone (ie) undo(T1).
⮚ As a result, the values of accounts A , B and C are $950, $2050, $700 respectively.
(c)
⮚ Assume that the system crash has occurred after the log record for the step
<T1 commit>
of transaction T1 has been written to the stable storage.
⮚ When the system comes back up, it finds the record <T0 start> and <T0 commit>
as do the records, <T1 start> and <T1 commit>.
⮚ Therefore the transaction T0 and T1 has to perform the operation redo(T0) and redo(T1).
⮚ As a result, the values of accounts A , B and C are $950, $2050, $600 respectively.
THANK YOU