Database-Database Recovery technology

Source: Internet
Author: User

Transaction definition

Jim (James) Gray James Gray
1998 Turing Award winner
Database technology and transaction processing specialists
Ii. Characteristics of the transaction

Defined
A sequence of database operations
An inseparable unit of work
Basic unit of recovery and concurrency control

Transaction and Program comparisons
In a relational database, a transaction can be one or more SQL statements, or it can contain one or more programs.
A program typically contains multiple transactions

显式定义方式   BEGIN TRANSACTION                   BEGIN TRANSACTION          SQL 语句1                                             SQL 语句1          SQL 语句2                                             SQL 语句2          。。。。。                                            。。。。。      COMMIT                                          ROLLBACK隐式方式当用户没有显式地定义事务时,DBMS按缺省规定自动划分事务
Characteristics of the transaction (ACID properties)

ACID properties of the transaction:
Atomicity (atomicity)
Consistency (consistency)
Isolation (Isolation)
Persistence (Durability)

The fault is unavoidable.
System failure: computer software and hardware failure
Human failure: operator error, malicious damage, etc.
Recovery of databases
Restores a database from an error state to a known correct state (also known as a consistent state), at which time the database contains only the data that was committed by the successful transaction.

Types of faults

Faults inside a transaction
System failure
Media failure
Computer viruses

Faults inside a transaction

Some can be found through the transaction program itself (see the transfer below
Examples of services)
Some are unexpected, such as: Deadlock and select the transaction revocation

例如,银行转账事务,这个事务把一笔金额从一个账户甲转给另一个账户乙。     BEGIN TRANSACTION    读账户甲的余额BALANCE;    BALANCE=BALANCE-AMOUNT;(AMOUNT 为转账金额)    写回BALANCE;    IF(BALANCE < 0 ) THEN     {         打印‘金额不足,不能转账‘;         ROLLBACK;(撤销刚才的修改,恢复事务)     }     ELSE     {          读账户乙的余额BALANCE1;          BALANCE1=BALANCE1+AMOUNT;          写回BALANCE1;          COMMIT;      }

The two update operations included in this example are either complete or not. Otherwise, the database will be in an inconsistent state, such as reducing the balance of account a only and not increasing the balance of account B.
In this procedure, if there is a shortfall in account a balance, the application can discover and let the transaction roll back, undo the modifications made, and restore the database to the correct or consistent state.

More failures within a transaction are unexpected and cannot be handled by the application.
Operation Overflow
The concurrent transaction has a deadlock and is selected to revoke the transaction
Violation of certain integrity limits, etc.
Later, transaction failures refer only to such unexpected failures
Recovery of transaction failure: Undo Transaction (undo)

System failure

Known as a soft fault, is any event that causes the system to stop functioning, making
The system will restart.
The whole system was suddenly destroyed.
All running transactions are not terminated properly
Do not destroy the database
All the information in the in-memory database buffers is missing

Specific types of hardware errors (such as CPU failure)
Operating system failure
DBMS code Error
System Power off

Recovery of system failures

When a system failure occurs, the transaction is not committed
Recovery policy: Forcibly undo (undo) All unfinished transactions
When a system failure occurs, the transaction is committed, but the information in the buffer has not been fully written back to disk.
Recovery policy: Redo (REDO) all committed transactions

Media failure

Called a hard fault, refers to a external memory fault
Disk corruption
Head collision
Some kind of potential error in the operating system
Instantaneous strong magnetic field interference

Mount database copy of data at some point before media failure occurs
Redo all successful transactions from this time, and re-write the results of these transactions into the database

Computer viruses

A kind of artificial fault or destruction, is a kind of computer program developed by some mischief-makers
can reproduce and spread
Harm
Destroying and stealing data from the system
Destroying system files

There are two possible types of failures that affect the database
One is that the database itself is destroyed
The second is that the database is not corrupted, but the data may be incorrect, because the operation of the transaction is aborted by an abnormal termination.

The implementation technology of recovery
恢复操作的基本原理:冗余    利用存储在系统其它地方的冗余数据来重建数据库中已被破坏或不正确的那部分数据恢复机制涉及的关键问题如何建立冗余数据数据转储(backup)登录日志文件(logging) 如何利用这些冗余数据实施数据库恢复  
Data dump (dump)

Refers to the process by which a DBA copies an entire database to a tape or another disk, and the alternate data is called a backup copy or back-up copy.
How to use
The backup copy can be re-loaded after the database has been compromised
Reloading a backup copy only restores the database to the state at the time of the dump
1. Static dumps and dynamic dumps

在系统中无运行事务时进行的转储操作转储开始时数据库处于一致性状态转储期间不允许对数据库的任何存取、修改活动得到的一定是一个数据一致性的副本 优点:实现简单缺点:降低了数据库的可用性,通常数据库是关闭的转储必须等待正运行的用户事务结束 新的事务必须等转储结束
转储操作与用户事务并发进行转储期间允许对数据库进行存取或修改优点不用等待正在运行的用户事务结束不会影响新事务的运行动态转储的缺点不能保证副本中的数据正确有效[例]在转储期间的某个时刻Tc,系统把数据A=100转储到磁带上,而在下一时刻Td,某一事务将A改为200。转储结束后,后备副本上的A已是过时的数据了利用动态转储得到的副本进行故障恢复需要把动态转储期间各事务对数据库的修改活动登记下来,建立日志文件后备副本加上日志文件才能把数据库恢复到某一时刻的正确状态

2. Mass dumps and incremental dumps

海量转储: 每次转储全部数据库增量转储: 只转储上次转储后更新过的数据海量转储与增量转储比较从恢复角度看,使用海量转储得到的后备副本进行恢复往往更方便但如果数据库很大,事务处理又十分频繁,则增量转储方式更实用更有效
Log file

A log file is a document used to record a transaction's update operation to a database.
Thing
Format of the log file
Log files in record units
Log files in blocks of data

Log file contents in record units
Start tag for each transaction (begin TRANSACTION)
End tag for each transaction (commit or rollback)
All update operations for each transaction
All of the above as a log record in the log file

Log files in records, contents of each log record
Transaction ID (which transaction is indicated)
Type of operation (insert, delete, or modify)
Manipulating objects (recording internal identities)
Old value of pre-update data (this is a null value for insert operations)
The new value of the updated data (this is a null value for the delete operation)

Format and content of the log file
<T1 start><T1, A, 0, ><T1 commit><T2 start><T2, B, 0, ><T3 start>                   <T3, C, 0, ><T3, C, ten, ><checkpoint><T4 start><T2 commit><T4, A, ten, ><T5 start><T4, D, 0, ><T4 commit>
logtoandoftwo members (fileson a separate disk driveon a separate disk controllerRedo logs heavily influence performance

Log files in blocks of data, the contents of each log record
Transaction ID (indicates that transaction)
Data blocks that are updated

The role of log files

For transaction failure recovery
For system failure recovery
Assist backup copy for media failure recovery

Database-Database Recovery technology

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.