Oracle檢視已被使用的open_cursors&session_cached_cursors
檢視當前session已使用的最大open cursor數 和cached cursor數:
SELECT 'session_cached_cursors' PARAMETER,
LPAD (VALUE, 5) VALUE,
DECODE (VALUE, 0, ' n/a', TO_CHAR (100 * USED / VALUE, '990') || '%')
USAGE
FROM (SELECT MAX (S.VALUE) USED
FROM V$STATNAME N, V$SESSTAT S
WHERE N.NAME = 'session cursor cache count'
AND S.STATISTIC# = N.STATISTIC#),
(SELECT VALUE
FROM V$PARAMETER
WHERE NAME = 'session_cached_cursors')
UNION ALL
SELECT 'open_cursors',
LPAD (VALUE, 5),
TO_CHAR (100 * USED / VALUE, '990') || '%'
FROM ( SELECT MAX (SUM (S.VALUE)) USED
FROM V$STATNAME N, V$SESSTAT S
WHERE N.NAME IN ('opened cursors current',
'session cursor cache count')
AND S.STATISTIC# = N.STATISTIC#
GROUP BY S.SID),
(SELECT VALUE
FROM V$PARAMETER
WHERE NAME = 'open_cursors');
注:如果查詢的session open cursor到達100% client就很可能報錯ORA-01000
檢視session open cursor的具體程式、open cursor數量:
SELECT a.inst_id,
a.sid,
a.USERNAME,
a.SCHEMANAME,
a.OSUSER,
a.machine,
a.TERMINAL,
a.LOGON_TIME,
a.PROGRAM,
a.STATUS,
b.name,
b.used
FROM gv$session a,
(SELECT n.inst_id,
sid,
n.name,
s.VALUE used
FROM gv$statname n, gv$sesstat s
WHERE n.name IN ('opened cursors current',
'session cursor cache count')
AND s.statistic# = n.statistic#
AND n.inst_id = s.inst_id) b
WHERE a.sid = b.sid
AND a.inst_id = b.inst_id
AND b.name <> 'session cursor cache count'
ORDER BY b.used DESC;
檢視session open cursor的具體SQL(此方法是聯合v$open_cursor得出的結果,可能有不準確。但session最多open_cursors的SQL一定是在執行結果中)
SELECT distinct a.inst_id,
a.sid,
a.USERNAME,
a.SCHEMANAME,
a.OSUSER,
a.machine,
a.TERMINAL,
a.LOGON_TIME,
a.PROGRAM,
a.STATUS,
b.name,
b.used,c.sql_id
FROM gv$session a,
(SELECT n.inst_id, sid, n.name, s.VALUE used
FROM gv$statname n, gv$sesstat s
WHERE n.name IN
('opened cursors current',
'session cursor cache count')
AND s.statistic# = n.statistic# and n.inst_id=s.inst_id ) b,v$open_cursor c
WHERE a.sid = b.sid and a.inst_id = b.inst_id and a.sid=c.sid and c.CURSOR_TYPE in('OPEN','OPEN-PL/SQL','OPEN-RECURSIVE')
and b.name <> 'session cursor cache count'
order by b.used desc;
SELECT 'session_cached_cursors' PARAMETER,
LPAD (VALUE, 5) VALUE,
DECODE (VALUE, 0, ' n/a', TO_CHAR (100 * USED / VALUE, '990') || '%')
USAGE
FROM (SELECT MAX (S.VALUE) USED
FROM V$STATNAME N, V$SESSTAT S
WHERE N.NAME = 'session cursor cache count'
AND S.STATISTIC# = N.STATISTIC#),
(SELECT VALUE
FROM V$PARAMETER
WHERE NAME = 'session_cached_cursors')
UNION ALL
SELECT 'open_cursors',
LPAD (VALUE, 5),
TO_CHAR (100 * USED / VALUE, '990') || '%'
FROM ( SELECT MAX (SUM (S.VALUE)) USED
FROM V$STATNAME N, V$SESSTAT S
WHERE N.NAME IN ('opened cursors current',
'session cursor cache count')
AND S.STATISTIC# = N.STATISTIC#
GROUP BY S.SID),
(SELECT VALUE
FROM V$PARAMETER
WHERE NAME = 'open_cursors');
注:如果查詢的session open cursor到達100% client就很可能報錯ORA-01000
檢視session open cursor的具體程式、open cursor數量:
SELECT a.inst_id,
a.sid,
a.USERNAME,
a.SCHEMANAME,
a.OSUSER,
a.machine,
a.TERMINAL,
a.LOGON_TIME,
a.PROGRAM,
a.STATUS,
b.name,
b.used
FROM gv$session a,
(SELECT n.inst_id,
sid,
n.name,
s.VALUE used
FROM gv$statname n, gv$sesstat s
WHERE n.name IN ('opened cursors current',
'session cursor cache count')
AND s.statistic# = n.statistic#
AND n.inst_id = s.inst_id) b
WHERE a.sid = b.sid
AND a.inst_id = b.inst_id
AND b.name <> 'session cursor cache count'
ORDER BY b.used DESC;
檢視session open cursor的具體SQL(此方法是聯合v$open_cursor得出的結果,可能有不準確。但session最多open_cursors的SQL一定是在執行結果中)
SELECT distinct a.inst_id,
a.sid,
a.USERNAME,
a.SCHEMANAME,
a.OSUSER,
a.machine,
a.TERMINAL,
a.LOGON_TIME,
a.PROGRAM,
a.STATUS,
b.name,
b.used,c.sql_id
FROM gv$session a,
(SELECT n.inst_id, sid, n.name, s.VALUE used
FROM gv$statname n, gv$sesstat s
WHERE n.name IN
('opened cursors current',
'session cursor cache count')
AND s.statistic# = n.statistic# and n.inst_id=s.inst_id ) b,v$open_cursor c
WHERE a.sid = b.sid and a.inst_id = b.inst_id and a.sid=c.sid and c.CURSOR_TYPE in('OPEN','OPEN-PL/SQL','OPEN-RECURSIVE')
and b.name <> 'session cursor cache count'
order by b.used desc;
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/25583515/viewspace-2152997/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle物化檢視的建立及使用(二)Oracle
- Oracle物化檢視的建立及使用(一)Oracle
- 檢視oracle資料庫的連線數以及使用者檢視Oracle資料庫
- Oracle普通檢視和物化檢視的區別Oracle
- 11、Oracle中的檢視Oracle
- 檢視oracle臨時表空間佔用率的檢視Oracle
- Oracle OCP(24):檢視Oracle
- Oracle OCP(27):使用資料字典檢視管理物件Oracle物件
- Oracle 如何高效的檢視官方文件Oracle
- oracle 檢視錶空間Oracle
- Oracle檢視執行計劃的命令Oracle
- 4.2.8 檢視元件的Oracle重啟配置元件Oracle
- oracle檢視被鎖的表和解鎖Oracle
- Oracle 檢視可以DML操作的條件Oracle
- Oracle檢視歷史TOP SQLOracleSQL
- oracle檢視物件DDL語句Oracle物件
- 檢視ORACLE中鎖定物件Oracle物件
- odoo檢視入門學習- tree檢視的使用Odoo
- oracle db link的檢視建立與刪除Oracle
- 檢視oracle被鎖的表是誰鎖的Oracle
- ORACLE 檢視IP,解析機器名Oracle
- Oracle相關資料字典檢視Oracle
- Oracle常用檢視錶結構命令Oracle
- 19 Oracle Data Guard 相關檢視Oracle
- ORACLE常見檢視和表整理Oracle
- 【PDB】Oracle跨PDB檢視查詢Oracle
- 【ADRCI】使用ADRCI (ADR Command Interpreter) 工具檢視Oracle alert警告日誌Oracle
- oracle 歷史檢視檢視,看這一篇就夠了Oracle
- 檢視Oracle的redo日誌切換頻率Oracle
- 關於Oracle dba_free_space 檢視的研究Oracle
- Oracle錶的歷史統計資訊檢視Oracle
- 小知識:使用oracle使用者檢視RAC叢集資源狀態Oracle
- linux:檢視使用中的埠Linux
- docker 容器的使用與檢視Docker
- 資料庫檢視的使用資料庫
- 使用Excel的2個檢視Excel
- Oracle資料庫scott使用者建立view檢視許可權Oracle資料庫View
- Oracle“並行執行”——監控檢視Oracle並行