很多軟件開發(fā)過程中,,沒有注意合理規(guī)劃索引,造成一個表上有N多個索引,,為后續(xù)的維護(hù)和優(yōu)化帶來麻煩,。因 此有時候需要監(jiān)控已有的索引是否在使用,,oracle提供了監(jiān)控索引是否使用的工具,很簡單,,簡要介紹一下,。
首先,我們?nèi)绻潜O(jiān)控一個表上的所有索引,,可以這樣先生成監(jiān)控的命令:
SQL> select 'alter index '||index_name||' monitoring usage;' from user_indexes where table_name=upper('mpaymentappl')
2 /'ALTERINDEX'||INDEX_NAME||'MONITORINGUSAGE;'
------------------------------------------------------------
alter index IDX_MPAYMENTAPPL_BCODE monitoring usage;
alter index MPAYMENTAPPL_FLAGS monitoring usage;
alter index MPAYMENTAPPL_PAICODE monitoring usage;
然后執(zhí)行這些腳本就開始監(jiān)控了,,監(jiān)控信息可通過V$OBJECT_USAGE查看,通過used列可知道這個索引是否被使用:
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 YES NO 03/24/2010 10:55:27
MPAYMENTAPPL_PAICODE MPAYMENTAPPL YES NO 03/24/2010 10:55:28
取消監(jiān)控某個索引:
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
那些持續(xù)關(guān)注一定時間沒有使用的索引就可以刪除了,,以提高DML操作效率,。