DAtabase Recovery
DAtabase Recovery
When an error or failure occurs, database recovery is the process of getting the database back
to a consistent and useable condition. Failures can be brought on by glitches in hardware or
software, power failures, human mistake, or other difficulties. Database recovery is essential
to preserving the database's integrity and guaranteeing the availability and accuracy of the
data.
2. Checkpoint:
A checkpoint is a database recovery technique that stores the database's current state to a
reliable storage medium, such a hard drive, to guarantee recoverability. The checkpoint
procedure comprises updating the log file and writing all updated pages to disc. In the case of
power or any other failure, the recovery procedure may begin from the previous checkpoint.
The main function of checkpoint is to minimise the amount of effort required during recovery
in the case of a failure. The checkpoint assures that all changes made to the database up to
that point are robust and recoverable by writing the database's current state to disc. As a
result, in the case of a failure, the recovery procedure may begin at the most recent
checkpoint rather than from the beginning of the transaction log.
Here's how the checkpoint technique works:
The DBMS periodically triggers a checkpoint to save the current state of the database
to a stable storage device.
During the checkpoint, the DBMS writes all the modified pages to disk and updates
the log file to indicate the checkpoint position.
After the checkpoint is completed, the DBMS can discard the log records before the
checkpoint position, since they are no longer needed for recovery.
If a failure occurs, the recovery process starts from the last checkpoint, and the DBMS
only needs to apply the log records after the checkpoint position.
The needs of the application and the system's features determine how frequently checkpoints
are made. The number of transactions completed, the volume of data updated, or the duration
of time from the previous checkpoint can all be used to determine when a checkpoint should
be made. To balance the recovery time and the performance overhead of the checkpoint
procedure, the checkpoint frequency must be properly used.
3. Redo:
Redoing is the process of replaying the changes made by committed transactions from the
transaction log to the database when a failure has occurred. By doing this, the database is
guaranteed to be restored to the condition it was in before to the failure.
A transaction is generally regarded as committed when the DBMS has made sure that the
changes made by the transaction have been recorded in the transaction log and the database
has been updated appropriately. The DBMS uses the information in the transaction log to
reapply the changes to the database in the case of a failure.
Here's how the redo technique works:
When a transaction is committed, the DBMS writes the transaction's changes to the
transaction log, along with a commit record.
If a failure occurs, the DBMS checks the transaction log to identify the last committed
transaction before the failure.
The DBMS then replays the changes made by the committed transactions from the
transaction log to the database.
Once the redo process is completed, the database is restored to the state it was in at
the time of the last committed transaction.
An advanced technique called redo can guarantee that the database is recovered
consistently after failure. But it can also take a while, mainly if there are many transactions to
replay. As a result, optimizing transaction processing and database architecture is critical to
lessen the need for redos and speed up recovery at the time of failure.
4. Undo
A transaction that failed or was aborted can be reversed as part of an undo database recovery
strategy. By reversing the consequences of the failed transaction, it is used to return the
database to a consistent state.
A transaction is often a sequence of actions carried out as a single piece of labour. The
database management system (DBMS) records the alterations that a transaction makes to the
database as it is carried out. The DBMS utilises the data in the transaction log to reverse the
changes made by the transaction if it fails or must be cancelled due to an error.
Here's how the undo technique works:
When a transaction starts, the DBMS creates a savepoint, which is a point in the
transaction where it can be rolled back to.
If the transaction encounters an error or is aborted, the DBMS uses the information in
the transaction log to undo the changes made by the transaction up to the savepoint.
The DBMS updates the transaction log to record the fact that the transaction was
undone.
Once the undo process is completed, the database is restored to the state it was in
before the failed transaction started.
After a failure, the database may be restored to a consistent form using the potent method of
undo. But, this method can also reduce the performance for the large number of transactions.
In order to reduce the need for undo, it's crucial to utilize it sparingly and optimize the
database design and transaction processing.
Shadow paging is an easy-to-use recovery method that eliminates the need for complicated
recovery algorithms and can reduce transaction recording costs.
However, maintaining the shadow copy consumes a significant amount of disc space,
particularly for big databases, and can also cause transactions to lag as every database page
must be replicated at the start of a transaction. Therefore, the usage of shadow paging must be
balanced with the requirements of the application and the limitations of the system.