-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathindex_monitoring.sql
55 lines (51 loc) · 1.78 KB
/
index_monitoring.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
-- Index monitoring usage scripts
select 'alter index '||owner||'.'||index_name||' monitoring usage;'
from dba_indexes
where owner = '&OWNER';
select index_name
, table_name
, monitoring
, used
, start_monitoring
, end_monitoring
from v$object_usage;
select p.object_name
, p.operation
, p.options
count(*)
from dba_hist_sql_plan p
, dba_hist_sqlstat s
where p.object_owner != 'SYS'
and p.operation like '%INDEX%'
and p.sql_id = s.sql_id
group by p.object_name
, p.operation
, p.options
order by 1, 2, 3;
column mbytes format 999,999,999.990
select io.name
, t.name
, decode(bitand(i.flags, 65536), 0, 'NO', 'YES')
, decode(bitand(ou.flags, 1), 0, 'NO', 'YES')
, ou.start_monitoring
--, ou.end_monitoring
, sum(ds.bytes/1024/1024) as mbytes
from sys.obj$ io
, sys.obj$ t
, sys.ind$ i
, sys.object_usage ou
, dba_users du
, dba_segments ds
where io.owner# = du.user_id
and du.username = '&OWNER'
and du.username = ds.owner
and io.name = ds.segment_name
and i.obj# = ou.obj#
and io.obj# = ou.obj#
and t.obj# = i.bo#
group by io.name
, t.name
, decode(bitand(i.flags, 65536), 0, 'NO', 'YES')
, decode(bitand(ou.flags, 1), 0, 'NO', 'YES')
, ou.start_monitoring
order by 6 asc;