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?
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
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...
Yes, that was a typo. It should be "=0".
I was thinking that but my fingers typed something else...
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;
/