// Oracle error reference

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
Error message
timeout occurred while waiting to lock object string string string string string

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 REPLACE or ALTER ... COMPILE on a package that other sessions are executing.
  • DDL on a table while long-running statements are using it.

How to fix it

  1. 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');
  2. Deploy the change when the object is idle, or ask the sessions using it to finish first.

  3. For zero-downtime PL/SQL changes, look at edition-based redefinition.

Related errors

More transactions and locking errors

The code and message text are from the Oracle Database Error Help. Browse the full Oracle error list or search every database error.

// fewer errors, faster fixes

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.