Professional Documents
Culture Documents
CHAPTER - 5 - Database Recovery Technique
CHAPTER - 5 - Database Recovery Technique
1
Introduction
• A computer system can be failed due to variety of reasons like disk
crash, power fluctuation, software error, sabotage and fire or flood at
computer site.
• There are several methods by which you can recover database from failure state.
5
Recovery Concept Cont’d . . .
• Log records are maintained in a serial manner in which different activities
are happened.
[Ti, Aj, V1, V2] : It records to log when Ti updates data item Aj, where
8
There are two types of Log Based Recovery techniques
» further, if a transaction reads a data item that it has updated, it must read
the value from its local copy.
9
There are two types of Log Based Recovery techniques
• In deferred database modification technique, deferred (stops) all the write operations
of any Transaction Ti until it partially commits.
• then a log record [Ti, Aj, V1, V2] is saved in log and it is used to modify database.
11
• Suppose, the initial values of A, B and C Accounts are 500 Birr, 1000
Birr and 600 Birr respectively,
12
• For a Redo Operation, log must contain [Ti start] and [Ti commit] log
records.
13
Crash will happen at any time of execution of transactions. Suppose
Crash Happened
1. After write (A) of T1: At that time log records in log are shown in Figure
10.3(a).
• There is no need to redo operation because no commit record
appears in the log.
• Log records of T1 can be deleted.
2. After write (C) of T2: At that time log records in log are shown in Figure
10.3(b).
• In this situation, you have to redo T1 because both [T1 start] and
[T1 commit] appears in log.
• After redo operation, value of A and B are 300 Birr and 1200 Birr
respectively.
• Values remain same because redo is idempotent.
• It means, real database is modified just after the write operation but after log
record is written to stable storage.
• For a transaction Ti to be undone, log must contain only [Ti start] record.
16
Crash will happen at any time of execution of transaction. Suppose
Crash Happened
1. After write (A) of T1: At that time log records in log are shown in Figure
10.5(a).
• Here only [T1 start] exists so undo transaction T1.
• As a result, Account A restores its old value 500.
2. After write (C) of T2: At that time log records in log are shown in Figure
10.5(b).
• During back-up record [T2 start] appears but there is no [T2 commit],
so undo transaction T2.
• As a result, Account C restores its old value 600.
• When you found both [T1 start] and [T1 commit] records in log, redo
transaction T1 and account A and B both keep their new value.
3. During recovery: If system is crashed at the time of recovery, simply
starts the recovery again.
17
Checkpoints
• Both the techniques discussed earlier ensures recovery from failure state, but they
have some disadvantages such as : -
1) They are time consuming because successfully completed transactions have
to be redone.
2) Searching procedure is also time consuming because the whole log has to
be searched.
• All the transactions completed successfully or having [Ti commit] record before
checkpoint record need not to be redone.
18
Checkpoints Cont’d . . .
• During the time of failure, search the most recent checkpoint.
• After searching checkpoint, search the most recent transaction Ti that started
execution before that checkpoint but not completed.
• The main idea behind the shadow paging is to keep two page tables in
database, one is used for current operations and other is used in case of
recovery.
• The entries which are present in current page table are used to point to
most recent database pages on disk.
20
Shadow Paging Cont’d . . .
• Another table i.e., shadow page table is used when the transaction starts
which is copying current page table.
• After this, shadow page table gets saved on disk and current page table
is going to be used for transaction.
• After performing all the above operations, the following steps are needed to commit Ti
1. Modified pages are transferred from main memory to disk (non-volatile or stable storage)
3. Change current page table into shadow page table (by changing the physical address).
• Shadow page table must be stored in non-volatile or stable storage because it is used at
the time of recovery.
• After every successful completion of transaction, current page table is converted into
shadow page table.
24
Shadow Paging - Example Figure
25
Page Table Cont’d . . .
database systems.
• For making the search simple, store shadow page table on fixed
26
Advantages and Disadvantages of Page Table
Advantages: The major advantages of shadow paging are:-
1. No overhead for writing log records.
2. No Undo / No Redo Algorithm.
3. Recovery is faster.
3. Each contain pointer to a page on disk (1 to 1st page on database and so on…)
a) The shadow page table is never changed over the duration of the
transaction.
write operation.
c) All input and output operations use the current page table to locate