--查询指定sql_id的执行情况
select * from table(dbms_xplan.display_cursor('ghnamt41nmgbt'));
-- 以前执行的
select * from table(dbms_xplan.display_awr('83bvz3hr8s5p7'));
--查询缓存中有的执行sql
select * from v$sqlarea t
where t.SQL_FULLTEXT like '%INSERT INTO tt_test%'
--查询历史执行sql
select * from dba_hist_sqltext t
where t.sql_text like '%INSERT INTO tt_test%'
--查找顶层ASH历史sql_id
select session_id,sql_id,sample_id,event,sample_time from v$active_session_history where session_id==&sid;
--c4sppvufpxurs
--查询执行计划历史记录
select to_char(x.end_interval_time, 'YYYYMMDD HH24:MI:SS'),
x.instance_number,
y.sql_id,
y.plan_hash_value,
y.executions_delta,
round(y.elapsed_time_delta ) as elapsed_time,
round(y.cpu_time_delta ) as cpu_time,
round(y.buffer_gets_delta ) as buffer_gets,
round(y.rows_processed_delta ) as rows_processed,
round(y.iowait_delta ) as iowait ,
round(y.disk_reads_total ) as disk_reads
from dba_hist_snapshot x, dba_hist_sqlstat y
where x.snap_id = y.snap_id
and y.sql_id in ('c4sppvufpxurs')
and x.instance_number = y.instance_number
and x.end_interval_time >
to_date('2014-06-01 00:30', 'yyyy-mm-dd hh24:mi')
-- and y.executions_delta <> 0
and x.instance_number = y.instance_number
order by 2 desc,1 asc;
--查询执行计划历史记录
SELECT TO_CHAR(X.END_INTERVAL_TIME, 'YYYYMMDD HH24:MI:SS'),
X.INSTANCE_NUMBER,
Y.SQL_ID,
Y.PLAN_HASH_VALUE,
Y.EXECUTIONS_DELTA,
S.SQL_TEXT,
ROUND(Y.ELAPSED_TIME_TOTAL / 1000000 /
DECODE(Y.ELAPSED_TIME_DELTA, 0, 1, Y.ELAPSED_TIME_DELTA)) AS ELAPSED_TIME_TOTAL,
ROUND(Y.ELAPSED_TIME_DELTA / 1000000) AS ELAPSED_TIME,
ROUND(Y.CPU_TIME_DELTA) AS CPU_TIME,
ROUND(Y.BUFFER_GETS_DELTA) AS BUFFER_GETS,
ROUND(Y.ROWS_PROCESSED_DELTA) AS ROWS_PROCESSED,
ROUND(Y.IOWAIT_DELTA) AS IOWAIT,
ROUND(Y.DISK_READS_TOTAL) AS DISK_READS
FROM DBA_HIST_SNAPSHOT X, DBA_HIST_SQLSTAT Y, DBA_HIST_SQLTEXT S
WHERE X.SNAP_ID = Y.SNAP_ID
AND Y.SQL_ID = S.SQL_ID
AND Y.SQL_ID IN
('28u8n116hn169', '1fgay470bc197', '8jgnfpsz00226', '6rjbrkfdn43fb',
'8h2j1894708fc', '3p2qy1rsmna5v', 'am99h3wj9smvu', 'dzc2qwv6qcu32',
'bmxbustu0ny8n', '3pb6qppwqwzkd', '8j2hsuc5kj05k', '4y698yw8nx5kd',
'4ybz610sbd96v', '8j6ncvdp25fgv', '7zb801tbb9qv4', 'a6htvk2k91rc5',
'9pvdwy3sf5srf', '1uu12vzu39ts7', 'cbgwx6u07pvt2', '3z01ksf8pdyz4',
'fdunu0d7t9zhg', '60yh8fdbv1zu3', 'bysaxanazq1uz', 'dsfg4sdvyy3pk',
'd03y3sxt024yj', 'gt6jkrh79f7ns', '27vy8sp32qb6b', 'c749bc43qqfz3',
'81ckw3jb36kkd', '8c9tr56n3ymug', 'b98ux06442nd2', 'g5dfv9qx1avvv',
'9zbhxb941z00k', '7dc1uvm9dm04g', '01ctrtrrqr1zp', '17ty9a78mr38f',
'as292kf3bv4zb', '5n4k60pf275td', '3zmdnya1xv800', '0szr8ztg8ggyz',
'9bj3ygf6mrr49', '86kwhy1f0bttn', '5rbdfvqy8mub1')
AND X.INSTANCE_NUMBER = Y.INSTANCE_NUMBER
AND X.END_INTERVAL_TIME >
TO_DATE('2014-07-15 00:30', 'yyyy-mm-dd hh24:mi')
-- and y.executions_delta <> 0
AND X.INSTANCE_NUMBER = Y.INSTANCE_NUMBER
ORDER BY 2 DESC, 1 ASC