运维联盟俱乐部

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

[日常管理] Script To Monitor Parallel Queries/SQL (Doc ID 457857.1)

[复制链接]
  • TA的每日心情
    开心
    2023-8-9 11:05
  • 发表于 2021-11-11 09:43:46 | 显示全部楼层 |阅读模式
    Purpose
    The script has 4 SQL commands. The first 1 gives an overview of all running parallel queries with all slaves. It shows whether a slave is waiting and for what event it waits. The second command shows for the PX Deq events the processes that are exchange data. The third 1 shows for long running processes what are the slaves do.  The fourth 1 shows what sqls are currently executing, and what is queued
    Requirements

    This is designed to work in SQL Plus. It also works with other tools, but than the formating is lost.
    Configuring

    The script needs privileges to do a select on  gv$px_session, gv$px_process gv$session_longops , gv$session_wait, gv$session and gv$sql_monitor
    Instructions

    You can run the the complete script or use only some of the SQL commands to monitor your database.
    Caution
    This sample code is provided for educational purposes only, and is not supported by Oracle Support. It has been tested internally, however, we do not guarantee that it will work for you. Ensure that you run it in your test environment before using.

    1. col username for a12
    2. col "QC SID" for A6
    3. col "SID" for A6
    4. col "QC/Slave" for A8
    5. col "Req. DOP" for 9999
    6. col "Actual DOP" for 9999
    7. col "Slaveset" for A8
    8. col "Slave INST" for A9
    9. col "QC INST" for A6
    10. set lines 250 pages 5000
    11. col wait_event format a30
    12. select
    13. decode(px.qcinst_id,NULL,username,
    14. ' - '||lower(substr(pp.SERVER_NAME,
    15. length(pp.SERVER_NAME)-4,4) ) )"Username",
    16. decode(px.qcinst_id,NULL, 'QC', '(Slave)') "QC/Slave" ,
    17. to_char( px.server_set) "SlaveSet",
    18. to_char(s.sid) "SID",
    19. to_char(px.inst_id) "Slave INST",
    20. decode(sw.state,'WAITING', 'WAIT', 'NOT WAIT' ) as STATE,
    21. case sw.state WHEN 'WAITING' THEN substr(sw.event,1,30) ELSE NULL end as wait_event ,
    22. decode(px.qcinst_id, NULL ,to_char(s.sid) ,px.qcsid) "QC SID",
    23. to_char(px.qcinst_id) "QC INST",
    24. px.req_degree "Req. DOP",
    25. px.degree "Actual DOP"
    26. from gv$px_session px,
    27. gv$session s ,
    28. gv$px_process pp,
    29. gv$session_wait sw
    30. where px.sid=s.sid (+)
    31. and px.serial#=s.serial#(+)
    32. and px.inst_id = s.inst_id(+)
    33. and px.sid = pp.sid (+)
    34. and px.serial#=pp.serial#(+)
    35. and sw.sid = s.sid
    36. and sw.inst_id = s.inst_id
    37. order by
    38. decode(px.QCINST_ID, NULL, px.INST_ID, px.QCINST_ID),
    39. px.QCSID,
    40. decode(px.SERVER_GROUP, NULL, 0, px.SERVER_GROUP),
    41. px.SERVER_SET,
    42. px.INST_ID
    43. /


    44. set lines 250 pages 5000
    45. col wait_event format a30
    46. select
    47. sw.SID as RCVSID,
    48. decode(pp.server_name,
    49. NULL, 'A QC',
    50. pp.server_name) as RCVR,
    51. sw.inst_id as RCVRINST,
    52. case sw.state WHEN 'WAITING' THEN substr(sw.event,1,30) ELSE NULL end as wait_event ,
    53. decode(bitand(p1, 65535),
    54. 65535, 'QC',
    55. 'P'||to_char(bitand(p1, 65535),'fm000')) as SNDR,
    56. mod(bitand(p1,16711680) , 65535) as SNDRINST,
    57. decode(bitand(p1, 65535),
    58. 65535, ps.qcsid,
    59. (select
    60. sid
    61. from
    62. gv$px_process
    63. where
    64. server_name = 'P'||to_char(bitand(sw.p1, 65535),'fm000') and
    65. inst_id = bitand(sw.p1, 16711680) - 65535)
    66. ) as SNDRSID,
    67. decode(sw.state,'WAITING', 'WAIT', 'NOT WAIT' ) as STATE
    68. from
    69. gv$session_wait sw,
    70. gv$px_process pp,
    71. gv$px_session ps
    72. where
    73. sw.sid = pp.sid (+) and
    74. sw.inst_id = pp.inst_id (+) and
    75. sw.sid = ps.sid (+) and
    76. sw.inst_id = ps.inst_id (+) and
    77. p1text = 'sleeptime/senderid' and
    78. bitand(p1, 268435456) = 268435456
    79. order by
    80. decode(ps.QCINST_ID, NULL, ps.INST_ID, ps.QCINST_ID),
    81. ps.QCSID,
    82. decode(ps.SERVER_GROUP, NULL, 0, ps.SERVER_GROUP),
    83. ps.SERVER_SET,
    84. ps.INST_ID
    85. /


    86. set lines 250 pages 5000
    87. col "Username" for a12
    88. col "QC/Slave" for A8
    89. col "Slaveset" for A8
    90. col "Slave INST" for A9
    91. col "QC SID" for A6
    92. col "QC INST" for A6
    93. col "operation_name" for A30
    94. col "target" for A30
    95. select
    96. decode(px.qcinst_id,NULL,username,
    97. ' - '||lower(substr(pp.SERVER_NAME,
    98. length(pp.SERVER_NAME)-4,4) ) )"Username",
    99. decode(px.qcinst_id,NULL, 'QC', '(Slave)') "QC/Slave" ,
    100. to_char( px.server_set) "SlaveSet",
    101. to_char(px.inst_id) "Slave INST",
    102. substr(opname,1,30) operation_name,
    103. substr(target,1,30) target,
    104. sofar,
    105. totalwork,
    106. units,
    107. start_time,
    108. timestamp,
    109. decode(px.qcinst_id, NULL ,to_char(s.sid) ,px.qcsid) "QC SID",
    110. to_char(px.qcinst_id) "QC INST"
    111. from gv$px_session px,
    112. gv$px_process pp,
    113. gv$session_longops s
    114. where px.sid=s.sid
    115. and px.serial#=s.serial#
    116. and px.inst_id = s.inst_id
    117. and px.sid = pp.sid (+)
    118. and px.serial#=pp.serial#(+)
    119. order by
    120. decode(px.QCINST_ID, NULL, px.INST_ID, px.QCINST_ID),
    121. px.QCSID,
    122. decode(px.SERVER_GROUP, NULL, 0, px.SERVER_GROUP),
    123. px.SERVER_SET,
    124. px.INST_ID
    125. /


    126. set lines 250 pages 5000
    127. col sql_text for a50
    128. col sid for 99999
    129. col status for a11
    130. col slv_req for 99999
    131. col slv_alloc for 99999
    132. col sql_id format a16
    133. col secs_in_q for 99999
    134. SELECT sql_id, sid,
    135. session_serial# sess#,
    136. status ,
    137. px_servers_requested slv_req,
    138. px_servers_allocated slv_alloc,
    139. substr(sql_text,1,50)||'...' sql_text,
    140. queuing_time/1000000 secs_in_q
    141. FROM gv$sql_monitor
    142. WHERE status in ('QUEUED','EXECUTING') and sql_text is not null
    143. ORDER BY status desc, secs_in_q desc, sql_id
    144. /
    复制代码
    1. set linesize 120
    2. col sql_text for a50
    3. col sid for 9999
    4. col status for a10
    5. col slv_req for 999
    6. col slv_alloc for 999
    7. col secs_in_q for 99999
    8. SELECT sql_id,
    9.        sid,
    10.        session_serial# sess#,
    11.        status ,
    12.        px_servers_requested slv_req,
    13.        px_servers_allocated slv_alloc,
    14.        substr(sql_text,1,50)||'...' sql_text,
    15.        queuing_time/1000000 secs_in_q
    16. FROM gv$sql_monitor
    17. WHERE  status in ('QUEUED','EXECUTING') and sql_text is not null
    18. ORDER BY status desc, secs_in_q desc, sql_id;
    复制代码




    回复

    使用道具 举报

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

    本版积分规则

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

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

    Powered by Discuz! X3.4

    © 2001-2023 Discuz! Team.

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