ORA-04021: 等待对象锁超时

17390阅读 0评论2013-01-18 iniestandroid
分类:Oracle

    中午一开发说更新了一个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.


上一篇:OGG目标端REPLICAT进程执行缓慢的一次优化
下一篇:Materialize View 的 GoldenGate 同步测试