Question:
When I attempt to let go of space by resizing
my datafile I
get ORA-03297. How do I get around this ORA-03297 error and resize
my data file?
ALTER DATABASE DATAFILE
'/d001/pi2006_01.dbf' RESIZE 3000M;
*
ERROR at line 1:
ORA-03297: file contains used data beyond requested RESIZE value
Answer:
First, always remember
that disk has become very cheap, and you should only reclaim space in an
emergency when you have mis-judged your disk space requirements. The Oracle documentation
notes the following about ORA-03297:
ORA-03297: file contains used
data beyond requested RESIZE value
Cause: Some portion of the file in the region to be
trimmed is currently in use by a database object
Action: Drop or move segments containing extents in
this region prior to resizing the file, or choose a resize value such
that only free space is in the trimmed.
Here is a sequence of steps to fix the ORA-03297
error:
1 - First, query the dba_extents
view, and run
oracle scripts
to map out the free space in the data file.
2 -
Purge the recycle bin and try again.
3 - Try coalescing the tablespace (alter
tablespace fred coalesce;)
If these do not fix the ORA-03297 error, you need
to reorganize the objects in the tablespace's data file such that there
is only free space into the area that you want to delete. To
reorganize the objects in the data files tablespace, you have these
options:
- Try "alter tablespace" coalesce
- Reorganize
objects with Data Pump export/import
- The "alter table"
shrink space command
- Use "alter index" rebuild (if there
are indexes in the tablespace)
- Reorganize the tablespace
objects with dbms_redefinition or Create table
As Select (CTAS) - This copies the table rows into a clean area,
lowering the high-water-mark, and packing the rows densely.
Phillip Bracken notes these solutions on the ORA-03297 error:
"You are trying to shrink the tablespace below its
high water mark. If you are running Oracle 10g and are using locally
management tablespaces with Automatic Storage Management and row
movement enabled on the tables, you could issue an Alter Table Shrink.
If you are not at Oracle 10g or are not using locally managed
tablespaces, the only way around this is to drop or move the tables or
indexes containing extents above region in the tablespace you are trying
to resize it to, or try a different size that is not below the tablespace's high water mark."