Home » RDBMS Server » Server Administration » Database fragmentation and shrinking
icon4.gif  Database fragmentation and shrinking [message #125979] Thu, 30 June 2005 06:06 Go to next message
rodionov
Messages: 6
Registered: June 2005
Junior Member

I've got a problem with my Oracle database. As I have understood my database fragmentation is high and that causes some problems with free space on a disk. Is it possible to do something with my tablespaces to make it un-fragmented?
I can give such example: I have tablespace which size is 32Gb Oracle Enterprise Manager shows that is is used 11Gb, but when I try to make a size of this tablespace 15 Gb an error message is shown: ORA-03297 file contains used data beyond requested RESIZE value.
I'm using Oracle database server 9.2.0.3.

I have to warn you that prioritized task is to unfragment my tablespace or maybe it is possible to do it for a whole database.

[Updated on: Thu, 30 June 2005 07:02]

Report message to a moderator

Re: Database fragmentation and shrinking [message #125985 is a reply to message #125979] Thu, 30 June 2005 06:29 Go to previous messageGo to next message
shettyshetty
Messages: 18
Registered: June 2005
Location: Malaysia
Junior Member
Hi Rodionov,

Use the scripts provided below to know how much you can shrink the datafiles without getting ORA-03297 error.(Orginal author of the script is Oracle Guru Tom Kyte)
OR else use ALTER TABLE <name> MOVE... & ALTER INDEX <name> REBUILD commands to move to a new tablespace. After moving all the objects you can drop the tablespace.

select value from v$parameter where name = 'db_block_size'
/

select file_name,
ceil( (nvl(hwm,1)*&&blksize)/1024/1024 ) smallest,
ceil( blocks*&&blksize/1024/1024) currsize,
ceil( blocks*&&blksize/1024/1024) -
ceil( (nvl(hwm,1)*&&blksize)/1024/1024 ) savings
from dba_data_files a,
( select file_id, max(block_id+blocks-1) hwm
from dba_extents
group by file_id ) b
where a.file_id = b.file_id(+);


select 'alter database datafile '''||file_name||''' resize ' ||
ceil( (nvl(hwm,1)*&&blksize)/1024/1024 ) || 'm;' cmd
from dba_data_files a,
( select file_id, max(block_id+blocks-1) hwm
from dba_extents
group by file_id ) b
where a.file_id = b.file_id(+)
and ceil( blocks*&&blksize/1024/1024) -
ceil( (nvl(hwm,1)*&&blksize)/1024/1024 ) > 0;

Sunil
Re: Database fragmentation and shrinking [message #126037 is a reply to message #125979] Thu, 30 June 2005 11:36 Go to previous messageGo to next message
smartin
Messages: 1803
Registered: March 2005
Location: Jacksonville, Florida
Senior Member
Just to add...I'm not sure I'd use the term fragmentation in this case. To me fragmentation implies having "holes", probably unusable ones, in your files. What you describe sounds to me like simply a case of a tablespace that was created with a much larger size than is currently being used, and you have decided to shrink it to reclaim some of the extra space.

Hopefully you have checked that the tablespace wasn't created with that larger size intentionally, and that by reducing the space you won't be causing problems down the road when the size of your data grows.

Also, in cases of true fragmentation, use locally managed tablespaces and it won't be an issue. Oh and 10g has some new online tablespace shrink capabilities that you may want to investigate (I haven't used them, I've always used the move and rebuild approach described above).
Re: Database fragmentation and shrinking [message #126108 is a reply to message #125979] Fri, 01 July 2005 00:48 Go to previous messageGo to next message
rodionov
Messages: 6
Registered: June 2005
Junior Member

You are right that database datafiles were big from the very begining. About 25 thousand tables were created for 2 mounth or maybe more by program that stores it's data in this database. Then they were drooped. Now there is a large holes in this tablespace I want to get rid of this holes.
As I understood from your reply in Oracle 9 there is no mechanism which can help me in it and this mechanism is implemented only on Oracle 10g.
Re: Database fragmentation and shrinking [message #126196 is a reply to message #125979] Fri, 01 July 2005 08:36 Go to previous message
smartin
Messages: 1803
Registered: March 2005
Location: Jacksonville, Florida
Senior Member
The alter table move approach described by shettyshetty above will work in 9i. Just have to rebuild indexes after.
Previous Topic: ORA-04067 error when exporting
Next Topic: Problem because of heterogeneous Service?
Goto Forum:
  


Current Time: Fri Sep 27 00:13:24 CDT 2024