Oracle principle: UNDO table space

UNDO table space is also known as rollback table space and undo table space. Undo segments are stored in the UNDO tablespace. A database can have multiple UNDO tablespaces, but at the same time, only the same UNDO tablespace can be used.

1. The role and mechanism of UNDO table space

For DML statements, as long as the data block is modified, Oracle will retain the original data block before modification and store it in the Undo segment (rollback segment). When the rollback operation is performed, the original data will be overwritten again. The rollback segment is stored in the UNDO tablespace. UNDO table space management is divided into manual management and automatic management. In 11g, the default is to use automatic management mode.

The role of UNDO: keep the original data block before modification. Mainly used for consistent reads, rollback transactions, and instance recovery.

Example of consistent reading: User A executes a SQL query operation select * from salary_tbl. It takes 1 minute. At this time user B executed

update salary_tbl set salary=2000 where salary = 1000; Then the data queried by user A is 1000 instead of 2000, the data queried at the current moment. If the UNDO tablespace size is insufficient, the UNDO space will be overwritten. At this time, the original data can not be queried when the original data is queried. At this time, an ORA-1555 error is reported: snapshoot too old   

Instance recovery after the database coredown: It occurs after the SMON process completes the roll forward and opens the database. The SMON process goes back to view the transaction table recorded in the first data block of UNDO SEGMENT. When the database is down, there will be no commit or rollback. Things are all rolled back.

undo_retention: It is the attribute in the UNDO block, which determines how many seconds the data in the undo block is saved at least. For example, for a 100-second query, undo_retention is 50. If the UNDO space is insufficient, the expired data will be reset first. If it is not reset, you can still query. If the data is reset, then the query operation for 100 seconds at this time will report an ORA-1555 error.

Retention garentee: It is an attribute in the UNDO block, a new feature starting at 10g. Ensure that the data in the UNDO segment has not reached undo_retention and will never be overwritten.

Therefore, the priority order of using UNDO tablespace is: empty undo data block>undo_retention expired data block>data block without retention garentee set>error

 

Two, UNDO table space related operations

Query table space select * from dba_tablespaces.. As long as the value of the field CONTENTS is UNDO, it is UNDO table space,

View UNDO table space management mode: >> show parameter undo_management

Create the UNDO tablespace:

create undo tablespace temp2 tempfile 
'D:\ORACLE\ORADATA\ORCL\undo2_01.dbf' size 10m autoextend on;

Allocate temporary files to the table space: alter tablespace <spacesname> add tempfile'<path/file name.dbf>' size [100m] autoextend on;

View the default UNDO tablespace: show parameter undo

The system default UNDO tablespace switch alter system set undo_tablespace ='<spacesname>';

启用[取消] retention garentee: alter tablespace <spacename> retention [ [garentee]  or [nogarentee] ];

查询 retention garentee 状态: select tablespace_name,a.retention from dba_tablespaces a ;

更改undo_retention :  alter system set undo_retention   =1000;

Query the usage of UNDO table space: select * from v$undostat; (Data block TXNCOUNT used by UNDOBLKS, number of transactions BEGIN_TIME and END_TIME UNDO effective time and end time)

 

Three, the new features of 11g UNDO table space

 RMAN backup and recovery UNDO tablespace: It is a backup optimization about UNDO tablespace. Before 11g, all UNDO tablespaces were automatically backed up. In the actual production environment, the historical data of the UNDO tablespace is very large, and the data that is not used for backup does not take up space tightly and affects the execution efficiency. RMAM backup: the data has been submitted and there is no need to back it up.

Guess you like

Origin blog.csdn.net/superSmart_Dong/article/details/107348641