Oracle® Database Administrator's Guide 10g Release 1 (10.1) Part Number B10739-01 |
|
|
View PDF |
This chapter describes how to manage the undo tablespace, which stores information used to roll back changes to the Oracle Database. It contains the following topics:
See Also: Part III, " Automated File and Storage Management " for information about creating an undo tablespace whose datafiles are both created and managed by the Oracle Database server. |
Every Oracle Database must have a method of maintaining information that is used to roll back, or undo, changes to the database. Such information consists of records of the actions of transactions, primarily before they are committed. These records are collectively referred to as undo.
Undo records are used to:
Roll back transactions when a ROLLBACK
statement is issued
Recover the database
Provide read consistency
Analyze data as of an earlier point in time by using Flashback Query
Recover from logical corruptions using Flashback features
When a ROLLBACK
statement is issued, undo records are used to undo changes that were made to the database by the uncommitted transaction. During database recovery, undo records are used to undo any uncommitted changes applied from the redo log to the datafiles. Undo records provide read consistency by maintaining the before image of the data for users who are accessing the data at the same time that another user is changing it.
Earlier releases of Oracle Database used rollback segments to store undo. Oracle9i introduced automatic undo management, which simplifies undo space management by eliminating the complexities associated with rollback segment management. Oracle strongly recommends that you use undo tablespace to manage undo rather than rollback segments.
See Also: "Migration to Automatic Undo Management" for information on how to migrate to automatic undo management |
This section introduces the concepts of Automatic Undo Management and discusses the following topics:
In past releases, when you used the rollback segment method of managing undo space, you were said to be operating in the manual undo management mode. Now, you use the undo tablespace method, and you are said to be operating in the automatic undo management mode. You determine the mode at instance startup using the UNDO_MANAGEMENT
initialization parameter. The default value for this parameter is MANUAL
. You set it to AUTO
to enable automatic undo management.
Notes:
|
The following initialization parameter setting causes the STARTUP
command to start an instance in automatic undo management mode:
UNDO_MANAGEMENT = AUTO
An undo tablespace must be available, into which the database will store undo records. The default undo tablespace is created at database creation, or an undo tablespace can be created explicitly. The methods of creating an undo tablespace are explained in "Creating an Undo Tablespace"
When the instance starts up, the database automatically selects for use the first available undo tablespace. If there is no undo tablespace available, the instance starts, but uses the SYSTEM
rollback segment for undo. This is not recommended in normal circumstances, and an alert message is written to the alert file to warn that the system is running without an undo tablespace. ORA-01552 errors are issued for any attempts to write non-SYSTEM
related undo to the SYSTEM
rollback segment.
If the database contains multiple undo tablespaces, you can optionally specify at startup that you want an Oracle Database instance to use a specific undo tablespace. This is done by setting the UNDO_TABLESPACE
initialization parameter. For example:
UNDO_TABLESPACE = undotbs_01
In this case, if you have not already created the undo tablespace (in this example, undotbs_01
), the STARTUP
command will fail. The UNDO_TABLESPACE
parameter can be used to assign a specific undo tablespace to an instance in an Oracle Real Application Clusters environment.
The following is a summary of the initialization parameters for automatic undo management mode:
Initialization Parameter | Description |
---|---|
UNDO_MANAGEMENT |
If AUTO , use automatic undo management mode. If MANUAL , use manual undo management mode. The default is MANUAL . |
UNDO_TABLESPACE |
An optional dynamic parameter specifying the name of an undo tablespace to use. This parameter should be used only when the database has multiple undo tablespaces and you want to direct the database instance to use a particular undo tablespace. |
UNDO_RETENTION |
A dynamic parameter specifying the minimum length of time to retain undo. The default is 900 seconds. The setting of this parameter should take into account any flashback requirements of the system. |
If the initialization parameter file contains parameters relating to manual undo management, they are ignored.
See Also: Oracle Database Reference for complete descriptions of initialization parameters used in automatic undo management mode |
Committed undo information normally is lost when its undo space is overwritten by a newer transaction. However, for consistent read purposes, long-running queries sometimes require old undo information for undoing changes and producing older images of data blocks. The success of several Flashback features can also depend upon older undo information.
Oracle Database 10g automatically tunes undo retention by collecting database use statistics and estimating undo capacity needs for the successful completion of the queries. You can set a low threshold value for the UNDO_RETENTION
parameter so that the system retains the undo for at least the time specified in the parameter, provided that the current undo tablespace has enough space. Under space constraint conditions, the system may retain undo for a shorter duration than that specified by the low threshold value in order to allow DML operations to succeed.
In order to guarantee the success of queries even at the price of compromising the success of DML operations, you can enable retention guarantee. The RETENTION GUARANTEE
clause of the CREATE UNDO TABLESPACE
and CREATE DATABASE
statements ensures that undo information is not overwritten. This option must be used with caution, because it can cause DML operations to fail if the undo tablespace is not big enough. However, with proper settings, long-running queries can complete without risk of receiving the "snapshot too old" message, and you can guarantee a time window in which the execution of Flashback features will succeed.
The default value for the UNDO_RETENTION
parameter is 900. Retention is specified in units of seconds. This parameter determines the low threshold value of undo retention. The system retains undo for at least the time specified in this parameter. The setting of this parameter should account for any flashback requirements of the system.
You can set the UNDO_RETENTION
parameter initially in the initialization parameter file that is used by the STARTUP
process:
UNDO_RETENTION = 1800
You can change the UNDO_RETENTION
parameter value at any time using the ALTER SYSTEM
statement:
ALTER SYSTEM SET UNDO_RETENTION = 2400
The effect of the UNDO_RETENTION
parameter is immediate, but it can only be honored if the current undo tablespace has enough space. If an active transaction requires undo space and the undo tablespace does not have available space, then the system starts reusing unexpired undo space. This action can potentially cause some queries to fail with the "snapshot too old" message.
The amount of time for which undo is retained for Oracle Database for the current undo tablespace can be obtained by querying the TUNED_UNDORETENTION
column of the V$UNDOSTAT
dynamic performance view.
Automatic tuning of undo retention is not supported for LOBs. The RETENTION
value for LOB columns is set to the value of the UNDO_RETENTION
parameter.
Oracle Database 10g lets you guarantee undo retention. When you enable this option, the database never overwrites unexpired undo data--that is, undo data whose age is less than the undo retention period. This option is disabled by default, which means that the database can overwrite the unexpired undo data in order to avoid failure of DML operations if there is not enough free space left in the undo tablespace.
By enabling the guarantee option, you instruct the database not to overwrite unexpired undo data even if it means risking failure of currently active DML operations. Therefore, use caution when using this feature. A typical use of the guarantee option is when you want to ensure deterministic and predictable behavior of Flashback Query by guaranteeing the availability of the required undo data.
You enable the guarantee option by specifying the RETENTION GUARANTEE
clause for the undo tablespace when it is created by either the CREATE DATABASE
or CREATE UNDO TABLESPACE
statement. Or, you can later specify this clause in an ALTER TABLESPACE
statement. You do not guarantee that unexpired undo is preserved if you specify the RETENTION NOGUARANTEE
clause.
You can use the DBA_TABLESPACES
view to determine the RETENTION
setting for the undo tablespace. A column named RETENTION
will contain a value on GUARANTEE
, NOGUARANTEE
, or NOT APPLY
(used for tablespaces other than the undo tablespace).
You can size the undo tablespace appropriately either by using automatic extension of the undo tablespace or by manually estimating the space you will need for undo. This section discusses both methods.
Oracle Database supports automatic extension of the undo tablespace to facilitate capacity planning of the undo tablespace in the production environment. When the system is first running in the production environment, you may be unsure of the space requirements of the undo tablespace. In this case, you can enable automatic extension for datafiles of the undo tablespace so that they automatically increase in size when more space is needed. By combining automatic extension of the undo tablespace with automatically tuned undo retention, you can ensure that long-running queries will succeed by guaranteeing the undo required for such queries.
After the system has stabilized and you are more familiar with undo space requirements, Oracle recommends that you set the maximum size of the tablespace to be slightly (10%) more than the current size of the undo tablespace.
If you have decided on a fixed-size undo tablespace, the Undo Advisor can help you estimate needed capacity, and you can then calculate the amount of retention your system will need. You can access the Undo Advisor through Enterprise Manager or through the DBMS_ADVISOR
PL/SQL package. Enterprise Manager is the preferred method of accessing the advisor. For more information on using the Undo Advisor through EM, please refer to Oracle Database 2 Day DBA.
The Undo Advisor relies for its analysis on data collected in the Automatic Workload Repository (AWR). An adjustment to the collection interval and retention period for AWR statistics can affect the precision and the type of recommendations the advisor produces. Please refer to "Automatic Workload Repository" for additional information.
Oracle Database provides an Undo Advisor that provides advice on and helps automate the establishment of your undo environment. You activate the Undo Advisor by creating an undo advisor task through the advisor framework. The following example creates an undo advisor task to evaluate the undo tablespace. The name of the advisor is 'Undo Advisor'. The analysis is based on Automatic Workload Repository snapshots, which you must specify by setting parameters START_SNAPSHOT
and END_SNAPSHOT
. In the following example, the START_SNAPSHOT
is "1" and END_SNAPSHOT
is "2".
DECLARE tid NUMBER; tname VARCHAR2(30); oid NUMBER; BEGIN DBMS_ADVISOR.CREATE_TASK('Undo Advisor', tid, tname, 'Undo Advisor Task'); DBMS_ADVISOR.CREATE_OBJECT(tname, 'UNDO_TBS', null, null, null, 'null', oid); DBMS_ADVISOR.SET_TASK_PARAMETER(tname, 'TARGET_OBJECTS', oid); DBMS_ADVISOR.SET_TASK_PARAMETER(tname, 'START_SNAPSHOT', 1); DBMS_ADVISOR.SET_TASK_PARAMETER(tname, 'END_SNAPSHOT', 2); DBMS_ADVISOR.execute_task(tname); end; /
Once you have created the advisor task, you can view the output and recommendations in the Automatic Database Diagnostic Monitor in Enterprise Manager. This information is also available in the DBA_ADVISOR_*
data dictionary views.
See Also:
|
You can calculate space requirements manually using the following formula:
UndoSpace = UR * UPS + overhead
where:
UndoSpace is the number of undo blocks
UR is UNDO_RETENTION
in seconds. This value should take into consideration long-running queries and any flashback requirements.
UPS is undo blocks for each second
overhead is the small overhead for metadata (transaction tables, bitmaps, and so forth)
As an example, if UNDO_RETENTION
is set to 2 hours, and the transaction rate (UPS) is 200 undo blocks for each second, with a 4K block size, the required undo space is computed as follows:
(2 * 3600 * 200 * 4K) = 5.8GBs
Such computation can be performed by using information in the V$UNDOSTAT
view. In the steady state, you can query the view to obtain the transaction rate. The overhead figure can also be obtained from the view.
This section describes the various steps involved in undo tablespace management and contains the following sections:
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, tablespaces are discussed in "Bigfile Tablespaces".
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 datafile, /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".
See Also: Oracle Database SQL Reference for the syntax for using theCREATE DATABASE statement to create an undo tablespace |
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:
CREATE UNDO TABLESPACE undotbs_02 DATAFILE '/u01/oracle/rbdb1/undo0201.dbf' SIZE 2M REUSE AUTOEXTEND ON;
You can create more than one undo tablespace, but only one of them can be active at any one time.
See Also: Oracle Database SQL Reference for the syntax for using theCREATE UNDO TABLESPACE statement to create an undo tablespace |
Undo tablespaces are altered using the ALTER TABLESPACE
statement. However, since most aspects of undo tablespaces are system managed, you need only be concerned with the following actions:
Adding a datafile
Renaming a datafile
Bringing a datafile online or taking it offline
Beginning or ending an open backup on a datafile
Enabling and disabling undo retention guarantee
These are also the only attributes you are permitted to alter.
If an undo tablespace runs out of space, or you want to prevent it from doing so, you can add more files to it or resize existing datafiles.
The following example adds another datafile to undo tablespace undotbs_01:
ALTER TABLESPACE undotbs_01 ADD DATAFILE '/u01/oracle/rbdb1/undo0102.dbf' AUTOEXTEND ON NEXT 1M MAXSIZE UNLIMITED;
You can use the ALTER DATABASE ... DATAFILE
statement to resize or extend a datafile.
Use the DROP TABLESPACE
statement to drop an undo tablespace. The following example drops the undo tablespace undotbs_01
:
DROP TABLESPACE undotbs_01;
An undo tablespace can only be dropped if it is not currently used by any instance. If the undo tablespace contains any outstanding transactions (for example, a transaction died but has not yet been recovered), the DROP TABLESPACE
statement fails. However, since DROP TABLESPACE
drops an undo tablespace even if it contains unexpired undo information (within retention period), you must be careful not to drop an undo tablespace if undo information is needed by some existing queries.
DROP TABLESPACE
for undo tablespaces behaves like DROP TABLESPACE ... INCLUDING CONTENTS
. All contents of the undo tablespace are removed.
You can switch from using one undo tablespace to another. Because the UNDO_TABLESPACE
initialization parameter is a dynamic parameter, the ALTER SYSTEM SET
statement can be used to assign a new undo tablespace.
The following statement switches to a new undo tablespace:
ALTER SYSTEM SET UNDO_TABLESPACE = undotbs_02;
Assuming undotbs_01
is the current undo tablespace, after this command successfully executes, the instance uses undotbs_02
in place of undotbs_01
as its undo tablespace.
If any of the following conditions exist for the tablespace being switched to, an error is reported and no switching occurs:
The tablespace does not exist
The tablespace is not an undo tablespace
The tablespace is already being used by another instance (in a RAC environment only)
The database is online while the switch operation is performed, and user transactions can be executed while this command is being executed. When the switch operation completes successfully, all transactions started after the switch operation began are assigned to transaction tables in the new undo tablespace.
The switch operation does not wait for transactions in the old undo tablespace to commit. If there are any pending transactions in the old undo tablespace, the old undo tablespace enters into a PENDING OFFLINE
mode (status). In this mode, existing transactions can continue to execute, but undo records for new user transactions cannot be stored in this undo tablespace.
An undo tablespace can exist in this PENDING OFFLINE
mode, even after the switch operation completes successfully. A PENDING OFFLINE
undo tablespace cannot be used by another instance, nor can it be dropped. Eventually, after all active transactions have committed, the undo tablespace automatically goes from the PENDING OFFLINE
mode to the OFFLINE
mode. From then on, the undo tablespace is available for other instances (in an Oracle Real Application Cluster environment).
If the parameter value for UNDO TABLESPACE
is set to '' (two single quotes), then the current undo tablespace is switched out and the next available undo tablespace is switched in. Use this statement with care, because if there is no undo tablespace available, the SYSTEM
rollback segment is used. This causes ORA-01552 errors to be issued for any attempts to write non-SYSTEM
related undo to the SYSTEM
rollback segment.
The following example unassigns the current undo tablespace:
ALTER SYSTEM SET UNDO_TABLESPACE = '';
The Oracle Database Resource Manager can be used to establish user quotas for undo space. The Database Resource Manager directive UNDO_POOL
allows DBAs to limit the amount of undo space consumed by a group of users (resource consumer group).
You can specify an undo pool for each consumer group. An undo pool controls the amount of total undo that can be generated by a consumer group. When the total undo generated by a consumer group exceeds its undo limit, the current UPDATE
transaction generating the redo is terminated. No other members of the consumer group can perform further updates until undo space is freed from the pool.
When no UNDO_POOL
directive is explicitly defined, users are allowed unlimited undo space.
This section lists views that are useful for viewing information about undo space in the automatic undo management mode and provides some examples. In addition to views listed here, you can obtain information from the views available for viewing tablespace and datafile information. Please refer to " Viewing Datafile Information" for information on getting information about those views.
Oracle Database also provides proactive help in managing tablespace disk space use by alerting you when tablespaces run low on available space. Please refer to "Managing Space in Tablespaces " for information on how to set alert thresholds for the undo tablespace.
In addition to the proactive undo space alerts, Oracle Database also provides alerts if your system has long-running queries that cause SNAPSHOT TOO OLD
errors. To prevent excessive alerts, the long query alert is issued at most once every 24 hours. When the alert is generated, you can check the Undo Advisor Page of Enterprise Manager to get more information about the undo tablespace.
The following dynamic performance views are useful for obtaining space information about the undo tablespace:
View | Description |
---|---|
V$UNDOSTAT |
Contains statistics for monitoring and tuning undo space. Use this view to help estimate the amount of undo space required for the current workload. The database also uses this information to help tune undo usage in the system. This view is meaningful only in automatic undo management mode. |
V$ROLLSTAT |
For automatic undo management mode, information reflects behavior of the undo segments in the undo tablespace |
V$TRANSACTION |
Contains undo segment information |
DBA_UNDO_EXTENTS |
Shows the status and size of each extent in the undo tablespace. |
WRH$_UNDOSTAT |
Contains statistical snapshots of V$UNDOSTAT information. Please refer to Oracle Database 2 Day DBA for more information. |
WRH$_ROLLSTAT |
Contains statistical snapshots of V$ROLLSTAT information. Please refer to Oracle Database 2 Day DBA for more information. |
See Also: Oracle Database Reference for complete descriptions of the views used in automatic undo management mode |
The V$UNDOSTAT
view is useful for monitoring the effects of transaction execution on undo space in the current instance. Statistics are available for undo space consumption, transaction concurrency, the tuning of undo retention, and the length and SQL ID of long-running queries in the instance.
Each row in the view contains statistics collected in the instance for a ten-minute interval. The rows are in descending order by the BEGIN_TIME
column value. Each row belongs to the time interval marked by (BEGIN_TIME
, END_TIME
). Each column represents the data collected for the particular statistic in that time interval. The first row of the view contains statistics for the (partial) current time period. The view contains a total of 1008 rows, spanning a 7 day cycle.
The following example shows the results of a query on the V$UNDOSTAT
view.
SELECT TO_CHAR(BEGIN_TIME, 'MM/DD/YYYY HH24:MI:SS') BEGIN_TIME, TO_CHAR(END_TIME, 'MM/DD/YYYY HH24:MI:SS') END_TIME, UNDOTSN, UNDOBLKS, TXNCOUNT, MAXCONCURRENCY AS "MAXCON" FROM v$UNDOSTAT WHERE rownum <= 144; BEGIN_TIME END_TIME UNDOTSN UNDOBLKS TXNCOUNT MAXCON ------------------- ------------------- ---------- ---------- ---------- ---------- 10/28/2003 14:25:12 10/28/2003 14:32:17 8 74 12071108 3 10/28/2003 14:15:12 10/28/2003 14:25:12 8 49 12070698 2 10/28/2003 14:05:12 10/28/2003 14:15:12 8 125 12070220 1 10/28/2003 13:55:12 10/28/2003 14:05:12 8 99 12066511 3 ... 10/27/2003 14:45:12 10/27/2003 14:55:12 8 15 11831676 1 10/27/2003 14:35:12 10/27/2003 14:45:12 8 154 11831165 2 144 rows selected.
The preceding example shows how undo space is consumed in the system for the previous 24 hours from the time 14:35:12 on 10/27/2003.
Your Oracle Database includes several features that are based upon undo information and that allow administrators and users to access database information from a previous point in time. These features are part of the overall flashback strategy incorporated into the database and include:
The retention period for undo information is an important factor for the successful execution of Flashback features. It determines how far back in time a database version can be established. Specifically, you must choose an undo retention interval that is long enough to enable users to construct a snapshot of the database for the oldest version of the database that they are interested in. For example, if an application requires that a version of the database be available reflecting its content 12 hours previously, then UNDO_RETENTION
must be set to 43200.
You might also want to guarantee that unexpired undo is not overwritten by specifying the RETENTION GUARANTEE
clause for the undo tablespace as described in "Undo Retention".
Using Oracle Flashback Query feature, users or applications can execute queries as of a previous time in the database. Application developers can use Flashback Query to design an application that allows users to correct their mistakes with minimal DBA intervention. You, as the DBA, need only configure the undo tablespace with an appropriate size and undo retention period. No further action on your part should be required.
The Oracle-supplied DBMS_FLASHBACK
package implements Flashback Query at the session level. At the object level, Flashback Query uses the AS OF
clause of the SELECT
statement to specify the previous point in time for which you wish to view data.
See Also:
|
The Flashback Version Query feature enables users to query the history of a given row. A SELECT
statement that specifies a VERSIONS
clause returns individual versions of a row between two specified SCNs (system change numbers) or timestamps. The UNDO_RETENTION
initialization parameter must be set to a value that is large enough to cover the period of time specified in the VERSIONS
clause. Otherwise, not all rows can be retrieved.
The VERSIONS
clause can also be used in subqueries of DML and DDL statements.
See Also:
|
Oracle Database provides a view, FLASHBACK_TRANSACTION_QUERY
, that enables you to identify changes made by a particular transaction, or by all transactions issued within a specified period of time. One use for this view could be if a user finds, by using the Flashback Transaction Query feature, that a row value has been changed inappropriately. Querying the FLASHBACK_TRANSACTION_QUERY
view can provide specific details of the transaction or transactions that changed the row value.
See Also: "Auditing Table Changes Using Flashback Transaction Query" for more information about using the Flashback Transaction Query feature |
The FLASHBACK TABLE
statement lets users recover a table to a previous point in time. It provides a fast, online solution for recovering a table that has been accidentally modified or deleted by a user or application. The UNDO_RETENTION
initialization parameter must be set to a value that is large enough to cover the period specified in the FLASHBACK TABLE
statement.
See Also: "Recovering Tables Using the Flashback Table Feature" for more information about theFLASHBACK TABLE statement |
If you are still using rollback segments to manage undo space, Oracle strongly recommends that you migrate your database to automatic undo management. Oracle Database provides a function that provides information on how to size your new undo tablespace based on the configuration and usage of the rollback segments in your system. DBA privileges are required to execute this function:
DECLARE utbsiz_in_MB NUMBER; BEGIN utbsiz_in_MB ;= DBMS_UNDO_ADV.RBU_MIGRATION; end; /
The function returns the sizing information directly.
This following list of recommendations will help you manage your undo space to best advantage.
You need not set a value for the UNDO_RETENTION
parameter unless your system has flashback or LOB retention requirements.
Allow 10 to 20% extra space in your undo tablespace to provide for some fluctuation in your workload.
Set the warning and critical alert thresholds for the undo tablespace alert properly. Please refer to "Managing Space in Tablespaces " for information on how to set alert thresholds for the undo tablespace.
To tune SQL queries or to check on runaway queries, use the value of the SQLID
column provided in the long query or in the V$UNDOSTAT
or WRH$_UNDOSTAT
views to retrieve SQL text and other details on the SQL from V$SQL
view.
Always use indexes for Flashback Version Query.