数据库优化之表碎片处理

查看碎片程度高的表

SELECT segment_name table_name , COUNT(*) extents
FROM dba_segments WHERE owner NOT IN ('SYS', 'SYSTEM') GROUP BY segment_name
HAVING COUNT(*) = (SELECT MAX( COUNT(*) ) FROM dba_segments GROUP BY segment_name);

If you have to rebuild a table,always consider the 'move' command first.Availability can be reduced,but the benefit to administrative safty and convenience is large.There are no windows of opportunity for data to go missing.----Jonathan Lewis.


如果必须要重建表,alter table ...move tablespace...绝对是第一选择,理由如下:
1 对于大表move时,对此表的查询不受影响,只有在move操作完成的瞬间受影响。DML操作受影响。
2 index结构不受影响,只需move完成后rebuild。
3 与其它对象依赖关系不受影响,操作前不必为对象间的依赖关系操心。
4 move操作可以parallel。
5 NOLOGGING选项对move操作有作用,可大大加快重建速度。如果要move的表是nologging的,则不需指定。
基于以上理由,move是rebuild table的最佳选择,应该优先考虑,大家可以对照以上优点考虑一下用exp/imp的优缺点。采取的策略根据实际需求的不同而不同,关键是得知道我们有哪几种方案,每种方案的优缺点。

碎片程度

select tablespace_name,count(tablespace_name) from dba_free_space group by tablespace_name having count(tablespace_name)>10;

alter tablespace name coalesce;
alter table name deallocate unused;

create or replace view ts_blocks_v as
select tablespace_name,block_id,bytes,blocks,'free space' segment_name from dba_free_space
union all
select tablespace_name,block_id,bytes,blocks,segment_name from dba_extents;

select * from ts_blocks_v;

select tablespace_name,sum(bytes),max(bytes),count(block_id) from dba_free_space
group by tablespace_name;

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/35489/viewspace-84949/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/35489/viewspace-84949/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值