[英]How to change the default tablespace of the schema in Oracle
There is a schema called Docker, in which there are tables named TABLE2, TABLE3.有一个名为 Docker 的模式,其中有名为 TABLE2、TABLE3 的表。
Example例子
SELECT * FROM all_all_tables WHERE TABLE_name= 'TABLE3';
Also, the Docker schema belongs to the DEFAULT TABLESPACE SYSTEM tablespace.此外,Docker 模式属于 DEFAULT TABLESPACE SYSTEM 表空间。
select
username
, default_tablespace from dba_users WHERE USERNAME = 'DOCKER';
The following syntax is used to change the default tablespace of the schema.以下语法用于更改模式的默认表空间。 (TS3 tablespace already exists)
(TS3 表空间已经存在)
ALTER USER docker DEFAULT tablespace TS3;
Then, when I searched again, I found that the DEFAULT TABLESPACE was changed.然后,当我再次搜索时,我发现 DEFAULT TABLESPACE 已更改。
select
username
, default_tablespace from dba_users WHERE USERNAME = 'DOCKER';
And, of course, I thought that the tablespace in which TABLE2 and TABLE3 were designated would also have been changed to TS3, and the following statement was executed.而且,当然,我以为指定了TABLE2和TABLE3的表空间也会改成TS3,于是执行了下面的语句。
However, the tablespace of the table was SYSTEM, not TS3.但是,该表的表空间是 SYSTEM,而不是 TS3。 I am curious about why it hasn't changed, and I want to know how.
我很好奇为什么它没有改变,我想知道如何。 SELECT * FROM all_all_tables WHERE TABLE_name= 'TABLE3';
SELECT * FROM all_all_tables WHERE TABLE_name='TABLE3';
The default tablespace is just that-- a default for when you create a segment (normally a table or an index but a segment could be a partition of a table, a materialized view, or anything else that requires space) and don't specify the tablespace.默认表空间就是这样——创建段时的默认值(通常是表或索引,但段可以是表的分区、物化视图或其他任何需要空间的东西)并且不指定表空间。 Once you create a segment and it is assigned to a particular tablespace, it will remain in that tablespace unless you move it.
一旦您创建了一个段并将其分配给特定的表空间,除非您移动它,否则它将保留在该表空间中。
Assuming you are on 12.2 or later so that online moves are an option (in other versions you'd need to remove the online
keyword)假设您使用的是 12.2 或更高版本,因此可以选择在线移动(在其他版本中,您需要删除
online
关键字)
alter table table3
move online tablespace ts3;
You'd need to do that for each table.你需要为每张桌子这样做。 If there are also indexes in the
system
tablespace, you'd want to move those as well如果
system
表空间中也有索引,您也需要移动这些索引
alter index index_name
rebuild online tablespace ts3;
Depending on the number of tables and indexes involved, you may want to write a bit of dynamic SQL to generate the various alter table
and alter index
statements for you.根据涉及的表和索引的数量,您可能需要编写一些动态 SQL 来为您生成各种
alter table
和alter index
语句。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.