ORA-04021: 等待物件鎖超時

perfychi發表於2014-05-27
ORA-04021: 等待物件鎖超時 

   中午一開發說更新了一個package body裡幾個procedure之後編譯一直不成功,PL/SQL Developer無響應不報錯,沒碰到過這種問題,看了alert也沒有發現異常,檢查了程式碼沒有問題,猜測是不是有可能procedure中涉及到的物件被鎖從而導致編譯不成功,查詢v$lock沒有看到blocker,然後編譯的那個會話就報錯了

ORA-04021: timeout occurred while waiting to lock object


[oracle@ASM ~]$ oerr ora 04021
04021, 00000, "timeout occurred while waiting to lock object %s%s%s%s%s"
// *Cause:  While waiting to lock a library object, a timeout occurred.
// *Action: Retry the operation later.


    google了一把,一般ORA-04021是因為這個包正在被其他會話呼叫,編譯時申請不到library lock導致的,透過dba_ddl_lock 找到呼叫這個包的會話kill之後據能夠正常編譯,按照這個方法問題得到解決。


下面把這個錯誤重現了一下:

SCOTT@ora11g> create or replace procedure p1 as 
  2  begin
  3  while true loop
  4  null;
  5  end loop;
  6  end;
  7  /


Procedure created.

SYS@ora11g> alter procedure scott.p1 compile;


Procedure altered.

SCOTT@ora11g> exec p1


SYS@ora11g> alter procedure scott.p1 compile;
alter procedure scott.p1 compile
*
ERROR at line 1:
ORA-04021: timeout occurred while waiting to lock object

SYS@ora11g> select * from dba_ddl_locks where name='P1';


SESSION_ID OWNER NAME  TYPE                                     MODE_HELD MODE_REQU
---------- ----- ----- ---------------------------------------- --------- ---------
        21 SCOTT P1    Table/Procedure/Type                     Null      None

SYS@ora11g> select sid,serial# from v$session where sid=21;


       SID    SERIAL#
---------- ----------
        21        149

SYS@ora11g> alter system kill session '21,149';


System altered.

SCOTT@ora11g> exec p1
BEGIN p1; END;


*
ERROR at line 1:
ORA-00028: your session has been killed
ORA-00028: your session has been killed


SCOTT@ora11g> 

SYS@ora11g> alter procedure scott.p1 compile;


Procedure altered.

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/27042095/viewspace-1171262/,如需轉載,請註明出處,否則將追究法律責任。

相關文章