单一会话引发的死锁

客户环境中出现了ORA-60死锁错误,检查日志发现,持有锁和等待锁的是同一个会话。

 

 

一般来说构成死锁至少需要两个会话,而当前的问题是一个会话引发的:

Wed Nov 23 10:19:46 2011
ORA-00060: Deadlock detected. More info in file /oracle/admin/db1/udump/db1_ora_3408686.trc.

对应的详细信息:

*** 2011-10-29 10:11:28.970
*** SERVICE NAME:(db1) 2011-10-29 10:11:28.960
*** SESSION ID:(5562.45) 2011-10-29 10:11:28.960
DEADLOCK DETECTED ( ORA-00060 )
[Transaction Deadlock]
The following deadlock is not an ORACLE error. It is a
deadlock due to user error in the design of an application
or from issuing incorrect ad-hoc SQL. The following
information may aid in determining the deadlock:
Deadlock graph:
                       ---------Blocker(s)--------  ---------Waiter(s)---------
Resource Name          process session holds waits  process session holds waits
TX-000c0016-000499ad        16    5562     X             16    5562           X
session 5562: DID 0001-0010-00000092 session 5562: DID 0001-0010-00000092
Rows waited on:
Session 5562: obj - rowid = 00009050 - AAAJBQAAWAAArQ6AAG
  (dictionary objn - 36944, file - 22, block - 177210, slot - 6)
Information on the OTHER waiting sessions:
End of information on OTHER waiting sessions.

可以看到,等待的和持有锁的是同一个会话。

根据trace信息记录的对象,发现问题是自治事务导致的。

在主事务中如果更新了部分记录,这是启动自治事务更新同样的记录,就会造成死锁,下面通过一个简单的例子模拟了这个错误的产生:

SQL> create table t (id number, name varchar2(30));

Table created.

SQL> insert into t select rownum, tname from tab;

4 rows created.

SQL> commit;

Commit complete.

SQL> create or replace procedure p_test as
2 pragma autonomous_transaction;
3 begin
4 update t set name = name where id = 1;
5 commit;
6 end;
7 /

Procedure created.

SQL> begin
2 update t set name = name where id = 1;
3 p_test;
4 end;
5 /

begin
*
ERROR at line 1:
ORA-00060: deadlock detected while waiting for resource
ORA-06512: at "TEST.P_TEST", line 4
ORA-06512: at line 3

在使用自治事务的时候要避免当前事务锁定的记录和自治事务中锁定的记录相互冲突。

 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/4227/viewspace-711881/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/4227/viewspace-711881/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值