Docsity

DataBase Development and Implementation Lec13 - Database Recovery, Study notes of Database Management Systems (DBMS)

Toggle sidebar
bg1
DBDI
Lecture 13_DB Recovery 1
Ala Al-Zobaidie
DBDI / Lecture 13
Database Recovery
The slides are based on the textbook Fundamentals of Database Systems by
Elmasri & Navathe
30/05/2007 DBDI 2
Lecture - Objectives
• Recovery Control
– Some causes of database failure.
– Purpose of transaction log file.
– Purpose of Checkpointing.
– How to recover from DB failure.
• Cashing and Flashing
• Deferred & Immediate updates
• Shadowing technique.
30/05/2007 DBDI 3
Database Recovery
• The restoration of a Database to a
consistent state after system failure.
• DBA should ensure that a complete copy
of the DB is stored at regular intervals in
an archive file (Periodic full backups).
• DB can be restored to a consistent and
up-to-date state using these archives.
30/05/2007 DBDI 4
Why Recovery Control
•Two types of storage:
Volatile (main memory) and Nonvolatile.
•Volatile storage
•does not survive system crashes.
•Stable storage
•represents information that has been
replicated in several nonvolatile storage
media with independent failure modes.
30/05/2007 DBDI 5
Types of Failures
• System crashes
– resulting in loss of main memory.
• Media failures
– resulting in loss of parts of secondary storage.
• Application software errors.
– Transaction Failures
– Transaction aborts due to software bugs, or deadlocks
– Average of 3% of transactions abort abnormally (not user-
intended)
• Natural physical disasters.
• Carelessness or unintentional destruction of
data or facilities.
• Sabotage.
30/05/2007 DBDI 6
Transactions & Recovery /1
• Transactions represent basic unit of
recovery.
• Recovery Manager (RM) responsible for
Atomicity and Durability.
• If failure occurs between Commit and
Flushing then,
to ensure Durability, RM has to Redo
(RollForward) transaction’s updates.
pf3
pf4
pf5

Partial preview of the text

Download DataBase Development and Implementation Lec13 - Database Recovery and more Study notes Database Management Systems (DBMS) in PDF only on Docsity!

Ala Al-Zobaidie

DBDI / Lecture 13

Database Recovery

The slides are based on the textbook Fundamentals of Database Systems byElmasri & Navathe

30/05/2007 DBDI 2

Lecture - Objectives

• Recovery Control

– Some causes of database failure.

– Purpose of transaction log file.

– Purpose of Checkpointing.

– How to recover from DB failure.

• Cashing and Flashing

• Deferred & Immediate updates

• Shadowing technique.

30/05/2007 DBDI 3

Database Recovery

• The restoration of a Database to a

consistent state after system failure.

• DBA should ensure that a complete copy

of the DB is stored at regular intervals in

an archive file (Periodic full backups).

• DB can be restored to a consistent and

up-to-date state using these archives.

30/05/2007 DBDI 4

Why Recovery Control

• Two types of storage:

Volatile (main memory) and Nonvolatile.

• Volatile storage

• does not survive system crashes.

• Stable storage

• represents information that has been

replicated in several nonvolatile storage

media with independent failure modes.

Types of Failures

  • System crashes
    • resulting in loss of main memory.
  • Media failures
    • resulting in loss of parts of secondary storage.
  • Application software errors.
    • Transaction Failures
      • Transaction aborts due to software bugs, or deadlocks
      • Average of 3% of transactions abort abnormally (not user- intended)
  • Natural physical disasters.
  • Carelessness or unintentional destruction of data or facilities.
  • Sabotage.

Transactions & Recovery /

• Transactions represent basic unit of

recovery.

• Recovery Manager ( RM ) responsible for

Atomicity and Durability.

• If failure occurs between Commit and

Flushing then,

to ensure Durability, RM has to Redo

(RollForward) transaction’s updates.

30/05/2007 DBDI 7

Transactions & Recovery /

• If transaction had not committed at failure

time, RM has to Undo (rollback) any

effects of that transaction for Atomicity.

• Partial undo - only one transaction has to

be undone.

• Global undo - all transactions have to be

undone.

30/05/2007 DBDI 8

Example

  • DBMS starts at time t0, but fails at time tf.
  • Assume data for transactions T2 and T3 have been written to secondary storage.
  • T1 and T6 have to be undone.
  • In absence of any other information, recovery manager has to Redo T2, T3, T4, and T5.

30/05/2007 DBDI 9

Recovery Facilities

• DBMS should provide following facilities to

assist with recovery:

  • Backup mechanism, which makes periodic backup copies of database.
  • Logging facilities, which keep track of current state of transactions & DB changes.
  • Checkpoint facility, which enables updates to DB in progress to be made permanent.
  • Recovery manager, which allows DBMS to restore DB to consistent state following a failure. 30/05/2007 DBDI 10

Recovery Facilities / Recovery Manager

  • Fetch: read a page from stable storage to DB buffer
  • Flush: force a write of a page from DB buffer onto the stable storage
  • DBSs under system failures result in losing of the volatile database
  • In order to recover from system failures the DBMS has to maintain some additional information to facilitate recovery

Recovery Facilities / Log File /

• Contains information about all

updates to database:

– Transaction records.

– Checkpoint records.

• Often used for other purposes

(for example, auditing).

Recovery Facilities / Log File /

• Transaction records contain:

  • Transaction identifier.
  • Type of log record, (transaction start, insert, update, delete, abort, commit).
  • Identifier of data item affected by database action (insert, delete, and update operations).
  • Before-image of data item.
  • After-image of data item.
  • Log management information.

30/05/2007 DBDI 19

Recovery Techniques

  • If database has been damaged:
    • Need to restore last backup copy of database and reapply updates of committed transactions using log file.
  • If database is only inconsistent:
    • Need to undo changes that caused inconsistency. May also need to redo some transactions to ensure updates reach secondary storage.
    • Do not need backup, but can restore database using before- and after-images in the log file.

30/05/2007 DBDI 20

Main Recovery Techniques

  • Three main recovery techniques:

1. Immediate (in place) Update

2. Deferred Update

3. Shadow Paging

30/05/2007 DBDI 21

Immediate Recovery or In-place Updating /

  • Physically changes the values of the

database items as they occur

  • In-place updates cause previous values of

the affected data items to be lost.

  • Therefore enough information needs to be

kept in the DB Log about states changes

to facilitate recovery of the database to a

consistent state

30/05/2007 DBDI 22

Write-ahead logging protocol

  • For undo:
    • before the stable storage is updated, the before images must be stored in stable log
    • The before image is used to undo effects of active transactions that had not committed at time of failure.
    • Undo operations are performed in reverse order in which they were written to log.
  • For redo:
    • before transaction commits, the after images must be stored in stable log prior to the updating of the stable DB
    • May be necessary to redo updates of committed transactions as their effect may not have reached DB.

Immediate Recovery or In-place Updating / 2

  • For every update, the DBMS must not only

perform the update but also must write a

log record to an append only file

Immediate Recovery or In-place Updating / 3

  • Assume that buffer page updates are reflected in stable storage only when a page is replaced.
  • Upon recovery the stable database must reflect updates done by T1 and not those done by T

30/05/2007 DBDI 25

Immediate Recovery or In-place Updating / 4

The log contains information like:

  • transaction-id,
  • begin transaction record,
  • before update image,
  • after update image

30/05/2007 DBDI 26

Deferred Update

  • Updates are not written to the DB until after

a transaction has reached its commit point.

  • If transaction fails before commit, it will not

have modified DB and so no undoing of

changes required.

  • May be necessary to redo updates of

committed transactions as their effect may

not have reached database.

30/05/2007 DBDI 27

Out-of-place recovery (Shadowing) /

  • Current page & Shadow page table.
  • no logging required.
  • DB is treated as a collection of pages.
  • Changes to a data page, creates a Shadow page,
  • Aborting transaction is simple
  • Committing a transaction by discarding original page

30/05/2007 DBDI 28

Out-of-place recovery (Shadowing) /

  • Whenever an update takes place;
    • instead of modifying the data in the DB stable pages, create a new page (shadow page) with new values and write it into the stable DB
  • When transaction completes;
    • current page table becomes shadow page table (update the access paths so that the subsequent accesses are to the shadow page).
  • The old page is retained for recovery

30/05/2007 DBDI 29

Summary

  • Recovery & types of storage
  • Causes of Failures
  • Recovery & ACID property
  • Recovery Facilities Backup mechanism, Logging facilities, Checkpoint facility & Recovery manager,
  • Main Recovery techniques Immediate Update, Deferred Update & Shadow Paging