Advertisement
BrokeDBA

check_wait_class.sql

Jun 2nd, 2021
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.55 KB | None | 0 0
  1. Set verify off
  2. set feed off
  3. set echo off
  4. undefine CLASS
  5.  
  6. /*
  7. V$SYSMETRIC – last 15 and 60 seconds
  8. V$SYSMETRIC_SUMMARY – values last hour (last snapshot) like avg, max, min etc
  9. V$SYSMETRIC_HISTORY – last hour for 1 minute, last 3 mintes for 15 second deltas
  10. DBA_HIST_SYSMETRIC_SUMMARY – hour summaries for last week.
  11. V$SYSTEM_WAIT_CLASS – cumulative since start up
  12. V$WAITCLASSMETRIC – last 60 seconds deltas
  13. V$WAITCLASSMETRIC_HISTORY – 60 seconds deltas for last hour
  14.  
  15. The relationships between the statistics:
  16.  
  17. 1) background elapsed time
  18. 2) background cpu time
  19. 3) RMAN cpu time (backup/restore)
  20. 1) DB time
  21. 2) DB CPU
  22. 2) connection management call elapsed time
  23. 2) sequence load elapsed time
  24. 2) sql execute elapsed time
  25. 2) parse time elapsed
  26. 3) hard parse elapsed time
  27. 4) hard parse (sharing criteria) elapsed time
  28. 5) hard parse (bind mismatch) elapsed time
  29. 3) failed parse elapsed time
  30. 4) failed parse (out of shared memory) elapsed time
  31. 2) PL/SQL execution elapsed time
  32. 2) inbound PL/SQL rpc elapsed time
  33. 2) PL/SQL compilation elapsed time
  34. 2) Java execution elapsed time
  35. 2) repeated bind elapsed time
  36. Children do not necessarily add up to the parent.
  37.  
  38. Children are not necessarily exclusive (that is, it is possible that they overlap).
  39.  
  40. The union of children does not necessarily cover the whole of the parent.
  41. WAIT_CLASS WAIT_CLASS_ID WAIT_CLASS#
  42. ------------------------- ------------- -----------
  43. Other 1893977003 0
  44. Application 4217450380 1
  45. Configuration 3290255840 2
  46. Concurrency 3875070507 4
  47. Commit 3386400367 5
  48. Idle 2723168908 6
  49. Network 2000153315 7
  50. User I/O 1740759767 8
  51. System I/O 4108307767 9
  52.  
  53. */
  54. REM DB TIME vs CPU Time last hour
  55. col C1 heading " WAIT_CLASS| EVENT" for a40
  56.  
  57. select s.Begin_time ,s.End_time,s.METRIC_NAME,round(MINVAL,2) MINIMUM,round(MAXVAL,2) MAXIMUM,round(AVERAGE,2) AVERAGE,round(VALUE,2) "CURRENT",s.METRIC_UNIT
  58. from SYS.V_$SYSMETRIC_SUMMARY s JOIN SYS.V_$SYSMETRIC m on (s.METRIC_NAME=m.METRIC_NAME)
  59. where s.METRIC_NAME IN ('Database CPU Time Ratio','Database Wait Time Ratio') AND
  60. m.INTSIZE_CSEC = (select max(INTSIZE_CSEC) from SYS.V_$SYSMETRIC)
  61. /
  62.  
  63. prompt===================================================================================================
  64.  
  65. prompt
  66. prompt-Administrative/: Waits caused by administrative commands, such as rebuilding an index, for example.
  67. prompt-Application/: Waits due to the application code.
  68. prompt-Commit/: Waits caused by commits in the database(log file sync event).
  69. prompt-Concurrency/: Waits for resources used for locking; for example, latches.
  70. prompt-Configuration/: Waits caused by database or instance configuration problems(example: low shared-pool memory size).
  71. prompt-Cluster/: Waits related to RAC Cluster management.
  72. prompt-Idle/: Waits when a session isn’t active;(i.e ‘SQL*Net message from client’ wait event.
  73.  
  74. col WAIT_CLASS for a25
  75. select WAIT_CLASS,
  76. TOTAL_WAITS,
  77. round(100 * (TOTAL_WAITS / SUM_WAITS),2) PCT_WAITS,
  78. ROUND((TIME_WAITED / 100),2) TIME_WAITED_SECS,
  79. round(100 * (TIME_WAITED / SUM_TIME),2) PCT_TIME,
  80. BEGIN_TIME,END_TIME
  81. from
  82. (select
  83. b.WAIT_CLASS,
  84. SUM(a.WAIT_COUNT) TOTAL_WAITS ,
  85. SUM(a.TIME_WAITED)TIME_WAITED,
  86. to_char(trunc(min(a.begin_time),'MI'),'DD-MON-YY HH24:MI') BEGIN_TIME,to_char(trunc(max(a.end_time),'MI'),'DD-MON-YY HH24:MI') END_TIME
  87. from v$waitclassmetric_history a,V$SYSTEM_WAIT_CLASS b
  88. where WAIT_CLASS != 'Idle'
  89. and a.wait_class# = b.wait_class#
  90. GROUP BY b.wait_class),
  91. (select sum(a.WAIT_COUNT) SUM_WAITS,
  92. sum(a.TIME_WAITED) SUM_TIME
  93. from v$waitclassmetric_history a,V$SYSTEM_WAIT_CLASS b
  94. where b.WAIT_CLASS != 'Idle'
  95. and a.wait_class# = b.wait_class# )
  96. order by 5 desc;
  97.  
  98. column wait_type format a35 heading "Wait Type"
  99. column lock_name format a12
  100. column waits_1000 format 99,999,999 heading "Waits|\1000"
  101. column time_waited_hours format 99,999.99 heading "Time|Hours"
  102. column pct format 99.99 Heading "Pct"
  103. column avg_wait_ms format 9,999.99 heading "Avg Wait|Ms"
  104. set pagesize 10000
  105. set lines 150
  106.  
  107. WITH system_event AS
  108. (SELECT CASE
  109. WHEN wait_class IN ('User I/O', 'System I/O')
  110. THEN event ELSE wait_class
  111. END wait_type, e.*
  112. FROM v$system_event e)
  113. SELECT wait_type, SUM(total_waits) / 1000 waits_1000,
  114. ROUND(SUM(time_waited_micro) / 1000000 / 3600, 2)
  115. time_waited_hours,
  116. ROUND(SUM(time_waited_micro) / SUM(total_waits) / 1000, 2)
  117. avg_wait_ms,
  118. ROUND( SUM(time_waited_micro)
  119. * 100
  120. / SUM(SUM(time_waited_micro)) OVER (), 2)
  121. pct
  122. FROM (SELECT wait_type, event, total_waits, time_waited_micro
  123. FROM system_event e
  124. UNION
  125. SELECT 'CPU', stat_name, NULL, VALUE
  126. FROM v$sys_time_model
  127. WHERE stat_name IN ('background cpu time', 'DB CPU')) l
  128. WHERE wait_type <> 'Idle'
  129. GROUP BY wait_type
  130. HAVING ROUND(SUM(time_waited_micro) / 1000000, 2) >0
  131. ORDER BY SUM(time_waited_micro) DESC,wait_type
  132. /
  133.  
  134. Prompt select WAIT_CLASS: Other ,User I/O ,Concurrency ,System I/O,Commit,Configuration,Application,Administrative
  135.  
  136. Select '==> PARENT WAIT_CLASS STAT: '||WAIT_CLASS c1,
  137. TOTAL_WAITS,
  138. round(100 * (TOTAL_WAITS / SUM_WAITS),2) PCT_WAITS,
  139. ROUND((TIME_WAITED / 100),2) TIME_WAITED_SECS,
  140. round(100 * (TIME_WAITED / SUM_TIME),2) PCT_TIME
  141. from
  142. (select WAIT_CLASS,
  143. TOTAL_WAITS,
  144. TIME_WAITED
  145. from V$SYSTEM_WAIT_CLASS where WAIT_CLASS = '&&CLASS'),
  146. (select sum(TOTAL_WAITS) SUM_WAITS,
  147. sum(TIME_WAITED) SUM_TIME
  148. from V$SYSTEM_WAIT_CLASS where WAIT_CLASS!= 'Idle')
  149. union
  150. Select EVENT,
  151. TOTAL_WAITS,
  152. round(100 * (TOTAL_WAITS / SUM_WAITS),2) PCT_WAITS,
  153. ROUND((TIME_WAITED / 100),2) TIME_WAITED_SECS,
  154. round(100 * (TIME_WAITED / SUM_TIME),2) PCT_TIME
  155. From ( select EVENT,
  156. TOTAL_WAITS,
  157. TIME_WAITED
  158. from V$SYSTEM_EVENT where WAIT_CLASS = '&&CLASS'),
  159. (select sum(TOTAL_WAITS) SUM_WAITS,
  160. sum(TIME_WAITED) SUM_TIME
  161. from V$SYSTEM_EVENT where WAIT_CLASS= '&&CLASS')
  162. WHERE ROUND((TIME_WAITED / 100),2)>0
  163. order by 1 desc,5 desc
  164. /
  165.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement