如何查询oracle死锁,Oracle死锁查看和解决办法汇总
由于生產(chǎn)的tomcat 經(jīng)常有假死問(wèn)題,困擾很久,最后發(fā)現(xiàn)有死鎖,解決辦法分享
1、查看死鎖
1)用dba用戶執(zhí)行以下語(yǔ)句select username,lockwait,status,machine,program from v$session where sid in
(select session_id from v$locked_object)
如果有輸出的結(jié)果,則說(shuō)明有死鎖,且能看到死鎖的機(jī)器是哪一臺(tái)。字段說(shuō)明:
Username:死鎖語(yǔ)句所用的數(shù)據(jù)庫(kù)用戶;
Lockwait:死鎖的狀態(tài),如果有內(nèi)容表示被死鎖。
Status: 狀態(tài),active表示被死鎖
Machine: 死鎖語(yǔ)句所在的機(jī)器。
Program: 產(chǎn)生死鎖的語(yǔ)句主要來(lái)自哪個(gè)應(yīng)用程序
2)用dba用戶執(zhí)行以下語(yǔ)句,可以查看到被死鎖的語(yǔ)句。select sql_text from v$sql where hash_value in
(select sql_hash_value from v$session where sid in
(select session_id from v$locked_object))
2、死鎖的解決方法
1)查找死鎖的進(jìn)程:SELECT s.username,l.OBJECT_ID,l.SESSION_ID,s.SERIAL#,
l.ORACLE_USERNAME,l.OS_USER_NAME,l.PROCESS
FROM V$LOCKED_OBJECT l,V$SESSION S WHERE l.SESSION_ID=S.SID;
2)kill掉這個(gè)死鎖的進(jìn)程:alter system kill session ‘sid,serial#’; (其中sid=l.session_id)
3)如果還不能解決:select pro.spid from v$session ses,
v$process pro
where
ses.sid=XX
and ses.paddr=pro.addr;
其中sid用死鎖的sid替換:
--ORACLE 就是查表,需要SYSTEM,SYS(有相應(yīng)權(quán)限的用戶)執(zhí)行下面的SQL語(yǔ)句就可以了查看鎖代碼SELECT sn.username,
m.SID,
sn.SERIAL#,
m.TYPE,
DECODE(m.lmode,
0,
'None',
1,
'Null',
2,
'Row Share',
3,
'Row Excl.',
4,
'Share',
5,
'S/Row Excl.',
6,
'Exclusive',
lmode,
LTRIM(TO_CHAR(lmode, '990'))) lmode,
DECODE(m.request,
0,
'None',
1,
'Null',
2,
'Row Share',
3,
'Row Excl.',
4,
'Share',
5,
'S/Row Excl.',
6,
'Exclusive',
request,
LTRIM(TO_CHAR(m.request, '990'))) request,
m.id1,
m.id2
FROM v$session sn, v$lock m
WHERE (sn.SID = m.SID AND m.request != 0) --存在鎖請(qǐng)求,即被阻塞
OR (sn.SID = m.SID --不存在鎖請(qǐng)求,但是鎖定的對(duì)象被其他會(huì)話請(qǐng)求鎖定
AND m.request = 0 AND lmode != 4 AND
(id1, id2) IN (SELECT s.id1, s.id2
FROM v$lock s
WHERE request != 0
AND s.id1 = m.id1
AND s.id2 = m.id2))
ORDER BY id1, id2, m.request;
--解鎖代碼alter system kill session 'sid,SERIAL#';
--查看死鎖信息SELECT bs.username "Blocking User", bs.username "DB User",
ws.username "Waiting User", bs.SID "SID", ws.SID "WSID",
bs.serial# "Serial#", bs.sql_address "address",
bs.sql_hash_value "Sql hash", bs.program "Blocking App",
ws.program "Waiting App", bs.machine "Blocking Machine",
ws.machine "Waiting Machine", bs.osuser "Blocking OS User",
ws.osuser "Waiting OS User", bs.serial# "Serial#",
ws.serial# "WSerial#",
DECODE (wk.TYPE,
'MR', 'Media Recovery',
'RT', 'Redo Thread',
'UN', 'USER Name',
'TX', 'Transaction',
'TM', 'DML',
'UL', 'PL/SQL USER LOCK',
'DX', 'Distributed Xaction',
'CF', 'Control FILE',
'IS', 'Instance State',
'FS', 'FILE SET',
'IR', 'Instance Recovery',
'ST', 'Disk SPACE Transaction',
'TS', 'Temp Segment',
'IV', 'Library Cache Invalidation',
'LS', 'LOG START OR Switch',
'RW', 'ROW Wait',
'SQ', 'Sequence Number',
'TE', 'Extend TABLE',
'TT', 'Temp TABLE',
wk.TYPE
) lock_type,
DECODE (hk.lmode,
0, 'None',
1, 'NULL',
2, 'ROW-S (SS)',
3, 'ROW-X (SX)',
4, 'SHARE',
5, 'S/ROW-X (SSX)',
6, 'EXCLUSIVE',
TO_CHAR (hk.lmode)
) mode_held,
DECODE (wk.request,
0, 'None',
1, 'NULL',
2, 'ROW-S (SS)',
3, 'ROW-X (SX)',
4, 'SHARE',
5, 'S/ROW-X (SSX)',
6, 'EXCLUSIVE',
TO_CHAR (wk.request)
) mode_requested,
TO_CHAR (hk.id1) lock_id1, TO_CHAR (hk.id2) lock_id2,
DECODE
(hk.BLOCK,
0, 'NOT Blocking', /**//* Not blocking any other processes */
1, 'Blocking', /**//* This lock blocks other processes */
2, 'Global', /**//* This lock is global, so we can't tell */
TO_CHAR (hk.BLOCK)
) blocking_others
FROM v$lock hk, v$session bs, v$lock wk, v$session ws
WHERE hk.BLOCK = 1
AND hk.lmode != 0
AND hk.lmode != 1
AND wk.request != 0
AND wk.TYPE(+) = hk.TYPE
AND wk.id1(+) = hk.id1
AND wk.id2(+) = hk.id2
AND hk.SID = bs.SID(+)
AND wk.SID = ws.SID(+)
AND (bs.username IS NOT NULL)
AND (bs.username <> 'SYSTEM')
AND (bs.username <> 'SYS')
ORDER BY 1;
由最代碼官方編輯于2013-12-13 22:58:42
總結(jié)
以上是生活随笔為你收集整理的如何查询oracle死锁,Oracle死锁查看和解决办法汇总的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 中华财险怎么样 了解中华财险的服务质量和
- 下一篇: 女孩说我想请问瓜子整颗吞进去会不会死掉?