-
Notifications
You must be signed in to change notification settings - Fork 9
/
run_awr_topsegments_advisor.sql
1037 lines (969 loc) · 46.9 KB
/
run_awr_topsegments_advisor.sql
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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- awr_topsqlx-exa.sql
-- AWR Top SQL Report, a version of "Top SQL" but across SNAP_IDs with AAS metric and more details
-- Karl Arao, Oracle ACE (bit.ly/karlarao), OCP-DBA, RHCE
-- http://karlarao.wordpress.com
--
-- NOTES: SEE COMMENTS ON THE SCRIPT..ESPECIALLY ON SQL_TEXT, TIME_RANK, AND ORDER BY SECTIONS
--
-- Changes:
-- 20100512 added timestamp to filter specific workload periods, must uncomment to use
-- 20120825 added the join of dba_hist_sqltext to audit_actions to show the short name of command_type
set feedback off pages 0 term off head on und off trimspool on echo off lines 4000 colsep ','
set arraysize 5000
set termout off
set echo off verify off
COLUMN blocksize NEW_VALUE _blocksize NOPRINT
select distinct block_size blocksize from v$datafile;
COLUMN dbid NEW_VALUE _dbid NOPRINT
select dbid from v$database;
COLUMN name NEW_VALUE _instname NOPRINT
select lower(instance_name) name from v$instance;
COLUMN name NEW_VALUE _hostname NOPRINT
select lower(host_name) name from v$instance;
COLUMN instancenumber NEW_VALUE _instancenumber NOPRINT
select instance_number instancenumber from v$instance;
-- ttitle center 'AWR Top SQL Report' skip 2
set pagesize 50000
set linesize 1500
col snap_id format 99999 heading -- "Snap|ID"
col tm format a15 heading -- "Snap|Start|Time"
col inst format 90 heading -- "i|n|s|t|#"
col dur format 990.00 heading -- "Snap|Dur|(m)"
col sql_id format a15 heading -- "SQL|ID"
col phv format 99999999999 heading -- "Plan|Hash|Value"
col module format a50
col action format a50
col elap format 999990.00 heading -- "Ela|Time|(s)"
col elapexec format 999990.00 heading -- "Ela|Time|per|exec|(s)"
col cput format 999990.00 heading -- "CPU|Time|(s)"
col iowait format 999990.00 heading -- "IO|Wait|(s)"
col appwait format 999990.00 heading -- "App|Wait|(s)"
col concurwait format 999990.00 heading -- "Ccr|Wait|(s)"
col clwait format 999990.00 heading -- "Cluster|Wait|(s)"
col bget format 99999999990 heading -- "LIO"
col dskr format 99999999990 heading -- "PIO"
col dpath format 99999999990 heading -- "Direct|Writes"
col rowp format 99999999990 heading -- "Rows"
col exec format 9999990 heading -- "Exec"
col prsc format 999999990 heading -- "Parse|Count"
col pxexec format 9999990 heading -- "PX|Server|Exec"
col icbytes format 99999990 heading -- "IC|MB"
col offloadbytes format 99999990 heading -- "Offload|MB"
col offloadreturnbytes format 99999990 heading -- "Offload|return|MB"
col flashcachereads format 99999990 heading -- "Flash|Cache|MB"
col uncompbytes format 99999990 heading -- "Uncomp|MB"
col pctdbt format 990 heading -- "DB Time|%"
col aas format 990.00 heading -- "A|A|S"
col time_rank format 90 heading -- "Time|Rank"
col sql_text format a6 heading -- "SQL|Text"
col fms format 99999999999999999999999999
VARIABLE g_retention NUMBER
DEFINE p_default = 8
DEFINE p_max = 300
SET VERIFY OFF
DECLARE
v_default NUMBER(3) := &p_default;
v_max NUMBER(3) := &p_max;
BEGIN
select
((TRUNC(SYSDATE) + RETENTION - TRUNC(SYSDATE)) * 86400)/60/60/24 AS RETENTION_DAYS
into :g_retention
from dba_hist_wr_control
where dbid in (select dbid from v$database);
if :g_retention > v_default then
:g_retention := v_max;
else
:g_retention := v_default;
end if;
END;
/
spool awr_topsqlx-tableau-exa-&_instname-&_hostname..csv
select *
from (
select
trim('&_instname') instname,
trim('&_dbid') db_id,
trim('&_hostname') hostname,
sqt.snap_id snap_id,
TO_CHAR(sqt.tm,'MM/DD/YY HH24:MI:SS') tm,
sqt.inst inst,
sqt.dur dur,
sqt.aas aas,
nvl((sqt.elap), to_number(null)) elap,
nvl((sqt.elapexec), 0) elapexec,
nvl((sqt.cput), to_number(null)) cput,
sqt.iowait iowait,
sqt.appwait appwait,
sqt.concurwait concurwait,
sqt.clwait clwait,
sqt.bget bget,
sqt.dskr dskr,
sqt.dpath dpath,
sqt.rowp rowp,
sqt.exec exec,
sqt.prsc prsc,
sqt.pxexec pxexec,
sqt.icbytes,
sqt.offloadbytes,
sqt.offloadreturnbytes,
sqt.flashcachereads,
sqt.uncompbytes,
sqt.time_rank time_rank,
sqt.sql_id sql_id,
sqt.phv phv,
sqt.fms fms,
sqt.parse_schema parse_schema,
substr(to_clob(decode(sqt.module, null, null, sqt.module)),1,50) module,
substr(to_clob(decode(sqt.action, null, null, sqt.action)),1,50) action,
st.sql_text sql_text -- PUT/REMOVE COMMENT TO HIDE/SHOW THE SQL_TEXT
from (
select snap_id, tm, inst, dur, sql_id, phv, fms, parse_schema, module, action, elap, elapexec, cput, iowait, appwait, concurwait, clwait, bget, dskr, dpath, rowp, exec, prsc, pxexec, icbytes, offloadbytes, offloadreturnbytes, flashcachereads, uncompbytes, aas, time_rank
from
(
select
s0.snap_id snap_id,
s0.END_INTERVAL_TIME tm,
s0.instance_number inst,
round(EXTRACT(DAY FROM s1.END_INTERVAL_TIME - s0.END_INTERVAL_TIME) * 1440
+ EXTRACT(HOUR FROM s1.END_INTERVAL_TIME - s0.END_INTERVAL_TIME) * 60
+ EXTRACT(MINUTE FROM s1.END_INTERVAL_TIME - s0.END_INTERVAL_TIME)
+ EXTRACT(SECOND FROM s1.END_INTERVAL_TIME - s0.END_INTERVAL_TIME) / 60, 2) dur,
e.sql_id sql_id,
e.plan_hash_value phv,
e.force_matching_signature fms,
e.parsing_schema_name parse_schema,
max(e.module) module,
max(e.action) action,
sum(e.elapsed_time_delta)/1000000 elap,
decode((sum(e.executions_delta)), 0, to_number(null), ((sum(e.elapsed_time_delta)) / (sum(e.executions_delta)) / 1000000)) elapexec,
sum(e.cpu_time_delta)/1000000 cput,
sum(e.iowait_delta)/1000000 iowait,
sum(e.apwait_delta)/1000000 appwait,
sum(e.ccwait_delta)/1000000 concurwait,
sum(e.clwait_delta)/1000000 clwait,
sum(e.buffer_gets_delta) bget,
sum(e.disk_reads_delta) dskr,
sum(e.direct_writes_delta) dpath,
sum(e.rows_processed_delta) rowp,
sum(e.executions_delta) exec,
sum(e.parse_calls_delta) prsc,
sum(e.px_servers_execs_delta) pxexec,
sum(e.io_interconnect_bytes_delta)/1024/1024 icbytes,
sum(e.io_offload_elig_bytes_delta)/1024/1024 offloadbytes,
sum(e.io_offload_return_bytes_delta)/1024/1024 offloadreturnbytes,
(sum(e.optimized_physical_reads_delta)* &_blocksize)/1024/1024 flashcachereads,
sum(e.cell_uncompressed_bytes_delta)/1024/1024 uncompbytes,
(sum(e.elapsed_time_delta)/1000000) / ((round(EXTRACT(DAY FROM s1.END_INTERVAL_TIME - s0.END_INTERVAL_TIME) * 1440
+ EXTRACT(HOUR FROM s1.END_INTERVAL_TIME - s0.END_INTERVAL_TIME) * 60
+ EXTRACT(MINUTE FROM s1.END_INTERVAL_TIME - s0.END_INTERVAL_TIME)
+ EXTRACT(SECOND FROM s1.END_INTERVAL_TIME - s0.END_INTERVAL_TIME) / 60, 2))*60) aas,
DENSE_RANK() OVER (
PARTITION BY s0.snap_id ORDER BY e.elapsed_time_delta DESC) time_rank
from
dba_hist_snapshot s0,
dba_hist_snapshot s1,
dba_hist_sqlstat e
where
s0.dbid = &_dbid -- CHANGE THE DBID HERE!
AND s1.dbid = s0.dbid
and e.dbid = s0.dbid
--AND s0.instance_number = &_instancenumber -- CHANGE THE INSTANCE_NUMBER HERE!
AND s1.instance_number = s0.instance_number
and e.instance_number = s0.instance_number
AND s1.snap_id = s0.snap_id + 1
and e.snap_id = s0.snap_id + 1
group by
s0.snap_id, s0.END_INTERVAL_TIME, s0.instance_number, e.sql_id, e.plan_hash_value, e.force_matching_signature, e.parsing_schema_name, e.elapsed_time_delta, s1.END_INTERVAL_TIME - s0.END_INTERVAL_TIME
)
where
time_rank <= 5 -- GET TOP 5 SQL ACROSS SNAP_IDs... YOU CAN ALTER THIS TO HAVE MORE DATA POINTS
)
sqt,
(select sql_id, dbid, nvl(b.name, a.command_type) sql_text from dba_hist_sqltext a, audit_actions b where a.command_type = b.action(+)) st
where st.sql_id(+) = sqt.sql_id
and st.dbid(+) = &_dbid
-- AND TO_CHAR(tm,'D') >= 1 -- Day of week: 1=Sunday 7=Saturday
-- AND TO_CHAR(tm,'D') <= 7
-- AND TO_CHAR(tm,'HH24MI') >= 0900 -- Hour
-- AND TO_CHAR(tm,'HH24MI') <= 1800
-- AND tm >= TO_DATE('2010-jan-17 00:00:00','yyyy-mon-dd hh24:mi:ss') -- Data range
-- AND tm <= TO_DATE('2010-aug-22 23:59:59','yyyy-mon-dd hh24:mi:ss')
-- AND snap_id in (338,339)
-- AND snap_id = 338
-- AND snap_id >= 335 and snap_id <= 339
-- AND lower(st.sql_text) like 'select%'
-- AND lower(st.sql_text) like 'insert%'
-- AND lower(st.sql_text) like 'update%'
-- AND lower(st.sql_text) like 'merge%'
-- AND pxexec > 0
-- AND aas > .5
order by
snap_id -- TO GET SQL OUTPUT ACROSS SNAP_IDs SEQUENTIALLY AND ASC
-- nvl(sqt.elap, -1) desc, sqt.sql_id -- TO GET SQL OUTPUT BY ELAPSED TIME
)
-- where rownum <= 20
WHERE
to_date(tm,'MM/DD/YY HH24:MI:SS') > sysdate - :g_retention
;
spool off
host sed -n -i '2,$ p' awr_topsqlx-tableau-exa-&_instname-&_hostname..csv
-- host gzip -v awr_topsqlx-tableau-exa-&_instname-&_hostname..csv
-- host tar -cvf awr_topsqlx-tableau-exa-&_instname-&_hostname..tar awr_topsqlx-tableau-exa-&_instname-&_hostname..csv.gz
-- host rm awr_topsqlx-tableau-exa-&_instname-&_hostname..csv.gz
-- awr_topsqlx-exa.sql
-- AWR Top SQL Report, a version of "Top SQL" but across SNAP_IDs with AAS metric and more details
-- Karl Arao, Oracle ACE (bit.ly/karlarao), OCP-DBA, RHCE
-- http://karlarao.wordpress.com
--
-- NOTES: SEE COMMENTS ON THE SCRIPT..ESPECIALLY ON SQL_TEXT, TIME_RANK, AND ORDER BY SECTIONS
--
-- Changes:
-- 20100512 added timestamp to filter specific workload periods, must uncomment to use
-- 20120825 added the join of dba_hist_sqltext to audit_actions to show the short name of command_type
set feedback off pages 0 term off head on und off trimspool on echo off lines 4000 colsep ','
set arraysize 5000
set termout off
set echo off verify off
COLUMN blocksize NEW_VALUE _blocksize NOPRINT
select distinct block_size blocksize from v$datafile;
COLUMN dbid NEW_VALUE _dbid NOPRINT
select dbid from v$database;
COLUMN name NEW_VALUE _instname NOPRINT
select lower(instance_name) name from v$instance;
COLUMN name NEW_VALUE _hostname NOPRINT
select lower(host_name) name from v$instance;
COLUMN instancenumber NEW_VALUE _instancenumber NOPRINT
select instance_number instancenumber from v$instance;
-- ttitle center 'AWR Top SQL Report' skip 2
set pagesize 50000
set linesize 1500
col snap_id format 99999 heading -- "Snap|ID"
col tm format a15 heading -- "Snap|Start|Time"
col inst format 90 heading -- "i|n|s|t|#"
col dur format 990.00 heading -- "Snap|Dur|(m)"
col sql_id format a15 heading -- "SQL|ID"
col phv format 99999999999 heading -- "Plan|Hash|Value"
col module format a50
col action format a50
col elap format 999990.00 heading -- "Ela|Time|(s)"
col elapexec format 999990.00 heading -- "Ela|Time|per|exec|(s)"
col cput format 999990.00 heading -- "CPU|Time|(s)"
col iowait format 999990.00 heading -- "IO|Wait|(s)"
col appwait format 999990.00 heading -- "App|Wait|(s)"
col concurwait format 999990.00 heading -- "Ccr|Wait|(s)"
col clwait format 999990.00 heading -- "Cluster|Wait|(s)"
col bget format 99999999990 heading -- "LIO"
col dskr format 99999999990 heading -- "PIO"
col dpath format 99999999990 heading -- "Direct|Writes"
col rowp format 99999999990 heading -- "Rows"
col exec format 9999990 heading -- "Exec"
col prsc format 999999990 heading -- "Parse|Count"
col pxexec format 9999990 heading -- "PX|Server|Exec"
col icbytes format 99999990 heading -- "IC|MB"
col offloadbytes format 99999990 heading -- "Offload|MB"
col offloadreturnbytes format 99999990 heading -- "Offload|return|MB"
col flashcachereads format 99999990 heading -- "Flash|Cache|MB"
col uncompbytes format 99999990 heading -- "Uncomp|MB"
col pctdbt format 990 heading -- "DB Time|%"
col aas format 990.00 heading -- "A|A|S"
col time_rank format 90 heading -- "Time|Rank"
col sql_text format a6 heading -- "SQL|Text"
col fms format 99999999999999999999999999
VARIABLE g_retention NUMBER
DEFINE p_default = 8
DEFINE p_max = 300
SET VERIFY OFF
DECLARE
v_default NUMBER(3) := &p_default;
v_max NUMBER(3) := &p_max;
BEGIN
select
((TRUNC(SYSDATE) + RETENTION - TRUNC(SYSDATE)) * 86400)/60/60/24 AS RETENTION_DAYS
into :g_retention
from dba_hist_wr_control
where dbid in (select dbid from v$database);
if :g_retention > v_default then
:g_retention := v_max;
else
:g_retention := v_default;
end if;
END;
/
spool awr_topsqlx_rlio-tableau-exa-&_instname-&_hostname..csv
select *
from (
select
trim('&_instname') instname,
trim('&_dbid') db_id,
trim('&_hostname') hostname,
sqt.snap_id snap_id,
TO_CHAR(sqt.tm,'MM/DD/YY HH24:MI:SS') tm,
sqt.inst inst,
sqt.dur dur,
sqt.aas aas,
nvl((sqt.elap), to_number(null)) elap,
nvl((sqt.elapexec), 0) elapexec,
nvl((sqt.cput), to_number(null)) cput,
sqt.iowait iowait,
sqt.appwait appwait,
sqt.concurwait concurwait,
sqt.clwait clwait,
sqt.bget bget,
sqt.dskr dskr,
sqt.dpath dpath,
sqt.rowp rowp,
sqt.exec exec,
sqt.prsc prsc,
sqt.pxexec pxexec,
sqt.icbytes,
sqt.offloadbytes,
sqt.offloadreturnbytes,
sqt.flashcachereads,
sqt.uncompbytes,
sqt.time_rank time_rank,
sqt.sql_id sql_id,
sqt.phv phv,
sqt.fms fms,
sqt.parse_schema parse_schema,
substr(to_clob(decode(sqt.module, null, null, sqt.module)),1,50) module,
substr(to_clob(decode(sqt.action, null, null, sqt.action)),1,50) action,
st.sql_text sql_text -- PUT/REMOVE COMMENT TO HIDE/SHOW THE SQL_TEXT
from (
select snap_id, tm, inst, dur, sql_id, phv, fms, parse_schema, module, action, elap, elapexec, cput, iowait, appwait, concurwait, clwait, bget, dskr, dpath, rowp, exec, prsc, pxexec, icbytes, offloadbytes, offloadreturnbytes, flashcachereads, uncompbytes, aas, time_rank
from
(
select
s0.snap_id snap_id,
s0.END_INTERVAL_TIME tm,
s0.instance_number inst,
round(EXTRACT(DAY FROM s1.END_INTERVAL_TIME - s0.END_INTERVAL_TIME) * 1440
+ EXTRACT(HOUR FROM s1.END_INTERVAL_TIME - s0.END_INTERVAL_TIME) * 60
+ EXTRACT(MINUTE FROM s1.END_INTERVAL_TIME - s0.END_INTERVAL_TIME)
+ EXTRACT(SECOND FROM s1.END_INTERVAL_TIME - s0.END_INTERVAL_TIME) / 60, 2) dur,
e.sql_id sql_id,
e.plan_hash_value phv,
e.force_matching_signature fms,
e.parsing_schema_name parse_schema,
max(e.module) module,
max(e.action) action,
sum(e.elapsed_time_delta)/1000000 elap,
decode((sum(e.executions_delta)), 0, to_number(null), ((sum(e.elapsed_time_delta)) / (sum(e.executions_delta)) / 1000000)) elapexec,
sum(e.cpu_time_delta)/1000000 cput,
sum(e.iowait_delta)/1000000 iowait,
sum(e.apwait_delta)/1000000 appwait,
sum(e.ccwait_delta)/1000000 concurwait,
sum(e.clwait_delta)/1000000 clwait,
sum(e.buffer_gets_delta) bget,
sum(e.disk_reads_delta) dskr,
sum(e.direct_writes_delta) dpath,
sum(e.rows_processed_delta) rowp,
sum(e.executions_delta) exec,
sum(e.parse_calls_delta) prsc,
sum(e.px_servers_execs_delta) pxexec,
sum(e.io_interconnect_bytes_delta)/1024/1024 icbytes,
sum(e.io_offload_elig_bytes_delta)/1024/1024 offloadbytes,
sum(e.io_offload_return_bytes_delta)/1024/1024 offloadreturnbytes,
(sum(e.optimized_physical_reads_delta)* &_blocksize)/1024/1024 flashcachereads,
sum(e.cell_uncompressed_bytes_delta)/1024/1024 uncompbytes,
(sum(e.elapsed_time_delta)/1000000) / ((round(EXTRACT(DAY FROM s1.END_INTERVAL_TIME - s0.END_INTERVAL_TIME) * 1440
+ EXTRACT(HOUR FROM s1.END_INTERVAL_TIME - s0.END_INTERVAL_TIME) * 60
+ EXTRACT(MINUTE FROM s1.END_INTERVAL_TIME - s0.END_INTERVAL_TIME)
+ EXTRACT(SECOND FROM s1.END_INTERVAL_TIME - s0.END_INTERVAL_TIME) / 60, 2))*60) aas,
DENSE_RANK() OVER (
PARTITION BY s0.snap_id ORDER BY e.buffer_gets_delta + e.disk_reads_delta DESC) time_rank
from
dba_hist_snapshot s0,
dba_hist_snapshot s1,
dba_hist_sqlstat e
where
s0.dbid = &_dbid -- CHANGE THE DBID HERE!
AND s1.dbid = s0.dbid
and e.dbid = s0.dbid
--AND s0.instance_number = &_instancenumber -- CHANGE THE INSTANCE_NUMBER HERE!
AND s1.instance_number = s0.instance_number
and e.instance_number = s0.instance_number
AND s1.snap_id = s0.snap_id + 1
and e.snap_id = s0.snap_id + 1
group by
s0.snap_id, s0.END_INTERVAL_TIME, s0.instance_number, e.sql_id, e.plan_hash_value, e.force_matching_signature, e.parsing_schema_name, e.buffer_gets_delta, e.disk_reads_delta, s1.END_INTERVAL_TIME - s0.END_INTERVAL_TIME
)
where
time_rank <= 15 -- GET TOP 5 SQL ACROSS SNAP_IDs... YOU CAN ALTER THIS TO HAVE MORE DATA POINTS
)
sqt,
(select sql_id, dbid, nvl(b.name, a.command_type) sql_text from dba_hist_sqltext a, audit_actions b where a.command_type = b.action(+)) st
where st.sql_id(+) = sqt.sql_id
and st.dbid(+) = &_dbid
-- AND TO_CHAR(tm,'D') >= 1 -- Day of week: 1=Sunday 7=Saturday
-- AND TO_CHAR(tm,'D') <= 7
-- AND TO_CHAR(tm,'HH24MI') >= 0900 -- Hour
-- AND TO_CHAR(tm,'HH24MI') <= 1800
-- AND tm >= TO_DATE('2010-jan-17 00:00:00','yyyy-mon-dd hh24:mi:ss') -- Data range
-- AND tm <= TO_DATE('2010-aug-22 23:59:59','yyyy-mon-dd hh24:mi:ss')
-- AND snap_id in (338,339)
-- AND snap_id = 338
-- AND snap_id >= 335 and snap_id <= 339
-- AND lower(st.sql_text) like 'select%'
-- AND lower(st.sql_text) like 'insert%'
-- AND lower(st.sql_text) like 'update%'
-- AND lower(st.sql_text) like 'merge%'
-- AND pxexec > 0
-- AND aas > .5
order by
snap_id -- TO GET SQL OUTPUT ACROSS SNAP_IDs SEQUENTIALLY AND ASC
-- nvl(sqt.elap, -1) desc, sqt.sql_id -- TO GET SQL OUTPUT BY ELAPSED TIME
)
-- where rownum <= 20
WHERE
to_date(tm,'MM/DD/YY HH24:MI:SS') > sysdate - :g_retention
;
spool off
host sed -n -i '2,$ p' awr_topsqlx_rlio-tableau-exa-&_instname-&_hostname..csv
-- host gzip -v awr_topsqlx-tableau-exa-&_instname-&_hostname..csv
-- host tar -cvf awr_topsqlx-tableau-exa-&_instname-&_hostname..tar awr_topsqlx-tableau-exa-&_instname-&_hostname..csv.gz
-- host rm awr_topsqlx-tableau-exa-&_instname-&_hostname..csv.gz
-- awr_topsegments
-- AWR CPU Workload Report
-- Karl Arao, Oracle ACE (bit.ly/karlarao), OCP-DBA, RHCE
-- http://karlarao.wordpress.com
--
set feedback off pages 0 term off head on und off trimspool on echo off lines 4000 colsep ','
set arraysize 5000
set termout off
set echo off verify off
COLUMN blocksize NEW_VALUE _blocksize NOPRINT
select distinct block_size blocksize from v$datafile;
COLUMN dbid NEW_VALUE _dbid NOPRINT
select dbid from v$database;
COLUMN name NEW_VALUE _instname NOPRINT
select lower(instance_name) name from v$instance;
COLUMN name NEW_VALUE _hostname NOPRINT
select lower(host_name) name from v$instance;
COLUMN instancenumber NEW_VALUE _instancenumber NOPRINT
select instance_number instancenumber from v$instance;
-- ttitle center 'AWR Top Segments' skip 2
col snap_id format 99999
col tm format a17
set pagesize 50000
VARIABLE g_retention NUMBER
DEFINE p_default = 8
DEFINE p_max = 300
SET VERIFY OFF
DECLARE
v_default NUMBER(3) := &p_default;
v_max NUMBER(3) := &p_max;
BEGIN
select
((TRUNC(SYSDATE) + RETENTION - TRUNC(SYSDATE)) * 86400)/60/60/24 AS RETENTION_DAYS
into :g_retention
from dba_hist_wr_control
where dbid in (select dbid from v$database);
if :g_retention > v_default then
:g_retention := v_max;
else
:g_retention := v_default;
end if;
END;
/
spool awr_topsegments-rlio-io-tableau-&_instname-&_hostname..csv
SELECT
trim('&_instname') instname,
trim('&_dbid') db_id,
trim('&_hostname') hostname,
snap_id, tm, inst,
owner,
tablespace_name,
dataobj#,
object_name,
subobject_name,
object_type,
physical_rlio,
LOGICAL_READS_DELTA,
BUFFER_BUSY_WAITS_DELTA,
DB_BLOCK_CHANGES_DELTA,
PHYSICAL_READS_DELTA,
PHYSICAL_WRITES_DELTA,
PHYSICAL_READS_DIRECT_DELTA,
PHYSICAL_WRITES_DIRECT_DELTA,
ITL_WAITS_DELTA,
ROW_LOCK_WAITS_DELTA,
GC_CR_BLOCKS_SERVED_DELTA,
GC_CU_BLOCKS_SERVED_DELTA,
GC_BUFFER_BUSY_DELTA,
GC_CR_BLOCKS_RECEIVED_DELTA,
GC_CU_BLOCKS_RECEIVED_DELTA,
SPACE_USED_DELTA,
SPACE_ALLOCATED_DELTA,
TABLE_SCANS_DELTA,
CHAIN_ROW_EXCESS_DELTA,
PHYSICAL_READ_REQUESTS_DELTA,
PHYSICAL_WRITE_REQUESTS_DELTA,
OPTIMIZED_PHYSICAL_READS_DELTA,
seg_rank
FROM
(
SELECT
r.snap_id,
TO_CHAR(r.tm,'MM/DD/YY HH24:MI:SS') tm,
r.inst,
n.owner,
n.tablespace_name,
n.dataobj#,
n.object_name,
CASE
WHEN LENGTH(n.subobject_name) < 11
THEN n.subobject_name
ELSE SUBSTR(n.subobject_name,LENGTH(n.subobject_name)-9)
END subobject_name,
n.object_type,
(r.PHYSICAL_READS_DELTA + r.LOGICAL_READS_DELTA) as physical_rlio,
r.LOGICAL_READS_DELTA,
r.BUFFER_BUSY_WAITS_DELTA,
r.DB_BLOCK_CHANGES_DELTA,
r.PHYSICAL_READS_DELTA,
r.PHYSICAL_WRITES_DELTA,
r.PHYSICAL_READS_DIRECT_DELTA,
r.PHYSICAL_WRITES_DIRECT_DELTA,
r.ITL_WAITS_DELTA,
r.ROW_LOCK_WAITS_DELTA,
r.GC_CR_BLOCKS_SERVED_DELTA,
r.GC_CU_BLOCKS_SERVED_DELTA,
r.GC_BUFFER_BUSY_DELTA,
r.GC_CR_BLOCKS_RECEIVED_DELTA,
r.GC_CU_BLOCKS_RECEIVED_DELTA,
r.SPACE_USED_DELTA,
r.SPACE_ALLOCATED_DELTA,
r.TABLE_SCANS_DELTA,
r.CHAIN_ROW_EXCESS_DELTA,
r.PHYSICAL_READ_REQUESTS_DELTA,
r.PHYSICAL_WRITE_REQUESTS_DELTA,
r.OPTIMIZED_PHYSICAL_READS_DELTA,
DENSE_RANK() OVER (PARTITION BY r.snap_id ORDER BY r.PHYSICAL_READS_DELTA + r.LOGICAL_READS_DELTA DESC) seg_rank
FROM
dba_hist_seg_stat_obj n,
(
SELECT
s0.snap_id snap_id,
s0.END_INTERVAL_TIME tm,
s0.instance_number inst,
b.dataobj#,
b.obj#,
b.dbid,
sum(b.LOGICAL_READS_DELTA) LOGICAL_READS_DELTA,
sum(b.BUFFER_BUSY_WAITS_DELTA) BUFFER_BUSY_WAITS_DELTA,
sum(b.DB_BLOCK_CHANGES_DELTA) DB_BLOCK_CHANGES_DELTA,
sum(b.PHYSICAL_READS_DELTA) PHYSICAL_READS_DELTA,
sum(b.PHYSICAL_WRITES_DELTA) PHYSICAL_WRITES_DELTA,
sum(b.PHYSICAL_READS_DIRECT_DELTA) PHYSICAL_READS_DIRECT_DELTA,
sum(b.PHYSICAL_WRITES_DIRECT_DELTA) PHYSICAL_WRITES_DIRECT_DELTA,
sum(b.ITL_WAITS_DELTA) ITL_WAITS_DELTA,
sum(b.ROW_LOCK_WAITS_DELTA) ROW_LOCK_WAITS_DELTA,
sum(b.GC_CR_BLOCKS_SERVED_DELTA) GC_CR_BLOCKS_SERVED_DELTA,
sum(b.GC_CU_BLOCKS_SERVED_DELTA) GC_CU_BLOCKS_SERVED_DELTA,
sum(b.GC_BUFFER_BUSY_DELTA) GC_BUFFER_BUSY_DELTA,
sum(b.GC_CR_BLOCKS_RECEIVED_DELTA) GC_CR_BLOCKS_RECEIVED_DELTA,
sum(b.GC_CU_BLOCKS_RECEIVED_DELTA) GC_CU_BLOCKS_RECEIVED_DELTA,
sum(b.SPACE_USED_DELTA) SPACE_USED_DELTA,
sum(b.SPACE_ALLOCATED_DELTA) SPACE_ALLOCATED_DELTA,
sum(b.TABLE_SCANS_DELTA) TABLE_SCANS_DELTA,
sum(b.CHAIN_ROW_EXCESS_DELTA) CHAIN_ROW_EXCESS_DELTA,
sum(b.PHYSICAL_READ_REQUESTS_DELTA) PHYSICAL_READ_REQUESTS_DELTA,
sum(b.PHYSICAL_WRITE_REQUESTS_DELTA) PHYSICAL_WRITE_REQUESTS_DELTA,
sum(b.OPTIMIZED_PHYSICAL_READS_DELTA) OPTIMIZED_PHYSICAL_READS_DELTA
FROM
dba_hist_snapshot s0,
dba_hist_snapshot s1,
dba_hist_seg_stat b
WHERE
s0.dbid = &_dbid
AND s1.dbid = s0.dbid
AND b.dbid = s0.dbid
AND s1.instance_number = s0.instance_number
AND b.instance_number = s0.instance_number
AND s1.snap_id = s0.snap_id + 1
AND b.snap_id = s0.snap_id + 1
AND s0.END_INTERVAL_TIME > sysdate - :g_retention
GROUP BY
s0.snap_id, s0.END_INTERVAL_TIME, s0.instance_number, b.dataobj#, b.obj#, b.dbid
) r
WHERE n.dataobj# = r.dataobj#
AND n.obj# = r.obj#
AND n.dbid = r.dbid
AND r.PHYSICAL_READS_DELTA + r.LOGICAL_READS_DELTA > 0
ORDER BY physical_rlio DESC,
object_name,
owner,
subobject_name
)
WHERE
seg_rank <=15
order by inst, snap_id, seg_rank asc;
spool off
host sed -n -i '2,$ p' awr_topsegments-rlio-io-tableau-&_instname-&_hostname..csv
-- host gzip -v awr_topsegments-tableau-&_instname-&_hostname..csv
-- host tar -cvf awr_topsegments-tableau-&_instname-&_hostname..tar awr_topsegments-tableau-&_instname-&_hostname..csv.gz
-- host rm awr_topsegments-tableau-&_instname-&_hostname..csv.gz
-- awr_topsegments
-- AWR CPU Workload Report
-- Karl Arao, Oracle ACE (bit.ly/karlarao), OCP-DBA, RHCE
-- http://karlarao.wordpress.com
--
set feedback off pages 0 term off head on und off trimspool on echo off lines 4000 colsep ','
set arraysize 5000
set termout off
set echo off verify off
COLUMN blocksize NEW_VALUE _blocksize NOPRINT
select distinct block_size blocksize from v$datafile;
COLUMN dbid NEW_VALUE _dbid NOPRINT
select dbid from v$database;
COLUMN name NEW_VALUE _instname NOPRINT
select lower(instance_name) name from v$instance;
COLUMN name NEW_VALUE _hostname NOPRINT
select lower(host_name) name from v$instance;
COLUMN instancenumber NEW_VALUE _instancenumber NOPRINT
select instance_number instancenumber from v$instance;
-- ttitle center 'AWR Top Segments' skip 2
col snap_id format 99999
col tm format a17
set pagesize 50000
VARIABLE g_retention NUMBER
DEFINE p_default = 8
DEFINE p_max = 300
SET VERIFY OFF
DECLARE
v_default NUMBER(3) := &p_default;
v_max NUMBER(3) := &p_max;
BEGIN
select
((TRUNC(SYSDATE) + RETENTION - TRUNC(SYSDATE)) * 86400)/60/60/24 AS RETENTION_DAYS
into :g_retention
from dba_hist_wr_control
where dbid in (select dbid from v$database);
if :g_retention > v_default then
:g_retention := v_max;
else
:g_retention := v_default;
end if;
END;
/
spool awr_topsegments-rw-io-tableau-&_instname-&_hostname..csv
SELECT
trim('&_instname') instname,
trim('&_dbid') db_id,
trim('&_hostname') hostname,
snap_id, tm, inst,
owner,
tablespace_name,
dataobj#,
object_name,
subobject_name,
object_type,
physical_rw,
LOGICAL_READS_DELTA,
BUFFER_BUSY_WAITS_DELTA,
DB_BLOCK_CHANGES_DELTA,
PHYSICAL_READS_DELTA,
PHYSICAL_WRITES_DELTA,
PHYSICAL_READS_DIRECT_DELTA,
PHYSICAL_WRITES_DIRECT_DELTA,
ITL_WAITS_DELTA,
ROW_LOCK_WAITS_DELTA,
GC_CR_BLOCKS_SERVED_DELTA,
GC_CU_BLOCKS_SERVED_DELTA,
GC_BUFFER_BUSY_DELTA,
GC_CR_BLOCKS_RECEIVED_DELTA,
GC_CU_BLOCKS_RECEIVED_DELTA,
SPACE_USED_DELTA,
SPACE_ALLOCATED_DELTA,
TABLE_SCANS_DELTA,
CHAIN_ROW_EXCESS_DELTA,
PHYSICAL_READ_REQUESTS_DELTA,
PHYSICAL_WRITE_REQUESTS_DELTA,
OPTIMIZED_PHYSICAL_READS_DELTA,
seg_rank
FROM
(
SELECT
r.snap_id,
TO_CHAR(r.tm,'MM/DD/YY HH24:MI:SS') tm,
r.inst,
n.owner,
n.tablespace_name,
n.dataobj#,
n.object_name,
CASE
WHEN LENGTH(n.subobject_name) < 11
THEN n.subobject_name
ELSE SUBSTR(n.subobject_name,LENGTH(n.subobject_name)-9)
END subobject_name,
n.object_type,
(r.PHYSICAL_READS_DELTA + r.PHYSICAL_WRITES_DELTA) as physical_rw,
r.LOGICAL_READS_DELTA,
r.BUFFER_BUSY_WAITS_DELTA,
r.DB_BLOCK_CHANGES_DELTA,
r.PHYSICAL_READS_DELTA,
r.PHYSICAL_WRITES_DELTA,
r.PHYSICAL_READS_DIRECT_DELTA,
r.PHYSICAL_WRITES_DIRECT_DELTA,
r.ITL_WAITS_DELTA,
r.ROW_LOCK_WAITS_DELTA,
r.GC_CR_BLOCKS_SERVED_DELTA,
r.GC_CU_BLOCKS_SERVED_DELTA,
r.GC_BUFFER_BUSY_DELTA,
r.GC_CR_BLOCKS_RECEIVED_DELTA,
r.GC_CU_BLOCKS_RECEIVED_DELTA,
r.SPACE_USED_DELTA,
r.SPACE_ALLOCATED_DELTA,
r.TABLE_SCANS_DELTA,
r.CHAIN_ROW_EXCESS_DELTA,
r.PHYSICAL_READ_REQUESTS_DELTA,
r.PHYSICAL_WRITE_REQUESTS_DELTA,
r.OPTIMIZED_PHYSICAL_READS_DELTA,
DENSE_RANK() OVER (PARTITION BY r.snap_id ORDER BY r.PHYSICAL_READS_DELTA + r.PHYSICAL_WRITES_DELTA DESC) seg_rank
FROM
dba_hist_seg_stat_obj n,
(
SELECT
s0.snap_id snap_id,
s0.END_INTERVAL_TIME tm,
s0.instance_number inst,
b.dataobj#,
b.obj#,
b.dbid,
sum(b.LOGICAL_READS_DELTA) LOGICAL_READS_DELTA,
sum(b.BUFFER_BUSY_WAITS_DELTA) BUFFER_BUSY_WAITS_DELTA,
sum(b.DB_BLOCK_CHANGES_DELTA) DB_BLOCK_CHANGES_DELTA,
sum(b.PHYSICAL_READS_DELTA) PHYSICAL_READS_DELTA,
sum(b.PHYSICAL_WRITES_DELTA) PHYSICAL_WRITES_DELTA,
sum(b.PHYSICAL_READS_DIRECT_DELTA) PHYSICAL_READS_DIRECT_DELTA,
sum(b.PHYSICAL_WRITES_DIRECT_DELTA) PHYSICAL_WRITES_DIRECT_DELTA,
sum(b.ITL_WAITS_DELTA) ITL_WAITS_DELTA,
sum(b.ROW_LOCK_WAITS_DELTA) ROW_LOCK_WAITS_DELTA,
sum(b.GC_CR_BLOCKS_SERVED_DELTA) GC_CR_BLOCKS_SERVED_DELTA,
sum(b.GC_CU_BLOCKS_SERVED_DELTA) GC_CU_BLOCKS_SERVED_DELTA,
sum(b.GC_BUFFER_BUSY_DELTA) GC_BUFFER_BUSY_DELTA,
sum(b.GC_CR_BLOCKS_RECEIVED_DELTA) GC_CR_BLOCKS_RECEIVED_DELTA,
sum(b.GC_CU_BLOCKS_RECEIVED_DELTA) GC_CU_BLOCKS_RECEIVED_DELTA,
sum(b.SPACE_USED_DELTA) SPACE_USED_DELTA,
sum(b.SPACE_ALLOCATED_DELTA) SPACE_ALLOCATED_DELTA,
sum(b.TABLE_SCANS_DELTA) TABLE_SCANS_DELTA,
sum(b.CHAIN_ROW_EXCESS_DELTA) CHAIN_ROW_EXCESS_DELTA,
sum(b.PHYSICAL_READ_REQUESTS_DELTA) PHYSICAL_READ_REQUESTS_DELTA,
sum(b.PHYSICAL_WRITE_REQUESTS_DELTA) PHYSICAL_WRITE_REQUESTS_DELTA,
sum(b.OPTIMIZED_PHYSICAL_READS_DELTA) OPTIMIZED_PHYSICAL_READS_DELTA
FROM
dba_hist_snapshot s0,
dba_hist_snapshot s1,
dba_hist_seg_stat b
WHERE
s0.dbid = &_dbid
AND s1.dbid = s0.dbid
AND b.dbid = s0.dbid
--AND s0.instance_number = &_instancenumber
AND s1.instance_number = s0.instance_number
AND b.instance_number = s0.instance_number
AND s1.snap_id = s0.snap_id + 1
AND b.snap_id = s0.snap_id + 1
AND s0.END_INTERVAL_TIME > sysdate - :g_retention
GROUP BY
s0.snap_id, s0.END_INTERVAL_TIME, s0.instance_number, b.dataobj#, b.obj#, b.dbid
) r
WHERE n.dataobj# = r.dataobj#
AND n.obj# = r.obj#
AND n.dbid = r.dbid
AND r.PHYSICAL_READS_DELTA + r.PHYSICAL_WRITES_DELTA > 0
ORDER BY physical_rw DESC,
object_name,
owner,
subobject_name
)
WHERE
seg_rank <=5
order by inst, snap_id, seg_rank asc;
spool off
host sed -n -i '2,$ p' awr_topsegments-rw-io-tableau-&_instname-&_hostname..csv
-- host gzip -v awr_topsegments-tableau-&_instname-&_hostname..csv
-- host tar -cvf awr_topsegments-tableau-&_instname-&_hostname..tar awr_topsegments-tableau-&_instname-&_hostname..csv.gz
-- host rm awr_topsegments-tableau-&_instname-&_hostname..csv.gz
-- awr_topsegments
-- AWR CPU Workload Report
-- Karl Arao, Oracle ACE (bit.ly/karlarao), OCP-DBA, RHCE
-- http://karlarao.wordpress.com
--
set feedback off pages 0 term off head on und off trimspool on echo off lines 4000 colsep ','
set arraysize 5000
set termout off
set echo off verify off
COLUMN blocksize NEW_VALUE _blocksize NOPRINT
select distinct block_size blocksize from v$datafile;
COLUMN dbid NEW_VALUE _dbid NOPRINT
select dbid from v$database;
COLUMN name NEW_VALUE _instname NOPRINT
select lower(instance_name) name from v$instance;
COLUMN name NEW_VALUE _hostname NOPRINT
select lower(host_name) name from v$instance;
COLUMN instancenumber NEW_VALUE _instancenumber NOPRINT
select instance_number instancenumber from v$instance;
-- ttitle center 'AWR Top Segments' skip 2
col snap_id format 99999
col tm format a17
set pagesize 50000
VARIABLE g_retention NUMBER
DEFINE p_default = 8
DEFINE p_max = 300
SET VERIFY OFF
DECLARE
v_default NUMBER(3) := &p_default;
v_max NUMBER(3) := &p_max;
BEGIN
select
((TRUNC(SYSDATE) + RETENTION - TRUNC(SYSDATE)) * 86400)/60/60/24 AS RETENTION_DAYS
into :g_retention
from dba_hist_wr_control
where dbid in (select dbid from v$database);
if :g_retention > v_default then
:g_retention := v_max;
else
:g_retention := v_default;
end if;
END;
/
spool awr_topsegments-space-used-tableau-&_instname-&_hostname..csv
SELECT
trim('&_instname') instname,
trim('&_dbid') db_id,
trim('&_hostname') hostname,
snap_id, tm, inst,
owner,
tablespace_name,
dataobj#,
object_name,
subobject_name,
object_type,
physical_rw,
LOGICAL_READS_DELTA,
BUFFER_BUSY_WAITS_DELTA,
DB_BLOCK_CHANGES_DELTA,
PHYSICAL_READS_DELTA,
PHYSICAL_WRITES_DELTA,
PHYSICAL_READS_DIRECT_DELTA,
PHYSICAL_WRITES_DIRECT_DELTA,
ITL_WAITS_DELTA,
ROW_LOCK_WAITS_DELTA,
GC_CR_BLOCKS_SERVED_DELTA,
GC_CU_BLOCKS_SERVED_DELTA,
GC_BUFFER_BUSY_DELTA,
GC_CR_BLOCKS_RECEIVED_DELTA,
GC_CU_BLOCKS_RECEIVED_DELTA,
SPACE_USED_DELTA,
SPACE_ALLOCATED_DELTA,
TABLE_SCANS_DELTA,
CHAIN_ROW_EXCESS_DELTA,
PHYSICAL_READ_REQUESTS_DELTA,
PHYSICAL_WRITE_REQUESTS_DELTA,
OPTIMIZED_PHYSICAL_READS_DELTA,
seg_rank
FROM
(
SELECT
r.snap_id,
TO_CHAR(r.tm,'MM/DD/YY HH24:MI:SS') tm,
r.inst,
n.owner,
n.tablespace_name,
n.dataobj#,
n.object_name,
CASE
WHEN LENGTH(n.subobject_name) < 11
THEN n.subobject_name
ELSE SUBSTR(n.subobject_name,LENGTH(n.subobject_name)-9)
END subobject_name,
n.object_type,
(r.PHYSICAL_READS_DELTA + r.PHYSICAL_WRITES_DELTA) as physical_rw,
r.LOGICAL_READS_DELTA,
r.BUFFER_BUSY_WAITS_DELTA,
r.DB_BLOCK_CHANGES_DELTA,
r.PHYSICAL_READS_DELTA,
r.PHYSICAL_WRITES_DELTA,
r.PHYSICAL_READS_DIRECT_DELTA,
r.PHYSICAL_WRITES_DIRECT_DELTA,
r.ITL_WAITS_DELTA,
r.ROW_LOCK_WAITS_DELTA,
r.GC_CR_BLOCKS_SERVED_DELTA,
r.GC_CU_BLOCKS_SERVED_DELTA,
r.GC_BUFFER_BUSY_DELTA,
r.GC_CR_BLOCKS_RECEIVED_DELTA,
r.GC_CU_BLOCKS_RECEIVED_DELTA,
r.SPACE_USED_DELTA,
r.SPACE_ALLOCATED_DELTA,
r.TABLE_SCANS_DELTA,
r.CHAIN_ROW_EXCESS_DELTA,
r.PHYSICAL_READ_REQUESTS_DELTA,
r.PHYSICAL_WRITE_REQUESTS_DELTA,
r.OPTIMIZED_PHYSICAL_READS_DELTA,
DENSE_RANK() OVER (PARTITION BY r.snap_id ORDER BY r.SPACE_USED_DELTA DESC) seg_rank
FROM
dba_hist_seg_stat_obj n,
(
SELECT
s0.snap_id snap_id,
s0.END_INTERVAL_TIME tm,
s0.instance_number inst,
b.dataobj#,
b.obj#,
b.dbid,
sum(b.LOGICAL_READS_DELTA) LOGICAL_READS_DELTA,
sum(b.BUFFER_BUSY_WAITS_DELTA) BUFFER_BUSY_WAITS_DELTA,
sum(b.DB_BLOCK_CHANGES_DELTA) DB_BLOCK_CHANGES_DELTA,
sum(b.PHYSICAL_READS_DELTA) PHYSICAL_READS_DELTA,
sum(b.PHYSICAL_WRITES_DELTA) PHYSICAL_WRITES_DELTA,
sum(b.PHYSICAL_READS_DIRECT_DELTA) PHYSICAL_READS_DIRECT_DELTA,
sum(b.PHYSICAL_WRITES_DIRECT_DELTA) PHYSICAL_WRITES_DIRECT_DELTA,
sum(b.ITL_WAITS_DELTA) ITL_WAITS_DELTA,
sum(b.ROW_LOCK_WAITS_DELTA) ROW_LOCK_WAITS_DELTA,
sum(b.GC_CR_BLOCKS_SERVED_DELTA) GC_CR_BLOCKS_SERVED_DELTA,
sum(b.GC_CU_BLOCKS_SERVED_DELTA) GC_CU_BLOCKS_SERVED_DELTA,
sum(b.GC_BUFFER_BUSY_DELTA) GC_BUFFER_BUSY_DELTA,
sum(b.GC_CR_BLOCKS_RECEIVED_DELTA) GC_CR_BLOCKS_RECEIVED_DELTA,
sum(b.GC_CU_BLOCKS_RECEIVED_DELTA) GC_CU_BLOCKS_RECEIVED_DELTA,
sum(b.SPACE_USED_DELTA) SPACE_USED_DELTA,
sum(b.SPACE_ALLOCATED_DELTA) SPACE_ALLOCATED_DELTA,
sum(b.TABLE_SCANS_DELTA) TABLE_SCANS_DELTA,
sum(b.CHAIN_ROW_EXCESS_DELTA) CHAIN_ROW_EXCESS_DELTA,
sum(b.PHYSICAL_READ_REQUESTS_DELTA) PHYSICAL_READ_REQUESTS_DELTA,
sum(b.PHYSICAL_WRITE_REQUESTS_DELTA) PHYSICAL_WRITE_REQUESTS_DELTA,
sum(b.OPTIMIZED_PHYSICAL_READS_DELTA) OPTIMIZED_PHYSICAL_READS_DELTA