ScholarQuill logoScholarQuillUniversity Notes
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
Study Tools
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
Contact
ScholarQuill logo
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
ScholarQuill logoScholarQuillUniversity Notes
Study PortalCSI-308Recovery Techniques
Ctrl + K
Login
Explore
Search
Semester
Papers
CGPA
    CSI-308

    Database Systems

    Progress0 / 22 done
    Topics22
    1Basic Database Concepts2Entity Relationship Modelling3Relational Data Model and Algebra4Structured Query Language (SQL)5RDBMS6Database Design7Functional Dependencies8Normal Forms9Transaction Processing10Optimization Concepts11Concurrency Control12Recovery Techniques13Database Security and Authorization14Small Group Project Implementing a Database15Physical Database Design16Storage and File Structure17Indexed Files18B-Trees19Files with Dense Index20Files with Variable Length Records21Database Efficiency22Database Tuning
    8 min read
    Topic 12 of 22
    Topic Study Note Illustration
    12

    Recovery Techniques

    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...

    Recovery Techniques in Database Systems

    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.

    Types of Failures

    Before understanding recovery techniques, it’s important to know the types of failures that may occur in a database system:

    1. Transaction Failures: Failures related to a specific transaction. These may be caused by issues such as logic errors, deadlock, or loss of connectivity.
    2. System Failures: Failures that affect the entire database system, such as power loss, operating system crashes, or hardware failures.
    3. Media Failures: Failures that affect the physical storage media, such as hard drive crashes or corrupted disk storage.
    4. Application Failures: Errors or failures caused by the application using the database.

    Key Concepts in Database Recovery

    1. Atomicity: A transaction is either fully completed (committed) or not executed at all (aborted). No intermediate state should be visible to other transactions.

    2. Durability: Once a transaction is committed, its effects are permanent, even in the event of a system failure.

    3. Consistency: After the recovery process, the database must return to a consistent state, where all integrity constraints are satisfied.

    4. 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.


    Recovery Techniques and Methods

    1. Transaction Log-Based Recovery

    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:

    • Start of a transaction.
    • Commit of a transaction.
    • Rollback information (if a transaction is aborted).
    • Data modifications: Before and after images of data (to support redo and undo operations).

    How Transaction Log-Based Recovery Works:

    • 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:

    • Transaction 1 updates the balance of a bank account. The update is first written to the log. If a failure occurs before the update is written to disk, the system will use the log to redo the transaction during recovery.

    1. Checkpointing

    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.

    • How it Works: The system writes a checkpoint record to the log and ensures that all transactions before this checkpoint are committed and their changes are written to disk.
    • Recovery after failure: If a failure occurs, the system only needs to roll back transactions that occurred after the last checkpoint, rather than going through the entire transaction log.

    Checkpoint Process:

    1. Write all modified data pages from memory to disk.
    2. Record the checkpoint in the log file, indicating that all changes before this point have been persisted to disk.
    3. After a failure, recovery starts from the most recent checkpoint, significantly reducing the time spent scanning the log.

    1. Shadow Paging

    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:

      • Initially, the database has a shadow copy of all pages.
      • When a transaction updates data, the changes are made to the active page, and a new version of the page is created.
      • After the transaction commits, the system updates the page table to point to the new page version.
      • If a failure occurs before the commit, the shadow page is restored.
    • Advantages:

      • No need for logging or undo operations; simply restore the shadow pages after a failure.
      • Provides a simpler mechanism than write-ahead logging.
    • Disadvantages:

      • Overhead of maintaining shadow copies, which increases storage requirements.

    1. Rollback/Commit Recovery

    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:

    • If a transaction is incomplete (not committed) when a crash happens, the changes made by the transaction are undone using the log.

    Commit Recovery:

    • If a transaction has committed, but the changes were not written to the database before a crash, the system uses the log to redo the transaction.

    1. Aries (Algorithms for Recovery and Isolation Exploitation)

    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:

    • Log-Based Recovery: ARIES relies on a transaction log and ensures that the log is written before the database pages are updated.
    • Write-Ahead Logging (WAL): Ensures that logs are written before the database is updated, even in the case of system crashes.
    • Deferred Update: Changes are not immediately written to the database; instead, they are written only after the transaction commits.
    • Recovery Phases:
      1. Analysis Phase: Determines which transactions were active at the time of the crash.
      2. Redo Phase: Redoes all transactions that were committed but not fully written to the database.
      3. Undo Phase: Undoes all transactions that were not committed by the time of the failure.

    1. Disk Shadowing and Replication

    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.

    • Disk Shadowing: Involves maintaining real-time copies of the database on separate disks.
    • Replication: A copy of the database is maintained on another server, and all changes are replicated across both copies.

    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.


    Conclusion

    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.

    ← Previous topic 11
    Concurrency Control
    Next topic 13 →
    Database Security and Authorization

    Past Papers

    Open this section to view and download past papers

    Click on Show Past Papers to load available exam papers.

    Reading Progress
    0%
    8mremaining
    1.3kwords
    Intermediatelevel
    On This Page

    No headings found

    Study Toolkit

    Subject Portal

    Database Systems