Ask the Expert

Decreasing tablespace size

I have an Oracle8i Database Server, which has a tablespace with 16 data files amounting to 32 GB of disk space usage. I have deleted a lot records that are using these tablespaces, but its apparent that the tablespace size will not decrease. How do I go ahead with freeing up space? I cannot create a new table and move data to it.

    Requires Free Membership to View

One of the principles of any database management system is to do as little work as possible. With that in mind, when you delete rows of data from a table, Oracle does not deallocate this once-used space. Instead, it leaves this space allocated for future insertions into the table. So how do you reclaim this space? First, you'll want to copy the data in that table to a temporary table. This can be done with a statement as simple as follows:

CREATE TABLE my_temp_table AS SELECT * FROM orig_table;

Then, disable any foreign key constraints to and from this original table. Also disable any triggers on the table. Next, you can remove all remaining data and reclaim all space, except for the INITIAL extent, by issuing the following command:

TRUNCATE TABLE orig_table;

Then, move the data back into the original table:

INSERT INTO orig_table SELECT * FROM my_temp_table;

Finally, enable any constraints or triggers that you disabled and drop the temporary table.

This was first published in December 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: