这篇文章给大家分享的是有关Oracle如何查看历史TOP SQL的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。
Oracle 查看历史TOP SQL
历史TOP SQL可以通过AWR直接查看,
但是有时AWR信息显示不全,默认只显示TOP 10,
可以通过dba_hist_sqltext,dba_hist_sqlstat等查看更详细的信息;
---查看快照信息
---选择2018-06-14全天的快照6504-6528;
---conn chenjch/chenjch
select SNAP_ID,
DBID,
to_char(BEGIN_INTERVAL_TIME, 'yyyy-mm-dd hh34:mi:ss'),
to_char(END_INTERVAL_TIME, 'yyyy-mm-dd hh34:mi:ss'),
FLUSH_ELAPSED,
SNAP_LEVEL
from dba_hist_snapshot order by 1;
---1 查看2018-06-14全天SQL ordered by Elapsed Time
---时间单位默认microseconds
select a.sql_id,
a.module,
a.elap,
a.exec,
decode(a.exec, 0, to_number(null), (a.elap / a.exec)) elap_one,
b.sql_text
from dba_hist_sqltext b,
(select sql_id,
max(module) module,
sum(elapsed_time_delta) / 1000000 elap,
sum(executions_delta) exec
from dba_hist_sqlstat
where dbid = 1000919065
and instance_number = 1
and 6504 < snap_id
and snap_id <= 6528
group by sql_id) a
where a.sql_id = b.sql_id
order by elap desc;
---2 查看2018-06-14全天SQL ordered by Gets
---时间单位默认microseconds
select a.sql_id,
a.module,
a.bget,
decode(a.exec, 0, to_number(null), a.bget / a.exec) get_per_exec,
a.exec,
(a.cput/1000000)/elap*100 CPU,
a.elap,
b.sql_text
from dba_hist_sqltext b,
(select sql_id,
max(module) module,
sum(buffer_gets_delta) bget,
sum(executions_delta) exec,
sum(cpu_time_delta) cput,
sum(elapsed_time_delta) / 1000000 elap
from dba_hist_sqlstat
where dbid = 1000919065
and instance_number = 1
and 6504 < snap_id
and snap_id <= 6528
group by sql_id) a
where a.sql_id = b.sql_id
order by bget desc;
---3 查看2018-06-14全天SQL ordered by Reads
---时间单位默认microseconds
select a.sql_id,
a.module,
a.diskread,
a.exec,
decode(a.exec, 0, to_number(null), a.diskread / a.exec) diskread_one,
(a.cput/1000000)/elap*100 CPU,
a.elap,
b.sql_text
from dba_hist_sqltext b,
(select sql_id,
max(module) module,
sum(disk_reads_delta) diskread,
sum(executions_delta) exec,
sum(cpu_time_delta) cput,
sum(elapsed_time_delta) / 1000000 elap
from dba_hist_sqlstat
where dbid = 1000919065
and instance_number = 1
and 6504 < snap_id
and snap_id <= 6528
group by sql_id) a
where a.sql_id = b.sql_id
order by diskread desc;
感谢各位的阅读!关于“Oracle如何查看历史TOP SQL”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。