Log Based Recovery in DBMS: WAL, Undo & Redo

Published: 2025-01-27
10 min read
Share:

Imagine a banking application processing a fund transfer. The money is deducted from one account, but the server crashes before the amount reaches the recipient's account. Without a recovery mechanism, the database could end up in an inconsistent state.

This is where log based recovery in DBMS becomes essential. It records every transaction change in a log before the database is updated, allowing the system to recover safely after crashes, hardware failures, power outages, or software errors.

By relying on transaction logs, the DBMS can preserve committed transactions, remove incomplete ones, and restore the database to a consistent state with minimal downtime.

Why Log Based Recovery in DBMS Matters

Modern applications cannot afford data corruption or prolonged outages. Whether you're working with banking systems, e-commerce platforms, healthcare applications, or cloud services, reliable recovery is a core requirement.

Ensuring Data Integrity

A database must never leave partially completed updates behind.

Log-based recovery helps maintain integrity by ensuring:

  • Complete transactions remain intact.
  • Incomplete transactions are rolled back.
  • Corrupted states are avoided.
  • Data remains consistent after failures.

Reducing Recovery Time

Database downtime directly affects users and business operations.

Using logs and checkpoints allows the DBMS to:

  • Recover faster after crashes.
  • Restore committed transactions efficiently.
  • Minimize service interruptions.
  • Improve system availability.

Building Reliable Systems

Users rarely think about database recovery until something goes wrong.

Recovery mechanisms ensure that crashes do not result in:

  • Missing payments
  • Lost orders
  • Corrupted records
  • Inconsistent account balances

Core Concepts Behind Log Based Recovery

Several concepts work together to make log based recovery effective.

Write-Ahead Logging (WAL)

Write-Ahead Logging (WAL) is the foundation of most recovery systems.

The principle is simple: before a change is written to the database, the corresponding log record must be written to stable storage.

This guarantees that recovery information always exists, even if the database crashes immediately afterward.

According to the official PostgreSQL documentation, WAL improves reliability by ensuring all modifications are first recorded in transaction logs before data files are updated.

Commit Records

When a transaction completes successfully, the DBMS writes a commit record to the log.

This record indicates that the transaction is considered permanent and must survive future failures.

Undo and Redo Operations

Recovery relies on two fundamental operations:

  • Undo: Reverses changes made by incomplete transactions.
  • Redo: Reapplies changes from committed transactions that were not fully written to disk.

Practical Example: PostgreSQL WAL

PostgreSQL uses WAL extensively.

Suppose a transaction updates customer information and the server crashes immediately afterward. During startup, PostgreSQL reads the WAL records and replays committed changes automatically.

This process allows the database to recover without losing committed transactions.

Checkpoints

A checkpoint is a recovery marker that reduces the amount of log data the DBMS must process during recovery.

Instead of replaying the entire log history, recovery can begin from the most recent checkpoint.

Benefits include:

  • Faster startup recovery
  • Reduced recovery workload
  • Improved system availability

Pro Tip

Checkpoint frequency requires careful tuning.

Very frequent checkpoints reduce recovery time but can increase runtime overhead because more memory pages must be flushed to disk. Less frequent checkpoints improve runtime performance but increase recovery duration after failures.

For a broader understanding of transaction recovery principles, read our guide on recovery and atomicity in DBMS.

How Undo and Redo Recovery Work

Recovery operations generally fall into two categories.

Rollback (Undo) Recovery

Rollback recovery is used when a transaction fails before reaching the commit stage.

Common causes include:

  • Application errors
  • Constraint violations
  • Invalid input
  • User-initiated cancellation

The DBMS identifies the transaction's changes in the log and reverses them.

This ensures no partial updates remain in the database.

Roll-Forward (Redo) Recovery

Redo recovery handles committed transactions that were not completely written to storage before a crash.

The DBMS:

  1. Reads committed transaction records.
  2. Reapplies logged operations.
  3. Restores the database to the correct state.

Redo operations ensure durability by preserving committed work.

Quick Recovery Workflow

A typical recovery process follows these steps:

  1. Detect system failure.
  2. Locate the latest checkpoint.
  3. Analyze transaction logs.
  4. Redo committed transactions.
  5. Undo incomplete transactions.
  6. Return the database to a consistent state.

How Log Based Recovery Supports ACID Properties

ACID properties are fundamental to transaction processing.

Supporting Atomicity

Atomicity means a transaction either completes entirely or not at all.

Log-based recovery achieves this by:

  • Recording every operation.
  • Undoing incomplete transactions.
  • Preventing partial updates from persisting.

Supporting Durability

Durability guarantees that committed transactions survive future failures.

The combination of:

  • WAL
  • Commit records
  • Redo recovery

ensures committed data remains permanent.

Supporting Consistency

Consistency requires every transaction to move the database from one valid state to another.

Recovery mechanisms restore the database to a valid state after unexpected interruptions.

Supporting Isolation

Isolation prevents concurrent transactions from interfering with one another.

Although isolation is primarily enforced through concurrency control, recovery systems help maintain isolation guarantees after crashes by restoring a consistent state.

You may also find our article on recovery with concurrent transactions in DBMS helpful for understanding recovery in multi-user environments.

Recovery Techniques Used in Modern DBMS

Several recovery techniques are built on top of transaction logging.

ARIES Algorithm

ARIES (Algorithm for Recovery and Isolation Exploiting Semantics) is one of the most widely used recovery algorithms.

It operates in three phases.

1. Analysis Phase

The DBMS identifies:

  • Active transactions
  • Dirty pages
  • Recovery starting points

2. Redo Phase

Committed operations are reapplied from the log.

This ensures no committed transaction is lost.

3. Undo Phase

Incomplete transactions are reversed.

This removes partial updates and restores consistency.

Many enterprise-grade database systems use ARIES-inspired recovery techniques because they provide efficient crash recovery with minimal performance impact.

Immediate Update Recovery

In immediate update systems:

  • Database pages may be updated before commit.
  • Log records must be written first.
  • Undo and redo operations may both be required.

Advantages include:

  • Better runtime performance
  • Faster visibility of updates

Deferred Update Recovery

In deferred update systems:

  • Changes are recorded in logs first.
  • Database updates occur only after commit.
  • Undo operations become simpler.

Advantages include:

  • Simpler recovery logic
  • Reduced rollback complexity

Handling Different Types of Database Failures

Not all failures are the same.

Different failures require different recovery strategies.

Transaction Failures

A transaction failure affects only a specific transaction.

Examples include:

  • Invalid SQL operations
  • Constraint violations
  • Application logic errors

The DBMS simply rolls back the affected transaction.

System Failures

System failures impact the entire database environment.

Examples include:

  • Operating system crashes
  • Power outages
  • Server reboots
  • Hardware malfunctions

Recovery uses transaction logs to:

  • Redo committed work
  • Undo incomplete work

Media Failures

Media failures occur when storage devices become unavailable or corrupted.

Examples include:

  • Disk crashes
  • SSD failures
  • Storage corruption

Recovery usually involves:

  1. Restoring the latest backup.
  2. Applying transaction logs.
  3. Reconstructing missing changes.

Performance Trade-Offs of Log Based Recovery

Recovery improves reliability, but it is not free.

Logging Overhead

Every transaction generates log records.

This creates additional write operations and storage requirements.

Checkpoint Overhead

Frequent checkpoints improve recovery speed but consume resources during normal operation.

Finding the right balance is important.

Storage Architecture

Many enterprises place transaction logs on dedicated storage devices.

For example, a financial database processing thousands of transactions per second can generate gigabytes of log data every day.

Separating log storage from database storage reduces contention and improves performance.

Hardware Considerations

Recovery performance benefits from:

  • High-speed SSDs
  • NVMe storage
  • Dedicated log disks
  • Sufficient RAM
  • Optimized checkpoint configuration

Real-World Applications of Log Based Recovery

Banking and Financial Systems

Financial transactions demand strict consistency.

Log-based recovery ensures:

  • Account balances remain accurate.
  • Transactions are never partially completed.
  • Funds are not duplicated or lost.

E-Commerce Platforms

Consider an online purchase.

If payment succeeds but the server crashes before the order is recorded, recovery logs help reconstruct the committed transaction after restart.

This prevents lost orders and customer disputes.

Healthcare Systems

Healthcare applications manage sensitive patient information.

Recovery mechanisms help preserve:

  • Medical histories
  • Prescription records
  • Diagnostic information

even when failures occur unexpectedly.

Log Based Recovery in Distributed Databases

Recovery becomes more challenging when multiple servers participate in transactions.

Distributed systems must coordinate recovery across several nodes.

Important mechanisms include:

  • Coordinated checkpoints
  • Distributed transaction logs
  • Consensus protocols
  • Two-phase commit (2PC)

These mechanisms help maintain consistency across the entire system.

If you're exploring broader database recovery concepts, also check our guide on database recovery techniques in DBMS.

Recovery technologies continue to evolve alongside modern database architectures.

Key trends include:

Cloud-Native Recovery

Cloud databases increasingly combine:

  • Transaction logs
  • Snapshots
  • Distributed storage

to reduce recovery times.

In-Memory Databases

Modern memory-centric databases reduce I/O overhead and allow faster checkpoint creation.

Intelligent Recovery Optimization

Machine learning techniques are beginning to assist with:

  • Checkpoint scheduling
  • Failure prediction
  • Recovery optimization

These improvements aim to reduce downtime while maintaining strong consistency guarantees.

FAQs About Log Based Recovery in DBMS

What is log based recovery in DBMS?

Log based recovery in DBMS records transaction changes in a log before updating database files. If a failure occurs, the system uses the log to undo incomplete transactions and redo committed ones.

Why is log based recovery important?

It protects databases from crashes, data corruption, and incomplete transactions while maintaining ACID properties and reducing downtime.

What is Write-Ahead Logging (WAL)?

WAL is a recovery technique that requires log records to be written before database pages are updated. This guarantees recovery information is available after failures.

How do checkpoints improve recovery?

Checkpoints create recovery starting points, reducing the amount of log data that must be processed after a crash.

What is the difference between undo and redo operations?

Undo reverses incomplete transactions, while redo reapplies committed transactions that were not fully written to disk before a failure.

Does log based recovery work in distributed databases?

Yes. Distributed databases use transaction logs along with protocols such as two-phase commit and consensus mechanisms to ensure recovery across multiple nodes.

Final Thoughts

Log based recovery in DBMS is one of the most important mechanisms for maintaining database reliability. By combining Write-Ahead Logging, checkpoints, undo operations, and redo operations, modern database systems can recover from failures while preserving consistency and durability.

Whether you're designing enterprise applications, managing production databases, or preparing for DBMS interviews, understanding how log-based recovery works is essential for building dependable systems.

Free Engineering ToolsNEW

8 free, 100% client-side tools for developers — no signup, no data uploads.

Explore all tools