Skip to Main Content

Breadcrumb

May 4th

Question and Answer

Tom Kyte

Thanks for the question, Sujith.

Asked: December 25, 2005 - 5:43 pm UTC

Last updated: February 18, 2010 - 9:25 am UTC

Version: 9205

Viewed 10K+ times! This question is

You Asked

Hi Tom,

If I shutdown immediate a Database that should rollback a huge transaction, How does the UNDO_RETENTION time comes into play?? In Oracle Student Guide it says it could take upto the time specified in UNDO_RETENTION to shutdown the Database if it is rolling back a transaction.
My understanding about UNDO_RETENTION was that oracle will keep the before image for the specified time in UNDO_RETENTION and use those again only after the UNDO_RETENTION is expired. If there is an transaction rolling back, it should find the before image in undo and should just use it to rollback right??
Please correct me here..

Thanks and I appreciate your help.

Kandy Train.

and Tom said...

The correlation between the time to rollback and undo_rentention is tenuous at best - if you could even draw one.

I don't see how you could "in general" even link the two concepts together.

If you have undo_retention set to 5 minutes.... but you run a 2 hour long transaction.... well - you'll have two hours of work to logically "undo" (and that could take much longer than two hours - there is not even really a direct correlation between transaction duration and time to rollback).

If you have undo_retention set to 2 hours... but you only run transactions that take 0.5 seconds..... well, it won't take much time at all to rollback those transactions.

This student guide - is it part of the oracle documentation? Do you have a link to it?

Rating

  (21 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

effect of UNDO_RETENTION

Sujith Wimalasooriya, December 26, 2005 - 2:23 pm UTC

Thanks for the answer. With my very little basic knowledge about oracle, I too couldn't see a relationship between these two.

I don't have a link for that.

I appreciate your time during the holidays, and have a happy holiday

Kandy Train

MAXQUERYLEN

Sal, December 13, 2006 - 11:58 am UTC

Tom,

For v$undostat, the column MAXQUERYLEN is supposed to show us the time it took to run the longest query during the interval. (This is from the manual: Identifies the length of the longest query (in number of seconds) executed in the instance during the period. You can use this statistic to estimate the proper setting of the UNDO_RETENTION initialization parameter.)

In my database (9.2.0,7) I see that value for MAXQUERYLEN gets higher than my UNDO_RETENTION setting, yet I do not get any ORA-1555 error. For example the value is 13142 in an interval, maxconcurrency is 3, SSOLDERRCNT is zero and my undo_retention is set to 7200.

Yet when I do get an ORA-1555 error, the query length reported in the error matches to the value of MAXQUERYLEN.

Please can you explain this?

Thanks

Tom Kyte
December 14, 2006 - 9:57 pm UTC

explain what?

so - the query length equals maxquerylen (everything else you said is not relevant at this point).



MAXQUERYLEN

Sal, December 14, 2006 - 11:00 pm UTC

Well, the way I understand this is that MAXQUERYLEN should be always smaller than undo_retention. If MAXQUERYLEN exceeds undo_retention, I would get ORA-01555.

I do not see the above happening.

Tom Kyte
December 15, 2006 - 8:42 am UTC

nope, not at all.

if your undo retention is set to 1 minute
and you run a query for 60 minutes...

BUT NO ONE GENERATES SUFFICIENT UNDO in the 60 minutes to overwrite stuff you need

OR - you are querying something that is not needing undo for read consistency

then you will not hit the 1555 at all.


you get a 1555 when you need some bit of undo that no longer exists, using undo_retention is a method to help ensure that does not happen, but it doesn't mean Oracle will fail queries if they run longer than that setting - if those queries are actually able to complete.

To: Sal

Michel Cadot, December 15, 2006 - 12:36 am UTC

From Reference manual:

<quote>
UNDO_RETENTION specifies (in seconds) the low threshold value of undo retention.
</quote>

UNDO_RETENTION does not mean that if a query takes more time it will get an ORA-1555 but it may get it.
The opposite is also true: if a query takes less time it may get an ORA-1555 unless you enabled retention guarantee in 10g.

Michel


What's the impact/harm to over estimate the undo_retention

John, March 22, 2007 - 2:44 pm UTC

I have a question here, what's the impact to over estimate the undo_retention? For example, the longest querey is 20 minutes, but I set undo_retention to 7200 ( 2 hrs ); Assume the size of UNDO tablespace is fixed, if there are no free segments on the UNDO tbs, then the segment with comitted data will be overwritten even it's still in the retention period, so what's the impact to set the undo_retention to a value higher than it's really need?
Tom Kyte
March 22, 2007 - 3:05 pm UTC

well, you set the undo retention for two reasons:

a) 1555 avoidance
b0 ability to recover from whoops type operations (flashback)


there can be a downside in extreme cases where physical IO performed by DBWR could go up. If you have 100 blocks to write undo into - we might write block 1 fifty times and just have in the buffer cache 100 dirty undo blocks before DBWR is asked to checkpoint it. If you have 1,000 blocks to write undo into - we might only use block 1 five times - and use all 1,000 blocks in the buffer cache, causing dbwr to have to write (checkpoint) 1,000 blocks....


John, March 22, 2007 - 4:58 pm UTC

Actually I am doing the work to migrate our current RBS to AUM, I am trying to correctly set up the undo_retention. The longest query in the system is around 4 hrs, the old RBS tablespace is pretty big with 20 RBSs, there was no ORA-1555 error happened for a long time in the past; Can I assume if I keep the UNDO tablespace the same size as it was in the RBS environment, then the undo_retention won't be an issue to get more chance of ora-1555 even it's set up to a small value ( since there was no ora-1555 issues in the RBS environment with the same tablespace size ). We don't care the flash back
Tom Kyte
March 22, 2007 - 6:37 pm UTC

no, you want undo_retention set high - else we'll just recycle and reuse (you want us to RETAIN for 4 hours)

John, March 22, 2007 - 10:11 pm UTC

But if I upgrade the RBS to AUM, keep the same size of the tablespace, but set the undo_retention low, shall I assume the CHANCE to get ORA-1555 is <= the old RBS mode? ( I understand that it still possible to get ORA-1555, I mena the CHANCE compare with the old RBS mode); If that's not true, can you explain why migrate to UNDO even get worse in avoiding ORA-1555 ( RBS has no undo_retention protection at all ! ).

Thanks a lot
Tom Kyte
March 23, 2007 - 9:42 am UTC

if you set the undo retention low, you can assume the odds you get a 1555 are greatly INCREASED.


so what if your undo tablespace is 15 kabillion gigawads. If you tell us "retain undo for like 5 minutes", that is all we'll do - we don't use the space until and unless we need to.

You want to set undo retention higher than your longest running queries AND ensure you have allocated sufficient space to hold that much.

If you could elaborate on earlier point

randomguy, March 23, 2007 - 7:28 pm UTC

From above with questions -
there can be a downside in extreme cases where physical IO performed by DBWR could go up. If you have 100 blocks to write undo into (we have a small undo I guess) - we might write block 1 fifty times (block 1 of our small undo?) and just have in the buffer cache 100 dirty undo blocks before DBWR is asked to checkpoint it. If you have 1,000 blocks to write undo into (we have more undo than before?) - we might only use block 1 five times - (block 1 of our undo? Why would we write 1*5 - 5 blocks of undo for 1,000 undo blocks?) and use all 1,000 blocks in the buffer cache, causing dbwr to have to write (checkpoint) 1,000 blocks....

Tom Kyte
March 26, 2007 - 7:11 am UTC

say your undo tablespace is 100 blocks in size.

undo is cached just like anything else.

So, when dbwr needs to checkpoint this instance, what is the maximum number of undo blocks that could possibly be in the buffer cache to be checkpointed?


Now, say your undo tablespace is 1000 blocks in size.

Do the above again.

dedicated Undo tablespace

A reader, June 25, 2008 - 3:21 pm UTC

I noticed that the client's db has two undo tablespaces- UNDOTBS1 AND UNDOTBS2, the paramater undo_tablespace uses UNDOTBS2 for the automatic undo management. I asked the Admin what's UNDOTBS1 for, and he told that is for some batch jobs.
I wonder if we can combine the two undo tbs to one and just a big one for automatic undo management for all the requirement.
Is that fine? it's 10.2.0 DB.
TIA
Tom Kyte
June 25, 2008 - 3:47 pm UTC

if they are using automatic undo management, how are they using this other one please?

dedicated undo tablespace

A reader, June 25, 2008 - 3:57 pm UTC

The guy to be asked lives in other side of the world.
I have to wait for the chance to ask him.

But can this work?
SET TRANSACTION USE ROLLBACK SEGMENTS UNDOTBS1
Tom Kyte
June 25, 2008 - 5:03 pm UTC

that is silently ignored.

and it would be "set transaction use rollback segment <segment-name>"
ops$tkyte%ORA10GR2> set transaction use rollback segment does_not_exist_in_my_database;

Transaction set.


A reader, June 25, 2008 - 4:03 pm UTC

It could be RAC....

A reader, June 25, 2008 - 4:24 pm UTC

to the reader: it's not RAC.

Can you clear this funda?

Pravin Baldawa, August 19, 2008 - 3:49 am UTC

Hi Tom,

I have the below question :

How to Set up automatic undo management in the PROD database to support the following requirements:

2.1 Avoid ORA- 01555 Snapshot too old errors for queries running up to 90 minutes on average.
2.2 The number of concurrent OLTP users will be approximately 120 during normal business hours.
2.3 The number of concurrent batch processes that will run in the evenings and weekends will be approximately 12 to 15.

Thanks

Tom Kyte
August 20, 2008 - 10:25 am UTC

funda?? what the heck is a funda



anyway, in answer to your question - what is the duration of the longest running query. Take that answer and set that to be the undo_retention period.

Then, ensure sufficient undo tablespace exists so that we can retain undo for that period of time.

v$undostat will be a useful view to learn about.

Funda = Concept

Pravin Baldawa, August 22, 2008 - 3:25 am UTC

Hey Tom,

Thanks for clearing this concept. Actually I was confused about the above query containing points 2.2 & 2.3 .
We generally use funda for "concept".

REgards


Tom Kyte
August 22, 2008 - 9:39 am UTC

funda is not a word. You might use it as a colloquialism, but you should use real words in written communication. It makes it easier to understand.


I know, I could look it up (and I did), but it makes it really hard to communicate

MAXQRYLEN doesn't appear to be correct

Rahul, January 12, 2010 - 2:15 am UTC

We are using RAC 2node 10.2.0.4.0 and one RAC node shows maxqrylen to be 1400-1800 accross interval. If I see v$sqlarea I found total elasped time to be 10 sec(as it is in microsecond)
So which figure I am interpretting wrongly.

below are some snaps.
BEGIN_TIME   END_TIME        UNDOTSN   UNDOBLKS   TXNCOUNT MAXQUERYLEN MAXQUERYID    MAXCONCURRENCY
------------ ------------- --------- ---------- ---------- ----------- ------------- --------------
12-jan-2010  12-jan-2010           1      18207      63102        1848 445jdv3pmzb4d             10
12-jan-2010  12-jan-2010           1       8796      31041        1861 445jdv3pmzb4d              8
12-jan-2010  12-jan-2010           1        915       3473        1318 445jdv3pmzb4d              5
12-jan-2010  12-jan-2010           1      16631      56684        1469 445jdv3pmzb4d             11
12-jan-2010  12-jan-2010           1      18294      61514         739 445jdv3pmzb4d             10
12-jan-2010  12-jan-2010           1      19663      63613        1340 445jdv3pmzb4d             12
12-jan-2010  12-jan-2010           1      19127      60079        1445 445jdv3pmzb4d             10
12-jan-2010  12-jan-2010           1      18838      61440        1683 445jdv3pmzb4d             10
12-jan-2010  12-jan-2010           1      17931      60275        1686 445jdv3pmzb4d             10
12-jan-2010  12-jan-2010           1       2430       8034        1445 445jdv3pmzb4d              9
12-jan-2010  12-jan-2010           1       5648      19160        1565 445jdv3pmzb4d             19


SYS@OLTPE> select executions,elapsed_time from v$sqlarea where sql_id='445jdv3pmzb4d';

EXECUTIONS ELAPSED_TIME
---------- ------------
     20472     10385942


Tom Kyte
January 18, 2010 - 12:44 pm UTC

v$sqlarea is an aggregation of v$sql, use v$sql to peek at stuff.

also, things come and go in v$sql/sqlarea - it is very transient.


and consider this:

open cursor;
go to sleep for a while
fetch a row;
go to sleep for a while
fetch a row;
(repeat...)
close cursor;


what is the

a) elapsed time for the open/fetch/close (v$sql information) versus
b) the undo retention needs.

But my undostat has huge maqrylen value.

A reader, January 19, 2010 - 1:21 am UTC

Thanks Tom, I will use v$sql from now.
Tom in my system we have 1.5gb of shared pool so frequently executed qry don't get flushed(99%) and I have observed this discrepancy behavior over long period of time in almost each of my Performance tests.
I have a doubt that because of this (high maxqrylen) my tuned_undo value in v$undostat reaches upto 55000 and I start to get undo contentions event.

I understand when you say

open cursor;
go to sleep for a while
fetch a row;
go to sleep for a while
fetch a row;
(repeat...)
close cursor;


This way my understanding is that elapsed time in v$sql will be inflated and not my v$undostat maxqrylen.

Thanks in advance for your reply.
Tom Kyte
January 19, 2010 - 4:32 pm UTC

.. This way my understanding is that elapsed time in v$sql will be inflated and
not my v$undostat maxqrylen.
...

you have that exactly backwards.

v$sql reports time spent in the database. it is the time it took to open plus the time it took to fetch plus the time it took to close. Minus the time spent in the client.

the maximum time a query needs undo included database time PLUS client time. It is the time from open till the time of close.

But my undostat has huge maqrylen value.

A reader, January 19, 2010 - 1:22 am UTC

Thanks Tom, I will use v$sql from now.
Tom in my system we have 1.5gb of shared pool so frequently executed qry don't get flushed(99%) and I have observed this discrepancy behavior over long period of time in almost each of my Performance tests.
I have a doubt that because of this (high maxqrylen) my tuned_undo value in v$undostat reaches upto 55000 and I start to get undo contentions event.

I understand when you say

open cursor;
go to sleep for a while
fetch a row;
go to sleep for a while
fetch a row;
(repeat...)
close cursor;


This way my understanding is that elapsed time in v$sql will be inflated and not my v$undostat maxqrylen.

Thanks in advance for your reply.

Thanks Tom

A reader, January 20, 2010 - 10:19 pm UTC

Thanks Tom for clearing my basic mistake in all this assumption.

Maxquerylen

Lidia Berbenets, February 17, 2010 - 7:42 am UTC

Hi, Tom!
Our database is Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi ( for Windows)
We received a big growth of undo tablespace few weeks ago.
I perfomed some queries to the database including query to the history of undostat.

select end_time, round(maxquerylen/60,0) maxq, maxquerysqlid,
undotsn, undoblks, txncount,
round(tuned_undoretention/60,0) tuned
from dba_hist_undostat
order by 1

Query Tuned
Maximum Undo # of Retention
Date/Time Minutes SqlID TBS Blocks Trans#(Minutes)
17-09:05 2,752 7k6rstttj9f9t 1 24,676 20,109 1,833
17-09:15 2,762 7k6rstttj9f9t 1 34,129 28,696 1,850
17-09:25 2,772 7k6rstttj9f9t 1 41,338 34,272 1,846
17-09:35 2,782 7k6rstttj9f9t 1 21,000 17,215 1,843
17-09:45 2,792 7k6rstttj9f9t 1 53,951 26,695 1,820
17-09:55 2,802 7k6rstttj9f9t 1 29,585 22,208 1,862
17-10:05 2,808 7k6rstttj9f9t 1 53,941 41,687 1,838
17-10:15 2,818 7k6rstttj9f9t 1 66,433 52,674 1,871
17-10:25 2,828 7k6rstttj9f9t 1 66,291 52,878 1,589
17-10:35 2,838 7k6rstttj9f9t 1 31,253 24,688 1,573
17-10:45 2,848 7k6rstttj9f9t 1 56,226 50,774 1,561
17-10:55 2,858 7k6rstttj9f9t 1 43,874 40,423 1,579
17-11:05 2,868 7k6rstttj9f9t 1 10,578 6,534 1,584
17-11:15 2,879 7k6rstttj9f9t 1 4,948 5,162 1,590
17-11:25 2,889 7k6rstttj9f9t 1 42,314 32,505 1,591
17-11:35 2,899 7k6rstttj9f9t 1 28,947 22,948 1,598
17-11:45 2,909 7k6rstttj9f9t 1 28,158 198,988 1,593
17-11:55 2,919 7k6rstttj9f9t 1 23,800 248,859 1,608
17-12:05 2,929 7k6rstttj9f9t 1 48,582 251,195 1,600
17-12:15 2,940 7k6rstttj9f9t 1 79,496 238,294 1,585
17-12:25 2,950 7k6rstttj9f9t 1 37,848 470,802 1,580
17-12:35 2,960 7k6rstttj9f9t 1 26,518 621,110 1,579
17-12:45 2,970 7k6rstttj9f9t 1 13,692 431,268 1,580
17-12:55 2,980 7k6rstttj9f9t 1 27,472 478,534 1,575
17-13:05 2,990 7k6rstttj9f9t 1 30,533 476,277 1,577
17-13:15 3,000 7k6rstttj9f9t 1 43,902 341,339 1,572
17-13:25 3,011 7k6rstttj9f9t 1 28,526 368,415 1,576
17-13:35 3,021 7k6rstttj9f9t 1 30,222 87,853 1,573
17-13:45 3,031 7k6rstttj9f9t 1 31,563 23,602 1,573
17-13:55 3,041 7k6rstttj9f9t 1 38,777 30,344 1,566

I was confused about the same sqlid in the result, and the value of maxquerylen in dba_hist_undostat (so large maxquerylen!!!).
I get the sql_text for this query from v$sql and can suppose what the applications executes this query. It is very often-executed function.
But I do not understand how it could happen - our users would not tolerate such "performance" ( 2 days)...
You can see also, that maxquerylen of this query increases
permanently.
It is very important for us , because big tuned undo retention causes growth of undo tablespace and ora-01555 occures.
It sems to me like never-ending circle...
Can you, please explain, how maxquerylen is calculated and what do my results mean?
May this only query be the main reason of growing undo tablespace?
Thank you in advance.
Lidia.




Tom Kyte
February 17, 2010 - 9:38 am UTC

someone has opened this cursor....

and left it open. They fetched a bit of it and stopped - never finished fetching from it.

Hence that query is still running as far as we are concerned. If the application that opened it tried to fetch from it again, we would need to rollback some 3,000 seconds of database activity to get the data.


that said, the tuned retention time is not increasing in the data you show, so I don't know if that was the cause (I don't know if retention time used to be very small and is now much larger).

it could be that the retention time increased.
it could be that you had some really large batch update.
it could be that you had a flurry of small transactions in a short period of time.

Maxquerylen

A reader, February 18, 2010 - 2:39 am UTC

Hi, Tom!
Thank you for your answer.
" someone has opened this cursor....and left it open."
Now I understand the reason of such results. And we find the application, that opened this cursor. This is application on Forms , which is called from another form and is not correctly closed.
So, please , next questions about cursors that are not closed.
Our application are all on forms, and there are many forms and reports , which are calling from another forms.Sometimes our users swith off the PC without closing the application.
Will such users behavior cause cursors that are not closed?
Will ever be closed cursors from the broken sessions?
And if some form is opened from morning till evening, our undo_retention must bigger then worktime (8 hours) ?
Thank you in advance.
Lidia


Tom Kyte
February 18, 2010 - 9:25 am UTC

You could, probably should, enable dead client detection to clean these out.

http://docs.oracle.com/docs/cd/E11882_01/network.112/e10835/sqlnet.htm#NETRF209

Maxquerylen

Lidia, February 19, 2010 - 4:22 am UTC

Thank you