I noticed that a Schema has been created in the USERS Tablespace but our local rule is that it should be in a Tablespace by itself. In Oracle how do you move a Schema to a different Tablespace?
3 Answers
A schema itself can not be stored nor can have changed tablespace en bloc in any way. In fact, it is just a meta-structucre. Instead - there is DEFAULT TABLESPACE
attribute of underlying USER
. If you change it, then new objects are created in this tablespace by default (unless you excplicitly specify another one).
In addition, each type of structure (Table/Index/Partition...) has it's own way of moving to another tablespace. (i.e. moving a table does not move indexes built upon it - which would be rather undesirable, because you want to store indexes in another filesystem for better performance). This means, that you will have to move contents of the schema object by object.
-
6Having seperate tablespaces for tables and indexes isn't really considered neccessary for performance, though it can still be done for admin reasons. See this old SO thread, or various AskTom articles. Commented Jun 20, 2012 at 7:02
-
2Also, keep in mind any LOB objects (BLOB, CLOB) have their storage separate from the rest of the table, with only a pointer stored in the table structure itself. If your intent is to move an entire table and its contents, you will need to move the LOB segments independently. "alter table t move lob(y) store as ( tablespace users )"– REWCommented Jun 23, 2012 at 4:41
For 10 & 11G, use data pump utility. Follow the tutorial here:
http://techxploration.blogspot.com.au/2012/10/changing-tablespace-of-oracle-schema.html
It is the safest if not the best way to do it.
I tried many scripts but didn't worked for all objects. You can't move clustered objects from one tablespace to another, for that you will have to use expdp. So I will suggest expdp is the best option to move all objects to different tablesapce.
Below is the command.
nohup expdp \"/ as sysdba\" DIRECTORY=test_dir DUMPFILE=users.dmp LOGFILE=users.log TABLESPACES=USERS &
For clear explanation: https://www.orahow.com/2018/06/move-all-objects-to-another-tablespace.html