SlideShare uma empresa Scribd logo
1 de 2
Baixar para ler offline
Moving a Table to a new Tablespace                                            Administration Tips




Moving a Table

Moving a table from one tablespace to another is a piece of cake -provided you have
Oracle 8i. The command there is simply:

ALTER TABLE       BLAH     MOVE TABLESPACE   XYZ;

The tablespace name in this command doesn't have to be a completely new tablespace: it's
perfectly permissible to move a table within a tablespace, and hence the name can
legitimately be the name of the tablespace it's already housed within.

There's only one slight word of warning with this command: the way it works is that a new
version of the table is created, under a temporary name, in the specified tablespace, and
then populated by selecting from the original table. When the populating exercise has
finished, the old version is dropped, and the new one simultaneously renamed as the old
one. For a split second, therefore, two versions of the table exist -and hence you need
sufficient disk space to accomodate those two versions. If this is 12Gb table you are
moving, that can be expensive!

Otherwise, there's not much to report on the 'move tablespace' command. It brings along
all constraints and permissions, so there's none of that to redefine. There is one slight
problem: all indexes on the table have got leaf nodes stuffed full of ROWIDs which point to
where the old table used to be. Now it's moved, those indexes are basically stuffed full of
worthless nonsense... hence the need to rebuild all indexes on a table that's been moved.

Suppose, however, you don't have the advantages of 8i and its "move tablespace" command.
How then do you do the deed?

Well, the simplest way would be to do a CTAS. That stands for "create table as select",
and refers to the fact that you could issue the following command:

CREATE TABLE NEW_EMP
TABLESPACE NEWONE
AS
SELECT    *   FROM OLD_EMP;


Only problem with this command is that you probably need to do it twice: assuming you
want the newly re-located table to be the same name as the original, you'd follow the
above command with a drop table old_emp; followed by a revamp of the earlier CTAS to
read 'create...old_emp as select * from new_emp'.




Copyright © Howard Rogers 2001                      10/17/2001                         Page 1 of 2
Moving a Table to a new Tablespace                                             Administration Tips


But the real nasty with this technique is that the tables you create each time you run the
CTAS command are new tables. That means no-one has any rights on them, there are no
constraints defined for them, and no indexes exist for them. You'll need to re-grant all
permissions, re-create all constraints, and re-specify and re-create all indexes, too (now
isn't that upgrade to 8i looking attractive??!).

Another possibility presents itself: export the old table, then drop it. Alter the user so
that their quota on the original tablespace is zero, and also alter that user so that their
default tablespace is the one you want the new table created in. Import, you see, always
likes to create tables in a tablespace of exactly the same name as the one the table
originally came from. But if it can't create it there (and the quota of zero prevents that),
it will instead choose to create the table in whoever is running import's default tablespace.
This technique can get a bit fiddly, but has the advantage of re-creating all indexes,
constraints and re-granting all permissions. You'd have to remember to set the quotas and
default tablespace for the User involved back to what they were earlier, too.

At the end of the day, whichever version of Oracle you use, and whichever technique you
go for, moving tables is not a cheap exercise. Best house them correctly in the first place.
But if you have to do it, the 'move tablespace' option has the distinct advantages of ease of
implementation.




Copyright © Howard Rogers 2001            10/17/2001                                    Page 2 of 2

Mais conteúdo relacionado

Destaque

Database Management System And Design Questions
Database Management System And Design QuestionsDatabase Management System And Design Questions
Database Management System And Design QuestionsSamir Sabry
 
2009 Punjab Technical University B.C.A Database Management System Question paper
2009 Punjab Technical University B.C.A Database Management System Question paper2009 Punjab Technical University B.C.A Database Management System Question paper
2009 Punjab Technical University B.C.A Database Management System Question paperMonica Sabharwal
 
FP304 DATABASE SYSTEM PAPER FINAL EXAM AGAIN
FP304 DATABASE SYSTEM  PAPER FINAL EXAM AGAINFP304 DATABASE SYSTEM  PAPER FINAL EXAM AGAIN
FP304 DATABASE SYSTEM PAPER FINAL EXAM AGAINSyahriha Ruslan
 
Fundamentals of Database Systems Questions and Answers
Fundamentals of Database Systems Questions and AnswersFundamentals of Database Systems Questions and Answers
Fundamentals of Database Systems Questions and AnswersAbdul Rahman Sherzad
 
Previous question papers of Database Management System (DBMS) By SHABEEB
Previous question papers of Database Management System (DBMS) By SHABEEBPrevious question papers of Database Management System (DBMS) By SHABEEB
Previous question papers of Database Management System (DBMS) By SHABEEBShabeeb Shabi
 
Internship Final Report
Internship Final Report Internship Final Report
Internship Final Report Nadia Nahar
 
Lec10 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Memory part2
Lec10 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Memory part2Lec10 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Memory part2
Lec10 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Memory part2Hsien-Hsin Sean Lee, Ph.D.
 

Destaque (11)

Oracle installation
Oracle installationOracle installation
Oracle installation
 
Les 07 Rman Rec
Les 07 Rman RecLes 07 Rman Rec
Les 07 Rman Rec
 
Database Management System And Design Questions
Database Management System And Design QuestionsDatabase Management System And Design Questions
Database Management System And Design Questions
 
2009 Punjab Technical University B.C.A Database Management System Question paper
2009 Punjab Technical University B.C.A Database Management System Question paper2009 Punjab Technical University B.C.A Database Management System Question paper
2009 Punjab Technical University B.C.A Database Management System Question paper
 
Dbms Final Examination Answer Key
Dbms Final Examination Answer KeyDbms Final Examination Answer Key
Dbms Final Examination Answer Key
 
FP304 DATABASE SYSTEM PAPER FINAL EXAM AGAIN
FP304 DATABASE SYSTEM  PAPER FINAL EXAM AGAINFP304 DATABASE SYSTEM  PAPER FINAL EXAM AGAIN
FP304 DATABASE SYSTEM PAPER FINAL EXAM AGAIN
 
Paper review
Paper reviewPaper review
Paper review
 
Fundamentals of Database Systems Questions and Answers
Fundamentals of Database Systems Questions and AnswersFundamentals of Database Systems Questions and Answers
Fundamentals of Database Systems Questions and Answers
 
Previous question papers of Database Management System (DBMS) By SHABEEB
Previous question papers of Database Management System (DBMS) By SHABEEBPrevious question papers of Database Management System (DBMS) By SHABEEB
Previous question papers of Database Management System (DBMS) By SHABEEB
 
Internship Final Report
Internship Final Report Internship Final Report
Internship Final Report
 
Lec10 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Memory part2
Lec10 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Memory part2Lec10 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Memory part2
Lec10 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Memory part2
 

Mais de oracle documents (20)

Applyinga blockcentricapproachtotuning
Applyinga blockcentricapproachtotuningApplyinga blockcentricapproachtotuning
Applyinga blockcentricapproachtotuning
 
Windowsosauthent
WindowsosauthentWindowsosauthent
Windowsosauthent
 
Whatistnsnames
WhatistnsnamesWhatistnsnames
Whatistnsnames
 
Whatisadatabaselink
WhatisadatabaselinkWhatisadatabaselink
Whatisadatabaselink
 
Varraysandnestedtables
VarraysandnestedtablesVarraysandnestedtables
Varraysandnestedtables
 
Usertracing
UsertracingUsertracing
Usertracing
 
Userpasswrd
UserpasswrdUserpasswrd
Userpasswrd
 
Userlimit
UserlimitUserlimit
Userlimit
 
Undo internalspresentation
Undo internalspresentationUndo internalspresentation
Undo internalspresentation
 
Undo internals paper
Undo internals paperUndo internals paper
Undo internals paper
 
Tablespacelmt
TablespacelmtTablespacelmt
Tablespacelmt
 
Tablerename
TablerenameTablerename
Tablerename
 
Sql scripting sorcerypresentation
Sql scripting sorcerypresentationSql scripting sorcerypresentation
Sql scripting sorcerypresentation
 
Sql scripting sorcerypaper
Sql scripting sorcerypaperSql scripting sorcerypaper
Sql scripting sorcerypaper
 
Sql for dbaspresentation
Sql for dbaspresentationSql for dbaspresentation
Sql for dbaspresentation
 
Sequencereset
SequenceresetSequencereset
Sequencereset
 
Rollbacksizes
RollbacksizesRollbacksizes
Rollbacksizes
 
Rollbackshrinks
RollbackshrinksRollbackshrinks
Rollbackshrinks
 
Rollbacklmt
RollbacklmtRollbacklmt
Rollbacklmt
 
Rollbackblocking
RollbackblockingRollbackblocking
Rollbackblocking
 

Movetablespace

  • 1. Moving a Table to a new Tablespace Administration Tips Moving a Table Moving a table from one tablespace to another is a piece of cake -provided you have Oracle 8i. The command there is simply: ALTER TABLE BLAH MOVE TABLESPACE XYZ; The tablespace name in this command doesn't have to be a completely new tablespace: it's perfectly permissible to move a table within a tablespace, and hence the name can legitimately be the name of the tablespace it's already housed within. There's only one slight word of warning with this command: the way it works is that a new version of the table is created, under a temporary name, in the specified tablespace, and then populated by selecting from the original table. When the populating exercise has finished, the old version is dropped, and the new one simultaneously renamed as the old one. For a split second, therefore, two versions of the table exist -and hence you need sufficient disk space to accomodate those two versions. If this is 12Gb table you are moving, that can be expensive! Otherwise, there's not much to report on the 'move tablespace' command. It brings along all constraints and permissions, so there's none of that to redefine. There is one slight problem: all indexes on the table have got leaf nodes stuffed full of ROWIDs which point to where the old table used to be. Now it's moved, those indexes are basically stuffed full of worthless nonsense... hence the need to rebuild all indexes on a table that's been moved. Suppose, however, you don't have the advantages of 8i and its "move tablespace" command. How then do you do the deed? Well, the simplest way would be to do a CTAS. That stands for "create table as select", and refers to the fact that you could issue the following command: CREATE TABLE NEW_EMP TABLESPACE NEWONE AS SELECT * FROM OLD_EMP; Only problem with this command is that you probably need to do it twice: assuming you want the newly re-located table to be the same name as the original, you'd follow the above command with a drop table old_emp; followed by a revamp of the earlier CTAS to read 'create...old_emp as select * from new_emp'. Copyright © Howard Rogers 2001 10/17/2001 Page 1 of 2
  • 2. Moving a Table to a new Tablespace Administration Tips But the real nasty with this technique is that the tables you create each time you run the CTAS command are new tables. That means no-one has any rights on them, there are no constraints defined for them, and no indexes exist for them. You'll need to re-grant all permissions, re-create all constraints, and re-specify and re-create all indexes, too (now isn't that upgrade to 8i looking attractive??!). Another possibility presents itself: export the old table, then drop it. Alter the user so that their quota on the original tablespace is zero, and also alter that user so that their default tablespace is the one you want the new table created in. Import, you see, always likes to create tables in a tablespace of exactly the same name as the one the table originally came from. But if it can't create it there (and the quota of zero prevents that), it will instead choose to create the table in whoever is running import's default tablespace. This technique can get a bit fiddly, but has the advantage of re-creating all indexes, constraints and re-granting all permissions. You'd have to remember to set the quotas and default tablespace for the User involved back to what they were earlier, too. At the end of the day, whichever version of Oracle you use, and whichever technique you go for, moving tables is not a cheap exercise. Best house them correctly in the first place. But if you have to do it, the 'move tablespace' option has the distinct advantages of ease of implementation. Copyright © Howard Rogers 2001 10/17/2001 Page 2 of 2