在外企呆得不长,笔记都开始全英文了。。呵呵。blog还是要中文滴
1个月前尝试着梳理oracle performance tuning,到现在隐约有些框架了,基本是以《trouble shooting oracle performance》这本apress的大作为主。参考了《oracle wait interface》。
首先看这个简单的公式: Response Time = Service Time + Wait Time
然后分而治之:
1. Service Time 是指CPU使用。包括了cpu parsed time, recursive cpu usage和cpu used for normal work(CPU_W);
涉及到的data dictionary view主要有v$sesstat, v$statname
注意点:a) 要启用service time statistics的收集,必须先将statistics_level 设置为typical或者all.
b) 这里的view一般都是累计值,要计算某一个session的统计数值,需要取delta值。
c) 统计值只有在某一个session断开的 时候才更新
2. Wait events的使用:用来分析某个session的各个event的所用时间统计值
涉及到的data dictionary view主要有v$session_wait, v$session_event, v$system_event
注意点:a) 设置timed_statistics为true;
b) v$session_wait ----> v$session_event ----> v$system_event基本是这个数据流向
c) 统计值及时更新
3. 使用logon trigger来记录每个session的service time 以及wait time的使用情况
附一个用excel来看我的开发库每天的登录人数情况:
看下logon trigger:首先要建立两个用来记录cpu statistics和event time的基表,可以从trigger里面类似的sql来建立,并考虑可以partition:
create or replace trigger sys.logff_trig
before logoff on database
declare
logoff_sid pls_integer;
logoff_time date :=systimestamp;
begin
select sid into logoff_sid from v$mystat where rownum<2 ;
insert into system.session_events_history
select b.sid,b.serial#,b.username,b.osuser,b.paddr,b.process,b.logon_time,b.type,b.program,b.module,
a.event,a.total_waits,a.total_timeouts,a.time_waited,a.average_wait,a.max_wait,systimestamp
from v$session_event a ,v$session b
where b.sid=logoff_sid
and a.sid=b.sid
and b.username=user;
insert into system.session_stats_history
select c.username,c.osuser,a.sid,c.serial#,c.paddr,c.program,c.module,c.process,c.logon_time,
a.statistic#,b.name,a.value,systimestamp
from v$sesstat a , v$statname b, v$session c
where c.sid=logoff_sid
and a.sid=c.sid
and a.statistic#=b.statistic#
and c.username=user
and a.value<>0;
commit;
end ;