Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe
CHAPTER 22 Database Recovery Techiques Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe
Itroductio Recovery algorithms Recovery cocepts Write-ahead loggig I-place versus shadow updates Rollback Deferred update Immediate update Certai recovery techiques best used with specific cocurrecy cotrol methods Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 22-3
22.1 Recovery Cocepts Recovery process restores database to most recet cosistet state before time of failure Iformatio kept i system log Typical recovery strategies Restore backed-up copy of database Best i cases of extesive damage Idetify ay chages that may cause icosistecy Best i cases of ocatastrophic failure Some operatios may require redo Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 22-4
Recovery Cocepts (cot d.) Deferred update techiques Do ot physically update the database util after trasactio commits Udo is ot eeded; redo may be eeded Immediate update techiques Database may be updated by some operatios of a trasactio before it reaches commit poit Operatios also recorded i log Recovery still possible Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 22-5
Recovery Cocepts (cot d.) Udo ad redo operatios required to be idempotet Executig operatios multiple times equivalet to executig just oce Etire recovery process should be idempotet Cachig (bufferig) of disk blocks DBMS cache: a collectio of i-memory buffers Cache directory keeps track of which database items are i the buffers Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 22-6
Recovery Cocepts (cot d.) Cache buffers replaced (flushed) to make space for ew items Dirty bit associated with each buffer i the cache Idicates whether the buffer has bee modified Cotets writte back to disk before flush if dirty bit equals oe Pi-upi bit Page is pied if it caot be writte back to disk yet Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 22-7
Recovery Cocepts (cot d.) Mai strategies I-place updatig Writes the buffer to the same origial disk locatio Overwrites old values of ay chaged data items Shadowig Writes a updated buffer at a differet disk locatio, to maitai multiple versios of data items Not typically used i practice Before-image: old value of data item After-image: ew value of data item Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 22-8
Recovery Cocepts (cot d.) Write-ahead loggig Esure the before-image (BFIM) is recorded Appropriate log etry flushed to disk Necessary for UNDO operatio if eeded UNDO-type log etries REDO-type log etries Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 22-9
Recovery Cocepts (cot d.) Steal/o-steal ad force/o-force Specify rules that gover whe a page from the database cache ca be writte to disk No-steal approach Cache buffer page updated by a trasactio caot be writte to disk before the trasactio commits Steal approach Recovery protocol allows writig a updated buffer before the trasactio commits Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 22-10
Recovery Cocepts (cot d.) Force approach All pages updated by a trasactio are immediately writte to disk before the trasactio commits Otherwise, o-force Typical database systems employ a steal/oforce strategy Avoids eed for very large buffer space Reduces disk I/O operatios for heavily updated pages Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 22-11
Recovery Cocepts (cot d.) Write-ahead loggig protocol for recovery algorithm requirig both UNDO ad REDO BFIM of a item caot be overwritte by its after image util all UNDO-type log etries have bee force-writte to disk Commit operatio of a trasactio caot be completed util all REDO-type ad UNDO-type log records for that trasactio have bee forcewritte to disk Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 22-12
Checkpoits i the System Log ad Fuzzy Checkpoitig Takig a checkpoit Susped executio of all trasactios temporarily Force-write all mai memory buffers that have bee modified to disk Write a checkpoit record to the log, ad forcewrite the log to the disk Resume executig trasactios DBMS recovery maager decides o checkpoit iterval Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 22-13
Checkpoits i the System Log ad Fuzzy Checkpoitig (cot d.) Fuzzy checkpoitig System ca resume trasactio processig after a begi_checkpoit record is writte to the log Previous checkpoit record maitaied util ed_checkpoit record is writte Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 22-14
Trasactio Rollback Trasactio failure after update but before commit Necessary to roll back the trasactio Old data values restored usig udo-type log etries Cascadig rollback If trasactio T is rolled back, ay trasactio S that has read value of item writte by T must also be rolled back Almost all recovery mechaisms desiged to avoid this Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 22-15
Figure 22.1 Illustratig cascadig rollback (a process that ever occurs i strict or cascadeless schedules) (a) The read ad write operatios of three trasactios (b) System log at poit of crash (c) Operatios before the crash Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 22-16
Trasactios that Do Not Affect the Database Example actios: geeratig ad pritig messages ad reports If trasactio fails before completio, may ot wat user to get these reports Reports should be geerated oly after trasactio reaches commit poit Commads that geerate reports issued as batch jobs executed oly after trasactio reaches commit poit Batch jobs caceled if trasactio fails Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 22-17
22.2 NO-UNDO/REDO Recovery Based o Deferred Update Deferred update cocept Postpoe updates to the database o disk util the trasactio completes successfully ad reaches its commit poit Redo-type log etries are eeded Udo-type log etries ot ecessary Ca oly be used for short trasactios ad trasactios that chage few items Buffer space a issue with loger trasactios Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 22-18
NO-UNDO/REDO Recovery Based o Deferred Update (cot d.) Deferred update protocol Trasactio caot chage the database o disk util it reaches its commit poit All buffers chaged by the trasactio must be pied util the trasactio commits (o-steal policy) Trasactio does ot reach its commit poit util all its REDO-type log etries are recorded i log ad log buffer is force-writte to disk Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 22-19
NO-UNDO/REDO Recovery Based o Deferred Update (cot d.) Figure 22.2 A example of a recovery timelie to illustrate the effect of checkpoitig Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 22-20
22.3 Recovery Techiques Based o Immediate Update Database ca be updated immediately No eed to wait for trasactio to reach commit poit Not a requiremet that every update be immediate UNDO-type log etries must be stored Recovery algorithms UNDO/NO-REDO (steal/force strategy) UNDO/REDO (steal/o-force strategy) Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 22-21
Figure 22.3 A example of recovery usig deferred update with cocurret trasactios (a) The READ ad WRITE operatios of four trasactios (b) System log at the poit of crash Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 22-22
22.4 Shadow Pagig No log required i a sigle-user eviromet Log may be eeded i a multiuser eviromet for the cocurrecy cotrol method Shadow pagig cosiders disk to be made of fixed-size disk pages Directory with etries is costructed Whe trasactio begis executig, directory copied ito shadow directory to save while curret directory is beig used Shadow directory is ever modified Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 22-23
Shadow Pagig (cot d.) New copy of the modified page created ad stored elsewhere Curret directory modified to poit to ew disk block Shadow directory still poits to old disk block Failure recovery Discard curret directory Free modified database pages NO-UNDO/NO-REDO techique Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 22-24
Shadow Pagig (cot d.) Figure 22.4 A example of shadow pagig Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 22-25
22.5 The ARIES Recovery Algorithm Used i may IBM relatioal database products Uses a steal/o-force approach for writig Cocepts Write-ahead loggig Repeatig history durig redo Retrace all database system actios prior to crash to recostruct database state whe crash occurred Loggig chages durig udo Prevets ARIES from repeatig completed udo operatios if failure occurs durig recovery Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 22-26
The ARIES Recovery Algorithm (cot d.) Aalysis step Idetifies dirty (updated) pages i the buffer ad set of trasactios active at the time of crash Determies appropriate start poit i the log for the REDO operatio REDO Reapplies updates from the log to the database Oly ecessary REDO operatios are applied Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 22-27
The ARIES Recovery Algorithm (cot d.) UNDO Log is scaed backward Operatios of trasactios that were active at the time of the crash are udoe i reverse order Every log record has associated log sequece umber (LSN) Idicates address of log record o disk Correspods to a specific chage of some trasactio Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 22-28
ARIES Recovery Example Figure 22.5 A example of recovery i ARIES (a) The log at poit of crash (b) The Trasactio ad Dirty Page Tables at time of checkpoit (c) The Trasactio ad Dirty Page Tables after the aalysis phase Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 16-29
22.6 Recovery i Multidatabase Systems Two-level recovery mechaism Global recovery maager (coordiator) eeded to maitai recovery iformatio Coordiator follows two-phase commit protocol Phase 1: Prepare for commit message Ready to commit or caot commit sigal retured Phase 2: Issue commit sigal Either all participatig databases commit the effect of the trasactio or oe of them do Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 22-30
Recovery i Multidatabase Systems (cot d.) Always possible to recover to a state where either the trasactio is committed or it is rolled back Failure durig phase 1 requires rollback Failure durig phase 2 meas successful trasactio ca recover ad commit Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 22-31
22.7 Database Backup ad Recovery from Catastrophic Failures Database backup Etire database ad log periodically copied oto iexpesive storage medium Latest backup copy ca be reloaded from disk i case of catastrophic failure Backups ofte moved to physically separate locatios Subterraea storage vaults Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 22-32
Database Backup ad Recovery from Catastrophic Failures (cot d.) Backup system log at more frequet itervals ad copy to magetic tape System log smaller tha database Ca be backed up more frequetly Beefit: users do ot lose all trasactios sice last database backup Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 22-33
22.8 Summary Mai goal of recovery Esure atomicity property of a trasactio Cachig I-place updatig versus shadowig Before ad after images of data items UNDO ad REDO operatios Deferred versus immediate update Shadow pagig Catastrophic failure recovery Copyright 2016 Ramez Elmasri ad Shamkat B. Navathe Slide 22-34