--?死鎖查詢語句
為鎮(zhèn)坪等地區(qū)用戶提供了全套網(wǎng)頁設(shè)計制作服務(wù),及鎮(zhèn)坪網(wǎng)站建設(shè)行業(yè)解決方案。主營業(yè)務(wù)為網(wǎng)站設(shè)計制作、成都網(wǎng)站設(shè)計、鎮(zhèn)坪網(wǎng)站設(shè)計,以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會得到認(rèn)可,從而選擇與我們長期合作。這樣,我們也可以走得更遠(yuǎn)!
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;
查詢發(fā)生死鎖的select語句
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)
)
-- 死鎖查詢語句
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;
查詢發(fā)生死鎖的select語句
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)
)
在對指定表做append操作,其他再做truncate時候,會產(chǎn)生鎖表,如下驗證步驟,
1、創(chuàng)建測試表,
create table test_lock(id number, value varchar2(200));
2、執(zhí)行append語句;并且不做提交,insert /*+append*/ into test_lock values(1,1);
3、再次執(zhí)行清表語句,truncate table test_lock;報鎖表錯誤,
4、查看鎖表語句,發(fā)現(xiàn)被鎖表,
select b.object_name, t.*
from v$locked_object t, user_objects b
where t.object_id = b.object_id