A simple way to reorganize a table and release the unused space
Rating: -3.18- (out of 5)
|Digg This! StumbleUpon Del.icio.us|
ttWriteMboxDiv(‘searchOracle_Tip_Content_Body’); ttWriteMboxContent(‘searchOracle_Tip_Content_Body’); 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 184.108.40.206.
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;
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.