yangtingkun
===========================================================
单一会话引发的死锁
===========================================================

客户环境中出现了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

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

yangtingkun 发表于:2011.11.23 23:28 ::分类: ( ORACLE ) ::阅读:(502次) :: 评论 (0)

发表评论
标题

在此添加评论
表情符号: smile laughing tongue angry crying sad wassat wink

称呼

邮箱地址(可选)

个人主页(可选)

 authimage


切换风格
新闻聚合
博客日历
文章归档...
最新发表...
最新评论...
最多阅读文章...
最多评论文章...
博客统计...
Blog信息
网站链接...