ORA-04021: timeout waiting to lock object
A session waited too long for a library cache lock on an object, typically while recompiling a package or altering a table that other sessions are using.
- Error code
ORA-04021- Category
- Transactions and locking
What it means
ORA-04021 means a session couldn't get a library cache lock or pin on an object within the timeout. It is common when compiling or replacing a PL/SQL package, procedure or view while other sessions are running it.
Common causes
CREATE OR REPLACEorALTER ... COMPILEon a package that other sessions are executing.- DDL on a table while long-running statements are using it.
How to fix it
-
Find who is using the object.
SELECT sid, serial#, username, program FROM v$session WHERE sid IN (SELECT sid FROM v$access WHERE object = 'BILLING_PKG');
-
Deploy the change when the object is idle, or ask the sessions using it to finish first.
-
For zero-downtime PL/SQL changes, look at edition-based redefinition.
Related errors
ORA-00054resource busy and acquire with NOWAIT specifiedORA-04068existing state of packages has been discarded
More transactions and locking errors
ORA-00060deadlock detected while waiting for resourceORA-08177can't serialize access for this transaction
The code and message text are from the Oracle Database Error Help. Browse the full Oracle error list or search every database error.
Work on Oracle in SQLly
A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for Oracle and the other databases you use.