Professional Documents
Culture Documents
Recovery
CISB314 Database 2 1
Basic
Introductio
Recovery
n
Facilities
Outline Types of
Recovery Database
and Restart failure and
Procedures its
response.
CISB314 Database 2 2
Introduction
CISB314 Database 2 3
Introduction
• RESPONSIBILITY OF DBA
CISB314 Database 2 4
Backup and
recovery
overview
• At t1, a database backup
operation is performed
• At t2, a problem that
damages the database
occurs
• At t3, all committed data
is recovered
Basic Recovery Facilities
• DBMS should provide four basic facilities for backup & recovery
of a database:
1. Backup Facility
– periodic backup
2. Journalizing Facility
– audit trail of transaction
3. Checkpoint Facility
– suspends & synchronize
4. Recovery Manager
- restore and restart processing
CISB314 Database 2 6
• Make copies of all or a portion of
database periodically to a different
devices.
• What can be backup?
• User data, catalogs and all control files
(buffer pool files, table space file,
1. Backup database configuration file)
Facility • Backups are stored in secure, off-site
location
• Backup copy is used to restore data in the
event of database failure
CISB314 Database 2 7
• Different types of Backup Modes:
1. Cold backup / offline backup
• Database is shut down during backup
• Does not allow other applications or
processes to access the database
2. Hot backup / online backup
1. Backup • Selected portion is shut down and
Facility backed up at a given time
• Allow other applications or
processes to access the database
while the backup is happening
• Also known as dynamic backup or
active backup
CISB314 Database 2 8
• Types of backup:
a) Full backups: all selected data
will be copied/backup to other
devices
b) Incremental backups: only
copy/backup changes made since
1. Backup the last backup
Facility c) Differential backups:
copy/backup all changes made
since the last full backup
• the differences since the last
full backup.
CISB314 Database 2 9
1. Backup
Facility
(cont’d)
CISB314 Database 2 10
1. Backup
Facility
(cont’d)
CISB314 Database 2 11
1. Backup Facility (cont’d)
CISB314 Database 2 12
• Backup devices/storage media:
• Magnetic Tape
• Hard disk
• Optical storage (CD-R, DVD, Blu-ray
1. Backup discs)
• Solid state drive (thumb drive, flash
Facility memory)
• Cloud
CISB314 Database 2 13
• To perform backup, DBA can either:
• Use DBMS COPY utility
1. Backup • Use SQL statements to set up
commands to perform backup
Facility
CISB314 Database 2 14
Database backup syntax (DB2)
Timestamp
Server
Table space backup
19
CISB314 Database 2
20
Database logging
• Logs keep track of changes made to database objects and their data.
• They are used for recovery: If there is a crash, logs are used to
playback/redo committed transactions, and undo uncommitted ones.
• Can be stored in files or raw devices
• Logging is always ON for regular tables in DB2
• It is possible to mark some tables or columns as NOT LOGGED
• It is possible to declare and use USER temporary tables which may
not be logged
CISB314 Database 2
22
CISB314 Database 2
2.
Journalizin
g Facility
23
• A point where DBMS periodically suspend
all processing and synchronize its files and
journals to establish a recovery point.
CISB314 Database 2 24
• DBMS writes a checkpoint record to the
3. Checkpoint log file, that contains information
necessary to restart the system.
Facility
CISB314 Database 2 25
3. Checkpoint Facility
CISB314 Database 2 26
• When a system with concurrent transactions
crashes and recovers, it behaves in the
following manner:
• The recovery system reads the logs
backwards from the end to the last
checkpoint.
• It maintains two lists, an undo-list and a
redo-list.
• If the recovery system sees a log with
<Tn, Start> and <Tn, Commit> or just <Tn,
3. Checkpoint Commit>, it puts the transaction in the
redo-list.
Facility (cont’d) • If the recovery system sees a log with
<Tn, Start> but no commit or abort log
found, it puts the transaction in undo-
list.
CISB314 Database 2 27
Transactions
T1
T2
T3
T4
Checkpoint Failure
CISB314 Database 2 28
• A module of the DBMS that
restores the database to a correct
condition when a failure occurs
4. and then resumes processing user
requests.
29
Recovery • The recovery manager used the
backup copy and logs to restore
• What is a transaction?
• Transaction integrity is very important in database recovery.
• Thus, any transactions in a database must follow ACID properties
in order to ensure correct and valid data. (Do you remember ACID
properties?
CISB314 Database 2 31
Recovery &
Restart Procedures
• The type of recovery procedure that is used in a given situation depends on the nature
of failure.
• The most frequently used recovery procedures:
1. Disk Mirroring – switch between identical copies of databases
2. Restore/Rerun – reprocess transactions against the backup
3. Backward Recovery (Rollback) – apply before images
4. Forward Recovery (Roll Forward) – apply after images
CISB314 Database 2 32
1. Disk Mirroring
o 2 copies of the database are kept and updated simultaneously.
o Media failure occurs - processing switch to the duplicate copy.
o In normal operations, changes are updated simultaneously to both
databases
o Allows fastest recovery
o Hot-swappable: damaged disk can be rebuilt from mirrored disk with no
disruption in service to user
CISB314 Database 2 33
1. Disk Mirroring (cont’d)
Advantages: Disadvantages:
CISB314 Database 2 34
1. Disk
Mirroring
CISB314 Database 2 35
2. Restore/Rerun
• Involves reprocessing the day’s transactions (up to the point of failure)
against the backup copy of the database
• Database is shut down
• The most recent copy of the database or file to be recovered is mounted
• All transactions that have occurred since that copy (stored on the
transaction log) are rerun
CISB314 Database 2 36
2. Restore/Rerun
Advantages: Disadvantages:
CISB314 Database 2 37
DB2 Restore Utility
SAMPLE.0.DB2INST.NODE0000.CATN0000.20110718131210.001
CISB314 Database 2 40
Backward Recovery (Rollback)
CISB314 Database 2 42
4. Forward Recovery
• Also called rollforward recovery.
• DBMS starts with an earlier copy of the database, from the last checkpoint.
• After images are applied to roll the database forward to the point of failure.
• Advantages:
• Faster than Restore/Rerun
• The series of after images of the data are applied. These are copies of the
data at that point not a rerun of the processes. Therefore sequencing is
no longer an issue.
CISB314 Database 2 43
4. Forward
Recovery
CISB314 Database 2 44
Types of database failures
1. Aborted transactions
• A transaction in progress that terminates abnormally
2. Incorrect data
• Database that has been updated with incorrect, but valid data
3. System failure
• Some components of the system fails (due to power loss, loss of
communication transmission, system software failure) but the
database is not damaged
4. Database destruction
• The database is lost, destroyed or cannot be read (which is
usually caused by disk drive failure)
CISB314 Database 2 45
Responses to Database Failures
CISB314 Database 2 46
Summary
CISB314 Database 2 47
END
CISB314 Database 2 48
What is a business transaction?
• A business transaction is a sequence of steps that constitute some well-defined business activity.
• Examples of business transactions are Admit Patient in a hospital and Enter Customer Order in a
manufacturing company.
• Normally, a business transaction requires several actions against the database.
When a new customer order is entered, the following steps may be performed by an application
program:
CISB314 Database 2 49
ACID properties
Atomic - the transaction cannot be subdivided and, hence, it must be processed in its entirety or not at all. Once
the whole transaction is processed, we say that the changes are committed. If the transaction fails at any
midpoint, we say that it has aborted. For example, suppose that the program accepts a new customer order,
increases Balance Due, and stores the updated CUSTOMER record. However, suppose that the new ORDER record
is not inserted successfully (perhaps due to a duplicate Order Number key or insufficient physical file space). In this
case, we want none of the parts of the transaction to affect the database.
Consistent - any database constraints that must be true before the transaction must also be true after the
transaction. For example, if the inventory on-hand balance must be the difference between total receipts minus
total issues, this will be true both before and after an order transaction, which depletes the on hand balance to
satisfy the order.
Isolated - changes to the database are not revealed to users until the transaction is committed. For example, this
property means that other users do not know what the on-hand inventory is until an inventory transaction is
complete; this property then usually means that other users are prohibited from simultaneously updating and
possibly even reading data that are in the process of being updated. A consequence of transactions being isolated
from one another is that concurrent transactions (i.e., several transactions in some partial state of completion) all
affect the database as if they were presented to the DBMS in serial fashion.
Durable - meaning that changes are permanent. Thus, once a transaction is committed, no subsequent failure of
the database can reverse the effect of the transaction.
CISB314 Database 2 50