Home » SQL & PL/SQL » SQL & PL/SQL » ORA-01555: snapshot too old: rollback segment number with name "" too small (Oracle 10g)
ORA-01555: snapshot too old: rollback segment number with name "" too small [message #546575] Wed, 07 March 2012 08:45 Go to next message
yavvie
Messages: 6
Registered: March 2012
Location: Prague
Junior Member
We are getting error "ORA-01555: snapshot too old: rollback segment number with name "" too small" in procedure inserting data from view (connected to remote DB) into local table. There should be approx 10 000 000 rows inserted. At first the procedure ran for about 4 hours (one year ago), now it runs 18 hours and sometimes fails with this error.

Is there any way to
1) check how the rollback segments are set and which are used by this procedure
2) calculate necessary rollback segment
3) modify the rollback segment for this procedure only (if possible)

I am not the DBA so I don't know what is set in the database or where it can be checked, so I'd need scripts that tell me what is there and what I should set and how.

The code in the procedure is as follows:


    
    execute immediate 'alter index TARGET_TABLECREDATE unusable';

    delete from TARGET_TABLE;

    insert into TARGET_TABLE
    select
      col1
     ,col2
     ,col3
     ,col4
     ,col9
      from SOURCE_VIEW oi
     where oi.change_date   between (sysdate - 10) and sysdate
        or oi.creation_date between (sysdate - 10) and sysdate;
    commit;

    execute immediate 'alter index TARGET_TABLECREDATE  rebuild';
    execute immediate 'analyze table TARGET_TABLE compute statistics';
Re: ORA-01555: snapshot too old: rollback segment number with name "" too small [message #546576 is a reply to message #546575] Wed, 07 March 2012 08:47 Go to previous messageGo to next message
Michel Cadot
Messages: 68765
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Ask your DBA to enlarge the undo tablespace and to increase the undo_retention parameter.

Regards
Michel

[Updated on: Wed, 07 March 2012 08:48]

Report message to a moderator

Re: ORA-01555: snapshot too old: rollback segment number with name "" too small [message #546577 is a reply to message #546575] Wed, 07 March 2012 08:50 Go to previous messageGo to next message
John Watson
Messages: 8985
Registered: January 2010
Location: Global Village
Senior Member
If you use TRUNCATE instead of DELETE, it will be much faster and use much less undo space.
Re: ORA-01555: snapshot too old: rollback segment number with name "" too small [message #546580 is a reply to message #546577] Wed, 07 March 2012 08:54 Go to previous messageGo to next message
Roachcoach
Messages: 1576
Registered: May 2010
Location: UK
Senior Member
Probably best to drop the index too rather than unusable I'd imagine (though have not checked).

Edit: And if truncating as you should, do a direct path insert.

[Updated on: Wed, 07 March 2012 08:54]

Report message to a moderator

Re: ORA-01555: snapshot too old: rollback segment number with name "" too small [message #546583 is a reply to message #546580] Wed, 07 March 2012 08:57 Go to previous messageGo to next message
Michel Cadot
Messages: 68765
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Quote:
Probably best to drop the index too rather than unusable I'd imagine (though have not checked).


No difference except you can't forget to recreate/rebuild an index if it is still there. Wink

Regards
Michel
Re: ORA-01555: snapshot too old: rollback segment number with name "" too small [message #546584 is a reply to message #546580] Wed, 07 March 2012 08:58 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>from SOURCE_VIEW oi
the problem is that some other session is doing DML & COMMIT against table beneath SOURCE_VIEW
Re: ORA-01555: snapshot too old: rollback segment number with name "" too small [message #546585 is a reply to message #546583] Wed, 07 March 2012 08:58 Go to previous messageGo to next message
Roachcoach
Messages: 1576
Registered: May 2010
Location: UK
Senior Member
Every day's a school day Smile
Re: ORA-01555: snapshot too old: rollback segment number with name "" too small [message #546586 is a reply to message #546584] Wed, 07 March 2012 09:07 Go to previous messageGo to next message
yavvie
Messages: 6
Registered: March 2012
Location: Prague
Junior Member
BlackSwan
>from SOURCE_VIEW oi
the problem is that some other session is doing DML & COMMIT against table beneath SOURCE_VIEW


That is possible but I cannot influence it since my procedure runs 18 hours.


John Watson
If you use TRUNCATE instead of DELETE, it will be much faster and use much less undo space.


If I truncate the table and procedure fails will it roll back or not? Since you write it will use much less undo space.


Roachcoach

Edit: And if truncating as you should, do a direct path insert.


I'm not sure what you mean by that. I cannot select directly from the DB link because I have only privileges to the view SOURCE_VIEW on top of it.


Michel Cadot

Ask your DBA to enlarge the undo tablespace and to increase the undo_retention parameter.


Can you please post script by which I can check what is set in the DB?
Re: ORA-01555: snapshot too old: rollback segment number with name "" too small [message #546587 is a reply to message #546586] Wed, 07 March 2012 09:11 Go to previous messageGo to next message
cookiemonster
Messages: 13967
Registered: September 2008
Location: Rainy Manchester
Senior Member
18 hours?
How many rows are we talking about here?
Re: ORA-01555: snapshot too old: rollback segment number with name "" too small [message #546588 is a reply to message #546587] Wed, 07 March 2012 09:14 Go to previous messageGo to next message
cookiemonster
Messages: 13967
Registered: September 2008
Location: Rainy Manchester
Senior Member
And the number is in the first post. That's really slow.
Truncate would reduce that figure considerably.
Re: ORA-01555: snapshot too old: rollback segment number with name "" too small [message #546590 is a reply to message #546588] Wed, 07 March 2012 09:19 Go to previous messageGo to next message
yavvie
Messages: 6
Registered: March 2012
Location: Prague
Junior Member
Its around 10 milion rows and the source DB is not fast either.

If I use truncate table in the procedure will I be able to rollback in case the procedure fails?
Re: ORA-01555: snapshot too old: rollback segment number with name "" too small [message #546591 is a reply to message #546590] Wed, 07 March 2012 09:19 Go to previous messageGo to next message
cookiemonster
Messages: 13967
Registered: September 2008
Location: Rainy Manchester
Senior Member
You can't roll truncate back.
Re: ORA-01555: snapshot too old: rollback segment number with name "" too small [message #546592 is a reply to message #546588] Wed, 07 March 2012 09:20 Go to previous messageGo to next message
Roachcoach
Messages: 1576
Registered: May 2010
Location: UK
Senior Member
Slowness would depend on the relative complexity of the view and the size of the underlying tables surely? Plus if there's mass DML going on at the time that can really slow things down.
Re: ORA-01555: snapshot too old: rollback segment number with name "" too small [message #546593 is a reply to message #546591] Wed, 07 March 2012 09:25 Go to previous messageGo to next message
John Watson
Messages: 8985
Registered: January 2010
Location: Global Village
Senior Member
Here's a test routine that will prove to you how much more efficient truncate and diurect load are than delete and conventional insert:
conn / as sysdba
drop user jon cascade;
grant dba to jon identified by jon;
set timing on
conn jon/jon
create table t1 as select * from all_objects;
--test using DELETE
conn jon/jon
delete from t1;
select name,value from v$mystat natural join v$statname where statistic# in (178,290);
--test conventional load
conn jon/jon
insert into t1 select * from all_objects;
select name,value from v$mystat natural join v$statname where statistic# in (178,290);
--test using TRUNCATE
conn jon/jon
truncate table t1;
select name,value from v$mystat natural join v$statname where statistic# in (178,290);
--test direct load
connect jon/jon
insert /*+ append */ into t1 select * from all_objects;
select name,value from v$mystat natural join v$statname where statistic# in (178,290);



Re: ORA-01555: snapshot too old: rollback segment number with name "" too small [message #546594 is a reply to message #546576] Wed, 07 March 2012 09:26 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>Ask your DBA to enlarge the undo tablespace and to increase the undo_retention parameter.
on which database?
Re: ORA-01555: snapshot too old: rollback segment number with name "" too small [message #546595 is a reply to message #546592] Wed, 07 March 2012 09:27 Go to previous messageGo to next message
yavvie
Messages: 6
Registered: March 2012
Location: Prague
Junior Member
So the only real solution would be increasing the undo tablespace and increasing the undo_retention parameter... How do I find out what is set in the DB? (the query please)
Of course I cannot truncate the table and in case of problems with the procedure/source etc. leave it empty.

The underlying table contains several hundred million rows, I select just the last 10 days which gives me 10 million.
Re: ORA-01555: snapshot too old: rollback segment number with name "" too small [message #546596 is a reply to message #546592] Wed, 07 March 2012 09:29 Go to previous messageGo to next message
cookiemonster
Messages: 13967
Registered: September 2008
Location: Rainy Manchester
Senior Member
Roachcoach wrote on Wed, 07 March 2012 15:20
Slowness would depend on the relative complexity of the view and the size of the underlying tables surely?

True, I kinda assumed it's a simple view, probably shouldn't

Roachcoach wrote on Wed, 07 March 2012 15:20

Plus if there's mass DML going on at the time that can really slow things down.

Yup, though if it's taking 18 hours a mass of DML becomes a given on most systems.
Re: ORA-01555: snapshot too old: rollback segment number with name "" too small [message #546597 is a reply to message #546595] Wed, 07 March 2012 09:30 Go to previous messageGo to next message
John Watson
Messages: 8985
Registered: January 2010
Location: Global Village
Senior Member
Quote:
Of course I cannot truncate the table and in case of problems with the procedure/source etc. leave it empty.
Why not?
But I notice that you haven't said "thank you" to anyone yet, so that is it for me.
Re: ORA-01555: snapshot too old: rollback segment number with name "" too small [message #546599 is a reply to message #546593] Wed, 07 March 2012 09:33 Go to previous messageGo to next message
yavvie
Messages: 6
Registered: March 2012
Location: Prague
Junior Member
John Watson wrote on Wed, 07 March 2012 16:25
Here's a test routine that will prove to you how much more efficient truncate and diurect load are than delete and conventional insert:
--test conventional load
conn jon/jon
insert into t1 select * from all_objects;
select name,value from v$mystat natural join v$statname where statistic# in (178,290);
--test direct load
connect jon/jon
insert /*+ append */ into t1 select * from all_objects;
select name,value from v$mystat natural join v$statname where statistic# in (178,290);



Thanks for the code, I'll have to do some reading on this.
I'm not sure what the difference here is, clause /*+ append */ in the select statement? Isn't that commented out?
Looking at the original procedure this part of code is in the insert statement, I just didn't write it here since I didn't know what it does, so my bad.

[Updated on: Wed, 07 March 2012 09:36]

Report message to a moderator

Re: ORA-01555: snapshot too old: rollback segment number with name "" too small [message #546600 is a reply to message #546599] Wed, 07 March 2012 09:39 Go to previous messageGo to next message
Roachcoach
Messages: 1576
Registered: May 2010
Location: UK
Senior Member
The +append is a hint directive to use direct load.

Sorry I forgot to answer that one. Probably best to check the documentation for it and its nuances.
Re: ORA-01555: snapshot too old: rollback segment number with name "" too small [message #546603 is a reply to message #546600] Wed, 07 March 2012 09:51 Go to previous messageGo to next message
yavvie
Messages: 6
Registered: March 2012
Location: Prague
Junior Member
No harm done, I thank you and everyone else for the replies, which have surely broadened my horizons (I work with Oracle only occasionally, so most of these special commands are lost to me).

So that I understand it correctly - basically all I can do is forward the problem to DBA to modify the undo tablespace and the undo_retention parameter. I've looked for some scripts that show me what is currently set in the DB, how do I know which undo tablespace/segment my procedure uses?

select * from V$ROLLSTAT gives me a list of 27 undo segments in the undo tablespace but I have no idea what to tell my DBA - how much I need, where do I need it... Or do I need to know this at all? (If anyone is DBA please tell me what you expect your average programmer to know Smile )
Re: ORA-01555: snapshot too old: rollback segment number with name "" too small [message #546604 is a reply to message #546603] Wed, 07 March 2012 09:56 Go to previous messageGo to next message
cookiemonster
Messages: 13967
Registered: September 2008
Location: Rainy Manchester
Senior Member
Generally speaking it will use what ever undo segments are available.
You'll need to increas the total size, not a given bit of it.

The other alternative is to speed it up. Generally the quicker a process runs the less chance there is of hitting that error.

For the amount of data and the time currently being taken you're going to need a lot of undo.
Re: ORA-01555: snapshot too old: rollback segment number with name "" too small [message #546606 is a reply to message #546603] Wed, 07 March 2012 10:03 Go to previous messageGo to next message
Roachcoach
Messages: 1576
Registered: May 2010
Location: UK
Senior Member
18 hours isn't a 'bad' duration to get an ora-01555.

It's caused by Oracle trying to get a read consistent view of a changed block (i.e. someone altered a record after your query started and the DB no longer has the information to work out what it was at the time the query started).

I'd be surprised if they are not using auto undo management and as mentioned 18 hours is a pretty good length to run for. Basically the DBA is unlikely to offer much assistance in that particular area.

I'd start by looking at that view and working out if you can apply the data in a more efficient way. Many a time I've seen slow queries accessing a view and it turns out the view is only accessed for convenience/laziness - if you only need a few tables worth of data, going through a view hitting a dozen is usually inefficient.

If this is a 'batch' style job and the server has capacity, it may be advantageous to look at parallel execution (if available) but use this with care, it is not a silver bullet.

Finally, what might be more a productive conversation with them, is to ask the DBAs what data replication options are available to your environment, perhaps there is a better way?

To be honest though, your quickest gain will be binning the delete and using a truncate.


PS: Use dbms_stats.gather_table_stats for the stats job

PPS: All of this assumes you are on 10g as mentioned.
Re: ORA-01555: snapshot too old: rollback segment number with name "" too small [message #546607 is a reply to message #546606] Wed, 07 March 2012 10:10 Go to previous messageGo to next message
Michel Cadot
Messages: 68765
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Quote:
select * from V$ROLLSTAT gives me a list of 27 undo segments in the undo tablespace but I have no idea what to tell my DBA - how much I need, where do I need it... Or do I need to know this at all?

Michel Cadot wrote on Wed, 07 March 2012 15:47
Ask your DBA to enlarge the undo tablespace and to increase the undo_retention parameter.

You have nothing more to know, it is to your DBA to size the UNDO tablespace and parameters to fit your needs (assuming the DBA has the means to do it, thta is the disk space).
He has the V$UNDOSTAT view (and DBA_HIST_UNDOSTAT if your client purchase the option) to estimate what you need.

Quote:
Of course I cannot truncate the table and in case of problems with the procedure/source etc. leave it empty.


But you can copy its content before into a work table and in the end truncate the work table or copy back the content to the original depending if your batch succeeded or failed.

Regards
Michel



Re: ORA-01555: snapshot too old: rollback segment number with name "" too small [message #546625 is a reply to message #546607] Wed, 07 March 2012 15:21 Go to previous messageGo to next message
Bill B
Messages: 1971
Registered: December 2004
Senior Member
Is change_date and creation_date both indexed. Your process will go much faster if they are.
Re: ORA-01555: snapshot too old: rollback segment number with name "" too small [message #558677 is a reply to message #546595] Mon, 25 June 2012 13:18 Go to previous messageGo to next message
ayub_f_khan
Messages: 1
Registered: September 2010
Location: Baltimore, MD
Junior Member
login as sysdba

show parameter UNDO

SQL> ALTER SYSTEM set undo_retention= 2700;

show parameter UNDO

SQL> ALTER DATABASE datafile 'd:\app\oracle\oradata\orcl\undotbs01.dbf' resize 10G;

Choose your size to be whatever you want to increase it to.
Re: ORA-01555: snapshot too old: rollback segment number with name "" too small [message #558680 is a reply to message #558677] Mon, 25 June 2012 13:30 Go to previous messageGo to next message
Michel Cadot
Messages: 68765
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Quote:
login as sysdba


NO!

- Never ever use SYS (or SYSDBA) but for maintenance purpose (startup, shutdown, backup, recover)
- SYS/SYSDBA is special
- SYS/SYSDBA is Oracle proprietary (try to open a SR/TAR starting with "i did that with SYS/SYSDBA" and you'll see the immediate answer)
- SYS/SYSDBA does not act like any other user
- When you use SYS/SYSDBA Oracle deactivates some code path and activates others
- Whatever you do with SYS/SYSDBA will neither validate nor invalidate the same thing with any other user.

NEVER EVER use SYS/SYSDBA for anything that can be done by another user.
Use SYS/SYSDBA ONLY for something that can't be done by someone else.


Regards
Michel
Re: ORA-01555: snapshot too old: rollback segment number with name "" too small [message #558684 is a reply to message #558680] Mon, 25 June 2012 14:07 Go to previous messageGo to next message
John Watson
Messages: 8985
Registered: January 2010
Location: Global Village
Senior Member
Man, that is not a nice reply to a new member! Sure, his post does not follow best DBA practices, but he is only trying to help. Ayub, Michel is incredibly knowledgeable and helpful - but he does have very high standards (with which I agree - but don't always follow).

Here is my usual "welcome" message:

Welcome to the forum. Please read our OraFAQ Forum Guide and How to use [code] tags and make your code easier to read

Re: ORA-01555: snapshot too old: rollback segment number with name "" too small [message #558703 is a reply to message #558684] Tue, 26 June 2012 01:02 Go to previous message
Michel Cadot
Messages: 68765
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
He is not really a new member, he registered in 09/2010; I agree this is his first post but I think he previoulsy read many topics before posting this one.

Regards
Michel
Previous Topic: Create view
Next Topic: Date Error in Execute Immediate Query through function
Goto Forum:
  


Current Time: Wed Aug 20 07:42:29 CDT 2025