Share Table Locks (S)死锁情况模拟

在看lock文档Share Table Locks (S)部分的时候看到这样一段话:

Caution:

Your transaction may or may not update the table later in the same transaction. However, if multiple transactions concurrently hold share table locks for the same table, no transaction can update the table (even if row locks are held as the result of a SELECT... FOR UPDATE statement). Therefore, if concurrent share table locks on the same table are common, updates cannot proceed and deadlocks are common. In this case, use share row exclusive or exclusive table locks instead.

即如果使用lock table t in share mode;对table进行锁定的情况下,如果在进行update的话很容易产生deadlock的情况,模拟如下:

第一步-session1
SQL> lock table t in share mode;

表已锁定。

第二步-session2
SQL> lock table t in share mode;

表已锁定。

第三步-session1
SQL>  update t set id=3 where id=1;
结果session1被hang住。

第四步-session2
SQL>  update t set id=3 where id=1;
结果session2也被hang住。

但是过了一会,session1出现提示:
SQL>  update t set id=3 where id=1;
 update t set id=3 where id=1
*
第 1 行出现错误:
ORA-00060: 等待资源时检测到死锁

并自动跳出update语句。此时只要在session1进行commit则session2就不会被hang住了。

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

转载于:http://blog.itpub.net/21805468/viewspace-620347/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值