Moving multiple tables and indexes between tablespaces at once
articles:
Here I present a simple query to use when we want to move the tables and indexes of several users at once.
To make it one by one:
ALTER TABLE xxxxxx MOVE TABLESPACE TEST; ALTER INDEX xxxxxx REBUILD TABLESPACE TEST;
To move data from multiple owners. In this example OWNER1 and OWNER2:
select 'ALTER INDEX ' || OWNER || '.' || INDEX_NAME || ' REBUILD TABLESPACE ' || OWNER || ';' from DBA_INDEXES WHERE OWNER IN ('OWNER1','OWNER2') select 'ALTER TABLE ' || OWNER || '.' || TABLE_NAME || ' MOVE TABLESPACE ' || OWNER || ';' from DBA_TABLES WHERE OWNER IN ('OWNER1','OWNER2')
»
- David Lozano Lucas's blog
- Log in to post comments
Comments
Typo error
Hi David,
Above query has a typo error.
Please use the below query:
select 'ALTER INDEX ' || OWNER || '.' || INDEX_NAME || ' REBUILD TABLESPACE ' || TABLESPACE_NAME || ';' from DBA_INDEXES WHERE OWNER IN ('OWNER1','OWNER2');
select 'ALTER TABLE ' || OWNER || '.' || TABLE_NAME || ' MOVE TABLESPACE ' || TABLESPACE_NAME || ';' from DBA_TABLES WHERE OWNER IN ('OWNER1','OWNER2');
Regards
Rajabaskar Thangaraj
pl/sql procedure
Hi David,
I will use a pl/sql procedure for such a task.
This procedure moves/rebuilds the tables/indexes of shema owners SUBBU/SUGGU to
usr_d_01, usr_x_01, usr_d_02 and usr_x_02 tablespaces as per the case condition.
You need to edit the CASE condition as per your database reorg requirements.
Test this procedure in a test db thoroughly, before running in a production db.
Thanks
JP