Why Recovery Is Needed in Database Systems

 

Why Recovery Is Needed in Database Systems

In a DBMS, many transactions execute continuously. During execution, failures may occur due to hardware issues, software errors, or other unexpected events.

To protect the correctness and consistency of the database, the DBMS must ensure one of the following outcomes for every transaction:

1️⃣ Commit

If the transaction finishes successfully:

  • All operations are completed

  • All changes are permanently stored in the database

This state is called commit.

2️⃣ Abort (Rollback)

If the transaction fails before completion:

  • All changes made by the transaction must be undone

  • The database must return to its previous consistent state

This is called abort or rollback.


Why Recovery Is Necessary

A transaction is a logical unit of work.
Therefore:

  • Either all operations must occur

  • Or none of them should occur

Partial execution of a transaction can cause:

  • Data inconsistency

  • Incorrect results

  • Corrupted database state

Example

Suppose a bank transfer transaction:

1. Deduct ₹500 from Account A 2. Add ₹500 to Account B

If the system crashes after step 1:

  • Money is deducted from A

  • But not added to B

This creates data inconsistency.

Recovery mechanisms ensure that:

  • Either both steps happen

  • Or neither happens


Types of Failures in DBMS

Failures that require recovery are generally classified into three main categories:

  1. Transaction failures

  2. System failures

  3. Media failures

There are  six common causes of these failures.


1. Computer Failure (System Crash)

A system crash occurs when the computer system suddenly stops working during transaction execution.

Causes

  • Hardware malfunction

  • Software bugs

  • Network failure

  • Memory failure

Example:

  • CPU crashes

  • Operating system failure

  • Power interruption

Effect

Transactions that were executing may stop in the middle of execution.

Some operations may have been completed while others were not.

Recovery Requirement

The DBMS must:

  • Undo incomplete transactions

  • Restore the database to a consistent state


2. Transaction or System Errors

Sometimes the transaction itself causes an error during execution.

Common Causes

  • Division by zero

  • Integer overflow

  • Invalid input values

  • Programming errors (bugs)

Example

balance = balance / 0

or

withdraw_amount > account_balance

Effect

The transaction cannot continue execution.

Recovery Requirement

The DBMS must:

  • Abort the transaction

  • Undo all operations already executed


3. Local Errors or Exception Conditions

During execution, certain conditions may arise that require the transaction to stop.

These are called exception conditions.

Examples

  • Requested data does not exist

  • Insufficient account balance

  • Seat not available in reservation system

Example in banking:

Withdraw ₹5000 Balance = ₹2000

The transaction is canceled.

Important Note

These exceptions are programmed conditions, so they are not considered system failures.

But the transaction still must be rolled back.


4. Concurrency Control Enforcement

In multiuser databases, concurrency control mechanisms manage simultaneous transactions.

Sometimes the system must abort a transaction to maintain correctness.

Two major reasons

Serializability Violation

If a transaction execution could produce incorrect results, the DBMS cancels the transaction.

Deadlock

A deadlock occurs when two or more transactions wait for each other indefinitely.

Example:

  • T1 waits for resource held by T2

  • T2 waits for resource held by T1

Neither can continue.

Solution

The DBMS:

  • Aborts one transaction

  • Restarts it later


5. Disk Failure (Media Failure)

This type of failure occurs when storage devices are damaged.

Causes

  • Disk read/write malfunction

  • Disk crash

  • Disk head failure

Example

A disk block storing database records may become corrupted or unreadable.

Effect

Some data may be lost permanently.

Recovery Requirement

The system must restore data using:

  • Backup copies

  • Recovery logs


6. Physical Problems and Catastrophes

These are rare but serious failures.

Examples

  • Power failure

  • Air-conditioning failure (causing overheating)

  • Fire or flood

  • Theft or sabotage

  • Human mistakes (overwriting disks or tapes)

Effect

Large portions of the database may be destroyed.

Recovery Requirement

Recovery becomes a major task and usually involves:

  • Backup restoration

  • Full database reconstruction


Frequency of Failures

Failure Type            Frequency
System crash                Common
Transaction errors                Common
Local exceptions                Common
Concurrency aborts                Common
Disk failures                Rare
Physical catastrophes                Very rare

Failures 1–4 happen frequently, so DBMS must maintain recovery information.

Failures 5–6 are rare but severe, requiring backup recovery mechanisms.


Key Idea

The concept of transactions allows the DBMS to:

  • Maintain database consistency

  • Recover from failures

  • Ensure reliable concurrent execution

Recovery mechanisms guarantee that:

A transaction is either fully completed OR Completely undone

Summary

Recovery ensures that database transactions remain consistent even when failures occur.

Comments

Popular posts from this blog

Database Management Systems DBMS PCCST402 Semester 4 KTU CS 2024 Scheme

Data Models, Schemas and Instances

Introduction to Database Management System -DBMS