Oracle数据库中的SQL基线信息,当数据库出现性能问题时,在业务无法提供相应业务信息时,通过对比SQL基线信息来查找SQL的变化。
查找数据库一天内运行次数大于5000次的sqlid
select sql_id,sum(EXECUTIONS_DELTA)
from dba_hist_sqlstat a,dba_hist_snapshot b
where a.snap_id=b.snap_id and a.INSTANCE_NUMBER=b.INSTANCE_NUMBER
and to_char(b.end_interval_time,'yyyymmdd')= '20170913'
group by sql_id having sum(EXECUTIONS_DELTA)>5000 order by 2;
通过这些sqlid在snapshot中查找出SQL历史执行信息
SELECT 'select to_char(b.end_interval_time,''yyyy-mm-dd hh24:mi:ss'') sample_time,
round(sum(ELAPSED_TIME_DELTA)/1000/sum(EXECUTIONS_DELTA),1) elapsed_time_per_exec_ms,
round(sum(BUFFER_GETS_DELTA)/sum(EXECUTIONS_DELTA),1) gets_per_exec
from dba_hist_sqlstat a,dba_hist_snapshot b
where a.snap_id=b.snap_id and a.INSTANCE_NUMBER=b.INSTANCE_NUMBER
and sql_id='
||Chr(39)
||sql_id
||Chr(39)
||' group by b.end_interval_time order by 1;'
FROM dba_hist_sqlstat a,
dba_hist_snapshot b
WHERE a.snap_id = b.snap_id
AND a.instance_number = b.instance_number
AND To_char(b.end_interval_time,'yyyymmdd') = '20170913'
GROUP BY sql_id
HAVING Sum(executions_delta) > 5000
ORDER BY Sum(executions_delta);