Wednesday, May 18, 2016

How to move an Oracle Table with LOBs and Indexes temporarily out of a TableSpace and then back in again?

On occasion, it becomes necessary to move an Oracle Table temporarily out of a TableSpace and then back in again. The following sequence of steps shows how to accomplish this task along with rebuilding associated Indexes and Large Objects (LOBs) as well.


=> Created new tablespace to move table ORACLE_TABLE_NAME temporarily out of OLDTBS_01 tablespace.
create tablespace NEWTBS_01 datafile '+DATA1' size 1G autoextend on maxsize unlimited;


=>Move Table,Index & LOB to temporary tablespace.
alter table "DBUSER"."ORACLE_TABLE_NAME" move tablespace NEWTBS_01;
alter index DBUSER.ORACLE_TABLE_NAME_COL1 rebuild tablespace NEWTBS_01;
alter index DBUSER.ORACLE_TABLE_NAME_COL2 rebuild tablespace NEWTBS_01;
alter index DBUSER.ORACLE_TABLE_NAME_COL3 rebuild tablespace NEWTBS_01;
Alter table DBUSER.ORACLE_TABLE_NAME move lob(LOBNAME_1) store as (tablespace NEWTBS_01);


=>Move ORACLE_TABLE_NAME table, indexes & LOB back to original tablespace  OLDTBS_01.
alter table "DBUSER"."ORACLE_TABLE_NAME" move tablespace OLDTBS_01;
alter index DBUSER.ORACLE_TABLE_NAME_COL1 rebuild tablespace OLDTBS_01;
alter index DBUSER.ORACLE_TABLE_NAME_COL2 rebuild tablespace OLDTBS_01;
alter index DBUSER.ORACLE_TABLE_NAME_COL3 rebuild tablespace OLDTBS_01;
Alter table DBUSER.ORACLE_TABLE_NAME move lob(LOBNAME_1) store as (tablespace OLDTBS_01);



=>Validate that no data was left was left on NEWTBS_01 tablespace before dropping it.
select * from dba_segments where tablespace_name='NEWTBS_01';
drop tablespace NEWTBS_01 including contents and datafiles;


And there you have it, a table with Indexes and LOBs was temporarily moved to a new tablespace and then back for administrative purposes.

No comments:

Post a Comment