Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> Re: How to move tables from one tablespace to another (Oracle 7.3.4)

Re: How to move tables from one tablespace to another (Oracle 7.3.4)

From: Michael Sun <mikeny31_at_speakeasy.org>
Date: Mon, 1 May 2000 01:24:51 -0400
Message-Id: <10483.104529@fatcity.com>


This is a multi-part message in MIME format.

------=_NextPart_000_0132_01BFB30C.0C1A68A0 Content-Type: text/plain;

        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I have posted this one before, but why not one more time. I can't claim = this script, it is from the very Mr. Thomas Kyte.

I'll give you the Oracle8.0 and before answer as well as the Oracle8i = and above answer (in 8i, this is *trivial*, in 8.0 and before, it takes = practice and time)....
=20

 you don't move procedures -- they are compiled into system and will = remain there forever. you can move tables and indexes mostly (there are = other things but this
 covers most of it)...
=20

 There are 2 methods we can use to do this. One is to use a combination = of "alter table X move tablespace Y" and "alter index X rebuild = tablespace Y" -- this works in
 Oracle8i release 8.1 and up ONLY. Attached is a script called = moveall.sql. It uses the user_segments table to generate all of the = needed "alter table move" and "alter
 index rebuild" statements to move a table/index into another tablespace = preserving the storage characteristics currently assigned to the object. =  For example, when we
 run moveall.sql in the SCOTT schema, we might see:
=20

 scott_at_ORACLE> @moveall
 scott_at_ORACLE> set echo off
=20

 alter TABLE ACCOUNT move
 tablespace users
 storage ( initial 10240 next 10240
 minextents 1 maxextents 121
 pctincrease 50 freelists 1);
=20

 alter TABLE BONUS move
 tablespace users
 storage ( initial 10240 next 10240
 minextents 1 maxextents 121
 pctincrease 50 freelists 1);
=20

 alter TABLE DEPT move
 tablespace users
 storage ( initial 10240 next 10240
 minextents 1 maxextents 121
 pctincrease 50 freelists 1);
=20

 alter INDEX PK_DEPT rebuild
 tablespace users
 storage ( initial 10240 next 10240
 minextents 1 maxextents 121
 pctincrease 50 freelists 1);
=20

 ....
=20

 It begins by moving a table and then rebuilding each of the indexes on = that table. Since the indexes on the tables being moved will become = unusable after the table, this
 script rebuilds them right after moving a table -- before moving the = next table (to reduce downtime).
=20

 Running the moveall.sql script is harmless as it is written. It = generates the SQL you need to run and saves the sql into yet another = script file "tmp.sql". You should edit
 tmp.sql, review it, modify it if you want (eg: if you have a multi-cpu = system, you could modify the index rebuilds to be "parallel N", = "unrecoverable" and add other options
 to make them go faster on your system), and then run it.
=20

------=_NextPart_000_0132_01BFB30C.0C1A68A0 Content-Type: text/html;

        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2919.6307" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>I have posted this one before, but why =
not one more=20
time. I can't claim this script, it is from the very Mr. Thomas=20 Kyte.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>I'll give you the Oracle8.0 and = before=20
answer as well as the Oracle8i and above answer (in 8i, this is = *trivial*, in=20
8.0 and before, it takes practice and time)....<BR>&nbsp; <BR>&nbsp;you = don't=20
move procedures -- they are compiled into system and will remain there=20 forever.&nbsp; you can move tables and indexes mostly (there are other = things=20
but this<BR>&nbsp;covers most of it)...<BR>&nbsp; <BR>&nbsp;There are 2 = methods=20
we can use to do this.&nbsp; One is to use a combination of "alter table = X move=20
tablespace Y" and "alter index X rebuild tablespace Y"&nbsp; -- this = works=20
in<BR>&nbsp;Oracle8i release 8.1 and up ONLY.&nbsp; Attached is a script = called=20
moveall.sql.&nbsp; It uses the user_segments table to generate all of = the needed=20
"alter table move" and "alter<BR>&nbsp;index rebuild" statements to move = a=20
table/index into another tablespace preserving the storage = characteristics=20
currently assigned to the object.&nbsp; For example, when = we<BR>&nbsp;run=20
moveall.sql in the SCOTT schema, we might see:<BR>&nbsp;=20 <BR>&nbsp;scott_at_ORACLE&gt; @moveall<BR>&nbsp;scott_at_ORACLE&gt; set echo=20 off<BR>&nbsp; <BR>&nbsp;alter TABLE ACCOUNT move<BR>&nbsp;tablespace=20 users<BR>&nbsp;storage ( initial 10240 next 10240<BR>&nbsp;minextents 1=20 maxextents 121<BR>&nbsp;pctincrease 50 freelists 1);<BR>&nbsp; = <BR>&nbsp;alter=20
TABLE BONUS move<BR>&nbsp;tablespace users<BR>&nbsp;storage ( initial = 10240 next=20
10240<BR>&nbsp;minextents 1 maxextents 121<BR>&nbsp;pctincrease 50 = freelists=20
1);<BR>&nbsp; <BR>&nbsp;alter TABLE DEPT move<BR>&nbsp;tablespace=20 users<BR>&nbsp;storage ( initial 10240 next 10240<BR>&nbsp;minextents 1=20 maxextents 121<BR>&nbsp;pctincrease 50 freelists 1);<BR>&nbsp; = <BR>&nbsp;alter=20
INDEX PK_DEPT rebuild<BR>&nbsp;tablespace users<BR>&nbsp;storage ( = initial 10240=20
next 10240<BR>&nbsp;minextents 1 maxextents 121<BR>&nbsp;pctincrease 50=20 freelists 1);<BR>&nbsp; <BR>&nbsp;....<BR>&nbsp; <BR>&nbsp;It begins by = moving a=20
table and then rebuilding each of the indexes on that table.&nbsp; Since = the=20
indexes on the tables being moved will become unusable after the table,=20 this<BR>&nbsp;script rebuilds them right after moving a table -- before = moving=20
the next table (to reduce downtime).<BR>&nbsp; <BR>&nbsp;Running the = moveall.sql=20
script is harmless as it is written.&nbsp; It generates the SQL you need = to run=20
and saves the sql into yet another script file "tmp.sql". You should=20 edit<BR>&nbsp;tmp.sql, review it, modify it if you want (eg: if you have = a=20
multi-cpu system, you could modify the index rebuilds to be "parallel = N",=20
"unrecoverable" and add other options<BR>&nbsp;to make them go faster on = your=20
system), and then run it.<BR>&nbsp; <BR>&nbsp;--------------------- =
moveall.sql=20
------------------------------------ set echo off<BR>&nbsp; =
<BR>&nbsp;column=20
order_col1 noprint<BR>&nbsp;column order_col2 noprint<BR>&nbsp; = <BR>&nbsp;set=20
heading off<BR>&nbsp;set verify off<BR>&nbsp;set feedback = off<BR>&nbsp;set echo=20
off<BR>&nbsp; <BR>&nbsp;spool tmp.sql<BR>&nbsp; <BR>&nbsp;select decode( =

segment_type, 'TABLE', segment_name, table_name )=20 order_col1,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; decode( segment_type, = 'TABLE',=20
1, 2 ) order_col2,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'alter ' ||=20 segment_type || ' ' || segment_name =
||<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20 decode( segment_type, 'TABLE', ' move ', ' rebuild ' ) || chr(10)=20 ||&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' tablespace &amp;1 ' || chr(10)=20 ||<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' storage ( initial ' ||=20 initial_extent || ' next ' || next_extent || chr(10)=20 ||<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' minextents ' || min_extents = || '=20
maxextents ' || max_extents || chr(10)=20 <BR>&nbsp;||<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' pctincrease ' ||=20 pct_increase || ' freelists ' || freelists || ');'&nbsp;&nbsp; from=20 user_segments, (select table_name, index_name from user_indexes ) where=20 segment_type in (<BR>&nbsp;'TABLE', 'INDEX' )<BR>&nbsp;&nbsp; and = segment_name =3D=20
index_name (+)<BR>&nbsp;order by 1, 2<BR>&nbsp;/<BR>&nbsp; = <BR>&nbsp;spool=20
off<BR>&nbsp; <BR>&nbsp;set heading on<BR>&nbsp;set verify = on<BR>&nbsp;set=20
feedback on<BR>&nbsp;set echo=20

on<BR>&nbsp;-------------------------------------------------------------=
-----=20
<BR>&nbsp; <BR>&nbsp;Another method would be to use EXPort and = IMPort.&nbsp; You=20
would<BR>&nbsp; <BR>&nbsp;o EXP the user account.<BR>&nbsp;o drop all of = the=20
objects this user owns.&nbsp; You can 'select' the drop statements you = need in=20
much the same way we 'select' the alter table/index statements o=20 revoke<BR>&nbsp;UNLIMITED TABLESPACE from the user<BR>&nbsp;o alter the = users=20
default tablespace to the target tablespace<BR>&nbsp;o give the user an=20 Received on Mon May 01 2000 - 00:24:51 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US