Oracle 在线段收缩(Online Segment Shrink)
Oracle的在线段收缩(Online Segment Shrink)是指在线整理段空间里的碎片,在线,即在段压缩过程中,DML几乎不受影响(只有在结
Oracle的在线段收缩(Online Segment Shrink)是指在线整理段空间里的碎片,它有以下几个特点:
它不但能够收回高水位线以上未使用的空间,还可以收回高水位线下为使用的空间,它的主要步骤是:
使用Shrink有两个前提条件:
在线段收缩的语法如下:
alter table/index/materialized view object_name shrink space [cascade] [compact];
下面我们以一个实际例子来说明:
首先创建一个测试表和其上的一个索引:
SYS@TEST16>create table t as select * from dba_objects;
Table created.
SYS@TEST16>create index i on t(object_id);
Index created.
查看表和索引的空间使用情况:
SYS@TEST16>select segment_name,segment_type,bytes,blocks from dba_segments where owner='TEST' and segment_name in
2 (select 'T' from dual UNION ALL select index_name from dba_indexes where table_owner='TEST' and TABLE_NAME='T');
SEGMENT_NAME SEGMENT_TYPE BYTES BLOCKS
------------------------------ ------------------ ---------- ----------
T TABLE 9437184 1152
I INDEX 2097152 256
删除表数据,发现表和索引的空间并没有被收回:
SYS@TEST16>delete from t;
72568 rows deleted.
SYS@TEST16>commit;
Commit complete.
SYS@TEST16>select segment_name,segment_type,bytes,blocks from dba_segments where owner='TEST' and segment_name in
2 (select 'T' from dual UNION ALL select index_name from dba_indexes where table_owner='TEST' and TABLE_NAME='T');
SEGMENT_NAME SEGMENT_TYPE BYTES BLOCKS
------------------------------ ------------------ ---------- ----------
T TABLE 9437184 1152
I INDEX 2097152 256
直到做了段收缩之后,空间才被真正收回:
SYS@TEST16>alter table t enable row movement;
Table altered.
SYS@TEST16>alter table t shrink space cascade compact;
Table altered.
SYS@TEST16>alter table t shrink space cascade;
Table altered.
SYS@TEST16>select segment_name,segment_type,bytes,blocks from dba_segments where owner='TEST' and segment_name in
2 (select 'T' from dual UNION ALL select index_name from dba_indexes where table_owner='TEST' and TABLE_NAME='T');
SEGMENT_NAME SEGMENT_TYPE BYTES BLOCKS
------------------------------ ------------------ ---------- ----------
T TABLE 65536 8
I INDEX 65536 8
推荐阅读:
Oracle基础教程之通过RMAN复制数据库
RMAN备份策略制定参考内容
RMAN备份学习笔记
Oracle数据库备份加密 RMAN加密
上一篇: 用Jquery实现修改页面selecte标签的默认选择
下一篇: 图片路径问题