- 最后登录
- 2014-9-10
- 在线时间
- 34 小时
- 威望
- 62
- 金钱
- 508
- 注册时间
- 2012-1-30
- 阅读权限
- 50
- 帖子
- 53
- 精华
- 1
- 积分
- 62
- UID
- 187
|
8#
发表于 2013-5-20 15:12:21
分享一个使用index monitor usage功能监控索引使用情况的脚本:)
/**监控索引是否被使用*/
--create table
CREATE TABLE dbamonitor.WZ_INDEX_USAGE
( "INDEX_NAME" VARCHAR2(30) NOT NULL,
"TABLE_NAME" VARCHAR2(30) NOT NULL,
"MONITORING" VARCHAR2(3),
"USED" VARCHAR2(3),
"START_MONITORING" VARCHAR2(19),
"END_MONITORING" VARCHAR2(19),
"CAPATURE_TIME" date
);
--record index usage status(capture v$object_usage regularly,and reset V$OBJECT_USAGE used flag with NO)
$ cat monitor_index_usage.sh
#!/bin/sh
#Description:monitor index usage
#check interval unit(seconds)
_INTERVAL=300
while true
do
sqlplus -s / as sysdba << EOF
whenever sqlerror exit rollback
INSERT INTO dbamonitor.WZ_INDEX_USAGE
select io.name index_name,
t.name table_name,
decode(bitand(i.flags, 65536), 0, 'NO', 'YES') monitoring,
decode(bitand(ou.flags, 1), 0, 'NO', 'YES') used,
ou.start_monitoring start_monitoring,
ou.end_monitoring end_monitoring,
sysdate
from sys.obj$ io, sys.obj$ t, sys.ind$ i, sys.object_usage ou
where io.owner# = 161 --modify this value to yours
and i.obj# = ou.obj#
and io.obj# = ou.obj#
and t.obj# = i.bo#
AND bitand(i.flags, 65536)<>0
AND bitand(ou.flags, 1)<>0;
UPDATE sys.Object_Usage SET flags=0;
commit;
EOF
sleep $_INTERVAL
done |
|