views:

5543

answers:

5

how do i shrink datafiles in oracle 10G?

A: 

For standard datafiles in Oracle, you can't shrink them. You would have to do something like:

  1. Move the segments to another tablespace, or export and drop them
  2. Drop the datafile
  3. Create a new smaller datafile
  4. Move the segments back to the first tables, or import them from the dump file

For a "bigfile" tablespace -- meaning that CREATE BIGFILE TABLESPACE was used to create it -- you can use ALTER TABLESPACE .. RESIZE ...

Dave Costa
Incorrect. Data files can be resized down to the last used block, which can be determined from the dba_extents data dictionary view.
David Aldridge
What command would you use for that, David?
Dave Costa
Nevermind, I see it in kdgregory's answer.
Dave Costa
+1  A: 

Caveat: I am not an Oracle system administrator, other than for personal installs. Take everything I say with a large grain of salt.

I'm assuming that you created the datafiles with auto-extend, and they've been extended past what you feel they should contain. There is a clause to ALTER DATABASE that will resize a file, here's the example from the Oracle SQL reference:

ALTER DATABASE
DATAFILE 'diskb:tbs_f5.dat' RESIZE 10 M;

However, I really don't think you want to do this blindly.A better approach IMO would be to use the export command to dump the tables that are in that datafile, then recreate the tablespace.

kdgregory
A: 

What is advantages and disadvantage for using BIGFILE TABLESPACE?

Onegin
A: 

Hi Roman,

Here is a way, courtesy of Tom Kyte to get the block size of your db, list how much space you can possibly reclaim, and to build the alter... commands to actually perform the database shrinks. Hope this helps,

http://cglendenningoracle.blogspot.com/2009/08/how-do-i-shrink-datafiles-to-reclaim.html

Craig Glendenning

Craig Glendenning
Or just go directly to AskTom and get maxshrink.sql, and you can get a script that works, and suffer no adverts:http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:859827301882
AdamH
A: 

The ALTER TABLESPACE....RESIZE is only allowed beyond the HWM. So you might have many unused segmnets below it. Before this operation, issue an:

ALTER TABLE .. .SHRINK SPACE on some tables of that tablespace/datafile in order to reorganize the contents of the datafiles.

Might be a long task, but you can generate the commands with SQL.