Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding column to Oracle OLTP table

I'm attempting to add a nullable column to a frequently used table in an Oracle 10 OLTP database while the application is running and busy. Adding a nullable column is only a data dictionary change and therefore any table lock is only held for a short period of time (which can be handled by the system).

The problem is that my ALTER TABLE often fails with this:

ORA-00054: resource busy and acquire with NOWAIT specified

My current approach is to bludgen the change in by running it until there happens to be no locks on the table. This means I can't run such a script in SQL*Plus in full, but need to copy and paste each statement and make sure it works.

Is there a better way?

like image 538
WW. Avatar asked Mar 25 '26 03:03

WW.


1 Answers

How about a brute force approach? Put it in an infinite loop and exit it when done. Pseudocode(haven't checked it):

create or replace 
procedure execDDL(ddl in varchar2) is
   myexp EXCEPTION;
   pragma exception_init (myexp, -54);
begin

 loop
   begin
      execute immediate ddl;
      exit;
   exception
      when myexp then 
         null;
 end loop;
 end;
like image 68
Samuel Avatar answered Mar 28 '26 00:03

Samuel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!