Vous êtes sur la page 1sur 15

Database II

Database Recovery

1
Muhammad Asghar Khan
Database Recovery (1/8)

 A mechanism for restoring a database quickly and


accurately after loss or damage

 Databases are damaged or lost of some system


problem that may be caused by
• human error,
• hardware failure,
• incorrect or invalid data,
• program error,
• computer viruses or
• natural catastrophes

2
Database Recovery (2/8)

 A DBMS should provide four basic facilities for


backup and recovery of a database
1. Backup facilities
2. Journaling facilities
3. Checkpoint facility
4. A Recovery manager

1. Backup Facilities
• Backup facility should produce a backup copy of the
entire database
• Backup copy is produced at least once per day
• Backup copy should be saved in safe place
3
Database Recovery (3/8)

• With large databases regular backups may be impractical,


as the time required to perform the backup

• As a result backups of dynamic data (data changing


frequently) is taken regularly as compared to backup of
static data (data changing less frequently)

• Incremental/differential backups record changes made


since the last full backup
2. Journalizing Facilities
• It produce the audit trial of transactions and database
changes

4
Database Recovery (4/8)

• Transaction is defined as unit of work that must be


completely processed or not processed at all with in the
computer system
DBMS

Database Database
Transaction
(Current) Change
Log
Log

Database
(Backup)
5
Database Recovery (5/8)

• Figure on previous slide shows there are two journals or


logs

• Transitional Log
• Contains a record of essential data for each transaction that is
processed against a database
• Record may include the transaction ID, time of transaction, user ID
or system ID, input data values, record accessed or record modified

• Database Change Log


• Contains before and after images of records that have been
modified by transactions
• Before-Image is simply a copy of record it has been modified by
transaction
6
Database Recovery (6/8)

• After-Image is a copy of same record after it has been modified

• Some systems also keeps security log which can alert


DBA to any security violations that are attempted
3. Checkpoint Facility
• A facility by which the DBMS periodically refuses to
accept any new transactions, the system is in a quite state
and the database and transaction logs are synchronized

• The DBMS writes a special record called checkpoint


record to the log file, which is like a snapshot of the state
of database
7
Database Recovery (7/8)

• Checkpoint record information necessary to restart the


system

• Any dirty data blocks (pages of memory that contain


changes that have not yet been written out to disk) are
written from memory to disk thus ensuring that all changes
made prior to taking the checkpoint have been written to
permanent storage

• A DBMS may perform checkpoints automatically

• Checkpoints should be taken frequently say several times


an hour
8
Database Recovery (8/8)

4. Recovery Manager
• A module of DBMS that restores the database to a correct
condition when a failure occurs and resumes processing
user requests

9
Types of Recovery Procedures (1/6)

 Type of recovery procedure depends up on the


• Nature of the failure
• DBMS recovery facilities
• Operational policies and procedures

 Given below are frequently used techniques


• Switch
• Restore/Rerun
• Backward Recovery/Roll back
• Forward Recovery/Roll forward

10
Types of Recovery Procedures (2/6)

 Switch
• In this type of technique the database must be mirrored

• That is at least two copies of database must be kept

• When failure occurs, processing is switched to the


duplicate copy of database

• Level 1 RAID implements mirroring

• This type of technique is called hot-swappable

• This strategy doesn’t provide against loss of power or


catastrophic damages 11
Types of Recovery Procedures (3/6)
 Restore / Rerun
• This technique involves re-processing the day’s transactions (up
to the point of failure) against the backup copy of database

• The most recent copy (say, from previous day) is restored and all
transactions that have occurred since that copy are restored from
transaction log

• Disadvantage is that new transactions will be delayed until


recovery is complete

• Second disadvantage is of inconsistency of sequence of


transactions

• Therefore it is not sufficient recovery procedure


12
Types of Recovery Procedures (4/6)

 Backward Recovery / Rollback


• In this technique the DBMS undo the unwanted changes to
the database
• This technique is used to reverse the changes made by
transactions that have aborted, or terminated abnormally

Database
(With
Changes) Database
DBMS (Without
Changes)

Before
Image
13
Types of Recovery Procedures (5/6)

 Forward Recovery/ Roll Forward


• In this technique the DBMS starts with earlier copy of the
database

• After-images (the results of good transactions) are applied


to the database, and the database is quickly moved forward
to a later state

• This technique is much faster and accurate than


restore/rerun technique because
• Time consuming logic of re-processing each transaction doesn’t
have to be repeated
• Also the problem of different sequencing of transactions is avoided
14
Types of Recovery Procedures (6/6)

Database
(Without
Changes) Database
DBMS (With
Changes)

After
Image

15

Vous aimerez peut-être aussi