Home » RDBMS Server » Server Administration » Shrinking a database after a cut-down
Shrinking a database after a cut-down [message #166352] Wed, 05 April 2006 20:09 Go to next message
rgoldwrx
Messages: 11
Registered: April 2006
Junior Member
Hi all,

This is the situation

- we are using oracle 9.2.0.1
- get a copy of a production database 80gb and put into another db
- run a cutdown script that culls about 70% of the data, for purposes of use as test databasese

What steps do we need to take to shrink this database now. I recalled an export and a import (with some option), then an export and then another reimport.

We need to shrink the tables that have had data removed as well as shrink the tablespaces (data files?). The resulting database will have a very small growth factor.

Is there a relatively easy way to achieve this?

Thanks for any advice.
Re: Shrinking a database after a cut-down [message #166376 is a reply to message #166352] Thu, 06 April 2006 01:14 Go to previous messageGo to next message
aciolac
Messages: 242
Registered: February 2006
Senior Member
At first I want to notice You that it is very difficult to drop file from database without loosing information(You must be sure that no one segment like TABLE or INDEX have not extents on this table before dropping). So, easiest way is to short them.
Oracle have the space managment that permit very easy to increase size of database but decrease size of database is harder(except Oracle 10G with ASM). Shorting of database performs by next steps:

1)The logic of space managment for tables are so, that even if You delete some data from table, size of them are not decrease(see documentation Oracle for more detailed description). For decreasing of table size, You must execute:
SQL>alter table your_table_name move;
After this command table become shorter, and You will be know really size of dates in Your database for the next calculations. Optionally You can move the table to other tablespace. Also this operation make indexes on this table unusable, so You must execute for every index of table(this operation is not necessarily to execute now, but execute only once at the ent of all operations):
SQL> alter index your_index_name rebuild;
This command will make index usable and will decrease size of index.

2)Even after shorting table size you cannot short datafiles. In Oracle databases You can short datafiles only if they have free space at the end of file(and You can short only until the last occupied block). You must create new tablespace(for temporar use) and to perform next set of operations:
a)To find table that have higest number of extents at the end of datafiles(this is the simplest method to find optimal table for our operations - mere efficient methods are more complex).
b)move them to the new created tablespace:
SQL>alter table your_table_name move tablespace new_created_tblsp;
Optionally, if Your tablespace permits, You can perform a)-b) until Your newly tablespace have free space - this will make shorting more effective. This thing make necessary to create our temporar tablespace so big so much possible(ideally to can move into them all tables from shorting tablespace).
c)to short datafile:
SQL> alter datafile 'your_datafile_name' resize 111M;
(number 111 is the ocasional).
Ideally You will can to short tablespace to the size of tables which will be palces on them.At the a) and c) will be good to write SQL command which helps to perform this operations, but I have no time now to create them - this task will perform You.
d)Move tables from temporarily created tablespace to the initial tablespace.

Perform a) -d) until the initial tablespace will be shorted enough(or until You will have time to short them Smile ). After that, rebuild Your indexes as are described in 1).

Regards.
Re: Shrinking a database after a cut-down [message #166611 is a reply to message #166376] Fri, 07 April 2006 04:07 Go to previous messageGo to next message
aciolac
Messages: 242
Registered: February 2006
Senior Member
Ia am writed a document which describe how tho short Your database. This is not the end version, but he can help You. I will be glad to see Your opinion about document and methods used in them.
Re: Shrinking a database after a cut-down [message #166639 is a reply to message #166352] Fri, 07 April 2006 06:10 Go to previous messageGo to next message
Mahesh Rajendran
Messages: 10708
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
>>- run a cutdown script that culls about 70% of the data,

How would you identify that 70% of data?
You can sure 'shrink' your tablespace/table whatever by the means said above. What about the data?
Re: Shrinking a database after a cut-down [message #166785 is a reply to message #166639] Sat, 08 April 2006 07:44 Go to previous messageGo to next message
ThomasG
Messages: 3212
Registered: April 2005
Location: Heilbronn, Germany
Senior Member
>>How would you identify that 70% of data?

With most applications that is quite straightforward once you figured out which tables you have to delete from. E.g. in any CRM or financials application you can just delete any documents older that one year.

Or delete all products except one product group.

etc, etc, ...


For shrinking itself there is also a script on AskTom that I use sometimes :

http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:153612348067

Re: Shrinking a database after a cut-down [message #166918 is a reply to message #166352] Mon, 10 April 2006 05:04 Go to previous message
alanm
Messages: 284
Registered: March 2005
Senior Member

Hi,
what you are trying to achieve is to move the High water mark for the datafiles. One way to do this is to export and import, I think the other way is to perform an alter table/index rebuild. I believe this will do what you need.


rgs

Alan.
Previous Topic: urgent
Next Topic: Discoverer for Oracle9i Enterprise Edition Release 9.2.0.3.0
Goto Forum:
  


Current Time: Sun Jan 26 14:41:58 CST 2025