统计信息不准,直方图等原因导致执行计划抖动头痛吧,下面脚本可以实现部分监控,为什么说是部分监控,因为可能某个SQL 在很长一段时间之前执行计划是最优的,问题时刻就跑得很慢,而绝大部分人在数据库中没有为SQL建立基线,无法进行前后对照的比较,就无法实现监控。
--执行计划抖动监控,最近15分钟内,执行次数超过20,执行计划存在2个的。
select min(sample_time) bg_time, max(sample_time) ed_time,a.inst_id,
a.sql_id,count( distinct SQL_PLAN_HASH_VALUE) plan_cnt,count(distinct sql_exec_id) exec_cnt from
gv$active_session_history a
where sample_time > sysdate - interval '15' minute
and sql_id is not null and sql_opname <> 'INSERT'
and sql_plan_hash_value <> 0 and sql_exec_id > 0
and MODULE in ('JDBC Thin Client')
group by a.INST_ID,a.sql_id
HAVING COUNT(distinct SQL_PLAN_HASH_VALUE) > 1 and count(distinct sql_exec_id) > 20
至于如何处理,可以使用OUTLINE, SQL PROFILE, BASELINE 固定执行计划。
--执行计划抖动监控,最近15分钟内,执行次数超过20,执行计划存在2个的。
select min(sample_time) bg_time, max(sample_time) ed_time,a.inst_id,
a.sql_id,count( distinct SQL_PLAN_HASH_VALUE) plan_cnt,count(distinct sql_exec_id) exec_cnt from
gv$active_session_history a
where sample_time > sysdate - interval '15' minute
and sql_id is not null and sql_opname <> 'INSERT'
and sql_plan_hash_value <> 0 and sql_exec_id > 0
and MODULE in ('JDBC Thin Client')
group by a.INST_ID,a.sql_id
HAVING COUNT(distinct SQL_PLAN_HASH_VALUE) > 1 and count(distinct sql_exec_id) > 20
至于如何处理,可以使用OUTLINE, SQL PROFILE, BASELINE 固定执行计划。
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/308563/viewspace-2136326/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/308563/viewspace-2136326/