v$object_usage可以用来监控系统中索引的使用情况
select * from v$object_usage;
只是当前用户下有效,只能看到当前用户下的监视索引。
开关监控:
alter index index_name monitoring usage;
alter index index_name nomonitoringusage;
v$object_usage只包括当前用户的索引使用记录,如果需要查出所有用户的索引使用记录,使用下面的sql,这个sql来自DBA日记:
select z.name||'.'||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
from sys.obj$ io, sys.obj$ t, sys.ind$ i, sys.object_usage ou ,sys.user$ z
Where i.obj# = ou.obj#
and io.obj# = ou.obj# And io.owner#=z.user#
and t.obj# = i.bo#
Order By 4 Desc,2 Desc;
原系统查询语句里面有io.owner# = userenv('SCHEMAID') 条件,用非owner 用户查询不出结果.
需要注意的是,如果使用了alter index rebuild,则monitoring停止。而且,原来未使用的索引,也标记为使用