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 appearing after [checkpoint] record. Checkpointing
Database Recovery 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. Recovery in a concurrent users environment.
Deferred Update with concurrent users 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 modifications 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 a modification is equivalent to multiple redone for the same modification.
Transactions and Recovery Types of Transactions Last CheckpointSystem Failure T1T1 T2T2 T3T3 T4T4 T5T5
Transactions and Recovery System Recovery Any transaction that was running at the time of failure needs to be undone and restarted Any transactions that committed since the last checkpoint need to be redone Transactions of type T 1 need no recovery Transactions of type T 3 or T 5 need to be undone and restarted Transactions of type T 2 or T 4 need to be redone
Transactions and Recovery Transaction Recovery UNDO and REDO: lists of transactions UNDO = all transactions running at the last checkpoint REDO = empty For each entry in the log, starting at the last checkpoint If a START TRANSACTION entry is found for T Add T to UNDO If a COMMIT entry is found for T Move T from UNDO to REDO
Transactions and Recovery Transaction Recovery T1T1 T2T2 T3T3 T4T4 T5T5 CheckpointFailure UNDO: T 2, T 3 REDO: Last Checkpoint Active transactions: T 2, T 3
Transactions and Recovery Transaction Recovery T1T1 T2T2 T3T3 T4T4 T5T5 CheckpointFailure UNDO: T 2, T 3, T 4 REDO: T4 Begins Add T 4 to UNDO
Transactions and Recovery Transaction Recovery T1T1 T2T2 T3T3 T4T4 T5T5 CheckpointFailure UNDO: T 2, T 3, T 4, T 5 REDO: T 5 begins Add T 5 to UNDO
Transactions and Recovery Transaction Recovery T1T1 T2T2 T3T3 T4T4 T5T5 CheckpointFailure UNDO: T 3, T 4, T 5 REDO: T 2 T 2 Commits Move T 2 to REDO
Transactions and Recovery Transaction Recovery T1T1 T2T2 T3T3 T4T4 T5T5 CheckpointFailure UNDO: T 3, T 5 REDO: T 2, T 4 T 4 Commits Move T 4 to REDO
Transactions and Recovery Forwards and Backwards Backwards recovery We need to undo some transactions Working backwards through the log we undo any operation by a transaction on the UNDO list This returns the database to a consistent state Forwards recovery Some transactions need to be redone Working forwards through the log we redo any operation by a transaction on the REDO list This brings the database up to date
FIGURE 19.4 An example of recovery using deferred update with concurrent transactions. (a) The READ and WRITE operations of four transactions. (b) System log at the point of crash. Recovery Techniques Based on Deferred Update
Transactions and Recovery Media Failures System failures are not too severe Only information since the last checkpoint is affected This can be recovered from the transaction log Media failures (disk crashes etc) are more serious The data stored to disk is damaged The transaction log itself may be damaged
Transactions and Recovery Backups Backups are needed to recover from media failure The transaction log and entire contents of the database is written to secondary storage (often tape) Time consuming, and often requires down time Backups frequency Frequent enough that little information is lost Not so frequent as to cause problems Every day (night) is common Backup storage
Transactions and Recovery Recovery from Media Failure Restore the database from the last backup Use the transaction log to redo any changes made since the last backup If the transaction log is damaged you can’t do step 2 Store the log on a separate physical device to the database The risk of losing both is then reduced