Tip

A simple way to reorganize a table and release the unused space

During Extract/Transform/Load (ETL) projects we do a lot of data loading, deleting and reloading. I have come up with this simple solution to better manage and organize the table space and performance during ETL operations. Our table size grew considerably though it has much less data. So any full table scan operation was taking a long time. After we used this method, we reduced the table size, released unused table space and gained lot of time during full table scan operations on the table.

I looked into Oracle documentation on how to reoganize a table and they say to use EXPORT or IMPORT, or it can be done by copying data into a temporary table, using TRUNCATE on the table, and then moving data back to the original table. We were planning to do something like that until I came up with this idea. We use this method to reorganize about 100 tables spanning several GBs of storage space. It was tested using Oralce 9.2.0.3.

We load data into a table by the direct path method:

INSERT /*+ APPEND */
In such a direct-path INSERT, data is appended to the end of the table rather than using existing space currently allocated to the table. When we load data into a table and delete some or all of the records by using the DELETE statement, the delete operation does not release the allocated space even if there isn't any data. So until the space is released, they are not going to be used by any direct load operation.
ALTER TABLE <table_name> MOVE;

    Requires Free Membership to View

The above command reorganizes the table in the same table space. Basically, the reorganization allocates new space that is needed for the amount of data the table has. Then it releases all the previously allocated space that doesn't have data any more. All the physical attributes of the table remain the same. Optionally, one can use the ONLINE option of the ALTER TABLE command.

For More Information

  • Feedback: E-mail the editor with your thoughts about this tip.
  • More tips: Hundreds of free Oracle tips and scripts.
  • Tip contest: Have an Oracle tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize -- submit your tip today!
  • Ask the Experts: Our SQL, database design, Oracle, SQL Server, DB2, metadata, and data warehousing gurus are waiting to answer your toughest questions.
  • Forums: Ask your technical Oracle questions--or help out your peers by answering them--in our active forums.
  • Best Web Links: Oracle tips, tutorials, and scripts from around the Web.

This was first published in August 2003

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.