LoginSignup
2
0

More than 5 years have passed since last update.

AWRから指定したSQL IDの実行統計を取得する方法

Posted at

SQLごとの実行時間や読込み量等の統計を取得するスクリプトです。

dba_hist_sqlstat.sql

set linesize 10000
set pagesize 10000
set trimspool on
set termout off
set colsep "|"
spool dba_hist_sqlstat_by_sqlid.log

select sn.BEGIN_INTERVAL_TIME, st.*
from DBA_HIST_SQLSTAT st,
     DBA_HIST_SNAPSHOT sn
where 
      st.SNAP_ID = sn.SNAP_ID
  and st.DBID = sn.DBID
  and st.INSTANCE_NUMBER = sn.INSTANCE_NUMBER
  and sn.BEGIN_INTERVAL_TIME between to_date('2016/03/01 13:50:00', 'yyyy/mm/dd hh24:mi:ss')
                                 and to_date('2016/03/31 19:10:00', 'yyyy/mm/dd hh24:mi:ss')
  and st.SQL_ID in ('a1dkahc57tu6k','958gy5ujrpcrd','7kmbrw7q8hn4g','fhf8upax5cxsz');
spool off

dba_hist_sqlstatにはsql idごとに実行時間や読み込み量などスナップ間のデルタ値を保持しているため、
例えば、ELAPSED_TIME_DELTA / EXECUTIONS_DELTA を求めることで1実行あたりの平均実行時間の算出ができます。

Excelに取り込み、ピボットグラフでの整形例
dba_hist_sqlstat_elap.png

Oracle® Databaseリファレンス 12c リリース1 (12.1) - DBA_HIST_SQLSTAT
(SQLはDB 12.1.0.2にて試行)

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0