You are on page 1of 2

Undo Retention Insights

Page

The UNDO_RETENTION parameter defines how long undo will remain in the undo tablespace. With old rollback segments, that information could be lost as soon as the transaction completed and that space was overwritten by a newer transaction. The UNDO_RETENTION initialization parameter can be tweaked and configured to provide read consistent images of past data for as long as required. This ensures that the queries do not fail with "ORA-01555 Snapshot too Old" errors. The Oracle Flashback Feature also relies on this parameter to get the past image of the data. V$UNDOSTAT dynamic performance view provides some valuable information and can be used to derive an optimal value for this parameter. This view contains data for the last 4 days and inserts a row for every 10 minute interval. V$UNDOSTAT provides a new TUNED_UNDORETENTION column which can be queried to get an optimal size of the UNDO_RETENTION setting. If the space in the UNDO_TABLESPACE is not sufficient to create new extents and if the tablespace is created with AUTOEXTEND OFF, then the running transaction might reuse the unexpired undo_records required for read consistent view, thus increasing the chances of ORA-01555. If there are no unexpired or expired blocks, the transaction might fail with space error. Expired undo records are those which happened longer ago than the UNDO_RETENTION value. Unexpired undo records are those which happened recently and have not crossed the timing limit set by the UNDO_RETENTION value. Whenever a Transaction needs some more space to grow in the Undo_Tablespace, then it will: 1. First try to allocate a new extent in the free space or will extend the tablespace, if AUTOEXTEND is ON. 2. If it fails in Step 1 due to insufficient free space or Autoextend is OFF, then it will try to take the space from the expired extents in its own Undo Segments. If it finds an expired extent, it will steal it and update the EXPSTEALCNT and EXPBLKREUCNT columns in V$UNDOSTAT. 3. If it fails in Step 2, then it will try to take the space from the expired extents in other Undo Segments. If it finds an expired extent, it will steal it and update the EXPSTEALCNT and EXPBLKRELCNT columns in V$UNDOSTAT. 4. If it fails in Step 3, then it looks for unexpired extents in it own undo segment. It will be the oldest one. If it finds unexpired extents, then it prematurely reuses it and updates UNXPSTEALCNT and UNXPBLKREUCNT columns in V$UNDOSTAT. 5. If it fails in Step 4,then it looks for unexpired extents in other undo segments. Probably, the oldest one. If it finds one it prematurely reuses it and updates UNXPSTEALCNT and UNXPBLKRELCNT columns in V$UNDOSTAT. 6. If it fails in Step 5, then the transaction will fail with space error and updates NOSPACEERRCNT column in V$UNDOSTAT. In Step 4 and 5, if the transaction succeeds, it reuses the records required for read consistent image for the queries. There are chances that these queries might fail with ORA-01555 error. In that case, these sessions will update SSOLDERRCNT column in V$UNDOSTAT. A better understanding of the application and the database will help the Administrator tune and set the optimal value of UNDO_RETENTION. TUNED_UNDORETENTION is one step to get the value for UNDO_RETENTION. Alternatively, the Undo Advisory Feature of OEM or DBMS_ADVISOR package can be used to assist in setting an optimal value for UNDO_RETENTION. Oracle 10g provides an initialization parameter RETENTION_GUARANTEE, which guarantees the success of long running queries and never overwrites unexpired undo records. If this parameter is set to TRUE, the specified minimum undo retention is guaranteed. The parameter setting gurantees that the undo will never be overwritten until it is expired. A transaction requiring more space to extend might fail with SPACE error, if this parameter is set to TRUE and there is insufficient space or if AUTOEXTEND is OFF.

Effects of UNDO_RETENTION
The UNDO_RETENTION parameter has two basic effects on database operations. If UNDO_RETENTION is set too low, long running queries will receive the ORA-1555 error, "snapshot too old." UNDO_RETENTION determines how far back Flashback Queries can go. It is important that the undo tablespace has enough space to hold undo information for the amount of time specified by the UNDO_RETENTION parameter. If there is not enough space in the undo tablespace, older undo information will be lost even before the UNDO_RETENTION time period has elapsed.

Monitoring Undo Retention


Oracle includes the V$UNDOSTAT view to monitor how the undo space, and undo retention is being used. Each line in the V$UNDOSTAT view corresponds to a ten minute interval in time. To see if any "snapshot too old" errors were generated, query the SSOLDERRCNT column as shown:
01.SQL> select begin_time,ssolderrcnt from v$undostat; 02. 03.BEGIN_TIME SSOLDERRCNT 04.------------------ ----------05.21-FEB-04 18:08:51 0 06.21-FEB-04 17:58:51 1 07.21-FEB-04 17:48:51 4 08.21-FEB-04 17:38:51 2 09.21-FEB-04 17:28:51 3 10.21-FEB-04 17:18:51 0 11.21-FEB-04 17:08:51 0 12.21-FEB-04 16:58:51 0 13.21-FEB-04 16:48:51 0

Above, we can see that a few of the ten minute intervals received more than zero "snapshot too old" errors. It is ideal to have these set at zero for every ten-minute interval. To avoid this, increase the value of UNDO_RENTENTION. Another check of UNDO_RETENTION is to find out what the maximum query length is. UNDO_RETENTION should be set to a value higher than the maximum query length.
01.SQL> select begin_time,maxquerylen from v$undostat; 02. 03.BEGIN_TIME MAXQUERYLEN 04.------------------ ----------05.21-FEB-04 18:08:51 47 06.21-FEB-04 17:58:51 54 07.21-FEB-04 17:48:51 712 08.21-FEB-04 17:38:51 608 09.21-FEB-04 17:28:51 154

In this example, we have one ten-minute interval where the maximum query length was 712 seconds. UNDO_RETENTION should be set to a value higher than 712 seconds. The longer we keep undo in the tablespace, the more overall space we will require. As stated, if there is not enough space in the undo tablespace, the system will use space that has not expired according to the UNDO_RETENTION parameter. The UNXPSTEALCNT column of V$UNDOSTAT shows the number of times unexpired space was stolen in that ten-minute interval. If this value is non-zero for any time-minute interval time period, then increase the size of the UNDO tablespace.

You might also like