Collecting Performance Statistics

在外企呆得不长,笔记都开始全英文了。。呵呵。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 ;



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

dbLenis

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值