0% found this document useful (0 votes)
9 views10 pages

Untitled Document

Uploaded by

pruthvi07u
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views10 pages

Untitled Document

Uploaded by

pruthvi07u
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Database Recovery Techniques

Database recovery is the process of restoring a database to a


consistent state after a failure, such as a system crash, power
failure, or disk crash. Recovery techniques ensure data integrity
and prevent data loss. There are two main recovery processes:

1. Rolling Forward (Redo Operation):

● Purpose: Applies changes from the redo log to restore


committed transactions that were not yet written to the data
files.

● Process:

○ The redo log records all changes made to the database,


including data changes, index updates, and rollback
segments. These changes can be committed or uncommitted.
○ During recovery, the redo log is used to reapply all
changes to the database, bringing it forward in time.
○ Rolling forward uses:
■ Online Redo Logs: Current logs in use at the time
of failure.
■ Archived Redo Logs: Older logs saved for recovery
purposes.
○ This ensures that all committed changes are applied to
the database.
● Outcome: After rolling forward, the database contains both
committed and uncommitted changes.

2. Rolling Back (Undo Operation):

● Purpose: Reverses uncommitted changes that were applied


during the rolling forward process.
● Process:
○ The rollback segments contain information about
uncommitted transactions.
○ After rolling forward, rollback segments are used to
undo the effects of incomplete or uncommitted
transactions.
○ This ensures that the database only retains committed
changes and removes any partial updates or changes made
by transactions that were not completed.

Types of Recovery

1. Forward Recovery (Rolling Forward):

○ Applies all committed changes from the redo logs to


restore the database to the most recent committed state.
2. Backward Recovery (Rolling Back):

○ Undoes uncommitted changes applied during the roll


forward process to maintain database consistency.

Recovery Techniques

1. Log-Based Recovery:

● Maintains a record of all activities performed in the


database, such as INSERT, UPDATE, and DELETE operations.
● These logs are used for recovery when a failure occurs:
○ Redo Operation: Reapplies committed changes.
○ Undo Operation: Reverts uncommitted changes.
● Example:

A log entry might record:


[Time: 10:15 AM] UPDATE salary SET amount = 5000 WHERE emp_id =
101;


○ During recovery, the log is used to restore the changes.

2. Shadow Paging Recovery:

● Divides the database into pages and uses a page table to


track the physical location of these pages on the disk.
● When changes are made:
○ A shadow copy of the page is created, leaving the
original page intact.
○ Changes are made to the shadow page, ensuring the
original page remains unchanged until the transaction is
committed.
● In case of a failure:
○ The system uses the original page to restore the
database to its consistent state.
● Advantage:
○ No logs are required, as shadow paging automatically
preserves the original state of the database.

3. Checkpoint Recovery:

● A checkpoint is a marker that records the state of the


database at a specific point in time.
● During recovery:
○ The system starts from the last checkpoint, avoiding the
need to reprocess older transactions.
○ All committed transactions up to the checkpoint are
guaranteed to be saved.
● Benefit:
○ Speeds up the recovery process as it reduces the amount
of data that needs to be processed.

Recovery Process Flow

1. Failure Occurs:
○ This could be a system crash, power failure, or disk
failure.
2. Roll Forward (Redo Operation):
○ Applies all changes from the redo log to bring the
database to the most recent state.
3. Roll Back (Undo Operation):
○ Undoes any uncommitted changes applied during the roll
forward.
4. Database Restored:
○ The database is now in a consistent state, containing
only committed transactions.
Database Backups

Regular backups are essential to protect the database and ensure


its restoration in case of failure. Different types of backups
provide varying levels of protection for the database. Backing up
and restoring data is a critical responsibility for IT
professionals. Below are the three common types of database
backups:

i) Normal or Full Backups

● What it does: A full backup copies all files on the selected


drive, including:
○ System files.
○ Application files.
○ User data.
● Destination: Backed-up files are saved to a selected
location (e.g., backup tapes, secondary drive, or cloud).
● Archive Bit: Clears all archive bits after the backup.
● Key Advantage:
○ Fastest way to restore lost data since all files are in
one backup set.

ii) Incremental Backups

● What it does: Backs up only the files that have been updated
since the last backup (either normal or incremental).
● Usage:
○ Typically used after a full backup, especially during
weekdays, to save time.
● Efficiency:
○ Only files that changed since the last backup are
copied.
○ The file will not be backed up again unless it changes.
● Key Advantage:
○ Requires less time and storage space compared to full
backups.

iii) Differential Backups

● What it does: Backs up files that have been updated since


the last normal (full) backup.
● Difference from Incremental Backup:
○ Does not clear the archive bit.
○ Files updated since the last full backup are archived
each time a differential backup runs.
● Key Advantage:
○ Less complicated restore process compared to incremental
backups.
● Restoration:
○ Only the last full backup and the latest differential
backup are needed
Iterative control:

1. The PL/SQL loops are used to repeat the execution of one or


more statements for a specified number of times.
2. These are also known as iterative control statements. The
iterative statement can be embedded in a PL/SQL procedure,
function, or anonymous block statement.
3. In PL/SQL we have three different loop options to choose
from when we want to execute a statement repeatedly in our
code block.
4. They are: a. Basic loop. b. For loop c. While loop

You might also like