暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

I have a very large table, but it only has a few rows left in it. How can I reclaim the space ?

2011-01-01
837

The Oracle (tm) Users' Co-Operative FAQ

I have a very large table, but it only has a few rows left in it. How can I reclaim the space ?


Author's name: Connor McDonald

Author's Email: connor_mcdonald@yahoo.com

Date written: November 10, 2001

Oracle version(s): 7.3+

I have a very large table, but it only has a few rows left in it. How can I reclaim the space ?


The answer to "Can I reclaim the space?" is always a resounding "YES". However a more appropriate question may be "Can I reclaim the space cheaply" to which the answer (as it always tend to be) is "maybe..."

Since Oracle 7.3, the "ALTER TABLE" command has included the option to release unused space from a table. The command is:

alter table MY_TABLE deallocate unused keep xx

(where xx is the amount of table free space you wish to retain)

The important thing here is the definition of "unused" - by this Oracle means never used space, that is, anything above the table's current high water mark. Unfortunately, in a table of 'n' blocks where 'm' are used (n>m), the distribution of those 'm' blocks is (as good as) random. So (if you're lucky) you might find that your large table was simply an error of initial allocation, and that much of the table has never been used. In this case, altering the table to deallocate unused space is an "instantaneous" way to reclaim the space.

Of course, if you're not so lucky, and the rows are dispersed widely across the table blocks, then they will need to be relocated to the "front" of the table to reclaim the space, and "relocated" means work. The easiest way to do this is to be on 8.1+, where you can issue

alter table MY_TABLE move

or even better, if you're on 9.0+

alter table MY_TABLE move online

Unfortunately, if you're on a release prior to 8.1, you're up for the standard unload/reload practices, namely export/import or create-table-as-select et al.


Further reading: (all via technet) "ALTER TABLE MOVE" command and "Export/Import" utilities



最后修改时间:2020-04-16 15:12:13
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论