Oracle 表空间收缩

Oracle 表空间收缩

业务表频繁写入,删除,清空后,表占用的空间不能够及时释放,需要通过如下方式手工释放空间。

操作流程如下:

  • 1、更新业务表统计信息
  • 2、收缩业务表空间占用;
  • 3、生成数据文件收缩算法:
    校验当前数据文件大小与高水位,如果有超过100M剩余空间,将剩余空间的80%释放掉;
  • 4、执行数据文件收缩脚本

sql脚本

-- 更新业务表统计信息
call dbms_stats.gather_table_stats('user_name','table_name');

-- 收缩业务表空间占用
alter table xxx enable row movement ;
alter table xxx shrink space cascade;

-- 生成数据文件收缩算法
-- 校验当前数据文件大小与高水位,如果有超过100M剩余空间,将剩余空间的80%释放掉;
select 'alter database datafile ''' || a.file_name || ''' resize ' || round (a.filesize - (a.filesize - c.hwmsize - 100) * 0.8) || 'm;'
    , a.filesize || 'm' as "数据文件的总大小"
    , c.hwmsize || 'm' as "数据文件的实用大小"
from (select file_id
          , file_name
          , round (bytes / 1024 / 1024) as filesize
      from dba_data_files) a
    , (select file_id
           , round (max (block_id) * 8 / 1024) as hwmsize
       from dba_extents
       group by file_id) c
where a.file_id = c.file_id
    and a.filesize - c.hwmsize > 100;

-- 执行数据文件收缩脚本

你可能感兴趣的:(oracle,表空间收缩)