Skip to Main Content

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Kiril.

Asked: October 12, 2004 - 2:46 am UTC

Last updated: October 12, 2004 - 3:56 pm UTC

Version: 9.2

Viewed 1000+ times

You Asked

Hi Tom
Because of reorganization of one of our datafiles I have to move one table to another datafile.
I was thinking about two possibilities:
Create another tablespace(datafile) and

1. Export of the table, drop the table ,create in another tablespace(datafile) and import.
2. Using move operation acros datafiles.

Could you please comment based on your knowledge which variant is better("downtime" of table, restartable and space consumption), because I have no test system and could not test it.

Consider that I have proper backup before above operation.

Details about our system:
DB 9.2 EE, Win 2000 AS.
Table - heap table about 3,5 Gb with one primary key. Table is in LMT tablespace(only one datafile) with another big table 6.5Gb.

Thanks
Kiril

and Tom said...

There are only two approaches I would even consider:

a) alter table T move tablespace NEW

- can be done nologging parallel
- no modifications while it is happening
- indexes must be rebuilt afterwards
- transactional -- no "loss" (like exp/imp could result in, anytime you take the
data OUT of the database, the data is unprotected)

b) dbms_redefinition (search for that term on this site for examples)

- modifications supported continously
- you are responsible to make sure the new object meets your needs (indexes,
constraints, triggers, etc -- in 10g this too can be automated)
- transactional -- no "loss"


So, all you need to do is ask "online -- redef" or "offline -- alter".

For 3.5gig, it is going to be pretty fast regardless, not very large.

Rating

  (4 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

A reader, October 12, 2004 - 8:59 am UTC


Kiril

A reader, October 12, 2004 - 10:38 am UTC

Thanks Tom for promp answer.
I think in my case alter table t move is more acceptable. After that I have to rebuild only PK, but this is table with old data and there in no way to fall PK rebuild.

Tom Kyte
October 12, 2004 - 10:41 am UTC

<quote>

but this is table with old data and there in no way to fall PK rebuild.
</quote>

??? huh?

rebuild

Kiril, October 12, 2004 - 10:52 am UTC

Tom,
In this table we are storing data from previous year and there is no insert , delete or update on this table, only Select.
Hence rebuild of inedex and add PK is only time consumeing procedure.


rebuild indexes

Sean, October 12, 2004 - 3:38 pm UTC

Hi Tom,

After I moved the table to new tablespace, I need to rebuild index.

Do I have to issue rebuild index one by one such as this one:

alter index index_name rebuid;

Or there is the command which will rebuild all indexes on the table at once, something like:
alter table table_name rebuild index;


Thanks so much for your help.

Sean




Tom Kyte
October 12, 2004 - 3:56 pm UTC

you have to enter the individual commands -- they can be done "in parallel" by opening many sqlplus sessions and running one in each -- but you are rebuilding an "index", not the "indexes on a table".


you can easily automate this:

begin
for x in (select * from user_indexes where status = 'UNUSABLE')
loop
execute immediate 'alter index ' || x.index_name || ' rebuild';
end loop;
end;
/


More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library