Oracle Roll forward and rollback

Source: Internet
Author: User
Tags commit rollback

Case study (1)

Let's say I modified a piece of data: Update people set name= ' Fusnow ' where name= ' old Fusnow ';

The things I need to do include:

Generate redo information in redo log buffer (including Redo,undo redo of the table, index or whatever)

Modify Name= ' Fusnow ' in buffer cache, modify undo segment

------------------

Situation 1

If everything is OK, I now commit,commit will trigger LGWR to write the information in redo log buffer to the redo log file of disk, if this operation completes successfully, then my data is safe, now if the system crashes, although may lose the buffer Cache in the dirty data, but can be found in the Redo log redo information, so you can recover, of course, this situation does not rollback.

------------------

Situation 2

If LGWR redo log buffer in the process of writing the information to disk redo log file in the course of the system collapsed, that in fact, the user is not successful commit the error, at this time datafile and redo log do not have the information we want, so just, When the system started, I changed the roll forward/back.

------------------

Situation 3

If a commit before, what causes us to flush buffer cache, such as buffer cache full, Oracle to the buffer cache dirty data written to disk, which will trigger the DBWR, But DBWR must trigger the LGWR before writing, write the data in the redo log buffer to redo log file first. The reason is simple, if the LGWR is not triggered, since the dirty data for my changes include table changes and undo changes, and Dbwr probably didn't write the dirty data to disk in one IO, if that's the case, we wrote the table changes before we could write undo dirty data. The database collapsed, and now our state is datafile inside have changed table data, no undo data, redo inside no redo information, because I was no commit, so to roll back, but this situation is impossible, because undo lost, The redo that can regenerate undo are also lost. Therefore, DBWR must trigger LGWR.

If in the DBWR trigger LGWR, we first wrote the table changes, before the time to write undo dirty data when the database collapsed, we are actually first roll forward, through the redo to generate undo, and then rollback, through the undo rollback transaction.

Of course, some brothers have also mentioned that the order is 1.roll forward, 2.open database, 3.rollback, I think this is mainly Oracle in order to save time, because the design according to 1.roll forward, 2.rollback, 3. The order of open database should also be OK, but this is slower, we can completely open the database at the end of roll forward, then let the user access to other parts of the databases, let Smon slowly rollback, At this point, if the user wants to access the data being rolled back will be blocked. Of course, in fast mode, Oracle prioritizes the blocks that users want to access, allowing users to access the data that is being rollback as quickly as possible. Rollback

Case Study (2)

Suppose you have an action statement:

Update GAOJF set name= ' Exitgogo ' where name= ' Old_exitgogo ';

This statement is executed in this way:

1: First check name= ' Old_exitgogo ' whether recorded in buffer cache, if not, read into the buffer.

2: The transaction segment is allocated in the corresponding Rollback segment Transaction table in the rollback segment table space, which generates redo information.

3: This operation also generates redo information and records write redo buffer by reading from the rollback segment or by creating a name= ' Old_exitgogo ' in buffer or buffer cache.

4: In the data buffer modifies name= ' Exitgogo ', this operation's log information is also written to redo buffer.

5: It is important to record the submission in redo buffer when the user submits, and to mark the transaction as inactive (inactive) in the rollback segment.

As you can see, redo and undo occur alternately during a transaction, and redo buffer first records the data before the transaction changes and the changed data, then writes the data before the change to the rollback segment before modifying the data in the data buffer.

Related Article

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.