Home > Ask the Oracle Database / Applications Experts > Oracle database design and architecture Questions & Answers > Defragmenting a tablespace to free up contiguous space?
Ask The Oracle Expert: Questions & Answers
EMAIL THIS

Defragmenting a tablespace to free up contiguous space?

Brian Peasland EXPERT RESPONSE FROM: Brian Peasland

Pose a Question
Other Oracle Categories
Meet all Oracle Experts
Become an Expert for this site


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


>
QUESTION POSED ON: 07 February 2003
I have a tablespace consisting of four data files. Each data file is 1 GB. Overall, the tablespace has around 1.5 GB of data free. But the maximum contiguous free space available is only 50 MB. Can I defragment a tablespace to solve this issue? If yes what is the command?

>

Your answer really depends on the database version and how you set up the tablespaces. What you describe is called "fragmentation of free space". This is a problem as you are noticing. You have tons of free space, but each piece of free space is so small as to make it unusable.

Since this is a problem for you, I'm assuming that you are using a Dictionary Managed Tablespace (DMT). Prior to Oracle 8i, DMT's were the only type of tablespace. In a DMT, SMON is responsible for coallescing free space, but it won't move objects around to unfragment free space. And there is no single command which will do this either.

Oracle 8i introduced the Locally Managed Tablespace (LMT). Most DBAs now use LMTs with a uniform extent size. This way, all free space chunks always equal the segment's extent size. You will never have fragmented free space that becomes unusable. All free space fragments always equal any extent size, therefore it is always usable.

To fix your problem, I would create a secondary tablespace and move all tables to this tablespace with the ALTER TABLE MOVE command. Indexes can be moved with the ALTER INDEX REBUILD. Then, drop your tablespace and recreate it. If you are using Oracle 8i+, then make sure that this is a LMT with uniform extent sizes. This can be done as follows:

CREATE TABLESPACE new_ts
DATAFILE '/somedir/new_ts01.dbf' SIZE 1000M
EXTENT MANAGEMENT LOCAL UNIFORM SIZE 64K;
Now move everything back into this tablespace and drop your secondary tablespace.

If you are using pre-Oracle 8i, then you cannot use a LMT. But you can still unfragment your free space. In this case, the ALTER TABLE MOVE command is not available to you. So you'll have to export your objects first, and then import them back.

For More Information


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
Oracle database design and architecture
Why am I receiving Oracle memory allocation errors?
How to join two tables with unique keys in Oracle
How does the Oracle LGWR write to online redo log files?
Can I check an Oracle instance without logging into the Oracle server?
How to use V$SEGMENT_STATISTICS to find the most accessed Oracle table
Can I install an Oracle client on Windows 7?
How to use the Oracle Database Upgrade Assistant (DBUA)
Can I specify Oracle column order in my database table?
Can I have a single Oracle 11g RAC instance across multiple databases?
How to use the Oracle export utility to duplicate database structure

Oracle database design and architecture
Why am I receiving Oracle memory allocation errors?
How to join two tables with unique keys in Oracle
Can I check an Oracle instance without logging into the Oracle server?
How does the Oracle LGWR write to online redo log files?
How to determine your SQL database through needs analysis
Breaking down the contenders in the SQL database market
The MySQL open source database in the enterprise
Diving deeper into the SQL database features
What managers should consider when starting a database scaling project
How to use V$SEGMENT_STATISTICS to find the most accessed Oracle table

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
E. F. Codd  (SearchOracle.com)
extent  (SearchOracle.com)
flexfield  (SearchOracle.com)
foreign key  (SearchOracle.com)
multidimensional database  (SearchOracle.com)
object-oriented database management system  (SearchOracle.com)
quad tree  (SearchOracle.com)
relational online analytical processing  (SearchOracle.com)
row  (SearchOracle.com)
splay tree  (SearchOracle.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice



Oracle White Papers: Fusion Middleware
HomeNewsTopicsTipsAsk the ExpertsMultimediaWhite PapersProductsBlogs
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2003 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts