Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I understand that DDL statements in Oracle have an implicit commit before and after the statement, which obviously affects the current transaction.

However, does a DDL statement in any way affect other transactions running against that table (assuming the change is compatible with the DML running against the table)?

For example, if I decide to modify a varchar2(10) columnn to varchar2(20), or add a new column altogether, or drop an obsolete, no longer used column -- are other transactions going to be happy about it, or is there going to be any sort of contention or interruption of running transactions?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

This article explains how DDL statements work and how they need exclusive table locks, which plays out nicely when there are transactions running against the table. To summarize:

If the table cannot be locked due to another transaction having a lock on the table

ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired

would be thrown. If the DDL manages to acquire the lock, obviously, any other transaction will block at the point where it needs a lock on the table, until the DDL finishes.

Additionally, since 11g, it is possible to enqueue DDL statements in FIFO order with other statements to get a lock on a table:

declare
begin
      -- We really want to drop that column and so wait for 1800 seconds.
      execute immediate 'alter session set ddl_lock_timeout=1800';
      execute immediate 'alter table t1 drop column n5 ';
exception
  when others then
     dbms_output.put_line(' No luck ');
     dbms_output.put_line(' SQL code'||sqlcode||','|| 'error '||sqlerrm );
end;
/

In older versions of Oracle, it could be a challenge to perform this task on a heavily used table.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.