首先,我们如果是监控一个表上的所有索引,可以这样先生成监控的命令:
SQL> select 'alter index '||index_name||' monitoring usage;' from user_indexes where table_name=upper('mpaymentappl');
'ALTERINDEX'||INDEX_NAME||'MONITORINGUSAGE;'
------------------------------------------------------------
alter index IDX_MPAYMENTAPPL_BCODE monitoring usage;
alter index MPAYMENTAPPL_FLAGS monitoring usage;
alter index MPAYMENTAPPL_PAICODE monitoring usage;
然后执行这些脚本就开始监控了,监控信息可通过V$OBJECT_USAGE查看,通过used列可知道这个索引是否被使用:
SQL> select * from V$OBJECT_USAGE;
INDEX_NAME TABLE_NAME MON USE START_MONITORING END_MONITORING
------------------------------ ------------------------------ --- --- ------------------- -------------------
IDX_MPAYMENTAPPL_BCODE MPAYMENTAPPL YES NO 03/24/2010 10:55:27
MPAYMENTAPPL_FLAGS MPAYMENTAPPL YES NO 03/24/2010 10:55:27
MPAYMENTAPPL_PAICODE MPAYMENTAPPL YES NO 03/24/2010 10:55:28
取消监控某个索引:
SQL> ALTER INDEX MPAYMENTAPPL_FLAGS NOMONITORING USAGE;
Index altered.
SQL> select * from V$OBJECT_USAGE
2 /
INDEX_NAME TABLE_NAME MON USE START_MONITORING END_MONITORING
------------------------------ ------------------------------ --- --- ------------------- -------------------
IDX_MPAYMENTAPPL_BCODE MPAYMENTAPPL YES NO 03/24/2010 10:55:27
MPAYMENTAPPL_FLAGS MPAYMENTAPPL NO NO 03/24/2010 10:55:27 03/24/2010 10:57:19
MPAYMENTAPPL_PAICODE MPAYMENTAPPL YES NO 03/24/2010 10:55:28
那些持续关注一定时间没有使用的索引就可以删除了,以提高DML操作效率
实际工作中,我们可以选择暂时禁用索引功能,来提高数据表插入、修改效率。因为,在索引起作用的情况下,大量数据的DML操作会带来很多的索引更新和Redo Log的生成。这在批量数据加载的时候是不需要的。所以,可以暂时禁用索引。