当表被执行过多的DELETE 回收碎片空间的几种方式

本文介绍了在数据库中,当表经历大量DELETE操作导致空间碎片时,可以采取的六种有效方法来回收空间。包括使用Create Table As Select (CTAS)、在线重定义、数据泵导入导出、Alter Table Move、Alter Table Shrink Space以及通过Insert Into和Truncate的组合操作。这些方法旨在减少碎片,提高表的性能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. 创建新表替换原来的表

Create table As Select (CTAS) - This copies the table rows into a clean area, lowering the high-water-mark, packing the rows densely (as dictated by PCTFREE) and releasing free space.

create table test nologging as select * from source_table; 

2. 在线重定义

Online reorg - Using the dbms_redefinition package you can use parallel CTAS to reorganize tables, while the tables continue to accept updates.

3. 导入导出

Data pump (expdp, impdp) - Rarely used in high-speed production apps, except for backups.

4. 使用 alter table move

Alter table move - The alter table xxx move command moves rows down into un-used space and adjusts the HWM but does not adjust the segments extents, and the table size remains the same.  The alter table move syntax also preserves the index and constraint definitions.

5.使用alter table shrink

Alter table shrink space - Using the "alter table xxx shrink space compact" command will re-pack the rows, move down the HWM, and releases unused extents.  With standard Oracle tables, you can reclaim space with the "alter table shrink space" 

6.使用insert into 到中间表, 再 truncat 原表, 最后在将数据插入原表中

insert  /*+ append nologging */  into target_test  select * from source_table;

需要将index disable, 重新 rebuild

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值