简体   繁体   English

如何更改 Oracle 中架构的默认表空间

[英]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 tablealter index语句。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Oracle数据库中仅为模式的LOB创建表空间 - How to create a tablespace only for schema's LOBs in Oracle database oracle - 如何将分区表复制到新表空间上的新架构 - oracle - how to copy partitioned table to a new schema on new tablespace 如何更改表空间 ORACLE 中 MAXBYTES 和 INCREMENT_BY 的值? - How can i change value of MAXBYTES and INCREMENT_BY in tablespace ORACLE? Oracle Apex:是否可以在运行时更改默认架构? - Oracle Apex: Is it possible to change the default schema at runtime? 使用默认表空间循环创建Oracle用户 - Create Oracle users in a loop with default tablespace 如何在oracle中缩小临时表空间? - How to shrink temp tablespace in oracle? 如何在 Oracle 中估计表空间大小 - How to estimate tablespace size in Oracle 如何将Oracle 11g用户导出到10g并在不同的默认表空间上 - How to export oracle 11g user to 10g and on a different default tablespace 如何在 Amazon ORACLE AWS RDS 的 TEMP TABLESPACE 表 DBA_TEMP_FILES 中将 AUTOEXTENSIBLE 列更改为 YES? - How to change the AUTOEXTENSIBLE column to YES in table DBA_TEMP_FILES for TEMP TABLESPACE in Amazon ORACLE AWS RDS? 在 Oracle 19c 数据库中,如何找出表空间、模式、允许访问的表、分配给按该用户名分组的用户的权限? - In Oracle 19c database, how can I find out tablespace, schema, tables allowed to access, privileges assigned to a user grouping by that username?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM