Database Recovery Unit 12 Database Recovery 12-1.

Slides:



Advertisements
Similar presentations
Transactions generalities 1 Transactions - generalities.
Advertisements

Data recovery 1. 2 Recovery - introduction recovery restoring a system, after an error or failure, to a state that was previously known as correct have.
Chapter 16: Recovery System
TRANSACTION PROCESSING SYSTEM ROHIT KHOKHER. TRANSACTION RECOVERY TRANSACTION RECOVERY TRANSACTION STATES SERIALIZABILITY CONFLICT SERIALIZABILITY VIEW.
1 CSIS 7102 Spring 2004 Lecture 8: Recovery (overview) Dr. King-Ip Lin.
Chapter 20: Recovery. 421B: Database Systems - Recovery 2 Failure Types q Transaction Failures: local recovery q System Failure: Global recovery I Main.
Recovery CPSC 356 Database Ellen Walker Hiram College (Includes figures from Database Systems by Connolly & Begg, © Addison Wesley 2002)
CSCI 3140 Module 8 – Database Recovery Theodore Chiasson Dalhousie University.
Database Systems, 8 th Edition Concurrency Control with Time Stamping Methods Assigns global unique time stamp to each transaction Produces explicit.
§1. Recovery Recovery (and concurrency) is tied to notion of transaction processing Transaction is a logical.
Crash Recovery. Review: The ACID properties A A tomicity: All actions in the Xaction happen, or none happen. C C onsistency: If each Xaction is consistent,
Recovery 10/18/05. Implementing atomicity Note, when a transaction commits, the portion of the system implementing durability ensures the transaction’s.
Transaction Management and Concurrency Control
CS-550 (M.Soneru): Recovery [SaS] 1 Recovery. CS-550 (M.Soneru): Recovery [SaS] 2 Recovery Computer system recovery: –Restore the system to a normal operational.
Chapter 8 : Transaction Management. u Function and importance of transactions. u Properties of transactions. u Concurrency Control – Meaning of serializability.
1 Transaction Management Database recovery Concurrency control.
Database Systems Chapter 17 ITM 354 Dr. Rick Kazman.
©Silberschatz, Korth and Sudarshan17.1Database System Concepts Chapter 17: Recovery System Failure Classification Storage Structure Recovery and Atomicity.
©Silberschatz, Korth and Sudarshan17.1Database System Concepts 3 rd Edition Chapter 17: Recovery System Failure Classification Storage Structure Recovery.
Transaction Management WXES 2103 Database. Content What is transaction Transaction properties Transaction management with SQL Transaction log DBMS Transaction.
Transactions and Recovery
TRANSACTIONS A sequence of SQL statements to be executed "together“ as a unit: A money transfer transaction: Reasons for Transactions : Concurrency control.
Academic Year 2014 Spring. MODULE CC3005NI: Advanced Database Systems “DATABASE RECOVERY” (PART – 1) Academic Year 2014 Spring.
1 Database Systems CS204 Lecture 21 Transaction Processing I Asma Ahmad FAST-NU April 7, 2011.
Switch off your Mobiles Phones or Change Profile to Silent Mode.
Transaction Processing Concepts. 1. Introduction To transaction Processing 1.1 Single User VS Multi User Systems One criteria to classify Database is.
Chapter 15 Recovery. Topics in this Chapter Transactions Transaction Recovery System Recovery Media Recovery Two-Phase Commit SQL Facilities.
Lecture 12 Recoverability and failure. 2 Optimistic Techniques Based on assumption that conflict is rare and more efficient to let transactions proceed.
Recovery Chapter 6.3 V3.1 Napier University Dr Gordon Russell.
CMPT 454, Simon Fraser University, Fall 2009, Martin Ester 294 Database Systems II Coping With System Failures.
Recovery System By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany) DIRECTOR ARUNAI ENGINEERING COLLEGE TIRUVANNAMALAI.
Chapter 16 Recovery Yonsei University 1 st Semester, 2015 Sanghyun Park.
Chapter 15 Recovery. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.15-2 Topics in this Chapter Transactions Transaction Recovery System.
CSCI Recovery Control Techniques 1 RECOVERY CONTROL TECHNIQUES Dr. Awad Khalil Computer Science Department AUC.
Database Systems Recovery & Concurrency Lecture # 20 1 st April, 2011.
Chapter 10 Recovery System. ACID Properties  Atomicity. Either all operations of the transaction are properly reflected in the database or none are.
Section 06 (a)RDBMS (a) Supplement RDBMS Issues 2 HSQ - DATABASES & SQL And Franchise Colleges By MANSHA NAWAZ.
Academic Year 2014 Spring. MODULE CC3005NI: Advanced Database Systems “DATABASE RECOVERY” (PART – 2) Academic Year 2014 Spring.
Chapter 17: Recovery System
Transactions.
Database System Concepts ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 17: Recovery System.
Recovery technique. Recovery concept Recovery from transactions failure mean data restored to the most recent consistent state just before the time of.
CREATE THE DIFFERENCE Back ups and Recovery. CREATE THE DIFFERENCE Aims This lecture aims to cover –Back ups –Transaction logging –Security threats.
Transactional Recovery and Checkpoints. Difference How is this different from schedule recovery? It is the details to implementing schedule recovery –It.
Database Recovery Zheng (Godric) Gu. Transaction Concept Storage Structure Failure Classification Log-Based Recovery Deferred Database Modification Immediate.
Recovery Techniques 1.Recovery concepts 2.Recovery techniques based on Deferred Update –No-UNDO/REDO 3.Recovery techniques based on Immediate Update –UNDO/REDO.
Jun-Ki Min. Slide Purpose of Database Recovery ◦ To bring the database into the last consistent stat e, which existed prior to the failure. ◦
16.1Database System Concepts - 6 th Edition Chapter 16: Recovery System Failure Classification Storage Structure Recovery and Atomicity Log-Based Recovery.

Database Recovery Techniques
Transactional Recovery and Checkpoints
Transaction Management and Concurrency Control
File Processing : Recovery
Chapter 10 Recover System
Transaction Processing
Operating System Reliability
Operating System Reliability
Ch 21: Transaction Processing
Chapter 16: Recovery System
Operating System Reliability
Operating System Reliability
Chapter 10 Transaction Management and Concurrency Control
Outline Introduction Background Distributed DBMS Architecture
Module 17: Recovery System
Recovery System.
Database Recovery 1 Purpose of Database Recovery
STRUCTURE OF PRESENTATION :
Recovery Unit 4.4 Dr Gordon Russell, Napier University
Operating System Reliability
Operating System Reliability
Presentation transcript:

Database Recovery Unit 12 Database Recovery 12-1

Wei-Pang Yang, Information Management, NDHU 12-2 Contents  12.1 Introduction  12.2 Transactions  12.3 Transaction Failures and Recovery  12.4 System Failures and Recovery  12.5 Media Failures and Recovery

Introduction

Wei-Pang Yang, Information Management, NDHU 12-4 Database Recovery: Introduction  The Problem of Database Recovery To restore the database to a state that is known to be correct after some failures.  Possible Failures programming errors, e.g. divide by 0, QTY < 0 hardware errors, e.g. disk crashed operator errors, e.g. mounting a wrong tape power supply, fire,...  Principle of Recovery: Backup is necessary

Wei-Pang Yang, Information Management, NDHU 12-5 Database Recovery (cont.)  Basic approach 1. Dump database periodically. 2. Write a log record for every change. e.g. E#, old_value, new_value, … 3. If a failure occurs: CASE1 : DB is damaged ==> archive copy + redo log = current DB. CASE2 : DB is not damaged but contents unreliable ==> undo some log. 8:00 update log 10:00 8:00 -10:00

Transactions unit of Work unit of Recovery unit of Concurrency (Unit 13)

Wei-Pang Yang, Information Management, NDHU 12-7 Transactions: Concepts A logical unit of work. Atomic from the point of view of the end-user. An all-or-nothing proposition. TRANSFER : PROC; /* transfer account */ GET (FROM, TO, AMOUNT); FIND UNIQUE (ACCOUNT WHERE ACC#=FROM); ASSIGN (BALANCE - AMOUNT) TO BALANCE; IF BALANCE < 0 THEN DO; PUT ( 'INSUFFICIENCY FUNDS'); ROLLBACK; END; ELSE DO; FIND UNIQUE (ACCOUNT WHERE ACC# = TO); ASSIGN (BALANCE + AMOUNT) TO BALANCE; PUT ('TRANSFER COMPLETE' ); COMMIT; END;

Wei-Pang Yang, Information Management, NDHU 12-8 Transactions: Example [CASCADE CHANGE ON S.S# TO SP.S#] CHANGE: PROC OPTIONS (MAIN) EXEC SQL WHENEVER SQLERROR GOTO UNDO; GET LIST (SX, SY); (i) EXEC SQL UPDATE S SET S# =: SY; WHERE S# =:SX; (ii) EXEC SQL UPDATE SP SET S# =: SY; WHERE S# =: SX; EXEC SQL COMMIT ; GO TO FINISH; UNDO: EXEC SQL ROLLBACK; FINISH: RETURN; END S# S1 S001 S S# S1 S001 SP

Wei-Pang Yang, Information Management, NDHU 12-9 Transactions: Structure  Structure of a Transaction BEGIN TRANSACTION; /* application specified sequence of operations*/. COMMIT; /* signal successful termination */ (or ROLLBACK; /* signal unsuccessful termination*/)  Implicit BEGIN TRANSACTION, COMMIT, ROLLBACK may be implicit: Program initiation BEGIN TRANSACTION Normal termination COMMIT Abnormal termination ROLLBACK  Program and Transaction : one program may contain several transactions. program initiation BEGIN TRANSACTION COMMIT BEGIN TRANSACTION ROLLBACK Time Tx1 Tx2 BEGIN TRANSACTION COMMIT program termination Tx3

Wei-Pang Yang, Information Management, NDHU Transactions: Manager  Transaction cannot be nested:  Transaction Manager: Transaction should not be lost, or partially done, or done more than once Consider the CASCADE example, if the system crashed between two updates ==> the first update must be undone ! Tx2 Tx1 Time BEGIN TRANSACTION BEGIN TRANSACTION COMMIT failure Does Tx2 need to be rolled back ?

Wei-Pang Yang, Information Management, NDHU Transactions: Commit and Rollback COMMIT: signal successful end-of-transaction. all updates made by that transaction can now be made permanent. (e.g. buffer to disk) ROLLBACK: signal unsuccessful end-of-transaction. the database may be in an inconsistent state. all update made by that transaction so far must be 'rolled back or undone' How to undone an update ? system maintain a log or journal on tape or disk on which details of all update are recorded. Begin Tx update write Commit End Tx

Wei-Pang Yang, Information Management, NDHU Transactions: Synchronization Point (SynchPoint) Represents the boundary between two consecutive transactions. Corresponds to the end of logical unit of work. A point at which the database is in a state of consistency. Established by COMMIT, ROLLBACK, and program initiation. When a synchpoint is established: All updates since the previous synchpoint are committed (COMMIT) or undone (ROLLBACK) All database positioning is lost. (e.g. cursor). All record locks are released. program initiation BEGIN TRANSACTION COMMIT BEGIN TRANSACTION ROLLBACK program termination SynchPoint......

Wei-Pang Yang, Information Management, NDHU Types of Transaction Failure  Type 1 Transaction Failures: detected by the application program itself. e.g. Insufficient Funds (balance < 0) How to handle ? Issue the ROLLBACK command after the detection. (ref. p.12-7)  Type2 Transaction Failures: not explicitly handled by the application e.g. divide by zero, arithmetic overflow,...  System Failures (Soft crash): affect all transactions currently in progress, but do not damage the database. e.g. CPU failure.  Media Failures (Hard crash): damage the database. affect all transactions currently using that portion. e.g. disk head crash. Application program 處理 § 12.3 § 12.4 § 12.5

Type 2 Transaction Failures and Recovery

Wei-Pang Yang, Information Management, NDHU Transaction Failures and Recovery  Transaction Failures: failures caused by unplanned, abnormal program termination. arithmetic overflow divided by zero storage protection violation log overflow...  How to recover transaction failures ? System force a rollback. the rollback is coordinated by Recovery Manager. working backward through the log to undo changes (replace new value by old value) until the “BEGIN TRANSACTION” is encountered.

Wei-Pang Yang, Information Management, NDHU UNDO Logic and REDO Logic  UNDO Logic => cause the rollback procedure to be restarted from the beginning. Idempotent Property : [Gray '78] UNDO ( UNDO ( UNDO (... ( x ) ) ) = UNDO ( x ) for all x i.e. undoing a given change any number of times is the same as undoing it exactly once.  REDO Logic REDO (REDO (REDO (...(x))) = REDO (x) for all x. UNDO failure failure again

Wei-Pang Yang, Information Management, NDHU Log  On-line log (active log) v.s. Off-line log (archive log) : log data: 200 million byte/day ==> infeasible to be stored entirely on-line active log: stored on disk if full ==> dump to tape ==> archive log.  Log Compression Archive log can be compressed => reduce storage, and then increasing efficiency How to compress archive log ? log records for transactions that failed to commit can be deleted (since they have been rolled back). old values are no longer needed for the transactions that did commit (since they will never have to be undone). changes can be consolidated (only the final value is kept) Log: 100 –10 90 r cancel 只可能做 redo program initiation BEGIN TRANSACTION COMMIT BEGIN TRANSACTION ROLLBACK Time Tx1 Tx2 BEGIN TRANSACTION COMMIT program termination Tx3

Wei-Pang Yang, Information Management, NDHU Long Transaction Transaction is unit of work, and unit of recovery. Transaction should be short. => reduce the amount that has to be undone. long transaction => subdivided into multiple transactions. T 1 : Update all supplier records, S. T 11 : Update all supplier records for supplier name is 'A%'. T 12 : Update all supplier records for supplier name is 'B%'. T 1,26 : Update all supplier records for supplier name is 'Z%'

System Failures and Recovery

Wei-Pang Yang, Information Management, NDHU System Failures and Recovery  Critical point : contents of main storage are lost, in particular, the database buffers are lost. e.g. CPU failure.  How to recover ? (1) UNDO the transactions in progress at the time of failure. (2) REDO the transactions that successfully complete but did not write to the physical disk.  e.g. T 3,T 5 tctf Time T1 T2 T3 T4 T5 check point system failure T1: no need to be undone or redone T2, T4: must be redone T3, T5: must be undone ? ?

Wei-Pang Yang, Information Management, NDHU System Failures and Recovery  How does the system know: which transaction to redo and which to undo? Taking a check point: at certain prescribed intervals involves: (1) writing the contents of the database buffers out to the physical database. e.g. disk (2) writing a special checkpoint record (contains a list of transactions which are in progress) e.g. {T2, T3} in progress e.g. T 3,T 5 e.g. T 1 tctf Time T1 T2 T3 T4 T5 check point system failure T1: no need to be undone or redone T2, T4: must be redone T3, T5: must be undone ? ?

Wei-Pang Yang, Information Management, NDHU System Failures and Recovery (cont.) Decide undo and redo list Decide the undo list and redo list by the following procedure : STEP1: UNDO-list = list of transactions given in the checkpoint record = {T2, T3} REDO-list = { } STEP2: Search forward through the log, starting from the checkpoint, to the end of log: if a 'BEGIN TRANSACTION' is found => add to UNDO-list {T2, T3, T4, T5} if a 'COMMIT' is found => remove from UNDO-list to REDO-list UNDO-list = {T3, T5} REDO-list = {T2, T4} Undo: System works backward through the log, undoing the UNDO-List. Redo: System then works forward through the log, redoing the REDO-List 做一半的,要 undo 應該已做完,不確定有無 write to disk

Wei-Pang Yang, Information Management, NDHU Write-Ahead Log Protocol  Write-Ahead Log Protocol (i.e. Log first protocol) Note : 'write a change to database' and 'write the log record to log' are two distinct operations => failure may occur between them! Before writing a record to physical database, the log record must first be written to physical log. Before committing a transaction, all log records must first be written to physical log. Time Write logdatabase Time Write db Commit Write log Write db Write log Write Commit log

Wei-Pang Yang, Information Management, NDHU Write-Ahead Log Protocol (cont.) tctf Time T1 T2 T3 T4 T5 check point system failure T1: no need to be undone or redone T2, T4: must be redone T3, T5: must be undone ? ?  Why log need to write ahead? (Think!) Time Write db Commit Write log Write db Write log Write Commit log Case 1 Case 2

Media Failures and Recovery

Wei-Pang Yang, Information Management, NDHU Types of Transaction Failure  Type 1 Transaction Failures: detected by the application program itself. e.g. Insufficient Funds (balance < 0) How to handle ? Issue the ROLLBACK command after the detection. (ref. p.12-7)  Type2 Transaction Failures: not explicitly handled by the application e.g. divide by zero, arithmetic overflow,...  System Failures (Soft crash): affect all transactions currently in progress, but do not damage the database. e.g. CPU failure.  Media Failures (Hard crash): damage the database. affect all transactions currently using that portion. e.g. disk head crash. Application program 處理 § 12.3 § 12.4 § 12.5

Wei-Pang Yang, Information Management, NDHU Media Failures and Recovery  Critical point: Some portion of the secondary storage is damaged.  How to recover? (1) load the database to new device from the most recent archive copy (old DB.) (2) use the log (both active and archive) to redo all the transactions that are completed since that dump was taken. Note: Assume log dose not fail. (Duplex log to avoid log failure.) Old DBlog New DB Report

Wei-Pang Yang, Information Management, NDHU end of unit 12