Recovery
Recovery
Database Recovery
Techniques
19.1 p 611-617
Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition
Copyright © 2004 Pearson Education, Inc.
Note
Chapter 19-4
19.1.1 Recovery Overview
p 612
Chapter 19-5
19.1.1 Recovery Overview
Types of Failure
Chapter 19-6
Failure Challenge 3
database
Application
code DBMS
Log
tape archival
storage
DBMS First, restore
the back up
copy of the
database
log
Then, reapply the operations
of committed transactions
up to the point of failure.
Chapter 19-9
How to Prepare for Recovery from
Catastrophic Failure
tape archival
storage
DBMS Periodically
copy the entire
database to
backup storage
p 630
Chapter 19-10
How to Recover from non-Catastrophic Failure
Chapter 19-11
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 are stored in a sequential file called
Transaction log.
Back P and Next P point to the previous and next log records of the same
transaction.
Chapter 19-12
19.1.1 Recovery Overview
Chapter 19-13
19.1.1 Recovery Outline
Database Data Update Techniques
database
memory
3. memory 4.
buffer data
catalog
Chapter 19-14
Recall: Introduction to Transaction
Processing
write_item(X) command includes the following
steps:
2. Find the address of the disk block that contains item X.
3. Copy that disk block into a buffer in main memory (if that
disk block is not already in some main memory buffer).
4. Copy item X from the program variable named X into its
correct location in the buffer.
5. Store the updated block from the buffer back to disk (either
immediately or at some later point in time).
1.
database
Application
code DBMS
2.
data
memory
3. memory catalog
buffer 4.
Chapter 19-15
Write_item Challenge #14
1.
database
Application
code DBMS
2.
data
memory
3. memory catalog
buffer 4.
• Immediate Update:
As soon as a data item is modified in cache,
the disk copy is updated.
Application
code DBMS database
memory
3. memory data
buffer 4. catalog
Immediate Update:
As soon as a data item is modified in cache,
the disk copy is updated.
Application
code DBMS database
memory
3. memory data
buffer 5. catalog
"Force writing" of 4.
the transaction log Log
Chapter 19-18
Deferred Update
Deferred Update:
All modified data items in the cache are written
to the database either after a transaction ends its
execution or after a fixed number of transactions
have completed their execution.
Application
code DBMS database
memory
3. memory data
buffer 5. catalog
database
Application
code DBMS
Application database
code DBMS
database
Application
code DBMS
Chapter 19-22
Deferred Update (when) with Shadow Update
(where)
Deferred Update: All modified data items in the cache are written to the
database either after a transaction ends its execution or after a fixed number
Shadow update: The modified version of a data item does not
overwrite its disk copy but is written at a separate disk location.
Application database
code DBMS
Chapter 19-23
DBMS Components
DBMS
Buffer Manager/
Cache Manager
Recovery Manager
Lock Manager
Chapter 19-26
19.1.3 Write-Ahead Logging (WAL)
memory
buffer
"force writing" of
Log p 614
the transaction log
Chapter 19-27
Immediate Update (when) with In-Place
Update (where) and WAL
Immediate Update: As soon as a data item is modified in cache,
the disk copy is updated.
In-place update: The disk version of the data item is overwritten
by the cache version.
database
Application
code DBMS
Where data
4. "Force writing" of 4. Log is written to
the transaction log (for
Undo) BFIM
Chapter 19-28
19.1.3 Write-Ahead Logging
database
Application
code DBMS
database
Application
code DBMS
T107 - Although the log says committed, the DBMS does not
know that the crash did not happen after the log was written and
before the database was updated. Thus it must undo this
transaction (to remove the database AFIM), and will re-do
(completely) it from the data in the log.
Chapter 19-32
19.1.3 Steal/No-Steal and Force/No-Force
If the file does not reside on a local device then no such guarantee is made.
Checkpointing
From 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:
2. Suspend execution of transactions temporarily.
3. Force write all modified buffer data to disk.
4. Write a [checkpoint] record to the log, save the log to disk.
5. Resume normal transaction execution.
During recovery redo or undo is required to transactions
appearing after [checkpoint] record.
p 615
Chapter 19-35
Transaction Log
Chapter 19-36
Transaction Log
Sample Transaction Log
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
T3 0 9 R N N = 400 N = 400
T1 5 nil End
checkpoint T1,T2,T3
The checkpoint log entry identifies all the transactions (Ts) that
are active. On subsequent failure, redo those Ts active at the last
checkpoint and any subsequent Ts which have a start and a
commit record in the log. Undo all Ts which were active at
the time of crash.
Chapter 19-37
19.1.5 Transaction Rollback
p 616
Chapter 19-38
19.1.5 Transaction Rollback
Roll-back
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)
p 617
Chapter 19-39
19.1.5 Transaction Rollback
Chapter 19-42
Notes
Chapter 19-43
Checkpoint Challenge 6
Log
...
checkpoint T21 database
T22 write X
T23 write Y data
commit T22
memory catalog
failure! buffer
wiped out!
Chapter 19-45