oracle deadlock itself

遇到一个奇怪的死锁报错,死锁的blockers和waiters都是同一个会话

 

在网上搜资料时发现有三种情况会导致deadlock itself

http://www.dba-oracle.com/t_session_deadlock_itself.htm

 

在官方文档查询相关资料,找到文档

ORA-00060 Single-Resource Deadlock Occurs on Autonomous Transaction (文档 ID 1511700.1)

Autonomous Transaction can cause locking (文档 ID 224305.1)

其中有该报错的复现方法(见下文)

 

报错的原因为:

The deadlock occurs because the MAIN and LOCAL procedures are trying to modify
the same records
. Since the LOCAL procedure is autonomous, it cannot see that
the MAIN procedure has acquired a lock on the row it is trying to access. The
MAIN procedure also cannot see that the LOCAL procedure has acquired a lock on
the row it needs.

 

解决方法:改代码。。。

 

如何复现该报错

 

Example of Autonomous Deadlock

 -- Login to scott/tiger , create table and populate --

sqlplus scott/tiger

CREATE TABLE test_emp AS SELECT * FROM emp;

INSERT INTO test_emp

VALUES      (9999,

             'SCOTT',

             99,

             99,

             SYSDATE,

             10000,

             0,

             10);

COMMIT;

 

-- Create Procedure using autonomous transaction --

CREATE OR replace PROCEDURE Proc_a

AS

  PRAGMA autonomous_transaction;

BEGIN

    UPDATE test_emp

    SET    sal = sal + 5000

    WHERE  empno = 9999;

    COMMIT;

END;

/

 

-- Create Main Procedure --

CREATE OR REPLACE PROCEDURE Main_p

AS

BEGIN

    UPDATE test_emp

    SET    comm = 5000

    WHERE  empno = 9999;

    proc_a;

    COMMIT;

END;

/

 

-- Call Main Procedure --

SQL> exec main_p

BEGIN main_p; END;

 

*

ERROR at line 1:

ORA-00060: deadlock detected while waiting for resource

ORA-06512: at "SCOTT.PROC_A", line 5

ORA-06512: at "SCOTT.MAIN_P", line 4

ORA-06512: at line 1

 

从trace file可以看到

 

With an autonomous transaction, there is only one session involved and the deadlock graph contains only one row where both blocker and waiter are the same session as shown in the following example:

As well as the deadlock graph, the trace file contains PROCESS STATE information. The information below shows different sections of the trace file that may be of interest:

 

关于自治事务

 

自治事务与死锁

 

https://blog.csdn.net/pan_tian/article/details/7675800

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Hehuyi_In

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值