1. 程式人生 > >索引幹貨-索引監控腳本

索引幹貨-索引監控腳本

輸出 name tor sta cts monitor objects rop mon

索引監控的查詢腳本

drop table t purge;

create table t as select * from dba_objects;

create index idx_t_id on t(object_id);

create index idx_t_name t(object_name);

--未監控索引時,v$object_usage查詢不到任何記錄

select * from v$object_usage;

--接下來對idx_t_id和idx_t_name兩列索引做監控

索引監控的實施

alter index idx_t_id monitoring usage;

alter index idx_t_name monitoring usage;

set linesize 166

col index_name for a10

col table_name for a10

col monitoring for a10

col used for a10

col start_monitoring for a25

col end_monitoring for a25

select * from v$object_usage;

索引監控的跟蹤

--以下查詢必然用到object_id列的索引

select object_id from t where object_id = 19;

--觀察分析,果然發現idx_t_id列的索引的used果然更改為YES

select * from v$object_usage;

查看輸出結果如下:


SQL> select * from v$object_usage;

INDEX_NAME TABLE_NAME MONITORING USED START_MONITORING END_MONITORING
---------- ---------- ---------- ---------- ------------------------- --------------------------------------------------------------------
IDX_T_ID T YES YES

04/24/2013 14:13:09
IDX_T_NAME T YES NO 04/24/2013 14:13:09

索引幹貨-索引監控腳本