Database Recovery Recovery Buffer Management Recovery Facilities Recover Techniques Chapter 22.3(20.3)
Recovery(1) Recovery:Restoring the database to a correct state in the event of a failure Storage device: memory, Disk, Tape (or other offline storage) Failure system crashes: memory loss media failures: parts of disk loss application software errors:one or more transactions fail disasters and carelessness Sabotage (惡意破壞)
Recovery(2) Objective:guarantee atomicity and durability Write: Write to Buffer then flush to disk Transaction committed: redo(rollforward) Transaction uncomitted:undo(rollback)
Buffer Management Write back policy steal policy:allows write back before commit force policy:all page updated write back immediately when commit no-steal policy need very large buffer force policy has lower efficiency most DBMS employ steal,no-force policy
Recovery Facilities(1) backup mechanism full or incremental store backup on offline storage logging facilities DBMS maintains a special file called a log or journal contains info about all updates log contains:Transaction and checkpoint records Fig. 22(20).25,may contain other info for management maybe 2 or 3 copies,store on separated disk log file may be bottleneck of DBMS
Recovery Facilities(2) checkpoint facility how far the log file need to be traced back when failure occurs use checkpointing to limit the amount of searching and processing on log file. checkpoint: the point of synchronization between DB and log. All buffers are flush to Disk. once per 15-20 min. redo Transactions after CP, undo Transactions when failure occure recovery manager
Recover Techniques extensively damaged:restore backup data and redo transactions on log file inconsistent:use undo and redo deferred update:write to log file until commited then write into DB by using log records only redo is needed, can redo any times immediate update:write-ahead log protocol need redo and undo(reverse order) Shadow paging:use current and shadow page, not log file system
Example PostgreSQL MySQL http://www.postgresql.org/docs/8.1/interactive/backup.html MySQL http://dev.mysql.com/doc/refman/5.1/en/disaster- prevention.html