DeadLock

http://blog.sina.com.cn/s/blog_5384afff0100rtcg.html


DeadLock


Step 1
create table t1 and t2
create table t1 (a int);
create table t2 (a int);


Step 2
insert values
insert into t1 values (1);
insert into t2 values (2);


Step 3
update t1 and t2 value as 1000 and 2000 and not commit in first session and second session
session1
update t1 set a = 1000 where a = 1;   (not commit)


session2
update t2 set a = 2000 where a = 2;   (not commit)


Step 4
to session 1 update table t2 same value,then find lock_wait(because session 2 has been execute the action,the line
has been locked !!)
session1
update t2 set a = 2000 where a = 2; 


Solution:
First Check 
sys@ORCL>@lock.sql


lock                      lock
holder                  holder            lock                                lock   request               blocked
username            session id    SERIAL# type           id1         id2      mode      mode      BLOCK session id
------------------ ----------- ---------- ------ ----------- ----------- --------- --------- ---------- ----------
USER1                        6          7 AE             100           0         4         0          0
USER1                      123         51 AE             100           0         4         0          0
USER1                      123         51 TM           86646           0         3         0          0
USER1                      123         51 TM           86645           0         3         0          0
USER1                      123         51 TX          589831        1179         6         0          0
USER1                      364         53 AE             100           0         4         0          0
USER1                      365         47 AE             100           0         4         0          0
USER1                      365         47 TM           86646           0         3         0          0
USER1                      365         47 TX           65547        1183         6         0          1        123
SYS                        124        319 AE             100           0         4         0          0
                             3          1 CF               0           0         2         0          0
                             3          1 RD               1           0         1         0          0
                             3          1 RS              25           1         2         0          0
                             3          1 XR               4           0         1         0          0
                           121          1 TS               3           1         3         0          0
                           121          1 TS               8           1         3         0          0
                           239          1 PW               1           0         3         0          0
                           357          1 KD               0           0         6         0          0
                           357          1 KT           12876           0         4         0          0
                           358          1 RT               1           0         6         0          0
                           359          1 AE             100           0         4         0          0


已选择21行。


sys@ORCL>


througth the output,we can find the lock wait session is 123.


then we check v$session
sys@ORCL>select sid,serial#,TERMINAL,PROGRAM from v$session where TERMINAL <> 'UNKNOWN';


       SID    SERIAL# TERMINAL                       PROGRAM
---------- ---------- ------------------------------ ------------------------------------------------
         6          7 0101—PC                 plsqldev.exe
       123         51 pts/2                   sqlplus@0001.com (TNS V1-V3)
       124        319 pts/4                   sqlplus@0001.com (TNS V1-V3)
       364         53 0101—PC                 plsqldev.exe
       365         47 0101—PC                 plsqldev.exe


sys@ORCL>


finaly:
alter system kill session '123,51';


the lock wait session 2 has been killed:
USER1@ORCL>update t2 set a = 2000 where a = 2;
ERROR:
ORA-03114: 未连接到 ORACLE




update t2 set a = 2000 where a = 2
       *
第 1 行出现错误:
ORA-00028: your session has been killed
ORA-00028: your session has been killed




USER1@ORCL>








@lock.sql


set pages 1000 lin 126
col kaddr heading 'lock|address'
col username heading 'lock|holder|username' for a18
col sid heading 'lock|holder|session id' format 9999999999
col type heading 'lock|type' format a6
col id1 heading 'id1' format 9999999999
col id2 heading 'id2' format 9999999999
col lmode heading 'lock|mode' format 99999999
col request heading 'request|mode' format 99999999
col blocking_sid format 999999 heading 'blocked|session id'
select /*+rule*/
--     a.kaddr, --
     (select username from v$session where sid = a.sid) username,
     a.sid,
     (select serial# from v$session where sid = a.sid) serial#,
--     (select ctime from v$lock where KADDR = a.kaddr) ctime, --
     a.type,
     a.id1,
     a.id2,
     a.lmode,
     a.request,
     a.block,
     b.sid blocking_sid
from v$lock a,
     ( select * from v$lock
       where request > 0
       and type <> 'MR'
     ) b
where a.id1 = b.id1(+) 
  and a.id2 = b.id2(+)
  and a.lmode > 0 
  and a.type <> 'MR' 
order by username,a.sid,serial#,a.type
/


column sid clear
column type clear
column request clear
column username clear




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值