oracle狀態查詢(補)
---正在執行的sql語句
select a.username, a.sid,b.SQL_TEXT, b.SQL_FULLTEXT
from v$session a, v$sqlarea b
where a.sql_address = b.address
---執行過的sql語句
select b.SQL_TEXT,b.FIRST_LOAD_TIME,b.SQL_FULLTEXT
from v$sqlarea b
where b.FIRST_LOAD_TIME between '2014-03-08/09:00:00' and
'2014-03-08/10:00:00' order by b.FIRST_LOAD_TIME
(此方法好處可以檢視某一時間段執行過的sql,並且 SQL_FULLTEXT 包含了完整的 sql 語句)
查詢效能差的sql.
SELECT * FROM (select PARSING_USER_ID,EXECUTIONS,SORTS,
COMMAND_TYPE,DISK_READS,sql_text FROM v$sqlarea
order BY disk_reads DESC )where ROWNUM<10 ;
(sql數目)
檢視佔io較大的正在執行的session
SELECT se.sid,se.serial#,pr.SPID,se.username,se.status,
se.terminal,se.program,se.MODULE,、se.sql_address,st.event,st.
p1text,si.physical_reads,
si.block_changes FROM v$session se,v$session_wait st,
v$sess_io si,v$process pr WHERE st.sid=se.sid AND st.
sid=si.sid AND se.PADDR=pr.ADDR AND se.sid>6 AND st.
wait_time=0 AND st.event NOT LIKE '%SQL%'
ORDER BY physical_reads DESC
查詢oracle被鎖的表:
SELECT A.OWNER,A.OBJECT_NAME,B.XIDUSN,B.XIDSLOT,B.XIDSQN,B.SESSION_ID,B.ORACLE_USERNAME,
B.OS_USER_NAME,B.PROCESS, B.LOCKED_MODE,C.MACHINE,C.STATUS,C.SERVER,C.SID,
C.SERIAL#,C.PROGRAM
FROM ALL_OBJECTS A,V$LOCKED_OBJECT B,SYS.GV_$SESSION C
WHERE ( A.OBJECT_ID = B.OBJECT_ID )
AND (B.PROCESS = C.PROCESS )
ORDER BY 1,2
釋放session Sql:
alter system kill session 'sid, serial#'
檢視死鎖的指令碼:
SELECT substr(v$lock.sid,1,4) "SID",
substr(username,1,12) "UserName",
substr(object_name,1,25) "ObjectName",
v$lock.type "LockType",
decode(rtrim(substr(lmode,1,4)),
'2','Row-S (SS)','3','Row-X (SX)',
'4','Share', '5','S/Row-X (SSX)',
'6','Exclusive', 'Other' ) "LockMode",
substr(v$session.program,1,25) "ProgramName"
FROM V$LOCK,SYS.DBA_OBJECTS,V$SESSION
WHERE (OBJECT_ID = v$lock.id1
AND v$lock.sid = v$session.sid
AND username IS NOT NULL
AND username NOT IN ('SYS','SYSTEM')
AND SERIAL# != 1);
如何定位重要(消耗資源多)的SQL:
select a.username, a.sid,b.SQL_TEXT, b.SQL_FULLTEXT
from v$session a, v$sqlarea b
where a.sql_address = b.address
---執行過的sql語句
select b.SQL_TEXT,b.FIRST_LOAD_TIME,b.SQL_FULLTEXT
from v$sqlarea b
where b.FIRST_LOAD_TIME between '2014-03-08/09:00:00' and
'2014-03-08/10:00:00' order by b.FIRST_LOAD_TIME
(此方法好處可以檢視某一時間段執行過的sql,並且 SQL_FULLTEXT 包含了完整的 sql 語句)
查詢效能差的sql.
SELECT * FROM (select PARSING_USER_ID,EXECUTIONS,SORTS,
COMMAND_TYPE,DISK_READS,sql_text FROM v$sqlarea
order BY disk_reads DESC )where ROWNUM<10 ;
(sql數目)
檢視佔io較大的正在執行的session
SELECT se.sid,se.serial#,pr.SPID,se.username,se.status,
se.terminal,se.program,se.MODULE,、se.sql_address,st.event,st.
p1text,si.physical_reads,
si.block_changes FROM v$session se,v$session_wait st,
v$sess_io si,v$process pr WHERE st.sid=se.sid AND st.
sid=si.sid AND se.PADDR=pr.ADDR AND se.sid>6 AND st.
wait_time=0 AND st.event NOT LIKE '%SQL%'
ORDER BY physical_reads DESC
查詢oracle被鎖的表:
SELECT A.OWNER,A.OBJECT_NAME,B.XIDUSN,B.XIDSLOT,B.XIDSQN,B.SESSION_ID,B.ORACLE_USERNAME,
B.OS_USER_NAME,B.PROCESS, B.LOCKED_MODE,C.MACHINE,C.STATUS,C.SERVER,C.SID,
C.SERIAL#,C.PROGRAM
FROM ALL_OBJECTS A,V$LOCKED_OBJECT B,SYS.GV_$SESSION C
WHERE ( A.OBJECT_ID = B.OBJECT_ID )
AND (B.PROCESS = C.PROCESS )
ORDER BY 1,2
釋放session Sql:
alter system kill session 'sid, serial#'
檢視死鎖的指令碼:
SELECT substr(v$lock.sid,1,4) "SID",
substr(username,1,12) "UserName",
substr(object_name,1,25) "ObjectName",
v$lock.type "LockType",
decode(rtrim(substr(lmode,1,4)),
'2','Row-S (SS)','3','Row-X (SX)',
'4','Share', '5','S/Row-X (SSX)',
'6','Exclusive', 'Other' ) "LockMode",
substr(v$session.program,1,25) "ProgramName"
FROM V$LOCK,SYS.DBA_OBJECTS,V$SESSION
WHERE (OBJECT_ID = v$lock.id1
AND v$lock.sid = v$session.sid
AND username IS NOT NULL
AND username NOT IN ('SYS','SYSTEM')
AND SERIAL# != 1);
如何定位重要(消耗資源多)的SQL:
select sql_text
from v$sql
where disk_reads > 1000 or (executions > 0 and buffer_gets/executions > 30000);
如何跟蹤某個session的SQL:
exec dbms_system.set_sql_trace_in_session(sid,serial#,&sql_trace);
查詢系統檢視:
select sid,serial# from v$session where sid = (select sid from v$mystat where rownum = 1);
10046的trace:
exec dbms_system.set_ev(&sid,&serial#,&event_10046,&level_12,'');
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29510932/viewspace-1103533/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- oracle常用狀態查詢Oracle
- 查詢網路狀態
- oracle最新補丁查詢Oracle
- Oracle補丁集查詢Oracle
- oracle 補丁號查詢Oracle
- oracle 9i physical standby database狀態查詢OracleDatabase
- openguass 資料庫狀態查詢資料庫
- Oracle SCN健康狀態檢查Oracle
- oracle物理dg狀態檢查Oracle
- HTTP狀態碼查詢簡單介紹HTTP
- MongoDB狀態查詢db.serverStatus()詳解MongoDBServer
- v$datafile_header 查詢datafile 狀態Header
- 常用的系統狀態查詢命令(轉)
- mcafee狀態程式碼含義列表以供查詢
- Oracle CPU補丁包查詢下載的方法Oracle
- 查詢(1)--靜態查詢
- 查詢(2)--動態查詢
- Permission API 統一查詢許可權狀態API
- 自動查詢並分析快遞的物流狀態
- RMAN筆記之查詢rman備份資訊狀態筆記
- Oracle索引或這類索引的分割槽處於不可用狀態 查詢Oracle索引
- 巢狀子查詢巢狀
- 資料庫 - 連線查詢、巢狀查詢、集合查詢資料庫巢狀
- 隨筆:MySQL 查詢事務狀態欄位說明MySql
- 資料庫查詢優化:巢狀查詢資料庫優化巢狀
- oracle 雜湊查詢與巢狀查詢跟表的先後關係測試Oracle巢狀
- mysql樹狀查詢(轉)MySql
- 【YashanDB資料庫】yasboot查詢資料庫狀態時顯示資料庫狀態為off資料庫boot
- Oracle 查詢Oracle
- MySQL——優化巢狀查詢和分頁查詢MySql優化巢狀
- Hierarchical Queries 級聯查詢(樹狀結構查詢)
- 關聯查詢時使用樹狀查詢要小心
- 對比SQL中簡單巢狀查詢與非巢狀查詢CFSQL巢狀
- MySQL探祕(五):InnoDB鎖的型別和狀態查詢MySql型別
- 查詢圓通快遞並設定物流狀態的方法
- DS靜態查詢之順序查詢
- EleasticSearch6.0 巢狀查詢AST巢狀
- Sql Server系列:巢狀查詢SQLServer巢狀