UNDO -- Concept

 Undo data
  
Records of the actions of transactions, primarily before they are committed. The database can use undo data to logically reverse the effect of SQL statements. Undo data is stored in undo segments.

回滚数据

  事务活动的被提交前的记录。数据库可以使用回滚数据来逻辑地撤销SQL语句的影响。UNDO数据存储在UNDO段中。

Undo Segments
  Oracle Database maintains records of the actions of transactions, collectively known as undo data. Oracle Database uses undo to do the following:
■Roll back an active transaction
■Recover a terminated transaction
■Provide read consistency
■Perform some logical flashback operations
  Oracle Database stores undo data inside the database rather than in external logs. Undo data is stored in blocks that are updated just like data blocks, with changes to these blocks generating redo. In this way, Oracle Database can efficiently access undo data without needing to read external logs.
Undo data is stored in an undo tablespace. Oracle Database provides a fully automated mechanism, known as automatic undo management mode, for managing undo segments and space in an undo tablespace.

UNDO段
ORACLE数据库管理事务活动的记录,收集位UNDO数据。数据库使用UNDO来实现以下功能:
■回滚一个活动的事务
■恢复一个终止的事务
■提供读一致性
■进行一些逻辑闪回操作
ORACLE数据库把undo数据存储在数据库内部而不是外部日志。UNDO数据是存储在块中的,它的更新是跟数据块一样的,对UNDO块的更新同样会产生日志。在这种方式下,ORACLE数据库可以高效地使用undo数据而不用去读外部日志。
UNDO数据存储在UNDO表空间中。ORACLE数据库提供一种全自动的管理机制,即UNDO自动管理模式,用来管理在一个UNDO表空间中管理UNDO段以及空间。


Undo Segments and Transactions
  When a transaction starts, the database binds (assigns) the transaction to an undo segment, and therefore to a transaction table, in the current undo tablespace. In rare circumstances, if the database instance does not have a designated undo tablespace, then the transaction binds to the system undo segment.
Multiple active transactions can write concurrently to the same undo segment or to different segments. For example, transactions T1 and T2 can both write to undo segment U1, or T1 can write to U1 while T2 writes to undo segment U2.
  Conceptually, the extents in an undo segment form a ring. Transactions write to one undo extent, and then to the next extent in the ring, and so on in cyclical fashion. Figure 12–20 shows two transactions, T1 and T2, which begin writing in the third extent (E3) of an undo segment and continue writing to the fourth extent (E4).

UNDO段和事务
当一个事务开始,数据库在当前的UNDO表空间中绑定(分配)一个UNDO段及一个事务表给事务。在少数环境中,如果数据库实例没有一个指定的UNDO表空间,那么事务会绑定SYSTEM的UNOD段。

多个活动的事务可以并发地写一样的UNDO段或者不同的段。比如说,事务T1和T2可以一起写UNDO段U1,或者T1可以写U1,同时T2写U2。
理论上来说,一个UNDO段里面的区是一个圆环的形式。事务在一个UNDO区中写数据,然后是圆环的下一个,一个一个这样子循环往复。
如表格12-20表现的两个事务T1和T2,它们同时在UNDO段的E3区开始写,然后接下来则到了E4区开始写。

  At any given time, a transaction writes sequentially to only one extent in an undo segment, known as the current extent for the transaction. Multiple active transactions can write simultaneously to the same current extent or to different current extents. Figure 12–20 shows transactions T1 and T2 writing simultaneously to extent E3. Within an undo extent, a data block contains data for only one transaction.
  As the current undo extent fills, the first transaction needing space checks the availability of the next allocated extent in the ring. If the next extent does not contain data from an active transaction, then this extent becomes the current extent. Now all transactions that need space can write to the new current extent. In Figure 12–21, when E4 is full, T1 and T2 continue writing to E1, overwriting the nonactive undo data in E1.

  在任意一个给定的时间,一个事务只在一个UNDO段中的一个区上顺序写,称之为事务的当前区。多个活动事务可以同时在同样的或者不同的当前区中写数据。如图12-20所显示的,事务T1和T2同时在写E3区。
在一个UNDO区里面,一个数据块里面的数据只是一个事务的。
当目前的UNDO区填满后,第一个需要空间的事务会检查圆圈的下一个区的可用性。假如下个区不包含活动事务的数据,那么这个区就将变为当前区。然后所有需要空间的事务都会往当前空间里写数据。
在图12-21中,当E4满了后,T1跟T2开始往E1里面写,覆盖掉E1里面的非活动的UNDO数据。

  At any given time, a transaction writes sequentially to only one extent in an undo segment, known as the current extent for the transaction. Multiple active transactions can write simultaneously to the same current extent or to different current extents. Figure 12–20 shows transactions T1 and T2 writing simultaneously to extent E3. Within an undo extent, a data block contains data for only one transaction.
  As the current undo extent fills, the first transaction needing space checks the availability of the next allocated extent in the ring. If the next extent does not contain data from an active transaction, then this extent becomes the current extent. Now all transactions that need space can write to the new current extent. In Figure 12–21, when E4 is full, T1 and T2 continue writing to E1, overwriting the nonactive undo data in E1.

在任意一个给定的时间,一个事务只在一个UNDO段中的一个区上顺序写,称之为事务的当前区。多个活动事务可以同时在同样的或者不同的当前区中写数据。如图12-20所显示的,事务T1和T2同时在写E3区。
在一个UNDO区里面,一个数据块里面的数据只是一个事务的。
当目前的UNDO区填满后,第一个需要空间的事务会检查圆圈的下一个区的可用性。假如下个区不包含活动事务的数据,那么这个区就将变为当前区。然后所有需要空间的事务都会往当前空间里写数据。
在图12-21中,当E4满了后,T1跟T2开始往E1里面写,覆盖掉E1里面的非活动的UNDO数据。

  If the next extent does contain data from an active transaction, then the database must allocate a new extent. Figure 12–22 shows a scenario in which T1 and T2 are writing to E4. When E4 fills up, the transactions cannot continue writing to E1 because E1 contains active undo entries. Therefore, the database allocates a new extent (E5) for this undo segment. The transactions continue writing to E5.

如果下一个区包含活动事务的数据,那么数据库必须分配一个新的区。图12-22显示的场景里,T1和T2正在写E4,当E4满了厚,事务没办法继续写E1,因为E1包含了活动UNDO的记录。所以,数据库分配了一个新的区E5给这个UNDO段,然后事务继续在E5里面写。

Transaction Rollback
  When a ROLLBACK statement is issued, the database uses undo records to roll back changes made to the database by the uncommitted transaction. During recovery, the database rolls back any uncommitted changes applied from the online redo log to the data files. Undo records provide read consistency by maintaining the before image of the data for users accessing data at the same time that another user is changing it.

事务回滚

  当一个“ROLLBACK"语句发出的时候,数据库使用undo记录来回滚未提交的事务变更。在恢复期间,数据库通过应用在线重做日志来回滚任何未提交的变更。UNDO保持数据的前镜像来让用户群获取到正在被其他用户修改的数据,通过这种方式实现了读一致性。

Managing Undo Tablespaces
This section describes the various steps involved in undo tablespace management and contains the following sections:
■ Creating an Undo Tablespace
■ Altering an Undo Tablespace
■ Dropping an Undo Tablespace
■ Switching Undo Tablespaces
■ Establishing User Quotas for Undo Space
■ Undo Space Data Dictionary Views

管理undo表空间
这一章节描述undo表空间管理的多个步骤,包含以下章节:
■ 创建undo表空间
■ 修改undo表空间
■ 删除undo表空间
■ 切换undo表空间
■ 设置用户undo表空间配额
■ undo空间数据字典视图

Creating an Undo Tablespace
Although Database Configuration Assistant (DBCA) automatically creates an undo tablespace for new installations of Oracle Database Release 11g, there may be occasions when you want to manually create an undo tablespace.
There are two methods of creating an undo tablespace. The first method creates the undo tablespace when the CREATE DATABASE statement is issued. This occurs when you are creating a new database, and the instance is started in automatic undo management mode (UNDO_MANAGEMENT = AUTO). The second method is used with an
existing database. It uses the CREATE UNDO TABLESPACE statement.
You cannot create database objects in an undo tablespace. It is reserved for system-managed undo data.
Oracle Database enables you to create a single-file undo tablespace. Single-file, or bigfile

Using CREATE DATABASE to Create an Undo Tablespace
You can create a specific undo tablespace using the UNDO TABLESPACE clause of the CREATE DATABASE statement.
The following statement illustrates using the UNDO TABLESPACE clause in a CREATE DATABASE statement. The undo tablespace is named undotbs_01 and one data file,
/u01/oracle/rbdb1/undo0101.dbf, is allocated for it.
CREATE DATABASE rbdb1
CONTROLFILE REUSE
.
.
.
UNDO TABLESPACE undotbs_01 DATAFILE '/u01/oracle/rbdb1/undo0101.dbf';

If the undo tablespace cannot be created successfully during CREATE DATABASE, the entire CREATE DATABASE operation fails. You must clean up the database files, correct the error and retry the CREATE DATABASE operation.
The CREATE DATABASE statement also lets you create a single-file undo tablespace at database creation. This is discussed in "Supporting Bigfile Tablespaces During Database Creation" on page 2-20.
Using the CREATE UNDO TABLESPACE Statement
The CREATE UNDO TABLESPACE statement is the same as the CREATE TABLESPACE statement, but the UNDO keyword is specified. The database determines most of the
attributes of the undo tablespace, but you can specify the DATAFILE clause.
This example creates the undotbs_02 undo tablespace with the AUTOEXTEND option:

创建undo表空间
虽然在11G的时候使用dbca创建新数据库的时候会自动创建一个undo表空间,某些情况下你仍然可能需要手动创建undo表空间。
有两种方式可以创建undo表空间。
第一种方式是在通过CREATE DATABASE语句创建数据库的时候创建。这发生在你创建新数据库的时候,实例以自动undo管理模式启动(UNDO_MANAGEMENT = AUTO)。
第二种方式是在现有的数据库中通过create undo tablespace来创建。
你不能在undo表空间中创建数据库对象。它是保留用于系统管理undo数据的。
oracle数据库允许你创建单文件undo表空间。单文件,或者bigfile。


























原文地址:https://www.cnblogs.com/ryanw/p/8530066.html