【转】ashtop 方便看当前活动会话 -凯发app官方网站

凯发app官方网站-凯发k8官网下载客户端中心 | | 凯发app官方网站-凯发k8官网下载客户端中心
  • 博客访问: 3502609
  • 博文数量: 718
  • 博客积分: 1860
  • 博客等级: 上尉
  • 技术积分: 7790
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-07 08:51
个人简介

偶尔有空上来看看

文章分类

全部博文(718)

文章存档

2024年(4)

2023年(74)

2022年(134)

2021年(238)

2020年(115)

2019年(11)

2018年(9)

2017年(9)

2016年(17)

2015年(7)

2014年(4)

2013年(1)

2012年(11)

2011年(27)

2010年(35)

2009年(11)

2008年(11)

最近访客
相关博文
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·

分类: oracle

2021-04-26 14:50:10



  1. -- 凯发app官方网站 copyright 2018 tanel poder. all rights reserved. more info at
  2. -- licensed under the apache license, version 2.0. see license.txt for terms & conditions.

  3. --------------------------------------------------------------------------------
  4. --
  5. -- file name: ashtop.sql v1.2
  6. -- purpose: display top ash time (count of ash samples) grouped by your
  7. -- specified dimensions
  8. --
  9. -- author: tanel poder
  10. -- 凯发app官方网站 copyright: (c) http://blog.tanelpoder.com
  11. --
  12. -- usage:
  13. -- @ashtop
  14. --
  15. -- example:
  16. -- @ashtop username,sql_id session_type='foreground' sysdate-1/24 sysdate
  17. --
  18. -- other:
  19. -- this script uses only the in-memory gv$active_session_history, use
  20. -- @dashtop.sql for accessiong the dba_hist_active_sess_history archive
  21. --
  22. --------------------------------------------------------------------------------
  23. col "%this" for a7
  24. --col p1 for 99999999999999
  25. --col p2 for 99999999999999
  26. --col p3 for 99999999999999
  27. col p1text for a30 word_wrap
  28. col p2text for a30 word_wrap
  29. col p3text for a30 word_wrap
  30. col p1hex for a17
  31. col p2hex for a17
  32. col p3hex for a17
  33. col dop for 99
  34. col aas for 9999.9
  35. col totalseconds head "total|seconds" for 99999999
  36. col dist_sqlexec_seen head "distinct|execs seen" for 999999
  37. col event for a42 word_wrap
  38. col event2 for a42 word_wrap
  39. col time_model_name for a50 word_wrap
  40. col program2 for a40 truncate
  41. col username for a20 wrap
  42. col obj for a30
  43. col objt for a50
  44. col sql_opname for a20
  45. col top_level_call_name for a30
  46. col wait_class for a15

  47. select
  48.     *
  49. from (
  50.     with bclass as (select /* inline */ class, rownum r from v$waitstat)
  51.     select /* leading(a) use_hash(u) */
  52.         count(*) totalseconds
  53.       , round(count(*) / ((cast(&4 as date) - cast(&3 as date)) * 86400), 1) aas
  54.       , lpad(round(ratio_to_report(count(*)) over () * 100)||'%',5,' ')||' |' "%this"
  55.       , &1
  56.       , to_char(min(sample_time), 'yyyy-mm-dd hh24:mi:ss') first_seen
  57.       , to_char(max(sample_time), 'yyyy-mm-dd hh24:mi:ss') last_seen
  58. -- , max(sql_exec_id) - min(sql_exec_id)
  59.       , count(distinct sql_exec_start||':'||sql_exec_id) dist_sqlexec_seen
  60.     from
  61.         (select
  62.              a.*
  63.            , session_id sid
  64.            , session_serial# serial
  65.            , to_char(case when session_state = 'waiting' then p1 else null end, '0xxxxxxxxxxxxxxx') p1hex
  66.            , to_char(case when session_state = 'waiting' then p2 else null end, '0xxxxxxxxxxxxxxx') p2hex
  67.            , to_char(case when session_state = 'waiting' then p3 else null end, '0xxxxxxxxxxxxxxx') p3hex
  68.            , trunc(px_flags / 2097152) dop
  69.            , nvl(a.event, a.session_state)||
  70.                 case
  71.                     when a.event like 'enq%' and session_state = 'waiting'
  72.                     then ' [mode='||bitand(p1, power(2,14)-1)||']'
  73.                     when a.event in (select name from v$event_name where parameter3 = 'class#')
  74.                     then ' ['||case when a.p3 <= (select max(r) from bclass)
  75.                                then (select class from bclass where r = a.p3)
  76.                                else (select decode(mod(bitand(a.p3,to_number('ffff','xxxx')) - 17,2),0,'undo header',1,'undo data', 'error') from dual)
  77.                                end ||']'
  78.                     else null
  79.                 end event2 -- event is null in ash if the session is not waiting (session_state = on cpu)
  80.            , case when a.session_type = 'background' or regexp_like(a.program, '.*\([pj]\d \)') then
  81.                 regexp_replace(substr(a.program,instr(a.program,'(')), '\d', 'n')
  82.              else
  83.                 '('||regexp_replace(regexp_replace(a.program, '(.*)@(.*)(\(.*\))', '\1'), '\d', 'n')||')'
  84.              end || ' ' program2
  85.            , case when bitand(time_model, power(2, 01)) = power(2, 01) then 'dbtime ' end
  86.            ||case when bitand(time_model, power(2, 02)) = power(2, 02) then 'background ' end
  87.            ||case when bitand(time_model, power(2, 03)) = power(2, 03) then 'connection_mgmt ' end
  88.            ||case when bitand(time_model, power(2, 04)) = power(2, 04) then 'parse ' end
  89.            ||case when bitand(time_model, power(2, 05)) = power(2, 05) then 'failed_parse ' end
  90.            ||case when bitand(time_model, power(2, 06)) = power(2, 06) then 'nomem_parse ' end
  91.            ||case when bitand(time_model, power(2, 07)) = power(2, 07) then 'hard_parse ' end
  92.            ||case when bitand(time_model, power(2, 08)) = power(2, 08) then 'no_sharers_parse ' end
  93.            ||case when bitand(time_model, power(2, 09)) = power(2, 09) then 'bind_mismatch_parse ' end
  94.            ||case when bitand(time_model, power(2, 10)) = power(2, 10) then 'sql_execution ' end
  95.            ||case when bitand(time_model, power(2, 11)) = power(2, 11) then 'plsql_execution ' end
  96.            ||case when bitand(time_model, power(2, 12)) = power(2, 12) then 'plsql_rpc ' end
  97.            ||case when bitand(time_model, power(2, 13)) = power(2, 13) then 'plsql_compilation ' end
  98.            ||case when bitand(time_model, power(2, 14)) = power(2, 14) then 'java_execution ' end
  99.            ||case when bitand(time_model, power(2, 15)) = power(2, 15) then 'bind ' end
  100.            ||case when bitand(time_model, power(2, 16)) = power(2, 16) then 'cursor_close ' end
  101.            ||case when bitand(time_model, power(2, 17)) = power(2, 17) then 'sequence_load ' end
  102.            ||case when bitand(time_model, power(2, 18)) = power(2, 18) then 'inmemory_query ' end
  103.            ||case when bitand(time_model, power(2, 19)) = power(2, 19) then 'inmemory_populate ' end
  104.            ||case when bitand(time_model, power(2, 20)) = power(2, 20) then 'inmemory_prepopulate ' end
  105.            ||case when bitand(time_model, power(2, 21)) = power(2, 21) then 'inmemory_repopulate ' end
  106.            ||case when bitand(time_model, power(2, 22)) = power(2, 22) then 'inmemory_trepopulate ' end
  107.            ||case when bitand(time_model, power(2, 23)) = power(2, 23) then 'tablespace_encryption ' end time_model_name
  108.         from gv$active_session_history a) a
  109.       , dba_users u
  110.       , (select
  111.              object_id,data_object_id,owner,object_name,subobject_name,object_type
  112.            , owner||'.'||object_name obj
  113.            , owner||'.'||object_name||' ['||object_type||']' objt
  114.          from dba_objects) o
  115.     where
  116.         a.user_id = u.user_id ()
  117.     and a.current_obj# = o.object_id()
  118.     and &2
  119.     and sample_time between &3 and &4
  120.     group by
  121.         &1
  122.     order by
  123.         totalseconds desc
  124.        , &1
  125. )
  126. where
  127.     rownum <= 15
  128. /



使用方法:
将上述脚本保存为 ashtop.sql

然后执行:
prompt what's going on? showing top timed events of last minute from ash...
@ashtop session_state,event &filter sysdate-1/24/60 sysdate


prompt showing top sql and wait classes of last minute from ash...
@ashtop sql_id,session_state,wait_class &filter sysdate-1/24/60 sysdate
阅读(1443) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~
")); function link(t){ var href= $(t).attr('href'); href ="?url=" encodeuricomponent(location.href); $(t).attr('href',href); //setcookie("returnouturl", location.href, 60, "/"); }
网站地图