forked from fatdba/Oracle-Database-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhourly_segment_stats.sql
222 lines (220 loc) · 6.48 KB
/
hourly_segment_stats.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
--
-- Hourly segment statistics for the last 4 hours from AWR
--
@big_job
@plusenv
col objid format 9999999
col sname format a45 head 'Segment Name' word_wrapped
col stype format a06 head 'SegTyp' trunc
col lread format 99999999999 head 'Logical Reads|Latest'
col pread format 99999999999 head 'Phys Reads|Latest'
col bbw3 format 9999999 head 'BBW|3Hours|Ago'
col bbw2 format 9999999 head 'BBW|2Hours|Agp'
col bbw1 format 9999999 head 'BBW|1Hour |Ago'
col bbw format 9999999 head 'BBW|Latest'
col itlw3 format 9999 head 'ITLW|3Hours|Ago'
col itlw2 format 9999 head 'ITLW|2Hours|Ago'
col itlw1 format 9999 head 'ITLW|1Hour |Ago'
col itlw format 9999 head 'ITLW|Latest'
col rowlk3 format 9999999 head 'ROWLW|3Hours|Ago'
col rowlk2 format 9999999 head 'ROWLW|2Hours|Ago'
col rowlk1 format 9999999 head 'ROWLW|1Hour|Ago'
col rowlk format 9999999 head 'ROWLW|Latest'
col pct_lread format 99 head 'L%'
col pct_pread format 99 head 'P%'
with SEGSTAT3 as
(
select * from
(
select o.owner||'.'||object_name||decode(subobject_name,null,' ',': '||subobject_name) sname
,decode(o.object_type, 'TABLE','TAB'
,'TABLE PARTITION','TABPART'
,'TABLE SUBPARTITION','TABSUBP'
,'INDEX','IDX'
,'INDEX PARTITION','IDXPART'
,'INDEX SUBPARTITION','IDXSUB'
,o.object_type) stype
,sum(LOGICAL_READS_DELTA) lread
,100*ratio_to_report(sum(LOGICAL_READS_DELTA)) over() pct_lread
,sum(PHYSICAL_READS_DELTA) pread
,100*ratio_to_report(sum(PHYSICAL_READS_DELTA)) over() pct_pread
,sum(BUFFER_BUSY_WAITS_DELTA) bbw
,sum(ITL_WAITS_DELTA) itlw
,sum(ROW_LOCK_WAITS_DELTA) rowlk
from dba_hist_seg_stat s
,dba_hist_snapshot sn
,dba_objects o
where BEGIN_INTERVAL_TIME between sysdate-4/24 and sysdate-3/24
and o.owner not in ('SYS')
and sn.snap_id = s.snap_id
and s.obj# = o.object_id
group by o.owner||'.'||object_name||decode(subobject_name,null,' ',': '||subobject_name)
,decode(o.object_type, 'TABLE','TAB'
,'TABLE PARTITION','TABPART'
,'TABLE SUBPARTITION','TABSUBP'
,'INDEX','IDX'
,'INDEX PARTITION','IDXPART'
,'INDEX SUBPARTITION','IDXSUB'
,o.object_type)
order by sum(LOGICAL_READS_DELTA) desc
)
where rownum <=100
)
,SEGSTAT2 as
(
select * from
(
select o.owner||'.'||object_name||decode(subobject_name,null,' ',': '||subobject_name) sname
,decode(o.object_type, 'TABLE','TAB'
,'TABLE PARTITION','TABPART'
,'TABLE SUBPARTITION','TABSUBP'
,'INDEX','IDX'
,'INDEX PARTITION','IDXPART'
,'INDEX SUBPARTITION','IDXSUB'
,o.object_type) stype
,sum(LOGICAL_READS_DELTA) lread
,100*ratio_to_report(sum(LOGICAL_READS_DELTA)) over() pct_lread
,sum(PHYSICAL_READS_DELTA) pread
,100*ratio_to_report(sum(PHYSICAL_READS_DELTA)) over() pct_pread
,sum(BUFFER_BUSY_WAITS_DELTA) bbw
,sum(ITL_WAITS_DELTA) itlw
,sum(ROW_LOCK_WAITS_DELTA) rowlk
from dba_hist_seg_stat s
,dba_hist_snapshot sn
,dba_objects o
where BEGIN_INTERVAL_TIME between sysdate-3/24 and sysdate-2/24
and o.owner not in ('SYS')
and sn.snap_id = s.snap_id
and s.obj# = o.object_id
group by o.owner||'.'||object_name||decode(subobject_name,null,' ',': '||subobject_name)
,decode(o.object_type, 'TABLE','TAB'
,'TABLE PARTITION','TABPART'
,'TABLE SUBPARTITION','TABSUBP'
,'INDEX','IDX'
,'INDEX PARTITION','IDXPART'
,'INDEX SUBPARTITION','IDXSUB'
,o.object_type)
order by sum(LOGICAL_READS_DELTA) desc
)
where rownum <=100
)
,SEGSTAT1 as
(
select * from
(
select o.owner||'.'||object_name||decode(subobject_name,null,' ',': '||subobject_name) sname
,decode(o.object_type, 'TABLE','TAB'
,'TABLE PARTITION','TABPART'
,'TABLE SUBPARTITION','TABSUBP'
,'INDEX','IDX'
,'INDEX PARTITION','IDXPART'
,'INDEX SUBPARTITION','IDXSUB'
,o.object_type) stype
,sum(LOGICAL_READS_DELTA) lread
,100*ratio_to_report(sum(LOGICAL_READS_DELTA)) over() pct_lread
,sum(PHYSICAL_READS_DELTA) pread
,100*ratio_to_report(sum(PHYSICAL_READS_DELTA)) over() pct_pread
,sum(BUFFER_BUSY_WAITS_DELTA) bbw
,sum(ITL_WAITS_DELTA) itlw
,sum(ROW_LOCK_WAITS_DELTA) rowlk
from dba_hist_seg_stat s
,dba_hist_snapshot sn
,dba_objects o
where BEGIN_INTERVAL_TIME between sysdate-2/24 and sysdate-1/24
and o.owner not in ('SYS')
and sn.snap_id = s.snap_id
and s.obj# = o.object_id
group by o.owner||'.'||object_name||decode(subobject_name,null,' ',': '||subobject_name)
,decode(o.object_type, 'TABLE','TAB'
,'TABLE PARTITION','TABPART'
,'TABLE SUBPARTITION','TABSUBP'
,'INDEX','IDX'
,'INDEX PARTITION','IDXPART'
,'INDEX SUBPARTITION','IDXSUB'
,o.object_type)
order by sum(LOGICAL_READS_DELTA) desc
)
where rownum <=100
)
,SEGSTAT0 as
(
select * from
(
select o.owner||'.'||object_name||decode(subobject_name,null,' ',': '||subobject_name) sname
,decode(o.object_type, 'TABLE','TAB'
,'TABLE PARTITION','TABPART'
,'TABLE SUBPARTITION','TABSUBP'
,'INDEX','IDX'
,'INDEX PARTITION','IDXPART'
,'INDEX SUBPARTITION','IDXSUB'
,o.object_type) stype
,sum(LOGICAL_READS_DELTA) lread
,100*ratio_to_report(sum(LOGICAL_READS_DELTA)) over() pct_lread
,sum(PHYSICAL_READS_DELTA) pread
,100*ratio_to_report(sum(PHYSICAL_READS_DELTA)) over() pct_pread
,sum(BUFFER_BUSY_WAITS_DELTA) bbw
,sum(ITL_WAITS_DELTA) itlw
,sum(ROW_LOCK_WAITS_DELTA) rowlk
from dba_hist_seg_stat s
,dba_hist_snapshot sn
,dba_objects o
where BEGIN_INTERVAL_TIME between sysdate-1/24 and sysdate
and o.owner not in ('SYS')
and sn.snap_id = s.snap_id
and s.obj# = o.object_id
group by o.owner||'.'||object_name||decode(subobject_name,null,' ',': '||subobject_name)
,decode(o.object_type, 'TABLE','TAB'
,'TABLE PARTITION','TABPART'
,'TABLE SUBPARTITION','TABSUBP'
,'INDEX','IDX'
,'INDEX PARTITION','IDXPART'
,'INDEX SUBPARTITION','IDXSUB'
,o.object_type)
order by sum(LOGICAL_READS_DELTA) desc
)
where rownum <=20
)
SELECT s0.sname
,s0.stype
,'|'
--,s3.lread
,s3.pct_lread
--,s3.pread
,s3.pct_pread
,s3.bbw bbw3
,s3.itlw itlw3
,s3.rowlk rowlk3
,'|'
--,s2.lread
,s2.pct_lread
--,s2.pread
,s2.pct_pread
,s2.bbw bbw2
,s2.itlw itlw2
,s2.rowlk rowlk2
,'|'
--,s1.lread
,s1.pct_lread
--,s1.pread
,s1.pct_pread
,s1.bbw bbw1
,s1.itlw itlw1
,s1.rowlk rowlk1
,'|'
,s0.lread
,s0.pct_lread
,s0.pread
,s0.pct_pread
,s0.bbw bbw
,s0.itlw itlw
,s0.rowlk rowlk
from segstat0 s0
,segstat1 s1
,segstat2 s2
,segstat3 s3
where s0.sname = s1.sname (+)
and s0.sname = s2.sname (+)
and s0.sname = s3.sname (+)
order by s0.pct_lread desc
;
@big_job_off