How To Reclaim Wasted Space on The Segment (Table, Index and LOB) and Tablespace Levels (文档 ID 16827

转到底部转到底部

In this Document

Purpose
 Details
 How to know if the segment is fragmented
 Table
 Index
 LOB segment (both Securefiles and Basic files) 
 How to reclaim free space (below HWM)
 Table
 Index
 LOB Segment
 How to reclaim the space back to the OS / ASM diskgroup by decreasing the datafile size
 System tablespace
 References

APPLIES TO:

Oracle Database - Enterprise Edition - Version 10.2.0.1 and later
Information in this document applies to any platform.

PURPOSE

  This note aims to provide guidance on how to reclaim wasted space (fragmented space) introduced by deleting rows, moving or dropping tables, etc ..

DETAILS

How to know if the segment is fragmented

Table
  1. Use Segment advisor (best and most accurate results) . Refer  
    1.  10g and above SEGMENT ADVISOR (Doc ID 242736.1
    2.   Automatic Segment Advisor in Oracle 10g Release 2 (10.2) (Doc ID 314112.1)
  2. Use the following query (Statistics must be fresh for the tables to be examined)
exec dbms_stats.gather_table_stats('<OWNER>','<TABLE NAME>');
select owner,table_name,round((blocks*8),2)||' kb' "TABLE SIZE",round((num_rows*avg_row_len/1024),2)||' kb' "ACTUAL DATA" from dba_tables where table_name='<YOUR TABLES'S NAME>';
Index

An index could grow to be even bigger than the table's size at times, if your table has only one column then it's expected than the index's size could slightly exceed the table's size. The other reason for index growth (bigger than table's size or not) would be fragmentation. Rebuilding an index or recreating it usually save space on the cost of index performance. Before you decide to rebuild / recreate and index please check the following document first: Index Rebuild, the Need vs the Implications (Doc ID 989093.1)

LOB segment (both Securefiles and Basic files) 
  1. You can use the function DBMS_SPACE.SPACE_USAGE . This is applicable only for LOBs on ASSM tablespaces.
  2. You can calculate the actual size of data and see if it's hugely lower than the size of the extent reported by DBA_EXTENTS. This is applicable on both ASSM and MSSM tablespaces.

The details for both methods are explained in the following document:

How to Determine what storage is used in a LOBSEGMENT and should it be shrunk / reorganized? (Doc ID 1453350.1)

How to reclaim free space (below HWM)

Table
  1. The first method is by recreating the table, there are many alternatives to accomplish this task:
    1. Create Table As Select (CTAS)
    2. Export / Import
    3. Alter table ... move
    4. Online Redefinition (only method that fully allows DMLs to run against the table while the operation is running)
      1. This is discussed in details in the following note:  How to Reorganize a Table (Doc ID 151588.1)
  2. The second method is by using the shrink command

            Refer: Why is no space released after an ALTER TABLE ... SHRINK? (Doc ID 820043.1)

Index
  1. Use alter index .. rebuild command
  2. Use alter index .. coalesce command
  3. Drop and recreate the index
LOB Segment

There are multiple options here:

  1. Shrink command (not applicable for Securefile LOBs)
  2. DBMS_REDEFINITION (Fully online operation)
  3. Export / Import

This is explained in more details in

How to Shrink (make less sparse) a LOB (BASICFILE or SECUREFILE)? (Doc ID 1451124.1)

How to reclaim the space back to the OS / ASM diskgroup by decreasing the datafile size

If you want to decrease the datafile's size by an amount bigger than the bytes at the end of the datafile you will have to do the following procedure:
1- Run SHRINK_DATAFILE.SQL from How to Resize a Datafile (Doc ID 1029252.6)

2- You will provide two pieces of information to the script, the file ID and the desired new size

3- Move the segments that appear in the script's result set to a new tablespace

4- Run the script again and make it returns no results

5- Use the "ALTER DATABASE DATAFILE '<full path and name of the file>' RESIZE [K|M|G];" command to resize the datafile

If you tried to resize the datafile beyond the the bytes at the end of the datafile you will hit an ORA-3297 error

For more details please refer to

How to Resize a Datafile (Doc ID 1029252.6)

System tablespace

Please note that the procedure described in the previous section doesn't apply to system tablespace, this tablespace contains many bootstrap objects that should not be moved, if system tablespace is fragmented the only possible way is to recreate the database. You can recreate the database and copy the data using TTS (Transportable Tablespace) or Export/Import method.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值