how to find number of times query executed?

余生颓废 提交于 2019-12-08 05:30:06

问题


I have few queries running in Oracle 11g database from application those are repeatable queries. I want to find number of times the query executed for the day and time it took for each execution based on sql_id or sql_text? Is there a way to find this?


回答1:


The number of executions is in the AWR reports. Which means it can probably also be derived from a DBA_HIST_ table but I don't know which one. Based on your previous question I assume you have AWR licensed.

--Find the SQL_ID.  If not in shared_pool it should be in a historical table.
select * from v$sql where sql_fulltext like ...;
select * from dba_hist_sqltext where sql_text like ...;

--Find the begin and end snapshot periods.
--Be careful here, I've seen some weird timezone issues, it can be annoyingly
--difficult to get the exact period of time you want.
select * from dba_hist_snapshot order by begin_interval_time desc;

--Get AWR report.
select dbms_workload_repository.awr_sql_report_text(l_dbid => 3037785498
  , l_inst_num => 1, l_bid => 53007, l_eid => 53020, l_sqlid => '57pfs5p8xc07w')
from dual;


WORKLOAD REPOSITORY SQL Report

Snapshot Period Summary

...

    Plan Hash           Total Elapsed                 1st Capture   Last Capture
#   Value                    Time(ms)    Executions       Snap ID        Snap ID
--- ---------------- ---------------- ------------- ------------- --------------
1   1329243004                    376           552         53008          53018

...


来源:https://stackoverflow.com/questions/21533421/how-to-find-number-of-times-query-executed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!