ScholarQuill logoScholarQuillUniversity Notes
  • Notes
  • Past Papers
  • Blogs
  • Todo
Login
ScholarQuill logoScholarQuillUniversity Notes
Login
NotesPast PapersBlogsTodo
More
SubjectsDiscussionCGPA CalculatorGPA CalculatorStudent PortalCourse Outline
About
About usPrivacy PolicyReportContact
Notes
Past Papers
Blogs
Todo
Analytics
    Current Subject
    🧩
    Database Systems
    CSI-308
    Progress0 / 22 topics
    Topics
    1. Basic Database Concepts2. Entity Relationship Modelling3. Relational Data Model and Algebra4. Structured Query Language (SQL)5. RDBMS6. Database Design7. Functional Dependencies8. Normal Forms9. Transaction Processing10. Optimization Concepts11. Concurrency Control12. Recovery Techniques13. Database Security and Authorization14. Small Group Project Implementing a Database15. Physical Database Design16. Storage and File Structure17. Indexed Files18. B-Trees19. Files with Dense Index20. Files with Variable Length Records21. Database Efficiency22. Database Tuning
    CSI-308›Recovery Techniques
    Database SystemsTopic 12 of 22

    Recovery Techniques

    8 minread
    1,344words
    Intermediatelevel

    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 load past papers

    Click on Show Past Papers to see past papers.
    On This Page
      Reading Stats
      Est. reading time8 min
      Word count1,344
      Code examples0
      DifficultyIntermediate