Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The difference between undo and redo

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Undo: undo, that is, cancel the previous operation.

Redo: redo and perform the previous operation again.

What is REDO?

REDO records transaction logs, which is divided into online and archived. For the purpose of recovery.

For example, if the machine has a power outage, then online redo logs is needed to restore the system to the point of failure after a restart.

For example, if the disk is broken, you need to use archived redo logs and online redo logs to recover the data.

For example, truncate a table or other operation that wants to return to its previous state is also needed.

What is UNDO?

REDO is to reimplement your operation, while UNDO, on the contrary, is to undo what you do, such as if you have a TRANSACTION execution that fails or you regret it.

Then you need to use the ROLLBACK command to fall back to before the operation. Rollback is implemented at the logical level rather than the physical level, because in a multi-user system, data structures, blocks, etc.

When we change from time to time, for example, when we INSERT a data, there is not enough space in the table, and a new EXTENT is extended. Our data is stored in the new EXTENT, and other users then

Data is also inserted into this EXTENT, and at this point I think ROLLBACK, then obviously this EXTENT undo is physically impossible, because doing so will affect the operations of other users.

. So, ROLLBACK is a logical rollback, for example, for INSERT, then ROLLBACK is DELETE.

1. Characteristics of data in undo:

one. It is a backup before data modification, mainly to ensure the read consistency of users.

two。 Generated when a transaction modifies data

three. Save at least until the end of the transaction

two. The role of undo data:

1. Rollback (rollback) operation

two。 Achieve read consistency and flashback query

3. Restore data from a failed transaction

4. Instance recovery after abnormal downtime

3. Characteristics of the undo rollback segment:

1. The rollback segment is a dedicated segment automatically created by the instance to support transaction operation, which is also composed of areas and blocks. The rollback top will automatically grow or shrink according to the actual needs.

A storage buffer for the specified transaction to recycle.

two。 Each transaction uses only one rollback segment, and one rollback segment may serve multiple transactions at the same time.

3. When a transaction starts, a rollback segment is specified, and during the transaction, when the data is modified, the original data is copied to the rollback segment.

four. In the rollback segment, the transaction will continue to fill the extent until the end of the transaction or all the space is used up. If the current extent is insufficient, the transaction will request an extension of the next disk in the segment.

Extent, if all allocated extents are used up, the transaction will cover the original extent or expand the new extent to use if the rollback segment allows.

five. The rollback segment exists in the undo table space, and there can be multiple undo table spaces in the database, but only one undo table space can be used at a time.

four。 Data types in the rollback segment:

The data in the rollback segment is mainly divided into the following three categories:

1.Uncommitted undo information; uncommitted rollback data, the transaction associated with the data is not committed and is used to achieve read consistency, so the data cannot be used by other

Covered by the data of the transaction

2.Committed undo information; has committed but not expired rollback data, and the transaction associated with the data has been committed, but is still subject to when the undo retention parameter is maintained

The influence between

The 3.Expired undo information; transaction has been committed, and the data preservation time has exceeded the time specified by the undo retention parameter, so it belongs to data that has expired.

When the rollback segment is full, the Expired undo information will be covered first. When the expired data space is used up, the area of the Committed undo information will be covered again.

At this point, the retention time specified by the undo retention parameter will be broken, and the data of Uncommitted undo information is not allowed to be overwritten. If the submitted data is required,

It will not be overwritten within the time specified in the undo retention parameter. You can specify RETENTION GUARANTEE on the undo table space. The syntax is as follows:

ALTER TABLESPACE UNDOTBS1 RETENTION GUARANTEE

five. The difference between undo data and redo data:

Redo-- > undo-- > datafile

When insert records, the table and undo information will be put into redo, before commit, redo information will be put on the hard disk. In the event of a failure, redo can restore those

Data that has been commit.

Redo- > every operation is first recorded in the redo log. When an instance failure occurs (such as a power outage), resulting in the data not being updated to the data file, the database must be restarted by redo and restarted.

Update the data to a data file

Undo- > record a copy before the change, but when you system rollback, overwrite the copy back to the original data

Redo- > record all actions for recovery (redo records all the database transaction used for recovery)

Undo- > record all previous impressions for undo is used to store uncommited data infor used for rollback

Redo- > transactions that have been submitted must be written to the data file when the instance is resumed

Undo- > uncommitted transactions.

The reason for redo is that every time you commit, changes to the data are immediately written to the online redo, but not necessarily to the data file at the same time. Because of the number

It has been submitted, but only exists in the online log file, so when restoring, you need to find the data from the online log file and reapply it so that the data has been changed in the number

Change it according to the file!

The reason for undo is that when oracle is running normally, in order to improve efficiency, if the user does not have commit but has not much free memory, the DBWR process will write dirty blocks to the data.

File to free up valuable memory for use by other processes. This is why UNDO is needed. Because no commit statement has been issued yet, but the dbwr process of oracle has already set the

The data that was not submitted was written to the data file.

Undo is also datafile. Maybe dirty buffer didn't write it back to disk.

Only when the redo apply is successful can we ensure that everything in the undo datafile is correct and then rollback.

The purpose of undo is to restore the system to the state before the system crash (before shutdown), and then redo is to ensure the consistency of the system.

Without undo, the system will not know the previous state, and redo will be out of the question.

six。 Related parameters related to undo

Undo_management = auto automatic undo tablespace management

Undo_tablespace = undotbs1 sets the name of the undo tablespace. Multiple undo tablespaces can exist, but only one can be used at the same time.

Undo_retention = 900s (seconds) set the minimum time for snapshots to be saved, which may still be overwritten during this period after setting

ALTER TABLESPACE UNDO_TS RETENTION GUARANTEE; forces all snapshots to be saved for the time specified by undo_retention.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report