查詢堵塞程式的幾種SQL--
逛論壇看到一篇關於blocking session的帖子 歸納一下幾種查詢
①
with vw_lock AS (SELECT * FROM v$lock)
select
a.sid,
'is blocking',
(select 'sid:'||s.sid||' object:'||do.object_name||' rowid:'||
dbms_rowid.rowid_create ( 1, ROW_WAIT_OBJ#, ROW_WAIT_FILE#, ROW_WAIT_BLOCK#, ROW_WAIT_ROW# )
||' sql_id:'||s.sql_id
from v$session s, dba_objects do
where s.sid=b.sid
and s.ROW_WAIT_OBJ# = do.OBJECT_ID
) blockee,
b.sid,b.id1,b.id2
from vw_lock a, vw_lock b
where a.block = 1
and b.request > 0
and a.id1 = b.id1
and a.id2 = b.id2;
②SELECT /*+ ORDERED USE_HASH(H,R) */
H.SID HOLD_SID,
R.SID WAIT_SID,
decode(H.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',
'TC', 'Thread Checkpoint',
'SS', 'Sort Segment',
'JQ', 'Job Queue',
'PI', 'Parallel operation',
'PS', 'Parallel operation',
'DL', 'Direct Index Creation',
H.type) type,
decode(H.lmode,
0, 'None', 1, 'Null',
2, 'Row-S (SS)', 3, 'Row-X (SX)',
4, 'Share', 5, 'S/Row-X (SSX)',
6, 'Exclusive', to_char(H.lmode)) hold,
decode(r.request, 0, 'None',
1, 'Null', 2, 'Row-S (SS)',
3, 'Row-X (SX)', 4, 'Share',
5, 'S/Row-X (SSX)',6, 'Exclusive',
to_char(R.request)) request,
R.ID1,R.ID2,R.CTIME
FROM V$LOCK H,V$LOCK R
WHERE H.BLOCK = 1 AND R.REQUEST > 0 AND H.SID <> R.SID
and H.TYPE <> 'MR' AND R.TYPE <> 'MR'
AND H.ID1 = R.ID1 AND H.ID2 = R.ID2 AND H.TYPE=R.TYPE
AND H.LMODE > 0 AND R.REQUEST > 0 ORDER BY 1,2;
③
④
①
with vw_lock AS (SELECT * FROM v$lock)
select
a.sid,
'is blocking',
(select 'sid:'||s.sid||' object:'||do.object_name||' rowid:'||
dbms_rowid.rowid_create ( 1, ROW_WAIT_OBJ#, ROW_WAIT_FILE#, ROW_WAIT_BLOCK#, ROW_WAIT_ROW# )
||' sql_id:'||s.sql_id
from v$session s, dba_objects do
where s.sid=b.sid
and s.ROW_WAIT_OBJ# = do.OBJECT_ID
) blockee,
b.sid,b.id1,b.id2
from vw_lock a, vw_lock b
where a.block = 1
and b.request > 0
and a.id1 = b.id1
and a.id2 = b.id2;
②SELECT /*+ ORDERED USE_HASH(H,R) */
H.SID HOLD_SID,
R.SID WAIT_SID,
decode(H.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',
'TC', 'Thread Checkpoint',
'SS', 'Sort Segment',
'JQ', 'Job Queue',
'PI', 'Parallel operation',
'PS', 'Parallel operation',
'DL', 'Direct Index Creation',
H.type) type,
decode(H.lmode,
0, 'None', 1, 'Null',
2, 'Row-S (SS)', 3, 'Row-X (SX)',
4, 'Share', 5, 'S/Row-X (SSX)',
6, 'Exclusive', to_char(H.lmode)) hold,
decode(r.request, 0, 'None',
1, 'Null', 2, 'Row-S (SS)',
3, 'Row-X (SX)', 4, 'Share',
5, 'S/Row-X (SSX)',6, 'Exclusive',
to_char(R.request)) request,
R.ID1,R.ID2,R.CTIME
FROM V$LOCK H,V$LOCK R
WHERE H.BLOCK = 1 AND R.REQUEST > 0 AND H.SID <> R.SID
and H.TYPE <> 'MR' AND R.TYPE <> 'MR'
AND H.ID1 = R.ID1 AND H.ID2 = R.ID2 AND H.TYPE=R.TYPE
AND H.LMODE > 0 AND R.REQUEST > 0 ORDER BY 1,2;
③
select /*+ rule */ l.block blk_status, l.inst_id, l.sid, /* s.serial#, */ p.spid, s.status, s.sql_hash_value hash_value, s.program, s.username, s.last_call_et, /* s.sql_id,s.sql_child_number c_n,*/ l.lmode, l.type, l.request, l.ctime from (select inst_id, sid, type, id1, id2, lmode, request, ctime, decode(block, 0, 'blocked', 1, 'blocking', 2, 'global') block from gv$lock where (id1, id2, type) in (select id1, id2, type from gv$lock where request > 0)) l, gv$session s, gv$process p where l.sid = s.sid and l.inst_id = s.inst_id and s.inst_id = p.inst_id and s.paddr = p.addr and s.username is not null order by 1, inst_id, status; |
④
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26526320/viewspace-2121361/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- SQL--查詢SQL
- SQL--子查詢SQL
- JAVA - mongodb 聚合幾種查詢方式JavaMongoDB
- Nhibernate 對view 查詢的幾種方法View
- mysql資料庫連表查詢的幾種方法MySql資料庫
- Linux下查詢漏洞的幾種必備工具Linux
- Percona-Xtrabackup 2.3.3 慢查詢不再堵塞備份(二)
- MySQL中幾種資料統計查詢的基本使用教程MySql
- [翻譯]查詢Windows記憶體洩露的幾種方法Windows記憶體洩露
- 轉載 ]查詢Windows記憶體洩露的幾種方法Windows記憶體洩露
- pandas 的幾個查詢方法
- 通過 v$sqlarea 查詢disk read嚴重(I/O)的SQL-- Oracle效能檢視SQLOracle
- 各種免費好用的api,含天氣查詢、IP查詢、物流查詢等API
- Percona-Xtrabackup 2.3.3 慢查詢依舊堵塞MariaDB備份(三)
- 教你幾招HASH表查詢的方法
- 【轉】有關dataguard的幾個查詢
- 幾個查詢系統資訊的命令!
- hibernate的三種查詢方式
- SSH綜合查詢的兩種方式
- 幾個SQL查詢小技巧SQL
- 程式查詢
- 並查集(一)並查集的幾種實現並查集
- Hibernate通常是三種:hql查詢,QBC查詢和QBE查詢:
- Mybatis各種模糊查詢MyBatis
- 幾個定位、查詢session的sql語句SessionSQL
- 無堵塞的併發程式設計程式設計
- pgrep 查詢程式的工具
- 提高mysql查詢效率的六種方法MySql
- oracle 查詢結果的各種格式Oracle
- spring和Mybatis的各種查詢SpringMyBatis
- 程式碼迭代的幾種方式
- 幾種常用的排序程式碼排序
- mongodb如何查詢最後幾項?MongoDB
- MySQL:FLTWL的堵塞和被堵塞總結MySql
- 轉:C++實現的變種二分查詢法(折半查詢)--二叉查詢樹C++
- 二分查詢 | 二分查詢的一種推薦寫法
- Nginx 做負載均衡的幾種輪詢策略Nginx負載
- Find命令查詢最近幾天修改的檔案