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?
Oracle Database

Avatar of undefined
Last Comment
slightwv (䄆 Netminder)

8/22/2022 - Mon
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
Sean Stuber

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Sean Stuber

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
Geert G

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
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
slightwv (䄆 Netminder)

>>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...