我刚得到ORA-00060: deadlock detected while waiting for resource。
我有一个在行中锁定特定列的查询,我想知道oracle如何设置查询匹配的行的锁?它是原子的还是不原子的?
例如,我有带有id和value列的表,并有以下查询:
select id, value from tbl where id > 1 and id < 100 for update of value有几个客户端执行此查询。在这种情况下有可能陷入僵局吗?
发布于 2013-09-04 11:10:14
在这种情况下有可能出现死锁吗?
当两个或多个会话试图获取彼此锁定的资源的独占锁时,这是可能的。
下面是一个简单的演示:
create table Deadlock1(col number);
create table DeadLock2(col number);
insert into DeadLock1(col) values(1);
insert into DeadLock2(col) values(1);会议#1
select *
from deadlock1
where col = 1
for update of col会议#2
select *
from deadlock2
where col = 1
for update of col会议#1
select *
from deadlock2
where col = 1
for update of col会议#2
select *
from deadlock1
where col = 1
for update of col如果会话#1中没有发出提交或回滚,则尝试获取会话#2中的锁定将导致ORA-00060: deadlock detected while waiting for resource。
在您的例子中,当session#1正在执行您的查询并且没有commit或rollback时,会话#2将被简单地阻塞。不会有死锁。所以一定是别的什么东西导致了僵局。
每次发生死锁时,Oracle都会创建一个跟踪文件,并将新创建的跟踪文件的名称和路径放置在alert.log文件中。因此,您需要检查创建的跟踪(*.trc)文件的内容,以确定相互阻塞的会话:
*** SESSION ID:(362.24645) 2013-09-04 14:46:05.297
*** CLIENT ID:() 2013-09-04 14:46:05.297
*** SERVICE NAME:(nkrasnov) 2013-09-04 14:46:05.297
*** MODULE NAME:(PL/SQL Developer) 2013-09-04 14:46:05.297
*** CONTAINER ID:(3) 2013-09-04 14:46:05.297
Deadlock graph:
---------Blocker(s)-------- ---------Waiter(s)---------
Resource Name process session holds waits process session holds waits
TX-000B0007-00002730-00000000-00000000 138 362 X 142 441 X
TX-00050011-00000A51-00000000-00000000 142 441 X 138 362 X
session 362: DID 0001-008A-00003BE6 session 441: DID 0001-008E-0000C55F
session 441: DID 0001-008E-0000C55F session 362: DID 0001-008A-00003BE6 考虑使用nowait或从for update子句的11g skip locked选项开始。
https://stackoverflow.com/questions/18610739
复制相似问题