Memory structure of Oracle log buffer

Source: Internet
Author: User
Tags commit rollback

We already know that log buffers are used to store log information about the changes in transactions to the data block. So what is the content of the log information here, and what is the structure of it?

The smallest unit of Oracle record database changes (that is, logging information) is the change vector. A change vector is used to describe a change made to any individual block of data in a database. The content of the change vector includes the version number of the changed block, the transaction operation code, the address of the altered block of data, and so on. The version number here is very important, and it helps the block to always reflect the current state. When Oracle creates a change vector, it copies its version number from the data block. When Oracle reads the change vector and applies the changes to the corresponding data block during recovery, the version number of the restored block is added to 1. The data block here can belong to a table or data index, or it can belong to a rollback segment. However, the change vector is not generated for temporary segments in the temporary table space.

When multiple change vectors are grouped together in order to complete a change to the database, Oracle calls the set of change vectors to be logged (redo record). The redo record is used to describe an atomic change to the database. The so-called atomic changes, that is, when the change in the application of changes in the vector, either all successful, or all failed, there is no part of the successful partial failure. Redo records can help the entire database reflect the current state.

A transaction produces at least one redo record and may produce multiple redo records. Oracle, in the process of applying log records for recovery, takes transactions as the smallest unit of recovery. Either restore the entire transaction or roll back the entire transaction. That is, either use the transaction redo all the change vectors in the record, or a change vector is not used.

Therefore, the log buffer is the number of redo records in the order in which they occur. At the same time, the log file is a file composed of a number of redo records sorted sequentially.

We give an example to illustrate the process of redo records and the generation of change vectors. For example, we issue the following UPDATE statement (assuming that there is no index on the Name column of table Redo_test):

Sql> select * from Redo_test;

ID NAME

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

1 ABC

2 ABC

sql> Update redo_test set name= ' CDF ' where id=1;

After the statement is issued, a redo record is generated to describe the modifications made to the data blocks in the table. Includes the following three change vectors.

Changes to the rollback Segment transaction table, which occurs in the rollback segment header. The transaction table contains the address of the modified block of data, the state of the transaction (commit or Active), and the address of the rollback segment used by the office. If the transaction table is modified, a change vector is generated for it.

Changes to the rollback segment data block. Store the old value (ABC) before the modification in the data block of the rollback segment. Then the rollback segment changes, resulting in a change vector.

Changes made to the data block of the Redo_test table. Store the modified new value (CDF) in the table's data block. When the data block changes, it generates a change vector.

As you can see from this process, there are three change vectors in the redo record for this update transaction. Of course, there may be other circumstances that will result in a new redo record, for example, if the modified column has an index, the index must be modified. A second redo record is generated to describe the modification of the indexed data block. The redo record at this time is the same as the first redo record, containing more than one change vector. In addition, when a commit or ROLLBACK statement is run after the transaction completes, a third redo record is generated. The redo record has only one change vector to record changes to the rollback Segment Transaction table, because the state of the transaction that is recorded in the transaction sheet needs to be updated when a commit or rollback is made.

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/database/Oracle/

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.