Home > Database > Mysql Tutorial > body text

What are the database recovery technologies?

青灯夜游
Release: 2023-01-07 11:45:53
Original
22307 people have browsed it

Database recovery technologies include: 1. Data dump, that is, the process in which the DBA regularly copies the entire database to a tape or another disk and saves it. 2. Register the log file. The log file is a file used to record the update operations of the transaction on the database. Setting up the log file can perform transaction failure recovery, system failure recovery, and assist backup copies in media failure recovery.

What are the database recovery technologies?

The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.

Overview of Database Recovery

The database management system must have the function of recovering the database from an error state to a known correct state. This is database recovery. . The recovery subsystem is an important part of the database management system and is quite large, often accounting for more than ten percent of the entire system code. Whether the recovery technology used in the database system is effective not only plays a decisive role in the reliability of the system, but also has a great impact on the operating efficiency of the system. It is an important indicator to measure the performance of the system.

System failure is called a soft failure, and media failure is called a hard failure. Hard faults refer to external storage faults, such as disk damage, head collision, instantaneous strong magnetic field interference, etc. This type of failure will destroy the database or part of the database and affect all transactions that are accessing this part of the data.

Computer virus

Summary of various types of failures, there are two possibilities for the impact on the database. One is that the database itself is damaged. The second is that the database has not been damaged, but the data may be incorrect. This is caused by the abnormal termination of the transaction.

Recovery implementation technology

The recovery mechanism involves two key issues:

1. How to establish redundant data;

2. How to use these redundant data to implement database recovery.

The most common techniques for creating redundant data are data dumps and log files. Usually in a database system, these two methods are used together.

Data dump

Data dump is the basic technology used in database recovery. The so-called dump is the process in which the DBA regularly copies the entire database to a tape or another disk and saves it. These spare data become standby copies or backup copies.

Dumps can be divided into static dumps and dynamic dumps.

  • Static dump is a dump operation performed when there are no running transactions in the system. That is, when the dump operation starts, the database is in a consistent state, and no access or modification activities to the database are allowed during the dump. Obviously, what you get from a static dump must be a consistent copy of the data.

  • Dynamic dump means that the database is allowed to be accessed or modified during the dump. However, the data on the backup copy at the end of the dump is not guaranteed to be correct and valid. To this end, it is necessary to register the modification activities of each transaction to the database during the dump period and create a log file. In this way, the backup copy plus the log file can restore the database to the correct state at a certain moment.

Dumps can be divided into two methods: massive dumps and incremental dumps. Mass dump refers to dumping the entire database each time. Incremental dump refers to dumping only the data updated since the previous dump. From a recovery perspective, it is generally more convenient to use backup copies obtained from mass dumps for recovery.
Data dump methods can be divided into four categories: dynamic incremental dump, dynamic mass dump, static incremental dump, and static mass dump.

Register log file

Format and content of log file

Log file is used to A file that records transaction updates to the database. There are two main formats of log files: log files in records and log files in data blocks.

For log files in units of records, the contents that need to be registered include:

1. The start mark of each transaction
2. The end mark of each transaction
3. Each transaction All update operations

The content of each log record includes:

1. Transaction identification (indicate which transaction it is)
2. Type of operation (insert, delete or modify)
3. Operation object (record internal identification)
4. Old value of data before update
5. New value of data after update

The role of log files

Log files play a very important role in data recovery. It can be used for transaction failure recovery and system failure recovery, and assists backup copies in media failure recovery.

The specific functions are:

1. Log files must be used for transaction failure recovery and system failure recovery.

2. In dynamic dump mode, log files must be created, backup copies and Log files are combined to effectively restore the database.

3. In static dump mode, log files can also be created.

Register log file

In order to ensure that the database is recoverable, two principles must be followed when registering log files:
1. The order of registration must be strictly in accordance with the time order of concurrent transaction execution
2. Log files must be written first, and then written database.

Recovery strategy

Recovery of transaction failure

Recovery of transaction failure is automatically performed by the system Completed, transparent to users. The system recovery steps are:

1. Scan the log file in reverse direction (that is, scan the log file from the end forward) to find the update operation of the transaction.

2. Perform the reverse operation of the update operation of the transaction. That is, the "value before update" in the log record is written to the database. In this way, if the record is an insertion operation, it is equivalent to a delete operation; if the record is a delete operation, an insertion operation is performed; if it is a modification operation, it is equivalent to modifying the previous value instead of the modified value.

3. Continue to scan the log file in reverse, find other update operations of the transaction, and perform the same processing.

4. Continue processing in this manner until the start mark of this transaction is read, and transaction failure recovery is completed.

Recovery from system failure

Recovery from transaction failure is automatically completed by the system and is transparent to users. The recovery steps of the system are:

1. Scan the log file forward to find the transactions that have been submitted before the failure occurs, and record their transaction identifiers in the redo queue. At the same time, find out the transactions that have not been completed when the failure occurs, and count their transaction representations into the undo queue.

2. Undo each transaction in the undo (UNDO) queue.

The method for UNDO processing is to reversely scan the log file and perform the reverse operation on the update operation of each UNDO transaction, that is, write the "pre-update value" in the log record to the database.

3. Redo REDO processing for each transaction in the redo queue

The method for REDO processing is: forward scan the log file and re-register the log file for each REDO transaction operation. That is, the "updated value" in the log record is written to the database.

Recovery from media failure

The method to recover from the failure is to reinstall the database and then redo the completed transactions.

1. Loading the latest database backup copy is to restore the database to the consistency state of the latest dump.

2. Load the corresponding copy of the log file and redo the completed transaction. That is, first scan the log file to find out the identity of the transaction that was committed when the failure occurred, and count it into the redo queue. Then scan the log file forward and redo all transactions in the redo queue. That is, the "updated value" in the log record is written to the database.

Recovery from media failure requires DBA intervention. However, the DBA only needs to reinstall the recently dumped database copy and related log file copies, and then order the recovery commands provided by the system. The specific recovery operation is still completed by the DBMS.

Database Mirroring

As the disk capacity becomes larger and larger, the price becomes cheaper and cheaper. In order to avoid disk media failure affecting the availability of the database, many database management systems Provides data distribution function for database recovery. According to the DBA's request, the entire database or key data in it is automatically copied to another disk.

Since database mirroring is achieved by copying data, frequent copying of data will naturally reduce system operating efficiency. Therefore, in time applications, users often choose to only mirror key data and log files instead of mirroring the entire database. Mirror.

(Recommended tutorial: mysql video tutorial)

The above is the detailed content of What are the database recovery technologies?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template