ITPub博客

首页 > Linux操作系统 > Linux操作系统 > Share Table Locks (S)死锁情况模拟

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

原创 Linux操作系统 作者:norows 时间:2009-11-23 22:03:13 0 删除 编辑

在看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博客 ” ,链接:https://blog.itpub.net/21805468/viewspace-620347/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: SQL语言艺术30则
下一篇: lock学习摘要
请登录后发表评论 登录
全部评论

注册时间:2009-06-03

  • 博文量
    31
  • 访问量
    88208