达梦有一个功能就是可以开启索引使用监控,监控索引有没有被使用到,根据这个我们可以对一些冗余索引进行处理
对索引进行监控的sql语法如下:
alter index 索引所属者.索引名 monitoring usage;
取消监控语法:
alter index 索引所属者.索引名 nomonitoring usage;
索引监控起来了,对应的索引使用情况怎样的?去哪里获知呢?
通过以下视图可以获知监控的索引使用情况
select *
from SYS.“V$OBJECT_USAGE”
运维案例:
1、确定需要监控的索引【达梦只能监控用户创建的二级索引】
begin
for rs in(
select ‘alter index ‘||owner||’.’||index_name||’ monitoring usage;’ as exec_sql,*
from SYS.DBA_INDEXES
where INDEX_TYPE=‘NORMAL’ and owner=‘SYSDBA’) --监控sysdba下面的二级索引
loop
execute immediate rs.exec_sql;
end loop;
end;
2、监控系统运行一段时间后
3、查看监控的索引使用情况 used字段 =yes 表示使用过 =no 表示未被使用过
select * from V$OBJECT_USAGE;
4、备份未使用的索引定义到表op_index,删除未使用的索引
–创建备忘表
CREATE TABLE OP_INDEX(A DATETIME DEFAULT NOW(),B CLOB);
begin
for rs in(
selec