Recovery in database systems refers to the process of restoring the database to a consistent state after a failure, ensuring that no data is lost and that the database maintains its integrity. Failures can occur due to various reasons such as power outages, hardware failures, software bugs, or even human errors. The goal of recovery techniques is to ensure that transactions are either completed correctly or rolled back entirely, and that no partial or inconsistent data is left behind.
A key aspect of recovery is to adhere to the ACID properties of transactions, particularly Atomicity, Consistency, and Durability. Recovery ensures that the Durability of transactions is maintained and that a consistent state is reached, even after a failure.
Before understanding recovery techniques, it’s important to know the types of failures that may occur in a database system:
Atomicity: A transaction is either fully completed (committed) or not executed at all (aborted). No intermediate state should be visible to other transactions.
Durability: Once a transaction is committed, its effects are permanent, even in the event of a system failure.
Consistency: After the recovery process, the database must return to a consistent state, where all integrity constraints are satisfied.
Logging: A log is used to record all changes made to the database, allowing recovery after a failure. A log contains records of transaction starts, updates to data, and transaction commits or rollbacks.
The most commonly used recovery technique is based on maintaining a transaction log. This log records every operation that modifies the database, enabling the system to redo or undo changes in the event of a failure.
Transaction Log contains entries such as:
Write-Ahead Logging (WAL): Before any changes are made to the database, the system first writes the changes to the log. This ensures that even if a failure occurs, the changes can be either undone or redone from the log.
Undo Operations: If a transaction is not committed at the time of failure, it must be rolled back to the state before it started. The system uses the log to find all changes made by the uncommitted transaction and reverses them.
Redo Operations: After a failure, some committed transactions may not have been written to disk. The log helps to redo those transactions, ensuring that committed data is recovered.
Example:
Checkpointing is a technique used to reduce the amount of work required during recovery by creating periodic snapshots of the database. A checkpoint is a point in time where the database and the transaction log are synchronized, meaning that all changes in the log up to that point have been written to disk.
Checkpoint Process:
Shadow paging is another recovery technique where the database maintains two versions of the database pages: an active page and a shadow page. When a transaction modifies a page, it updates the active page but leaves the shadow page unchanged. This ensures that if a failure occurs, the shadow page (which represents the database state before the transaction) can be used to restore consistency.
How it Works:
Advantages:
Disadvantages:
In some systems, rollback and commit logs (also called write-ahead logs) are used to manage recovery. These logs record the beginning, modification, and commit or abort of transactions. If a system crashes, the recovery process uses these logs to either commit the changes (if the transaction was completed) or rollback the changes (if the transaction was aborted).
Rollback Recovery:
Commit Recovery:
The ARIES algorithm is a popular recovery algorithm that combines aspects of both write-ahead logging and checkpointing. It is widely used in database management systems (DBMS) to handle transaction recovery in a robust manner.
Key Features of ARIES:
Disk shadowing and replication involve maintaining duplicate copies of the database in different locations. In the event of a failure, the system can switch to the backup copy of the database to continue operations.
This ensures high availability and can be used to recover from major failures like media failures or system crashes by switching to the replicated copy.
Recovery techniques in database systems are essential to ensuring the integrity and durability of the database after a failure. By using methods like transaction log-based recovery, checkpointing, shadow paging, and ARIES, databases can guarantee that operations are either fully completed or rolled back, ensuring that no inconsistencies or partial changes are left behind. Effective recovery mechanisms help maintain the ACID properties and allow the database to recover efficiently from system, transaction, or media failures.
Open this section to load past papers