FAQ – Automatic Undo Management (AUM) / System Managed Undo (SMU)

教程发布:风哥 教程分类:ITPUX技术网 更新日期:2022-02-12 浏览学习:872

本文介绍关于Oracle undo回滚段的疑问及解答。文档来自官方FAQ – Automatic Undo Management (AUM) / System Managed Undo (SMU) (文档 ID 461480.1)
In this Document
Purpose
Questions and Answers
What is Undo?
Which are the major initialization parameters that controls AUM?
How to set the undo_retention value ?
What is the Fast Ramp-up Routine ?

How to switch to a new undo tablespace?
What is UNDO Retention?
What is Automatic UNDO Retention (10g New Feature)? Explain.
Why TUNED_UNDORETENTION is calculated so high making undo space grow fast ?
Explain the DBA_UNDO_EXTENTS View, and usage?
What are the various statuses for Undo Extents? Explain.
Explain V$TRANSACTION, and usage?
Explain DBA_ROLLBACK_SEGS, and usage?
Do we have scripts to monitor the undo growth/usage of the database?
What are the possible causes for excessive undo growth?
How to resize the undo datafile?
Can the Undo Tablespace be set to Autoextend?
What is In Memory Undo?

Questions and AnswersWhat is Undo?
Oracle maintains information to nullify changes made to the database. Such information consists of records of the actions of transactions, collectively known as undo. Oracle uses the undo to do the following:
- Rollback an active transaction
- Recover a terminated transaction
- Provide read consistency
- Recovery from logical corruptions

What is AUM / SMU?Automatic Undo Management(AUM) is introduced in Oracle 9i, which replaces the rollback segments.
This is also called System Managed Undo(SMU) as the undo is managed by oracle.

Automatic undo management is undo-tablespace based. You allocate space in the form of an undo tablespace, instead of allocating many rollback segments in different sizes.

Oracle strongly recommends their customers to use Automatic Undo Management (AUM).

Which are the major initialization parameters that controls AUM?

UNDO_MANAGEMENT Initialization Parameter

UNDO_MANAGEMENT specifies which undo space management mode the system should use. When set to AUTO, the instance starts in automatic undo management mode. In manual undo management mode, undo space is allocated externally as rollback segments.

By default, this parameter is set to MANUAL. Set this parameter to AUTO to enable automatic undo management mode.

This is a static parameter and cannot be modified dynamically using alter system command.
So if you wish to switch between Rollback Segments and AUM, then you need to restart the instance.

In RAC, multiple instances must have the same value.

UNDO_TABLESPACE Initialization Parameter
When an instance starts up in automatic undo management mode, it attempts to select an undo tablespace for storage of undo data.

UNDO_RETENTION Initialization Parameter
This parameter specifies (in seconds) the low threshold value of undo retention.

The UNDO_RETENTION parameter 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 a "snapshot too old" message.

The amount of time for which undo is retained for the Oracle Database for the current undo tablespace can be obtained by querying the TUNED_UNDORETENTION column of the V$UNDOSTAT dynamic performance view.

How to set the undo_retention value ?
In case you are using Automatic tuning of undo retention (_undo_autotune=TRUE), The best way to set your undo retention is to determine the average value of maximum query length in your database as follow :
a. Let the database run without bounce for at least one week or more for your normal DB workload.
b. Run the following query to determine the average maximum query in your database and set undo_retention to that value.

SQL> select avg(maxquerylen) from v$undostat;

In case you are not using Automatic tuning of undo retention (_undo_autotune=FALSE), You will need to set undo_retention to a value larger than the maximum query length in your database.
NOTE: If you have very long running queries or you set undo_retention to large value, this will require/allocate large undo space. So it is highly recommended to tune your long running queries and set undo_retention to a resonable value.

What is the Fast Ramp-up Routine ?

The concept of Fast Ramp-Up indicates the following:

"In previous versions, when the instance was restarted or when you switched undo tablespaces, the ramp-up time for the system to grow the number of online undo segments could be several minutes. Generally, this time delay was unacceptable.

After an instance startup or a switch of undo tablespaces in Oracle Database 10g, the database decides how many segments to place online, based on existing data stored in the the AWR.
The algorithm to compute the # of undo segments to online for "Fast Ramp Up" is:

Has the instance been up for more than 7 days?
Yes- use max(maxconcurrency) from v$undostat
No- Is this he first time this function is called?
Yes - Is there select_workload_repository function (SWRF) snaphot data?
No- online minimal # of undo segs
Yes- attempt to get the max(maxconcurrency) from wrh$_undostat for the last 7 days.
If we cannot find that information, attempt to get the max(rbs cnt) from wrh$_rollstat
for the last 7 days.
Store the value in internal variable.
No- use an internal variable.
SMON decides on the # of undo segs to offline and drop based on the max transaction concurrency over a 12 hour period in 9i. This behavior is altered in 10g where the max concurrency is maintained over a 7-day period. Moreover, in 10g SMON doesn't drop the extra undo segs, but simply offlines them.
SMON uses the same values with "fast ramp up" to adjust the number of undo segments online.
The 10511 event is actually used as a workaround to avoid excessive onlines of undo segments.

The 10511 event does not skip "Fast Ramp Up", it only disables SMON's workload for undo segments. Once the 10511 event is set, we leave all undo segments created at that point online.
With 10g, "Fast Ramp Up" avoids problems seen in earlier releases with waits/performance issues associated with SMON and undo segments.
The fast startup can be bypassed by setting following parameter in the parameter file:

_rollback_segment_count=10

This will place 10 segments online at startup. You can change th value as per your requirement on undo segments.

[font=Arial, Helvetica, sans-serif][size=11px]How many Undo tablespaces can we have for a database?

We can have many undo tablespaces in a database, but only one can be Active per instance.

In Oracle Real Application Clusters (RAC) enviornment, we need to have one Active undo tablespace per instance. The UNDO_TABLESPACE parameter will be used for assigning a particular undo tablespace to an instance.
How to switch to a new undo tablespace?

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) 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 there may be no undo tablespace available.

The following example unassigns the current undo tablespace:
ALTER SYSTEM SET UNDO_TABLESPACE = '';
NOTE: There is not a way to shrink an existing UNDO tablespace. You can change UNDO tablespaces instead. See Note 268870.1 How to Shrink the datafile of Undo Tablespace

What is UNDO Retention?
Undo Retention refers to duration of retaining the undo data after a transaction.
After a transaction is committed, undo data is no longer needed for rollback or transaction recovery purposes. However, for consistent read purposes, long-running queries may require this old undo information for producing older images of data blocks. Furthermore, the success of several Oracle Flashback features can also depend upon the availability of older undo information. For these reasons, it is desirable to retain the old undo information for as long as possible.

Automatic undo management eliminates the complexities of managing rollback segment space and lets you exert control over how long undo is retained before being overwritten.

You can set the UNDO_RETENTION parameter to a low threshold value so that the system retains the undo for at least the time specified in the parameter.

What is Automatic UNDO Retention (10g New Feature)? Explain.
There is no parameter for this, Automatic UNDO Retention is enabled by default in 10g.
In Oracle Database 10g when automatic undo management is enabled, there is always a current undo retention period, which is the minimum amount of time that Oracle Database attempts to retain old undo information before overwriting it - Which means the undo information for committed transactions can be overwritten. The database collects usage statistics and tunes the undo retention period based on these statistics and on undo tablespace size.
Oracle Database automatically tunes the undo retention period based on undo tablespace size and system activity. You can specify a minimum undo retention period (in seconds) by setting the [font=NSimsun]UNDO_RETENTION initialization parameter. The database makes its best effort to honor the specified minimum undo retention period, provided that the undo tablespace has space available for new transactions
The current value for tuned undo retention can be viewed by following query.

SELECT TO_CHAR(BEGIN_TIME, 'MM/DD/YYYY HH24:MI:SS') BEGIN_TIME,
TUNED_UNDORETENTION FROM V$UNDOSTAT;

For AUTOEXTEND undo tablespaces, the system retains undo for at least the time specified in this parameter, and automatically tunes the undo retention period to satisfy the undo requirements of the queries.
This could lead to excessive undo generation, to honor undo retention

For fixed- size undo tablespaces, the system automatically tunes for the maximum possible undo retention period, based on undo tablespace size and usage history, and ignores UNDO_RETENTION unless retention guarantee is enabled.

Automatic tuning of undo retention is not supported for LOBs. Because we don't store any undo information in undo tablespace for transactions on LOBs.

[font=Arial, Helvetica, sans-serif][size=11px]Why TUNED_UNDORETENTION is calculated so high making undo space grow fast ?
When non-autoextensible undo space is used, tuned_undoretention is calculated based on a percentage of the undo tablespace size. In some cases especially with large undo tablespace, This will make it to be calculated so large.
To fix this behaviour, Set the following instance parameter:
_smu_debug_mode=33554432
With this setting, TUNED_UNDORETENTION is not calculated based on a percentage of the fixed size undo tablespace. Instead it is set to the maximum of (MAXQUERYLEN secs + 300) and UNDO_RETENTION.

[font=Arial, Helvetica, sans-serif][size=11px]What is Guaranteed UNDO Retention? Explain.
Oracle Database 10g lets you guarantee undo retention. In Oracle 10g Release 2, you can enable and disable 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 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 enabling this feature.

To enable do the following against the undo tablespace.
ALTER TABLESPACE UNDOTBS RETENTION GUARANTEE;

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.

Explain V$UNDOSTAT, and usage?
This view is a replacement / enhancement for V$ROLLSTAT.

This view 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.

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.

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",
MAXQUERYLEN, TUNED_UNDORETENTION
FROM v$UNDOSTAT;

BEGIN_TIME END_TIME UNDOTSN UNDOBLKS TXNCOUNT MAXCON MAXQUERYLEN TUNED_UNDORETENTION
------------------- ------------------- ---------- ---------- ---------- ---------- ----------- -------------------
04/22/2014 11:59:03 04/22/2014 12:04:07 4 122 83 3 1226 1947
04/22/2014 11:49:03 04/22/2014 11:59:03 4 5 158 1 923 1705
04/22/2014 11:39:03 04/22/2014 11:49:03 4 4 72 2 371 1153
04/22/2014 11:29:03 04/22/2014 11:39:03 4 8 8 2 921 1703
04/22/2014 11:19:03 04/22/2014 11:29:03 4 6 139 1 315 1097
04/22/2014 11:09:03 04/22/2014 11:19:03 4 744 116 2 923 1705
04/22/2014 10:59:03 04/22/2014 11:09:03 4 1 2 1 317 1099
04/22/2014 10:49:03 04/22/2014 10:59:03 4 84 452 3 917 1696
04/22/2014 10:39:03 04/22/2014 10:49:03 4 62 87 4 296 1146
9 rows selected.

The following table explains other useful columns of V$UNDOSTAT view

[table=98%]
UNXPSTEALCNTThe number of attempts when unexpired blocks were stolen from other undo segments to satisfy space requests
UNXPBLKRELCNTThe number of unexpired blocks removed from undo segments to be used by other transactions
UNXPBLKREUCNTThe number of unexpired undo blocks reused by transactions
EXPSTEALCNTThe number of attempts when expired extents were stolen from other undo segments to satisfy a space requests
EXPBLKRELCNTThe number of expired extents stolen from other undo segments to satisfy a space request
EXPBLKREUCNTThe number of expired undo blocks reused within the same undo segments
SSOLDERRCNTThe number of ORA-1555 errors that occurred during the interval
NOSPACEERRCNTThe number of Out-of-Space errors

When the columns UNXPSTEALCNT through EXPBLKREUCNT hold non-zero values, it is an indication of space pressure.
If the column SSOLDERRCNT is non-zero, then UNDO_RETENTION is not properly set.
If the column NOSPACEERRCNT is non-zero, then there is a serious space problem.
In 10g DBA_HIST_UNDOSTAT view contains statistical snapshots of V$UNDOSTAT information.

Note: If the parameter _undo_autotune=FALSE, there will be no data generated in table X$KTUSMST2 which is the source table of view dba_hist_undostats

Explain the DBA_UNDO_EXTENTS View, and usage?

DBA_UNDO_EXTENTS describes the extents comprising the segments in all undo tablespaces in the database. This view shows the status and size of each extent in the undo tablespace.
What are the various statuses for Undo Extents? Explain.

Transaction Status of the undo in the extent can be any of the following:
SELECT DISTINCT STATUS, SUM(BYTES), COUNT(*)
FROM DBA_UNDO_EXTENTS GROUP BY STATUS;

ACTIVE - Undo Extent is Active, Used by a transaction.

EXPIRED - Undo Extent is expired (Exceeded the Undo Retention).

UNEXPIRED - Undo Extent will be required to honor UNDO_RETENTION.

Explain V$TRANSACTION, and usage?

V$TRANSACTION lists the active transactions in the system.

(a) The following columns together points to a transaction. (ie) The combination of the following should give unique transaction id for that database.

XIDUSN - Undo segment number
XIDSLOT - NUMBER Slot number
XIDSQN - NUMBER Sequence number

(b) The following columns explains the number of undo blocks / undo records used per transaction.
USED_UBLK - Number of undo blocks used
USED_UREC - Number of undo records used

In the case of transaction rollback, the above columns will give estimation about the number of undo blocks that needs to be rolled back.

The number of undo records and undo blocks (USED_UREC and USED_UBLK) decrease while the transaction is rolling back. When they reach 0, the transaction disappears from v$transaction.

The following query can be used to monitor the transaction rollback.

SELECT A.SID, A.USERNAME, B.XIDUSN, B.USED_UREC, B.USED_UBLK
FROM V$SESSION A, V$TRANSACTION B
WHERE A.SADDR=B.SES_ADDR;

(c) The STATUS following column explains the status of a transaction.

ACTIVE - Explains the transaction is active.

Before performing a normal/transactional shutdown, we can check this view to understand if we have any ACTIVE transactions.

SELECT XIDUSN, XIDSLT, XIDSEQ , SES_ADDR, STATUS FROM V$TRANSACTION;

Explain DBA_ROLLBACK_SEGS, and usage?

This view explains the various status of Undo Segments.
In RAC, we can also see the Instance number, and its associated tablespaces.

SELECT INSTANCE_NUM,TABLESPACE_NAME,SEGMENT_NAME,STATUS FROM DBA_ROLLBACK_SEGS;

In AUM DBA's don't have privileges to offline/online undo segments. And this is controlled by SMON process. So this will be useful only in few scenarios, where we have internal errors with undo segments.

Do we have scripts to monitor the undo growth/usage of the database?
To understand the free space with undo tablespace.

SELECT SUM(BYTES) FROM DBA_FREE_SPACE WHERE TABLESPACE_NAME='&UNDOTBS';

To understand state of the extents, space-used in the current undo tablespace.

SELECT DISTINCT STATUS, SUM(BYTES), COUNT(*) FROM DBA_UNDO_EXTENTS GROUP BY STATUS;

To understand the no of active transactions and its undo usage.

SELECT XIDUSN, XIDSLOT, XIDSQN, USED_UBLK FROM V$TRANSACTION WHERE STATUS='ACTIVE' ;

What are the possible causes for excessive undo growth?
There could be various causes for excessive undo growth. To start the diagnosis we need to understand the following.

Transactions with huge undo
It is obvious to see high undo usage when there are huge transactions.
If that is going to be the case this growth should be expected behavior.

UNDO RETENTION
Higher undo retention will cause higher undo growth. Because we wont mark the undo extents as EXPIRED till the duration of undo retention.

Disabling autoextend on datafiles of active undo tablespace will reuse the UNEXPIRED extents when it has space crunch. It is a trade-off between undo retention and undo space.
If you wish to satisfy Undo Retention, switch on autoextend in undo tablespace datafiles.

SELECT FILE_ID, AUTOEXTENSIBLE FROM DBA_DATA_FILES WHERE
TABLESPACE_NAME='&UNDOTBS';

To make those datafile auto extensible, run the following command.
ALTER DATABASE DATAFILE '&FILE_ID' AUTOEXTEND ON;
If you wish to switch off auto extend and to reuse the UNEXPIRED space, do the following
ALTER DATABASE DATAFILE '&FILE_ID' AUTOEXTEND OFF;

State of undo extents
The status of the undo extents needs to be closely monitored.
There are few bugs with different releases where EXPIRED extents are not being reused.

(a) If good number of extents in UNEXPIRED status, it could be due to high undo_retention.
SELECT DISTINCT STATUS, SUM(BYTES), COUNT(*)
FROM DBA_UNDO_EXTENTS GROUP BY STATUS;

(b) There are few bugs associated with undo usage,

The unpublished bug 5442919 affects 10.2.0.3, 10.1.0.5 , 9.2.0.8 and its lesser patch levels, and the issue is fixed in 10.2.0.4.

Bug 5442919 EXPIRED EXTENTS NOT BEING REUSED
The above bug is unpublished, and the details can be reviewed through Note:5442919.8
And we also have Patch:5442919 for most of the latest versions. Kindly check metalink for patch availability.

How to resize the undo datafile?

It is possible to increase an undo datafile. For example, to increase the undo datafile size from 2000 MB to 3000MB we can do the following
ALTER DATABASE DATAFILE 39 RESIZE 3000M;
But it may not be possible to resize to lesser value, when a undo datafile got auto extended to higher value. Even after the transactions are completed those undo extents will remain in EXPIRED status.
As the blocks are being used by undo extents, oracle will not allow you to resize, It will result in errors similar to following. In the following case the datafile size was 3500MB and a resize to 3000MB results in following errors.
SQL> alter database datafile 39 resize 3000m;
alter database datafile 39 resize 3000m
*
ERROR at line 1:
ORA-03297: file contains used data beyond requested RESIZE value

Can the Undo Tablespace be set to Autoextend?
It should be noted that by default Oracle will not auto extend the undo tablespace unless in GUARANTEE mode, as extending the undo tablespace is an expensive operation and would lock all undo segments in the database. This would thereby effectively hang the database, and so the default is to re-use all unexpired undo extents first which can therefore result in ORA-1555 errors when customers expect the tablespace to have auto extended.

What is In Memory Undo?
In Oracle 10g and higher, some of the top level DML's were performed in memory without any disk undo data. Which is termed as In Memory Undo (IMU). This can be controlled by an Underscore Parameter. For more information, Please contact Oracle Support

本文标签:
网站声明:本文由风哥整理发布,转载请保留此段声明,本站所有内容将不对其使用后果做任何承诺,请读者谨慎使用!
【上一篇】
【下一篇】