Chapter 5 Database Recovery Techniques
Chapter 5 Database Recovery Techniques
Database recovery refers to the processes and techniques used to restore a database to a correct
state after a failure or corruption. Failures can stem from a variety of issues, including hardware
malfunctions, software bugs, human errors, or natural disasters. Here are several common
database recovery techniques:
Many databases maintain a transaction log that records all changes made to the database.
In the event of a failure, transaction logs can be used to redo or undo operations to restore
the database to a consistent state.
Point-in-Time Recovery: Allows a database to be restored to a specific moment in time
by applying or undoing transactions recorded in the log.
3. Shadow Paging
A method where the database maintains two pages for each data page: a current page and
a shadow page. Changes are made to the current page, while the shadow page remains
intact for recovery purposes. If a failure occurs, the system can revert to the shadow page.
4. Checkpointing
A mechanism to periodically save the state of the database to disk, reducing the amount
of work necessary to recover from a crash. In the event of a failure, the system can start
recovery from the last checkpoint instead of from the beginning.
6. Consistent Snapshots
Creating snapshots of the database at specific intervals (usually leveraging storage
systems that support snapshots), providing a quick recovery option to a known consistent
state.
7. Log Shipping
A technique where transaction logs from a primary database are sent to a secondary
database at regular intervals. If the primary database fails, the secondary can be recovered
using the logs.
Implementing systems that automatically detect failures and switch to backup systems or
replicas without significant downtime (e.g., clustering solutions).
Systems may have built-in mechanisms to handle specific errors, such as deadlocks and
concurrency control issues, by rolling back specific transactions.
Periodic validation of data using checksums or other integrity techniques, allowing for
the detection of corruption and initiating remedial actions.
Providing users with interfaces or tools to recover lost or corrupted data based on
application-level requirements (e.g., undo functions).
Recovery Concepts
Recovery concepts refer to strategies and approaches aimed at helping individuals regain a sense
of control and improve their lives after experiencing trauma, illness, or significant setbacks,
particularly in mental health contexts. Here are some key recovery concepts with suitable
examples:
1. Person-Centered Approach
3. Strengths-Based Perspective
4. Holistic Approach
Example: A recovery program that includes not only therapy but also nutritional
counseling, physical fitness activities, and mindfulness practices. For instance, a
participant in a mental health recovery program might engage in yoga sessions, learn
about balanced diets, and practice meditation alongside traditional psychotherapy.
5. Social Inclusion
Example: A community initiative that promotes social activities for individuals with
mental health conditions, such as an inclusive sports league or art classes. This fosters
connections with others, reduces isolation, and helps participants develop friendships and
support networks.
6. Relapse Prevention
Example: A client recovering from addiction develops a relapse prevention plan during
therapy, identifying triggers and creating coping strategies. They might engage in role-
playing scenarios to practice how to handle situations where they may be tempted to use
substances.
7. Resilience Building
Example: A school program that teaches children coping skills, emotional regulation,
and problem-solving techniques to help them bounce back from difficulties. Through
workshops and activities, children practice dealing with stress and adversity in a
supportive environment.
8. Self-Management and Advocacy
Example: An individual diagnosed with bipolar disorder learns to track their mood
patterns and medication effects, becoming their own advocate in managing their
condition and communicating effectively with healthcare providers about their needs.
9. Community Support
Example: Peer support groups for individuals recovering from mental health issues
provide a sense of belonging and shared understanding. Participants may offer each other
practical advice, emotional support, and insight into their recovery journeys.
Example: A mental health service adapts its recovery strategies to respect and
incorporate the cultural backgrounds of its clients. This may include understanding
cultural beliefs about mental health, using culturally relevant materials, and involving
traditional healing practices when appropriate.
Certainly! Recovery concepts in database management are essential to ensure data integrity and
consistency, especially in the event of system failures, crashes, or errors. Two prominent
approaches for database recovery are "Deferred Update" and "Immediate Update." Let's explore
both concepts with examples.
Deferred Update:
In the deferred update approach, updates to the database are not immediately applied. Instead,
changes are recorded in a log (a write-ahead log) and only applied to the database when a
transaction is successfully committed. If a transaction fails, the changes are ignored, which
allows for easier recovery.
Key Characteristics:
1. Changes are only written to the database when the transaction commits.
2. Log entries are written before the actual update to ensure a record of proposed changes.
3. If a transaction aborts, the state of the database remains unchanged.
Example:
Imagine a banking system where a customer wants to transfer $100 from Account A to Account
B. Here’s how deferred update works:
1. The transaction initiates and the system records the intention of transferring $100 in the
log.
o Log Entry: "Transfer $100 from Account A to Account B - Pending"
2. Then, the system modifies the balances in memory:
o Account A: $900 (initially $1000)
o Account B: $1100 (initially $1000)
3. If the transaction is successful, the changes are logged:
o Log Entry: "Transfer $100 from Account A to Account B - Committed"
o Now, the system applies the updates to the database.
4. If an error occurs before the commit (e.g., power failure), the original balances remain:
o Account A: $1000
o Account B: $1000
With deferred updates, since changes are not applied until commit, this guarantees that either all
changes are made or none at all.
Immediate Update:
In the immediate update approach, updates are applied to the database as soon as they are made,
without waiting for the transaction to commit. This approach allows transactions to interact with
the database immediately, but it can make recovery more complex if a failure occurs.
Key Characteristics:
Example:
Using the same banking system example, let's see how immediate update would work:
1. The transaction initiates with the request to transfer $100 from Account A to Account B.
2. Changes are applied directly to the database:
o Account A: $900 (reduction applied immediately)
o Account B: $1100 (increase applied immediately)
3. Log entries are updated immediately:
o Log Entry: "Transfer $100 from Account A to Account B - Applied"
4. If the transaction then fails (e.g., crashes before committing), the database might reflect
the transfer despite the transaction not being considered complete.
5. Upon recovery, the system checks the log and rolls back any transaction that did not
reach the commit:
o In this case, $100 should be added back to Account A and subtracted from
Account B, ensuring that the final accounts reflect only completed transactions.
Deferred Update:
o Changes are applied only after a transaction commits.
o Easier recovery process as incomplete transactions do not alter the database.
Immediate Update:
o Changes are made instantaneously upon execution.
o More flexible interaction with database but requires additional procedures for data
integrity during recovery.
Certainly! Let's break down each of these topics: Shadow Paging, the ARIES recovery
algorithm, and recovery in multi-database systems.
Shadow Paging
How it works:
1. Two Page Tables: There are two versions of the page table - the current page table and
the shadow page table.
2. Updates: When a page is updated, a new page is created. The current page table is
updated to point to this new page, while the shadow page table remains unchanged.
3. Commit: A transaction is committed when all updates have been made to the current
page table and the system marks the shadow page as “old” and the current as “new”.
4. Rollback: In the event of a failure, the system can simply revert to the shadow page
table, which has not been modified since the last commit.
Advantages:
Disadvantages:
ARIES (Algorithm for Recovery and Isolation Exploiting Semantics) is a widely used
recovery method that provides support for concurrent transactions. It uses a combination of both
logging and checkpoints to provide efficient recovery.
Key Components:
1. Log Structure: ARIES keeps a log of all operations, which facilitates recovery.
2. Write-Ahead Logging (WAL): Before any changes are made to the database, the log is
updated with the operations that will occur.
3. Checkpoints: A checkpoint is a point in time where the database state is saved, allowing
recovery to be faster as it can truncate the log before the checkpoint.
4. Three Phases for Recovery:
o Analysis Phase: It determines which transactions were active at the time of the
crash and identifies the last checkpoint.
o Redo Phase: All logged changes are reapplied from the last checkpoint to ensure
the database is consistent.
o Undo Phase: Any transactions that were active and not committed at the time of
the crash are rolled back to maintain consistency.
Advantages:
Disadvantages:
Multi-database Systems often involve scenarios where multiple databases need to maintain
consistency and recoverability, especially in distributed environments. Recovery mechanisms in
such systems are critical for ensuring data integrity across different databases.
Challenges:
If the debit in DB_A is successful, but the credit in DB_B fails, the transaction must be
rolled back in DB_A to ensure data integrity.
Using the two-phase commit protocol would ensure that both databases either commit or
rollback together.
Techniques:
Logging across databases: Each database has its log, and a central coordinator can
manage commit/rollback operations.
Global Recovery Protocols: This encompasses managing and coordinating the recovery
process across multiple databases.