Oracle查看索引状态及索引重建
目录
1,查询索引状态
1.1 查询user_indexes表
1.2 查询分区索引-user_ind_partitions表
1.3 检查损坏索引
2,索引重建
2.1全局索引重建
2.2 local索引重建
1,查询索引状态
1.1 查询user_indexes表
select status,T.* from user_indexes T where table_name='表名'
状态列STATUS说明:
valid:当前索引有效
N/A :分区索引 有效
unusable:索引失效
1.2 查询分区索引-user_ind_partitions表
select index_name, partition_name, status
from user_ind_partitions
where index_name = '索引名称';
索引状态说明:
USABLE:索引有效
UNUSABLE:索引失效
1.3 检查损坏索引
SELECT status, COUNT(*)
FROM dba_indexes
GROUP BY status
UNION
SELECT status, COUNT(*)
FROM dba_ind_partitions
GROUP BY status
UNION
SELECT status, COUNT(*)
FROM dba_ind_subpartitions
GROUP BY status
2,索引重建
2.1全局索引重建
alter index pk_kc03 rebuild nologging;
or
alter index pk_kc03 rebuild
2.2 local索引重建
select b.table_name,
a.INDEX_NAME,
a.PARTITION_NAME,
a.STATUS,
'alter index ' || a.index_name || ' rebuild partition ' ||partition_name || ';' --重建列
from USER_IND_PARTITIONS a, user_part_indexes b
where a.index_name = b.index_name
and b.TABLE_NAME IN ('PART_TAB_SPLIT')
and STATUS = 'UNUSABLE'
ORDER BY b.table_name, a.INDEX_NAME, a.PARTITION_NAME;
在针对truncate等 操作时直接更新 index 也可以搞定。
alter table part_tab_trunc truncate partition p2 Update GLOBAL indexes;