Clean up user tablespaces

The table space is enlarged due to the usual test. What should I do if the disk is full? There are two methods, one is to shrink the file, and the other is to rebuild:
it is easier to rebuild the table space, but the reconstruction of the USERS table space is a little more troublesome. 1. First, clear out the USERS tablespace




in the system, and migrate all tables and indexes. Assuming that the destination tablespace is TEST,
   you can run the following SQL after the SYS user logs in:
   Select 'alter table '||t.owner||'.'||t.table_name||' move tablespace TEST;' 
     From all_all_tables t where t.tablespace_name='USERS';


   Select 'alter index '||t.owner ||'.'|| index_name || ' rebuild tablespace test;' 
     From all_indexes t where t.tablespace_name ='USERS';


   Run the generated script and migrate all objects away.
Retract table space:
In fact, if all objects in the table space are migrated, we can use the command to retract directly, the command is as follows:
alter database datafile 'D:\DATA\orcl\USERS01.DBF' resize 1024m;





   alter database datafile 'D:\DATA\orcl\USERS01.DBF ' offline drop;
   then start the database:
   alter database open;
   modify the default tablespace:
   alter database default tablespace test;
   offline tablespace users:
   alter tablespace users online;
   delete the table space, delete the file by the way:
   DROP TABLESPACE users INCLUDING CONTENTS and datafiles;
   table space deleted;
   possible problems:
   system prompt:
error on line 1:
ORA-00604: recursive SQL level 1 error
ORA-02429 : Unable to drop the index used to enforce the unique/primary key The
problem is that all objects in the users tablespace are not emptied, check if there are any objects that have not been removed in the first step.
4. Rebuild the tablespace:
   create tablespace users datafile 'D:\DATA\orcl\USERS01.DBF' size 2048M autoextend off;
   set the default tablespace:
   alter database default tablespace users;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324769644&siteId=291194637