运维联盟俱乐部

 找回密码
 立即注册
查看: 1804|回复: 0

[日常管理] q_topevent

[复制链接]
  • TA的每日心情
    开心
    2023-8-9 11:05
  • 发表于 2020-9-11 15:11:26 | 显示全部楼层 |阅读模式
    1. --等待事件组
    2. select WAIT_CLASS,
    3.        TOTAL_WAITS,
    4.        round(100 * (TOTAL_WAITS / SUM_WAITS), 2) PCT_WAITS,
    5.        ROUND((TIME_WAITED / 100), 2) TIME_WAITED_SECS,
    6.        round(100 * (TIME_WAITED / SUM_TIME), 2) PCT_TIME
    7.   from (select WAIT_CLASS, TOTAL_WAITS, TIME_WAITED
    8.           from V$SYSTEM_WAIT_CLASS
    9.          where WAIT_CLASS != 'Idle'),
    10.        (select sum(TOTAL_WAITS) SUM_WAITS, sum(TIME_WAITED) SUM_TIME
    11.           from V$SYSTEM_WAIT_CLASS
    12.          where WAIT_CLASS != 'Idle')
    13. order by 5 desc;
    14. select WAIT_CLASS,count(*) from v$session_wait where wait_time is not null group by WAIT_CLASS order by 2 desc;
    15. --等待事件top
    16. set linesize 120
    17. col event for a60
    18. select event,
    19.        sum(decode(wait_time, 0, 0, 1)) prev,
    20.        sum(decode(wait_time, 0, 1, 0)) cur,
    21.        count(*) tot
    22.   from v$session_wait
    23. group by event
    24. order by 4 desc;

    25. --等待耗时top
    26. select *
    27.   from (select event, total_waits, average_wait
    28.           from v$system_event
    29.          where event not like 'SQL%'
    30.          order by 3 desc)
    31. where rownum <= 10;

    32. --查询当前的top_sql,根据cpu_time,elapsed_time,disk_read,executions等条件替换
    33. select sql_id,command_type,cpu_time
    34. from
    35. (select sql_id,
    36.         command_type,
    37.         cpu_time,
    38.                rank() over(order by disk_read desc) exec_rank
    39.           from v$sql)
    40. where  exec_rank <= 10
    41. --根据等待事件查询相关的sql语句
    42. select b.*, sq.sql_text
    43.   from v$session se,
    44.        v$sql sq,
    45.        (select a.*
    46.           from v$sql s,
    47.                (select sid, p1
    48.                   from v$session_wait
    49.                  where event = 'library cache: mutex X') a
    50.          where s.hash_value = a.p1) b
    51. where se.sid = b.sid
    52.    and se.sql_hash_value = sq.hash_value
    53. select sql_id
    54.   from v$sql
    55. where hash_value in (select distinct p1 from v$session_wait
    56. where event = 'log file sync')

    57. select sid,serial#,username,blocking_session,ROW_WAIT_OBJ#,ROW_WAIT_BLOCK# from v$session where event='select b.*, sq.sql_text
    58.   from v$session se,
    59.        v$sql sq,
    60.        (select a.*
    61.           from v$sql s,
    62.                (select sid, p1
    63.                   from v$session_wait
    64.                  where event = 'library cache: mutex X') a
    65.          where s.hash_value = a.p1) b
    66. where se.sid = b.sid
    67.    and se.sql_hash_value = sq.hash_value
    68. select sql_id
    69.   from v$sql
    70. where hash_value in (select distinct p1 from v$session_wait
    71. where event = 'log file sync')';
    72. --根据等待事件查询cursor pin s wait on x 的语句
    73. select a.*, s.sql_text
    74.   from v$sql s,
    75.        (select sid,
    76.                event,
    77.                wait_class,
    78.                p1 cursor_hash_value,
    79.                p2raw Mutex_value,
    80.                to_number(substr(p2raw, 1, 8), 'xxxxxxxx') hold_nutex_x_sid
    81.           from v$session_wait
    82.          where event like 'cursor%') a
    83. where s.hash_value = a.cursor_hash_value
    复制代码



    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    运维联盟俱乐部 ( 冀ICP备19036648号 )

    GMT+8, 2024-5-17 11:46 , Processed in 0.046435 second(s), 21 queries , Gzip On.

    Powered by Discuz! X3.4

    © 2001-2023 Discuz! Team.

    快速回复 返回顶部 返回列表