You try to add a column, create an index or truncate a table, and Oracle refuses immediately:
ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired
You didn't specify NOWAIT. So why does it give up right away, and who is holding the table?
Why DDL fails instead of waiting
Most DDL (ALTER TABLE, CREATE INDEX, TRUNCATE, DROP) needs an exclusive DDL lock on the table. Any session with an uncommitted DML transaction on that table holds a table lock (TM) that conflicts with it.
By default, DDL doesn't queue: if the lock isn't free, it fails at once with ORA-00054. This protects the application: a DDL statement waiting in the queue would block every new DML behind it.
The usual blockers:
- an application session that updated rows and hasn't committed (a long transaction, or a connection-pool bug);
- a developer's SQL Developer or Toad session with uncommitted changes;
- a long-running batch job.
Find the blocking session
SELECT lo.session_id AS sid, s.serial#, s.username, s.osuser, s.machine, s.program,
s.status, s.last_call_et AS seconds_in_state, o.owner, o.object_name
FROM v$locked_object lo
JOIN dba_objects o ON o.object_id = lo.object_id
JOIN v$session s ON s.sid = lo.session_id
WHERE o.object_name = 'ORDERS';
status = INACTIVE with a large last_call_et means someone modified rows and walked away without committing.
Option 1: let the DDL wait a little
Since Oracle 11g, you can have DDL wait for the lock instead of failing:
