ORA-00054: Resource Busy and Acquire with NOWAIT Specified – Complete Oracle Fix Guide
The ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired error is a common Oracle Database locking issue that occurs when a session attempts to access an object currently locked by another session.
This error is frequently encountered during DDL operations such as ALTER, DROP, TRUNCATE, or during maintenance activities when another user or process is actively using the object.
In this complete guide, you will learn:
- What ORA-00054 means
- Why the error occurs
- How Oracle locking works
- How to identify blocking sessions
- Step-by-step solutions
- Real-world DBA troubleshooting examples
- Best practices to avoid locking issues
What is ORA-00054 Error?
The ORA-00054 error occurs when Oracle cannot obtain the required lock on a database object because another session is already using it.
This commonly happens when:
- A table is being modified by another session
- A transaction is still open
- A DDL operation is attempted on an active object
- The NOWAIT clause prevents waiting for lock release
Error Message
ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired
Quick Solution
Quick Fix: Identify the blocking session, wait for the transaction to complete, or terminate the locking session if appropriate.
How Oracle Locking Works
Oracle Database uses locks to maintain data consistency and prevent conflicts between multiple users.
There are two main types of locks:
- DML Locks: Used during INSERT, UPDATE, DELETE operations
- DDL Locks: Used during ALTER, DROP, TRUNCATE operations
When a session locks an object, another session may be unable to perform conflicting operations until the lock is released.
Common Causes of ORA-00054
- Another session is using the table
- Uncommitted transactions
- Long-running queries
- DDL operation attempted during active usage
- NOWAIT clause specified
- Application sessions holding locks
- Background jobs accessing the same object
Common Situations Where ORA-00054 Appears
1. Altering a Busy Table
ALTER TABLE employees ADD salary NUMBER;
If another user is modifying the EMPLOYEES table, Oracle may return ORA-00054.
2. Dropping a Table in Use
DROP TABLE employees;
3. Truncating Active Tables
TRUNCATE TABLE employees;
Step-by-Step Solutions
1. Identify Blocking Sessions
Use the following query to identify sessions holding locks:
SELECT
s.sid,
s.serial#,
s.username,
s.status,
s.machine,
s.program
FROM v$session s
WHERE s.sid IN (
SELECT blocking_session
FROM v$session
WHERE blocking_session IS NOT NULL
);
This query helps locate the blocking user and session details.
2. Identify Locked Objects
SELECT
lo.session_id,
do.object_name,
lo.locked_mode
FROM v$locked_object lo
JOIN dba_objects do
ON lo.object_id = do.object_id;
This displays which database objects are currently locked.
3. Wait for Transaction Completion
In many cases, the safest solution is simply to wait until the current transaction completes.
Once the lock is released, retry the operation.
4. Kill Blocking Session (Use Carefully)
If the blocking session is inactive or causing major issues, terminate it.
ALTER SYSTEM KILL SESSION 'sid,serial#';
Example:
ALTER SYSTEM KILL SESSION '145,2201';
Warning: Only kill sessions after verifying business impact.
5. Commit or Rollback Transactions
Developers sometimes forget to commit transactions.
Commit changes to release locks:
COMMIT;
Or rollback if necessary:
ROLLBACK;
6. Use DDL_LOCK_TIMEOUT Parameter
Instead of failing immediately, Oracle can wait for locks to be released.
ALTER SESSION SET ddl_lock_timeout = 60;
This instructs Oracle to wait 60 seconds before returning ORA-00054.
7. Retry the Operation
After resolving locks, retry the command.
ALTER TABLE employees ADD salary NUMBER;
Real-World Scenario
A DBA attempted to add a column to a production table during office hours:
ALTER TABLE orders ADD order_status VARCHAR2(20);
The operation failed with ORA-00054 because application users were actively updating the ORDERS table.
The DBA identified the blocking sessions using V$SESSION and scheduled the maintenance during off-peak hours.
After user activity reduced, the operation completed successfully.
Using NOWAIT Clause
The NOWAIT clause instructs Oracle not to wait for locks.
Example:
LOCK TABLE employees IN EXCLUSIVE MODE NOWAIT;
If another session already holds a lock, Oracle immediately returns ORA-00054.
Difference Between WAIT and NOWAIT
| Option | Behavior |
|---|---|
| NOWAIT | Fails immediately if locked |
| WAIT | Waits until lock released |
Best Practices to Prevent ORA-00054
- Schedule maintenance during low activity periods
- Keep transactions short
- Commit frequently
- Monitor locking sessions regularly
- Avoid unnecessary table locks
- Use DDL_LOCK_TIMEOUT wisely
- Coordinate maintenance with application teams
Common Mistakes
- Killing active production sessions without analysis
- Running DDL during peak hours
- Ignoring uncommitted transactions
- Using NOWAIT unnecessarily
Image: ORA-00054 Locking Example
| ORA-00054: resource busy |
Frequently Asked Questions
What causes ORA-00054?
The error occurs when another session already holds a lock on the requested database object.
How do I fix ORA-00054?
Identify the blocking session, wait for lock release, or terminate the blocking session if appropriate.
How do I identify locking sessions?
SELECT blocking_session FROM v$session;
Can I avoid ORA-00054?
Yes, by scheduling maintenance during low activity periods and keeping transactions short.
Related Posts
- ORA-01555 Snapshot Too Old – Solution
- ORA-12514 Listener Error – Fix
- ORA-01017 Invalid Username Password
- ORA-00001 Unique Constraint Violated
👉 Check our complete guide: Oracle Error Codes Guide
Conclusion
The ORA-00054 error is a common Oracle locking issue that occurs when database objects are busy or locked by other sessions.
Understanding Oracle locking mechanisms, identifying blocking sessions, and properly managing transactions are essential skills for every DBA.
By following the troubleshooting methods and best practices explained in this guide, you can efficiently resolve ORA-00054 errors and maintain stable database operations.
No comments:
Post a Comment