--查詢正在執行的SQL語句
SELECT OSUSER 電腦登錄身份,
PROGRAM 發起請求的程序,
USERNAME 登錄系統的用戶名,
SCHEMANAME,
B.Cpu_Time 花費cpu的時間,
STATUS,
B.SQL_TEXT 執行的sql,
B.
FROM V$SESSION A
LEFT JOIN V$SQL B ON A.SQL_ADDRESS = B.ADDRESS
AND A.SQL_HASH_VALUE = B.HASH_VALUE
ORDER BY b.cpu_time DESC;
--查詢比較耗CPU的SQL語句
select *
from (select v.sql_id,
v.child_number,
v.sql_text,
v.elapsed_time,
v.cpu_time,
v.disk_reads,
rank() over(order by v.cpu_time desc) elapsed_rank
from v$sql v) a
where elapsed_rank <= 10;
--查詢比較耗磁盤的SQL語句
select * from (select v.sql_id,
v.child_number, v.sql_text,
v.elapsed_time, v.cpu_time,
v.disk_reads,
rank() over(order by v.disk_reads desc) elapsed_rank
from v$sql v) a where elapsed_rank <= 10;
--查詢比較慢的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
--Oracle 對未提交事務的查詢
select a.sid,a.blocking_session,a.last_call_et,a.event,
object_name,
dbms_rowid.rowid_create(1,data_object_id,rfile#,ROW_WAIT_BLOCK#,ROW_WAIT_ROW#) "rowid" ,
c.sql_text,c.sql_fulltext
from v$session a,v$sqlarea c ,dba_objects,v$datafile
where a.blocking_session is not null
and a.sql_hash_value = c.hash_value
and ROW_WAIT_OBJ#=object_id and file#=ROW_WAIT_FILE#;