oracle10g动态性能表v$sess_time_model确定当前session的sql语句性能

来源:互联网 发布:jy零食淘宝店 编辑:程序博客网 时间:2024/06/01 09:07

1. v$sess_time_model 是 oracle10g 新引入的一个动态性能表,属于会话 session 级的视图,(系统级的视图是 v$sys_time_model) ,
   通过这个视图我们可以实现时间模型统计
   时间模型统计 ( time model statistics )主要是用来找出某一类数据库操作中耗费的时间

关于 v$sess_time_model 的一些参数
DB Time
-  执行用户调用的总的时间(微秒 ), 是数据库处理所花费的时间,等待用户调用 的时间没有包括在内。

DB CPU
-  执行用户调用的总的 CPU 的时间(微秒 ), 不包括运行后台进程的时间 , 比如 PMON 。

SQL execute elapsed time
-  SQL statements 执行所花费的总的时间 , 注意对于 select 语句来说 . 这同样包括获取 (fetch) 查询结果的时间

parse time elapsed
-  解析 SQLStatements 的总共时间 , 它包括了软解析和硬解析 .

hard parse elapsed time
-  硬解析所花费的总的时间

sequence load elapsed time
-  从 data dictionary 中获取下一个 sequence 的总的时间,如果 sequence 使用 cached, 那么这个时间是重装 (replenish)cached
   的时间,而在cache中寻找新的sequence的时间是不计算在内; 而对于 non-cached 的情况,那么这个时间就是获取 nextval 的时间

connection management call elapsed time
-  所以 Session 连接和断开连接所消耗的时间 .

failed parse elapsed time
-  所有最后遇到错误的 SQL 的解析所花费时间 .

hard parse (sharing criteria) elapsed time
-  当无法从 SQL Cache 中找到一个已经存在的 cursor 的时候 , 所有硬解析所花费的时间 .

hard parse (bind mismatch) elapsed time
-  当可以从 SQL Cache 找到一个已经存在的 curosr, 但是绑定变量不匹配的时候 , 所有硬解析花费的时间 .

PL/SQL execution elapsed time
-  所有花在执行 PL/SQL interpreter 的时间 (PL/SQL interpreter - 就是 debug workspace), 但这不包括花在
   recursively executing/parsing SQL statements 上的时间,以及 recursively executing the Java VM 上的时间

PL/SQL compilation elapsed time
-  所有花在 PL/SQL compiler 上的时间 .

inbound PL/SQL rpc elapsed time
-  所有入站的远程调用所运行的时间(也就是说,从其他的instance通过数据链接到本数据库的调用),包括了所有SQL和Java
   的递归调用

 

 

2.使用v$sess_time_model获得当前session中所有哪一类操作消耗了最多的时间

a 根据时间降序获得当前数据的中的所有session
  SELECT SID,status,machine,program,
         sql_id, prev_sql_id,logon_time,
         event, wait_class, wait_time,
         seconds_in_wait,state
  FROM v$session
  ORDER BY logon_time DESC;


b 获得需要分析的SID,使用下面语句处理用户调用这个session所耗费的所有时间(不包括等待用户调用的时间)
     with db_time as(select sid,value from v$sess_time_model
             where sid=1112 and stat_name='DB time'
             )
    select stm.stat_name as statistic,trunc(stm.value/1000000,3) as seconds,
              trunc(stm.value/tot.value*100,1) as "%"
    from  v$sess_time_model stm,db_time tot
    where stm.sid=tot.sid and stm.stat_name<>'DB time'
               and stm.value>0 order by stm.value desc;

 c 分析之后根据SID获得相关的sql语句
   select sid,sql_text
   from v$session s,v$sql q
   where (q.sql_id=s.sql_id or q.sql_id = s.prev_sql_id) and sid = 1112;