forked from abdulirfan3/Oracle_SQL_Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathawr_event_class_trends.sql
More file actions
383 lines (374 loc) · 20.7 KB
/
Copy pathawr_event_class_trends.sql
File metadata and controls
383 lines (374 loc) · 20.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
/**********************************************************************
* File: awr_evclasstrends.sql
* Type: SQL*Plus script
* Author: Tim Gorman (Evergreen Database Technologies, Inc.)
* Date: 23-Mar 2011
*
* Description:
* Query to display "trends" for event-classes captured in
* the AWR repository, and display summarized totals daily and
* hourly as a ratio using the RATIO_FOR_REPORT analytic function.
*
* The intent is to find the readings with the greatest deviation
* from the average value, as these are likely to be "periods of
* interest" for further, more detailed research...
*
* Modifications:
*********************************************************************/
set echo off feedback off timing off pagesize 500 linesize 160
set trimout on trimspool on verify off
col sort0 noprint
col day format a6 heading "Day"
col hr format a6 heading "Hour"
col tm format a6 heading "Time"
col wait_class format a20 heading "Wait Class Name"
col event_name format a25 truncate heading "Event Name"
col total_waits format 999,990 heading "Total|Waits (m)"
col time_waited format 999,990.00 heading "Secs|Waited"
col tot_wts format 990.00 heading "% Total|Waits"
col tot_pct format 990.00 heading "% Secs|Waited"
col avg_wait format 990.00 heading "Avg|hSecs|Per|Wait"
col avg_pct format 990.00 heading "% Avg|hSecs|Per|Wait"
col wt_graph format a20 heading "Graphical view|of % total|waits overall"
col tot_graph format a20 heading "Graphical view|of % total|secs waited overall"
col avg_graph format a20 heading "Graphical view|of % avg hSecs|per wait overall"
ttitle off
clear breaks computes
col instance_name new_value V_INST_NAME noprint
col instance_number new_value V_INST_NBR noprint
col dbid new_value V_DBID noprint
select i.instance_name,
i.instance_number,
d.dbid
from v$instance i,
v$database d;
accept V_NBR_DAYS prompt "How many days of AWR information should we use? "
ttitle center 'Wait Class totals over the past &&V_NBR_DAYS days' skip line
col total_waits format 999,999,990.00 heading "Waits (m)"
col time_waited format 999,999,990.00 heading "Secs|Waited"
prompt
select wait_class,
total_waits/1000000 total_waits,
(ratio_to_report(total_waits) over ()*100) tot_wts,
rpad('*', round((ratio_to_report(total_waits) over ()*100)/6, 0), '*') wt_graph,
time_waited,
(ratio_to_report(time_waited) over ()*100) tot_pct,
rpad('*', round((ratio_to_report(time_waited) over ()*100)/6, 0), '*') tot_graph,
avg_wait*100 avg_wait,
(ratio_to_report(avg_wait) over ()*100) avg_pct,
rpad('*', round((ratio_to_report(avg_wait) over ()*100)/6, 0), '*') avg_graph
from (select wait_class,
sum(total_waits) total_waits,
sum(time_waited)/1000000 time_waited,
decode(sum(total_waits),0,0,(sum(time_waited)/sum(total_waits))/1000000) avg_wait
from (select s.snap_id,
s.wait_class,
nvl(decode(greatest(s.time_waited_micro,
lag(s.time_waited_micro,1,0)
over (partition by s.dbid,
s.instance_number
order by s.snap_id)),
s.time_waited_micro,
s.time_waited_micro - lag(s.time_waited_micro)
over (partition by s.dbid,
s.instance_number
order by s.snap_id),
s.time_waited_micro), 0) time_waited,
nvl(decode(greatest(s.total_waits,
lag(s.total_waits,1,0)
over (partition by s.dbid,
s.instance_number
order by s.snap_id)),
s.total_waits,
s.total_waits - lag(s.total_waits)
over (partition by s.dbid,
s.instance_number
order by s.snap_id),
s.total_waits), 0) total_waits
from dba_hist_system_event s,
dba_hist_snapshot ss
where s.dbid = &&V_DBID
and s.instance_number = &&V_INST_NBR
and ss.snap_id = s.snap_id
and ss.dbid = s.dbid
and ss.instance_number = s.instance_number
and ss.begin_interval_time >= trunc(sysdate) - &&V_NBR_DAYS)
group by wait_class)
order by time_waited desc;
prompt
accept V_INPUT_CLASSNAME prompt "What wait-event class do you want to analyze? "
ttitle off
clear breaks computes
col classname new_value V_CLASSNAME noprint
col spoolname new_value V_SPOOLNAME noprint
select initcap('&&V_INPUT_CLASSNAME') classname,
replace(replace(replace(replace(lower('&&V_INPUT_CLASSNAME'),' ','_'),'(',''),')',''),'/','') spoolname
from dual;
--spool awr_evclasstrends_&&V_INST_NAME._&&V_SPOOLNAME
clear breaks computes
break on day on report
ttitle center 'Trends for waits on class "&&V_CLASSNAME" over the past &&V_NBR_DAYS days' skip line
col total_waits format 999,990.00 heading "Waits (m)"
col time_waited format 999,990.00 heading "Secs|Waited"
prompt
select event_name,
total_waits/1000000 total_waits,
(ratio_to_report(total_waits) over ()*100) tot_wts,
rpad('*', round((ratio_to_report(total_waits) over ()*100)/6, 0), '*') wt_graph,
time_waited,
(ratio_to_report(time_waited) over ()*100) tot_pct,
rpad('*', round((ratio_to_report(time_waited) over ()*100)/6, 0), '*') tot_graph,
avg_wait*100 avg_wait,
(ratio_to_report(avg_wait) over ()*100) avg_pct,
rpad('*', round((ratio_to_report(avg_wait) over ()*100)/6, 0), '*') avg_graph
from (select event_name,
sum(total_waits) total_waits,
sum(time_waited)/1000000 time_waited,
decode(sum(total_waits),0,0,(sum(time_waited)/sum(total_waits))/1000000) avg_wait
from (select s.snap_id,
s.event_name,
nvl(decode(greatest(s.time_waited_micro,
lag(s.time_waited_micro,1,0)
over (partition by s.dbid,
s.instance_number
order by s.snap_id)),
s.time_waited_micro,
s.time_waited_micro - lag(s.time_waited_micro)
over (partition by s.dbid,
s.instance_number
order by s.snap_id),
s.time_waited_micro), 0) time_waited,
nvl(decode(greatest(s.total_waits,
lag(s.total_waits,1,0)
over (partition by s.dbid,
s.instance_number
order by s.snap_id)),
s.total_waits,
s.total_waits - lag(s.total_waits)
over (partition by s.dbid,
s.instance_number
order by s.snap_id),
s.total_waits), 0) total_waits
from dba_hist_system_event s,
dba_hist_snapshot ss
where s.wait_class = '&&V_CLASSNAME'
and s.dbid = &&V_DBID
and s.instance_number = &&V_INST_NBR
and ss.snap_id = s.snap_id
and ss.dbid = s.dbid
and ss.instance_number = s.instance_number
and ss.begin_interval_time >= trunc(sysdate) - &&V_NBR_DAYS)
group by event_name)
order by time_waited desc;
clear breaks computes
break on day on report
ttitle center 'Daily trends for waits on class "&&V_CLASSNAME" over the past &&V_NBR_DAYS days' skip line
col total_waits format 999,990.00 heading "Waits (m)"
prompt
select sort_day || trim(to_char(999999999999999-time_waited,'000000000000000')) sort0,
day,
event_name,
total_waits/1000000 total_waits,
(ratio_to_report(total_waits) over ()*100) tot_wts,
rpad('*', round((ratio_to_report(total_waits) over ()*100)/6, 0), '*') wt_graph,
time_waited,
(ratio_to_report(time_waited) over ()*100) tot_pct,
rpad('*', round((ratio_to_report(time_waited) over ()*100)/6, 0), '*') tot_graph,
avg_wait*100 avg_wait,
(ratio_to_report(avg_wait) over ()*100) avg_pct,
rpad('*', round((ratio_to_report(avg_wait) over ()*100)/6, 0), '*') avg_graph
from (select sort_day,
day,
event_name,
sum(total_waits) total_waits,
sum(time_waited)/1000000 time_waited,
decode(sum(total_waits),0,0,(sum(time_waited)/sum(total_waits))/1000000) avg_wait
from (select to_char(ss.begin_interval_time, 'YYYYMMDD') sort_day,
to_char(ss.begin_interval_time, 'DD-MON') day,
s.snap_id,
s.event_name,
nvl(decode(greatest(s.time_waited_micro,
lag(s.time_waited_micro,1,0)
over (partition by s.dbid,
s.instance_number
order by s.snap_id)),
s.time_waited_micro,
s.time_waited_micro - lag(s.time_waited_micro)
over (partition by s.dbid,
s.instance_number
order by s.snap_id),
s.time_waited_micro), 0) time_waited,
nvl(decode(greatest(s.total_waits,
lag(s.total_waits,1,0)
over (partition by s.dbid,
s.instance_number
order by s.snap_id)),
s.total_waits,
s.total_waits - lag(s.total_waits)
over (partition by s.dbid,
s.instance_number
order by s.snap_id),
s.total_waits), 0) total_waits
from dba_hist_system_event s,
dba_hist_snapshot ss
where s.wait_class = '&&V_CLASSNAME'
and s.dbid = &&V_DBID
and s.instance_number = &&V_INST_NBR
and ss.snap_id = s.snap_id
and ss.dbid = s.dbid
and ss.instance_number = s.instance_number
and ss.begin_interval_time >= trunc(sysdate) - &&V_NBR_DAYS)
group by sort_day,
day,
event_name)
order by sort0;
clear breaks computes
ttitle center 'Hourly trends for waits on class "&&V_CLASSNAME" over the past &&V_NBR_DAYS days' skip line
col total_waits format 9,990.00 heading "Waits (m)"
break on day skip 1 on hr on report
prompt
select sort_hr || trim(to_char(999999999999999-time_waited,'000000000000000')) sort0,
day,
hr,
event_name,
total_waits/1000000 total_waits,
(ratio_to_report(total_waits) over (partition by day)*100) tot_wts,
rpad('*', round((ratio_to_report(total_waits) over (partition by day)*100)/4, 0), '*') wt_graph,
time_waited,
(ratio_to_report(time_waited) over (partition by day)*100) tot_pct,
rpad('*', round((ratio_to_report(time_waited) over (partition by day)*100)/4, 0), '*') tot_graph,
avg_wait*100 avg_wait,
(ratio_to_report(avg_wait) over (partition by day)*100) avg_pct,
rpad('*', round((ratio_to_report(avg_wait) over (partition by day)*100)/4, 0), '*') avg_graph
from (select sort_hr,
day,
hr,
event_name,
sum(total_waits) total_waits,
sum(time_waited)/1000000 time_waited,
decode(sum(total_waits),0,0,(sum(time_waited)/sum(total_waits))/1000000) avg_wait
from (select to_char(ss.begin_interval_time, 'YYYYMMDDHH24') sort_hr,
to_char(ss.begin_interval_time, 'DD-MON') day,
to_char(ss.begin_interval_time, 'HH24')||':00' hr,
s.snap_id,
event_name,
nvl(decode(greatest(s.time_waited_micro,
lag(s.time_waited_micro,1,0)
over (partition by s.dbid,
s.instance_number
order by s.snap_id)),
s.time_waited_micro,
s.time_waited_micro - lag(s.time_waited_micro)
over (partition by s.dbid,
s.instance_number
order by s.snap_id),
s.time_waited_micro), 0) time_waited,
nvl(decode(greatest(s.total_waits,
lag(s.total_waits,1,0)
over (partition by s.dbid,
s.instance_number
order by s.snap_id)),
s.total_waits,
s.total_waits - lag(s.total_waits)
over (partition by s.dbid,
s.instance_number
order by s.snap_id),
s.total_waits), 0) total_waits
from dba_hist_system_event s,
dba_hist_snapshot ss
where s.wait_class = '&&V_CLASSNAME'
and s.dbid = &&V_DBID
and s.instance_number = &&V_INST_NBR
and ss.snap_id = s.snap_id
and ss.dbid = s.dbid
and ss.instance_number = s.instance_number
and ss.begin_interval_time >= trunc(sysdate) - &&V_NBR_DAYS)
group by sort_hr,
day,
hr,
event_name)
order by sort0;
ttitle off
clear breaks computes
col avg_snap_frequency new_value V_AVG_SNAP_FREQUENCY noprint
select decode(greatest(count(*), &&V_NBR_DAYS * 4), &&V_NBR_DAYS * 4, 'HOURLY', 'MULTIPLE TIMES/HOUR') avg_snap_frequency
from (select count(*) cnt
from dba_hist_snapshot
where begin_interval_time >= trunc(sysdate) - &&V_NBR_DAYS
and dbid = &&V_DBID
and instance_number = &&V_INST_NBR
group by trunc(begin_interval_time, 'HH24')
having count(*) > 1);
ttitle center 'Snapshot-by-snapshot trends for waits on class "&&V_CLASSNAME" over the past &&V_NBR_DAYS days' skip line
select sort_snap || trim(to_char(999999999999999-time_waited,'000000000000000')) sort0,
day,
tm,
event_name,
total_waits/1000000 total_waits,
(ratio_to_report(total_waits) over (partition by day)*100) tot_wts,
rpad('*', round((ratio_to_report(total_waits) over (partition by day)*100)/4, 0), '*') wt_graph,
time_waited,
(ratio_to_report(time_waited) over (partition by day)*100) tot_pct,
rpad('*', round((ratio_to_report(time_waited) over (partition by day)*100)/4, 0), '*') tot_graph,
avg_wait*100 avg_wait,
(ratio_to_report(avg_wait) over (partition by day)*100) avg_pct,
rpad('*', round((ratio_to_report(avg_wait) over (partition by day)*100)/4, 0), '*') avg_graph
from (select sort_snap,
day,
tm,
event_name,
total_waits total_waits,
time_waited/1000000 time_waited,
decode(total_waits,0,0,((time_waited/total_waits)/1000000)) avg_wait
from (select to_char(ss.begin_interval_time, 'YYYYMMDDHH24MI') sort_snap,
to_char(ss.begin_interval_time, 'DD-MON') day,
to_char(ss.begin_interval_time, 'HH24:MI') tm,
s.snap_id,
event_name,
nvl(decode(greatest(s.time_waited_micro,
lag(s.time_waited_micro,1,0)
over (partition by s.dbid,
s.instance_number
order by s.snap_id)),
s.time_waited_micro,
s.time_waited_micro - lag(s.time_waited_micro)
over (partition by s.dbid,
s.instance_number
order by s.snap_id),
s.time_waited_micro), 0) time_waited,
nvl(decode(greatest(s.total_waits,
lag(s.total_waits,1,0)
over (partition by s.dbid,
s.instance_number
order by s.snap_id)),
s.total_waits,
s.total_waits - lag(s.total_waits)
over (partition by s.dbid,
s.instance_number
order by s.snap_id),
s.total_waits), 0) total_waits
from dba_hist_system_event s,
dba_hist_snapshot ss
where '&&V_AVG_SNAP_FREQUENCY' <> 'HOURLY'
and s.wait_class = '&&V_CLASSNAME'
and s.dbid = &&V_DBID
and s.instance_number = &&V_INST_NBR
and ss.snap_id = s.snap_id
and ss.dbid = s.dbid
and ss.instance_number = s.instance_number
and ss.begin_interval_time >= trunc(sysdate) - &&V_NBR_DAYS))
order by sort0;
--spool off
ttitle off
clear breaks computes
set feedback 6 verify on pagesize 100 echo off linesize 1500
set pages 100 lines 1500
set termout on
--set time on
set timi on
--Sets the column separator character printed between columns in output.
SET COLSEP '|'
SET verify OFF
-- to remove spaces (white spaces)
SET tab off
set arraysize 100;