索引的维护和管理:
-----查系统表空间非系统用户的索引情况
select count(*)
from dba_indexes
where tablespace_name='SYSTEM' and owner not in('SYS','SYSTEM');
select table_name,index_name
from dba_indexes
where tablespace_name='SYSTEM' and owner not in('SYS','SYSTEM');
----index's storage check
select segment_name,count(*) ---查看索引SEGMENT中extent的数量
from dba_extents
where segment_type='INDEX'
and owner=upper(&owner)
group by segment_name
---查看指定表空间内的索引的扩展情况:
select
substr(segment_name,1,20),bytes,count(bytes)
from dba_extents
where segment_name in
(select index_name
from dba_indexes
where tablespace_name=upper(&表空间))
group by segment_name,bytes
order by segment_name;
索引的选择性:
就是索引列中不同值数量与表中记录数据的比
一个索引的选择性越接近于1,这个索引越好.
测定索引选择性的办法:
1,手工 select count(distinct col1)/count(*) from table ---在创建索引前就可以知道索引的选择性
2,自动 analyze table tablename compute statisitics;
select distinct_keys from user_indexes where table_name='&tablename' and index_name='&indexname';
select num_rows from user_tables where table_name='&tablename';
select i.distinct_keys/t.num_rows
from user_indexes i,user_tables t
where i.table_name='&tablename'
and i.index_name='&indexname' and i.table_name=t.table_name;
you also get selectivity of every column
select column_name,num_distinct
from user_tab_columns where table_name='&tablename';---note,这个方法不能精确测定.还要分析表
确定索引的实际碎片:
产生:因为对表的频繁的dml,(for mostly insert and delete),you must rebuild index for optimal performace in i/o
验证索引:validate index owner.indexname;---将有索引信息放入index_stats表
select name,del_if_rows,lf_rows,round((del_if_rows/(if_rows+0000000001))*100)
from index_stats;查询index_stats表以确定索引中删除的、未填满的叶子行的百分比。
---如果索引的叶子行的碎片超过10%,对索引进行重建
alter index owner.indexname rebuild tablespace tablespacename storage (intial value next value ) nologging;
当然,如果空间有限,不能重建索引,可以整理索引
alter index owner.indexname coalsce;
analyze index owner.indexname ---perge information on analyze
delete statistics;
---确认表和索引不在同一个表空间:为了balance io load
select i.owner,i.index_name,t.table_name,i.tablespace_name
from dba_indexes i.dba_tables t
where i.owner=t.owner and i.table_name=t.table_name and
i.tablespace_name=t.tablespace_name
and i.owner not in('SYS','SYSTEM');
查看数据表空间有哪些索引
select owner,segment_name,sum(bytes) from dba_segments where
tablespace_name='data tablespace' and segment_type='INDEX'
group by owner,segment_name;
查哪些索引扩展次数太多(>=10)
索引依赖于表,表记录加大,它也会加大,如果一个索引的next extent设置不合理(大小),
索引segment的扩展变得很频繁.索引extent太多,检索速度会影响.
set linesize 100
select count(*),owner,segment_name,tablespace_name
from dba_extents
where segment_type='INDEX' and
owner not in('SYS','SYSTEM')
group by owner,segment_name,tablespace_name
having count(*)>10
order by count(*) desc
找出要重建的索引后,确定索引的大小,以设置合理的存储参数
select owner,segment_name,tablespace_name,bytes,sum(bytes),round(sum(bytes)/(1024*1024),0),
count(bytes) from dba_extents where segment_type='INDEX' and segment_name in
('index1','index2','index3')
group by owner,segment_name,segment_type,tablespace_name,bytes
order by owner,segment_name;
确定索引表空间有足够的空间吗
select round(bytes/(1024*1024),2)
from sm$ts_free
where tablespace_name='tablespacename';要把索引重建到哪个索引表空间中。要保证相应的索引表空间有足够的剩余空间
重建索引注意:
1,如不指定tablespace,默认创建在用户的default tablespace
2,因为索引重建没有恢复,可以nologging
3,如果出现资源busy,表示有进程在用,可以过会再提交
alter index indexname tablespace indextablespace storage(inital value next value) nologging;
检查索引
对重建的索引进行检查
select * from dba_extents where segment_name='indexname';
DBA_FREE_SPACE_COALESCEDDBA_FREE_SPACE_COALESCED
it describes statistics on coalesced space in all tablespaces in the database
找出有碎片有表空间,收集其碎片,重建索引后,原有索引被删除,这样会造成表空间的碎片
select 'alter tablespace '||tablespace_name||' coalesce;'
from dba_free_space_coalsces
where percent_blocks_coalsced!=100;
alter tablespace tablespacename coalsce;--整理表空间的碎片
[ 本帖最后由 wisdomone1 于 2008-4-27 02:20 编辑 ]

dba_free_space_coalesced.GIF
-----查系统表空间非系统用户的索引情况
select count(*)
from dba_indexes
where tablespace_name='SYSTEM' and owner not in('SYS','SYSTEM');
select table_name,index_name
from dba_indexes
where tablespace_name='SYSTEM' and owner not in('SYS','SYSTEM');
----index's storage check
select segment_name,count(*) ---查看索引SEGMENT中extent的数量
from dba_extents
where segment_type='INDEX'
and owner=upper(&owner)
group by segment_name
---查看指定表空间内的索引的扩展情况:
select
substr(segment_name,1,20),bytes,count(bytes)
from dba_extents
where segment_name in
(select index_name
from dba_indexes
where tablespace_name=upper(&表空间))
group by segment_name,bytes
order by segment_name;
索引的选择性:
就是索引列中不同值数量与表中记录数据的比
一个索引的选择性越接近于1,这个索引越好.
测定索引选择性的办法:
1,手工 select count(distinct col1)/count(*) from table ---在创建索引前就可以知道索引的选择性
2,自动 analyze table tablename compute statisitics;
select distinct_keys from user_indexes where table_name='&tablename' and index_name='&indexname';
select num_rows from user_tables where table_name='&tablename';
select i.distinct_keys/t.num_rows
from user_indexes i,user_tables t
where i.table_name='&tablename'
and i.index_name='&indexname' and i.table_name=t.table_name;
you also get selectivity of every column
select column_name,num_distinct
from user_tab_columns where table_name='&tablename';---note,这个方法不能精确测定.还要分析表
确定索引的实际碎片:
产生:因为对表的频繁的dml,(for mostly insert and delete),you must rebuild index for optimal performace in i/o
验证索引:validate index owner.indexname;---将有索引信息放入index_stats表
select name,del_if_rows,lf_rows,round((del_if_rows/(if_rows+0000000001))*100)
from index_stats;查询index_stats表以确定索引中删除的、未填满的叶子行的百分比。
---如果索引的叶子行的碎片超过10%,对索引进行重建
alter index owner.indexname rebuild tablespace tablespacename storage (intial value next value ) nologging;
当然,如果空间有限,不能重建索引,可以整理索引
alter index owner.indexname coalsce;
analyze index owner.indexname ---perge information on analyze
delete statistics;
---确认表和索引不在同一个表空间:为了balance io load
select i.owner,i.index_name,t.table_name,i.tablespace_name
from dba_indexes i.dba_tables t
where i.owner=t.owner and i.table_name=t.table_name and
i.tablespace_name=t.tablespace_name
and i.owner not in('SYS','SYSTEM');
查看数据表空间有哪些索引
select owner,segment_name,sum(bytes) from dba_segments where
tablespace_name='data tablespace' and segment_type='INDEX'
group by owner,segment_name;
查哪些索引扩展次数太多(>=10)
索引依赖于表,表记录加大,它也会加大,如果一个索引的next extent设置不合理(大小),
索引segment的扩展变得很频繁.索引extent太多,检索速度会影响.
set linesize 100
select count(*),owner,segment_name,tablespace_name
from dba_extents
where segment_type='INDEX' and
owner not in('SYS','SYSTEM')
group by owner,segment_name,tablespace_name
having count(*)>10
order by count(*) desc
找出要重建的索引后,确定索引的大小,以设置合理的存储参数
select owner,segment_name,tablespace_name,bytes,sum(bytes),round(sum(bytes)/(1024*1024),0),
count(bytes) from dba_extents where segment_type='INDEX' and segment_name in
('index1','index2','index3')
group by owner,segment_name,segment_type,tablespace_name,bytes
order by owner,segment_name;
确定索引表空间有足够的空间吗
select round(bytes/(1024*1024),2)
from sm$ts_free
where tablespace_name='tablespacename';要把索引重建到哪个索引表空间中。要保证相应的索引表空间有足够的剩余空间
重建索引注意:
1,如不指定tablespace,默认创建在用户的default tablespace
2,因为索引重建没有恢复,可以nologging
3,如果出现资源busy,表示有进程在用,可以过会再提交
alter index indexname tablespace indextablespace storage(inital value next value) nologging;
检查索引
对重建的索引进行检查
select * from dba_extents where segment_name='indexname';
DBA_FREE_SPACE_COALESCEDDBA_FREE_SPACE_COALESCED
it describes statistics on coalesced space in all tablespaces in the database
找出有碎片有表空间,收集其碎片,重建索引后,原有索引被删除,这样会造成表空间的碎片
select 'alter tablespace '||tablespace_name||' coalesce;'
from dba_free_space_coalsces
where percent_blocks_coalsced!=100;
alter tablespace tablespacename coalsce;--整理表空间的碎片
[ 本帖最后由 wisdomone1 于 2008-4-27 02:20 编辑 ]
dba_free_space_coalesced.GIF
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9240380/viewspace-350554/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/9240380/viewspace-350554/