在看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/