Link to home
Start Free TrialLog in
Avatar of xbox360dp
xbox360dp

asked on

Delete statement causing UNDO tablespace to reach limit.

Gurus,

I need to delete orphan data from a table with 682 million records.

When execute the following delete statement I receive "ORA-30036: unable to extend segment by 8 in undo tablespace 'UNDOTBS2':

DELETE FROM afl WHERE NOT EXISTS
      ( SELECT 1 FROM fty WHERE ftykeyi = afl.aflftykeyi );
COMMIT;

I know that I can continue to add datafiles. Is there a better way to write the statement or any other suggestions?
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Delete inside a loop that commits every XXX rows.

something like this (untested, just typed in):

declare
    rows_deleted number;
begin

loop
     DELETE FROM afl WHERE NOT EXISTS
       ( SELECT 1 FROM fty WHERE ftykeyi = afl.aflftykeyi ) and rownum<100000;
     rows_deleted := sql%rowcount;
     commit;
exit when rows_deleted>0;
end loop;
end;
/
ASKER CERTIFIED SOLUTION
Avatar of Sean Stuber
Sean Stuber

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ha - same idea at the same time

but...

you don't want your delete count > 0,  if you do that then the deletes will stop after one batch
off course that will happen

how many records would remain after the delete

it might be a lot faster to
create table tmp_table as select * from yourtable
where conditioning = remaining records

copy constraints and triggers

drop the old table

and rename the new table to the old table
>>you don't want your delete count > 0,

Yes, that was a typo.  It should be "=0".

I was thinking that but my fingers typed something else...