做运行报告的时候,主机可以取CPU,内存,进程数的相关参数做报表,而数据库却很难做出长时间性能参数的报告。Statspack是Oracle性能分析的一个报告,但这个报告只能取一个规定时间段的值,可以用来分析问题,但不能反映随时间的变化趋势,也很难进行图表展示。
Oracle相关工具toad提供了statspack的简单图表展示,但选择时间点很麻烦,且只有有限几个参数。原则上来说,工具能实现的功能利用sql语句都能实现。下面是一个利用statspack进行oracle性能分析的一个简单例子。
具体sql语句如下
select w.snap_id,
sn.SNAP_TIME,
w.event event,
w.total_waits - w.last_wait waits,
w.total_timeouts - w.last_timeout timeouts,
(w.time_waited - w.last_time_waited)/1000000 time_waited_S
from perfstat.stats$snapshot sn,
(select snap_id, dbid, instance_number, event,
total_waits,
lag(total_waits, 1) over (order by event, snap_id) last_wait,
total_timeouts,
lag(total_timeouts, 1) over (order by event, snap_id) last_timeout, time_waited_micro time_waited,
lag(time_waited_micro, 1) over (order by event, snap_id)
last_time_waited from perfstat.stats$system_event
where event not in (select event from perfstat.stats$IDLE_EVENT)
and snap_id in (select snap_id from stats$snapshot where snap_time >sysdate -300) ----300 days
) w
where w.time_waited - w.last_time_waited > 0
and w.snap_id > (select min(snap_id) from stats$snapshot where snap_time >sysdate -300) ----300 days
--and SN.snap_id in (22391,22392,22393)
and sn.snap_id = w.snap_id
and sn.dbid = w.dbid
and sn.instance_number = w.instance_number
and event not like '%message%'
and event not like 'SQL*Net%'
and (w.time_waited - w.last_time_waited) > 600*1000000 ---- wait time >10 min
UNION ALL
select ss.snap_id, sn.SNAP_TIME, 'CPU TIME' ,0, 0,ROUND((ss.value - lag(ss.value,1) over (order by ss.snap_id))/100,0) as value_cputime
from perfstat.stats$sysstat ss, perfstat.stats$snapshot sn
where ss.snap_id = sn.snap_id
and ss.name = 'CPU used by this session'
and ss.snap_id in (select snap_id from stats$snapshot where snap_time >sysdate -300)
--and ss.snap_id in (22391,22392,22393)
and ss.dbid = sn.dbid
and ss.instance_number = sn.instance_number
order by 1, 6 desc
通过sql查询出来的数据,导入到excel中(可以利用taod、pl/sql等工具),利用excel的透视图功能,进行图形绘制,如下图是某系统2011年1月的top wait event的结果。从图可以看出主要等待事件是db file sequential read和cpu time。db file sequentialread事件多说明系统IO压力大。
命中率的图(本周),低点一般在凌晨4点,其它命中率98%以上
理论上讲,statspack报告中的所有性能参数都可以进行图表展示,前提是拥有定期收集的数据。