DBAtlas · Database operations atlas

ORA-04021: timeout occurred while waiting to lock object

Oracle

What does it mean?

A timeout occurred while waiting to acquire a library cache lock/pin on an object (package, procedure, type, etc.). Usually occurs when trying to compile or alter a PL/SQL object while it is being executed or locked by another session.

Why does it happen?

The object to be altered/compiled is actively executing in another session or is locked by another DDL, so the exclusive library cache lock cannot be acquired. A long-running procedure call or a hung session may be holding the lock.

How to fix it

Find the session locking the object: SELECT * FROM dba_kgllock WHERE kgllkhdl IN (SELECT p1raw FROM v$session WHERE event LIKE 'library cache%'); or identify the session using the object with v$access and v$session. Retry the DDL/compile in a maintenance window with low workload. If needed, terminate the session safely. Briefly stopping the application makes acquiring the lock easier.

Open in DBAtlas →

More from this engine