The difference between undo and redo

Source: Internet
Author: User



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



Redo: Redo, perform the previous operation again.



What is Redo



Redo records transaction logs, divided into online and archived. For the purpose of recovery.



For example, if the machine is out of power, then the online redo logs is required to recover the system to the point of failure after the restart.



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



For example, truncate a table or other operation, want to revert to the previous state, also need.



What is Undo



REDO is to re-implement your operation, and undo, instead, is to undo the actions you have made, such as if you have a transaction execution failure or you regret it,






You need to fallback to the operation with the rollback command. Rollback is implemented at the logical level rather than the physical plane, because in a multiuser system, data structures, blocks, etc.






Change constantly, such as we insert a data, the table space is not enough, expand a new extent, our data is stored in this new extent, other users then






Also inserted in this extent data, and at this time I want to rollback, then obviously physically this extent revocation is not possible, because doing so will affect the operation of other users






。 So, rollback is a logical rollback, for example, for INSERT, then rollback is the delete.












First. Features of the data in undo:



1. Is the backup before data modification, mainly to ensure the user's read consistency



2. Generated when transaction modifies data



3. Save at least to end of transaction





Second. Undo Data's role:



1. Rollback (rollback) operation



2. Achieve read consistency and flashback query



3. Restoring data from a failed transaction



4. Instance recovery after a non-normal shutdown






Third. Undo Rollback Segment Features:



1. A rollback segment is a dedicated segment that is automatically created by an instance to support transaction runs, as well as a zone and block, and the rollback top automatically grows or shrinks as needed, which can be






The storage buffer to use for the specified transaction loop.



2. Only one rollback segment is used per transaction, and a rollback segment may serve multiple transactions at the same time



3. When a transaction begins, a rollback segment is specified, and the original data is copied to the rollback segment as the transaction is made, when the data is modified.



4. In the rollback segment, the transaction fills the extents until the end of the transaction or all of the space is exhausted, and if the current extents are not sufficient, the transaction requests the extension of the next disk in the segment






area, if all allocated extents are exhausted, the transaction overwrites the original extents or expands the new extents to be used if the rollback segment allows.



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









Fourth. Data types in the rollback segment:



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



1.Uncommitted undo information; Uncommitted rollback data, the transaction to which the data is associated is not committed and is used for read consistency, so the data cannot be






The data of the transaction is overwritten



2.Committed undo information; rollback data that has been committed but not expired, the transaction for which the data is associated has been committed, but is still being persisted by the undo retention parameter






The impact of inter-



3.Expired undo information; The transaction has been committed and the data has been saved longer than the time specified by the undo retention parameter, which is the data that has expired



When the rollback segment is full, the expired undo information is overridden, and when the expired data space is exhausted, the area of the committed undo information is overwritten,






The retention time specified by the undo retention parameter is destroyed and the data for uncommitted undo information is not allowed to be overwritten if the data submitted is requested






The time specified in the undo retention parameter is not overwritten, and you can specify retention GUARANTEE on the undo tablespace, with the following syntax:



ALTER tablespace UNDOTBS1 RETENTION GUARANTEE;









Fifth. The difference between the undo data and the redo data:









Redo--> Undo-->datafile



When you insert a record, both the table and the undo information are put into the redo, and the redo information is placed on the hard disk before commit or before. Failure, redo can restore those






Data that has been commit.






Redo-> Each operation is recorded in the Redo log, when an instance failure (like a power outage), resulting in data failure to update to the data file, the database must be restarted redo, re-






Update data to a data file



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






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



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






Redo-> the transaction that has been submitted, the instance will be written to the data file when it is restored.



Undo-> a business not submitted.






Redo is due to the fact that every commit, the modification of the data is immediately written to the online redo, but it does not necessarily write changes to the data file at the same time. Because the number






It has been submitted, but only exists in the online log file, so you need to recover the data from the online log files, re-apply, so that the data has changed in the number






According to the document also changed!






The reason for undo is that, in order to improve efficiency when Oracle is running, the DBWR process writes dirty blocks to the data if the user has not yet made a commit, but does not have much free memory.






File in order to free up valuable memory for use by other processes. That's why you need to undo. Because the commit statement has not been issued yet, Oracle's DBWR process has






No submitted data is written to the data file.






Undo is also datafile, possibly dirty buffer does not write back to the disk inside.



Only the first redo apply success, to ensure that the undo datafile inside the things are correct, and then can rollback






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



Without undo, the system will not know the previous state, redo can not talk about









Six. Relevant parameters related to undo



Undo_management = auto Automatic undo table space Management



Undo_tablespace = UNDOTBS1 Sets the name of the undo Tablespace, which can have multiple undo table spaces, but can only use one



Undo_retention = 900 (seconds) sets the minimum time for a snapshot to be saved and may still be overwritten within this time period



ALTER tablespace undo_ts RETENTION GUARANTEE; Forces all snapshots to be kept for the time specified by Undo_retention.






The difference between undo and redo


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.