下面查詢可以查到死鎖,但是注意其實查詢到的不是真正的死鎖,查詢到的只是是死鎖發(fā)生前的等待條件,真正的死鎖在10G中會被系統(tǒng)所阻止掉
成都創(chuàng)新互聯公司是一家集網站建設,東陽企業(yè)網站建設,東陽品牌網站建設,網站定制,東陽網站建設報價,網絡營銷,網絡優(yōu)化,東陽網站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強企業(yè)競爭力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯網需求。同時我們時刻保持專業(yè)、時尚、前沿,時刻以成就客戶成長自我,堅持不斷學習、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實用型網站。
select t2.username||' '||t2.sid||' '||t2.serial#||' '||t2.logon_time||' '||t3.sql_text
from v$locked_object t1,v$session t2,v$sqltext t3
where t1.session_id=t2.sid
and t2.sql_address=t3.address
order by t2.logon_time ;
此外,從V$LOCK的BLOCK字段可以看到,BLOCK0表示有等待發(fā)生了,注意是行級等待,而在表級沒有死鎖或等待
select * from v$lock where block0 ;
--?死鎖查詢語句
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)
)
1.可能在Oracle中可以有計時器,在頻繁操作數據庫,update,insert,delete語句,在jobs中能查看到(如圖)
2.可能在.net程序中使用到timer控件,頻繁的操作數據庫update,insert,delete語句(如圖)
3.可能在.net程序中使用到Thead(線程)頻繁的操作數據庫update,insert,delete語句(這個條為個人觀點,還未得到證實)
【注釋】:此處更新數據量都比較大,比如說update的數據庫條數可能在1000條以上,
導致其他操作在等待(update跟其他操作都是同一張表)
4.可能使用到事務處理(Tran),沒有提交事務(CommintTran)或者沒有回滾事務(Rollback)
【注釋】:在SqlServer數據庫里面有一個隱式事務,關閉時候,每次修改插入都需要手動提交,不然就會導致死鎖
當前標題:php在類中鏈接數據庫,php與數據庫連接
文章鏈接:http://jinyejixie.com/article10/hsdsdo.html
成都網站建設公司_創(chuàng)新互聯,為您提供App設計、商城網站、搜索引擎優(yōu)化、建站公司、企業(yè)建站、網站內鏈
聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯