Oracle Database undo space explained

Source: Internet
Author: User
Document directory
  • Rollback
  • Read consistency
  • Flashback
  • Active
  • Expired
  • Unexpired
  • Summary
  • 'Normal' operation
  • Out of free/expired extents
  • Out of Undo Space
  • Retention to large or undo to small?
  • Fixed size
  • Fixed size, out of unexpired extents? Check tuned_undoretention!
  • Fixed/auto retention
  • Shrink undo tablespace
  • Retention guaranteed
  • Setting the undo_retention parameter to the longest running Query
  • How much undo will this generate?
Oracle Database undo space explainedian hoogeboom
29. Aug 2010 in Oracle
14 comments

In this blog post I will talk about the basic workings of automatic undo management, which can cause ORA-01555 and ORA-30036 issues.

The scope is automatic undo Management Used in 10g and 11g, but has to be explicitly set for 9I (undo_management = auto). Manual undo management is out of scope for this blog.

The undo tablespace is a normal tablespace like any other, but only oracle is controlling what is happening inside it.

Undo something

The undo tablespace is used for several features: rollback, read consistency and Flashback Technology.

Rollback

Rollback is easy to understand, if you are not happy with some data modifications, You Want To 'undo 'it: rollback.
The original (non modified) information within a transaction is stored in a separate undo tablespace, because the database is designed for commit to be fast, not rolling back.

Read consistency

Another mechanic undo information is used for is read consistency, which means if you run a query at for 10 minutes, you want all the data to be from. you don't want it to read data that has been modified at and or data that hasn't been
Committed yet.

So, to support read consistency, Oracle must keep the original data (committed or not) for these 10 minutes until the query is finished.

The problem is, you actually don't know how long the query will run, so the general rule is to set this 'keep-old-data-period 'to the longest running query. this is because you also want your longest running query to read consistent data.

This 'keep-old-data-period 'is called'undo _ retention' and defaults to 900 seconds, which means the database tries to keep all old changed information for 900 seconds.

Flashback

Some Oracle features are built based upon using undo information, meaning Undo is more utilized.
Because 'old' data is stored for a certain time (undo_retention), one can access this information to have look at data back in time by using flashback features: 'How did the contents of this table looked like ten minutes ago? '. This information can be used
For recovery from user-errors.

Flashback features using undo are:

  • Flashback query (Based on Time)
  • Flashback versions query (based on SCN)
  • Flashback transaction query (based on period)
  • Flashback table (Based on Time)

Flashback drop and flashback database do not use undo information. flashback drop is using 'not yet recycled segment and extents' and flashback database is a separate mechanic using the Flash/fast recovery area, by taking 'snapshots' and redo information.

Undo lifetime

Undo information has different States during it's lifecycle, depending on running transactions and retention settings.

There are three states or types of extents in the Undo tablespace: active, expired and unexpired. Oracle is still using rollback segments, but with automatic undo management these are completely controlled by Oracle.

Active

Active undo extents are used by transactions and will always be active, because they are needed for rollback. the undo_retention setting is not used here, because one can not say something like: 'After 900 seconds you are not allowed to rollback anymore... '

You will get'ORA-30036 unable to extend segment in undo tablespace'Errors when no more space is left to store active undo. This will automatically rollback the transaction causing it.
NospaceerrcntColumn in V $ undostat is a good indication how many times this has occurred.

Expired

Expired extents are not used by transactions, the data in these extends is committed and the undo_retention time has passed, so it is not needed for read consistency.

Unexpired

Unexpired extents are non-active extents that still honor fail. The transactions belonging to these undo extents are committed, but the retention time has not passed: You still want/need these for read consistency!

When the Undo mechanic requires more extents for active extents, it is allowed to steal unexpired extents when there are no expired extents left for reuse and it can not allocate more free extents (autoextend maxsize reached or fixed tablespace size ). one
Can check the steal-count inUnxpstealcntIn V $ undostat.

You will get'ORA-01555 snapshot too old'Errors if no read consistency information for a query is available.
SsolderrcntIn V $ undostat will show a count of these errors.

Summary
  • Active Undo is used by active transactions: rollback and read consistency.
  • Expired Undo is old and can be reused.
  • Unexpired Undo is used for read consistency, retention time has not passed yet.
  • Unexpired Undo can be stolen for active undo. If this is happening you can get ORA-01555 before undo retention has passed.
  • Unexpired Undo can be secured by setting the retention guarantee option when creating the Undo tablespace (see undo sizing ).
Undo extent status examples

With the next query you go through the contents of the Undo tablespace and sum the extent types:

select status,  round(sum_bytes / (1024*1024), 0) as MB,  round((sum_bytes / undo_size) * 100, 0) as PERCfrom(  select status, sum(bytes) sum_bytes  from dba_undo_extents  group by status),(  select sum(a.bytes) undo_size  from dba_tablespaces c    join v$tablespace b on b.name = c.tablespace_name    join v$datafile a on a.ts# = b.ts#  where c.contents = 'UNDO'    and c.status = 'ONLINE');

It will sum the three types of extents and shows the distribution of them within the Undo tablespace. 'free' extents are not shown.

'Normal' operation
STATUS            MB       PERC--------- ---------- ----------ACTIVE            10          4EXPIRED          110         43UNEXPIRED         25         10

This is an example of 'normal' contents of the Undo tablespace. The system is using active extents, some are unexpired used for read consistency and there are expired extents which can be reused.

Out of free/expired extents
STATUS            MB       PERC--------- ---------- ----------ACTIVE           230         90EXPIRED            0          0UNEXPIRED         26         10

When the system is under load and the expired extents are near 0%, the total of active and unexpired is near 100% and the Undo tablespace is not able to extend, oracle will steal unexpired extents for active extents. if this is the case you might wrong CT
ORA-01555 errors, because undo retention can not be met.

Out of Undo Space
STATUS            MB       PERC--------- ---------- ----------ACTIVE           255        100EXPIRED            0          0UNEXPIRED          1          0

When the system is under load and the active extents are near 100%, the total of expired and unexpired is near 0% and the Undo tablespace is not able to extend, oracle is not able to allocate free extents or steal unexpired extents for active extents. if
This is the case you might Except CT ORA-30036 errors.

Retention to large or undo to small?
STATUS            MB       PERC--------- ---------- ----------ACTIVE             2          1EXPIRED            0          0UNEXPIRED        254         99

In this case, all undo extents are used for the retention period. it might be the retention is to large, or the Undo tablespace is to small. a dba must investigate this and take a demo!

Undo Sizing

Storing undo data for a certain amount of time will need space and based on the activity on the database system, it is written at a certain 'rate '.
From this you can deduct an equation: rate X retention = space. Some overhead must be added, but that varies between database versions used and data tystored.

If you look at the Undo equation, the Undo tablespace size or the retention time can be fixed. A fixed rate can not be set, because it depends on database load.

Since Oracle 10g, the database will be more efficient if the same record is updated more than once in a transaction, it will re-use those active extents.

Fixed size

When the Undo tablespace size is fixed (datafile autoextend = no), Oracle tunes the retention time for the amount of Undo data it is generating to fit into the Undo tablespace. the undo_retention parameter will now be used as a minimum, but may be automatically
Be tuned larger when enough space is available.

One can check the tuned undo retention time in V $ undostat, usingTuned_undoretentionColumn.

In Oracle 9i, it seems oracle is not actually tuning this, but is only trying to maintain the Undo retention time. Also the tuned_undoretention column is absent in 9i.

When you choose the Undo tablespace to be fixed, you can use the Undo advisor to estimate the needed sizing.

Fixed size, out of unexpired extents? Check tuned_undoretention!
STATUS            MB       PERC--------- ---------- ----------ACTIVE             2          1EXPIRED            0          0UNEXPIRED        254         99

Because oracle is able to extend the retention time, more unexpired extents are created. in this case, if the Undo tablespace is full, check the tuned_undoretention against undo_retention. if the tuned retention is much larger, 99% full does not mean a problem!

Take a look at the following query, it will calculate the Undo total with the following assumption: Active takes what is needs, expired' is empty 'and unexpired will be re-calculated against the division of undo_retention/tuned_undoretention.

BREAK ON REPORTCOMPUTE SUM OF MB ON REPORTCOMPUTE SUM OF PERC ON REPORTCOMPUTE SUM OF FULL ON REPORTselect status, round(sum_bytes / (1024*1024), 0) as MB, round((sum_bytes / undo_size) * 100, 0) as PERC, decode(status, 'UNEXPIRED', round((sum_bytes / undo_size * factor) * 100, 0),                'EXPIRED',   0,                             round((sum_bytes / undo_size) * 100, 0)) FULLfrom( select status, sum(bytes) sum_bytes from dba_undo_extents group by status),( select sum(a.bytes) undo_size from dba_tablespaces c join v$tablespace b on b.name = c.tablespace_name join v$datafile a on a.ts# = b.ts# where c.contents = 'UNDO' and c.status = 'ONLINE'),( select tuned_undoretention, u.value, u.value/tuned_undoretention factor from v$undostat us join (select max(end_time) end_time from v$undostat) usm    on usm.end_time = us.end_time join (select name, value from v$parameter) u    on u.name = 'undo_retention');

When running this query, the next result will show when undo_retention = 900 and tuned_undoretention is about 1800 seconds:

STATUS            MB       PERC       FULL--------- ---------- ---------- ----------ACTIVE             2          1          1EXPIRED            0          0          0UNEXPIRED        254         99         50          ---------- ---------- ----------sum              256        100         51

Unexpired at 99% is not really a problem here, because the tuned retention is twice as large as the desired retention!

Since 10gr2, a maximum retention is introduced. the longest period of tuned undo I have seen is 96 hours. automatic Tuning retention can also be turned off using the hidden '_ undo_autotune = false 'parameter (don't use until Oracle suggested this hidden parameter ).
See also my Oracle Support note:
Full undo tablespace in 10gr2 [ID 413732.1].

Fixed/auto retention

If the Undo tablespace is configured with the autoextend option for the data files, Oracle sets the retention time to the time it takes for the longest-running query to run. this can result in a large undo tablespace if there are un-tuned queries running
On your system.

Again in 9i, even though it is called automatic undo management, undo_retention parameter seems always 'fixed', but it does mean you don't have to bother about rollback segments.

Shrink undo tablespace

The undo tablespace can only grow larger, but it can not shrink by itself. If you want to shrink the Undo tablespace, create a new one and set the undo_tablespace parameter to the new undo tablespace.

Retention guaranteed

When you create the Undo tablespace with the retention guarantee option, unexpired undo information will never get stolen. set this if you want to guarantee read consistency or when you want to use flashback with a guaranteed point-in-time!

Beware that when this is set, the chance of ORA-30036 errors increases. It's your choice: ORA-30036 or ORA-01555...

Setting the undo_retention parameter to the longest running Query

A good practice is to set the undo_retention parameter to the longest running query, to avoid ORA-01555 (read consistency) errors. to get a good indication about the longest running query in the last 7 days, try:

select max(maxquerylen) from v$undostat;

One can also try V $ session_longops and V $ transaction.
If you want to increase your flashback period, take the largest of these two.

How much undo will this generate?

Again take a look at V $ undostat and the undoblks column in particle.
Multiply these undoblks (per 10 minutes by default) times your blocksize times the maxquerylen.

For a worst case scenario size you can calculate much undo wowould have been generated when you multiply the highest rate with the longest query:

select  round(max(undoblks/600)*8192*max(maxquerylen)/(1024*1024)) as "UNDO in MB"from v$undostat;

But, it cocould be your longest running query will not run when the most Undo is generated...

Undo Advisor

The undo advisor can be found in the Oracle Enterprise Manager or by using the dbms_advisor package.

Undo Advisor

When opening the Undo advisor, it will show the current retention time and tablespace settings, but also shows analysis results, potential problems and recommendations.
These results are based on a 7 days period, analyzing longest query or flashback duration and undo generation rates. This can be made visible thought the Undo graph.

Undo retention Graph

New: When unchanged, this shows the current retention time setting. You can change the undo_retention to a new value by selecting a dot on the line in the graph.
Auto-tuned undo retention: This is the retention time oracle can currently hold. It will use the undo_retention as a minimum.
Best Possible undo retention: With the current size (fixed) or maxsize (autoextend) of the Undo tablespace, This is the retention time it possibly cocould hold.

Oracle uses the statistics in the V $ undostat view to tune the Undo mechanic. a dba can also use this view, together with V $ rollstat to get a good indication of current workload. the dba_hist_undostat view contains statistical snapshots of V $ undostat information.

All this information is based on the selected analysis time period with the Undo generation rate within that period.

Lobs

Automatic undo management not supported for lobs. undo information for lobs is not stored undo tablespace, but in the segment itself. for lobs, the database uses the undo_retention as a minimum, but when space becomes a problem, the unexpired undo Information
For the lob may be reused.

Conclusion

Even though automatic undo management is able to tune itself, one needs to keep an eye on transaction duration, retention time and space consumed.

With the addition of Flashback Technology to the database, the Undo tablespace is now also used to recover from user errors. when retention guaranteed is used, more priority is given to support read consistency and flashback operations, because Oracle will
Not Steal unexpired extents.

Furthermore the Undo advisor can be used to visualise retention time. space consumed, but in case of Undo related errors, a DBA still needs to analyze v $ undostat and related views to solve problems other than 'just enlarge 'the Undo tablespace.

Information in this article is based on my own experience and derived from articles and documentation found on the Internet.

From: http://blog.oracle48.nl/oracle-database-undo-space-explained/
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.