重庆思庄Oracle、Redhat认证学习论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1435|回复: 4
打印 上一主题 下一主题

创建PDB语句的USER_TABLESPACES字句使用

[复制链接]
跳转到指定楼层
楼主
发表于 2021-8-18 22:43:36 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式


You can use this clause to separate the data for multiple schemas into different PDBs. For example, when you move a non-CDB to a PDB, and the non-CDB had several schemas that each supported a different application, you can use this clause to separate the data belonging to each schema into a separate PDB. This technique assumes that each schema used a separate tablespace in the non-CDB.

You can use this clause to specify one of the following options:

List one or more tablespaces to include.

Specify ALL, the default, to include all tablespaces.

Specify ALL EXCEPT to include all tablespaces, except for the tablespaces listed.

Specify NONE to exclude all tablespaces.

If the creation mode of the user tablespaces must be different from the creation mode for the Oracle-supplied tablespaces (such as SYSTEM and SYSAUX), then specify one of the following in the USER_TABLESPACES clause:

COPY: The files of the tablespaces are copied to a new location.

MOVE: The files of the tablespaces are moved to a new location.

NOCOPY: The files of the tablespaces are not copied or moved.

SNAPSHOT COPY: The tablespaces are cloned with storage snapshots.

NO DATA: The data model definition of the tablespaces is cloned but not the tablespaces’ data.


When the compatibility level of the CDB is 12.2.0 or higher, the tablespaces that are excluded by this clause are created offline in the new PDB, and they have no data files associated with them. When the compatibility level of the CDB is lower than 12.2.0, the tablespaces that are excluded by this clause are offline in the new PDB, and all data files that belong to these tablespaces are unnamed and offline.

This clause does not apply to the SYSTEM, SYSAUX, or TEMP tablespaces. Do not include these tablespaces in a tablespace list for this clause.

The following are examples that use the USER_TABLESPACES clause.

Example 5-4 USER_TABLESPACES Clause That Includes One Tablespace

Assume that the non-CDB or PDB from which a PDB is being created includes the following tablespaces: tbs1, tbs2, and tbs3. This USER_TABLESPACES clause includes the tbs2 tablespace, but excludes the tbs1 and tbs3 tablespaces.

USER_TABLESPACES=('tbs2')
Example 5-5 USER_TABLESPACES Clause That Includes a List of Tablespaces

Assume that the non-CDB or PDB from which a PDB is being created includes the following tablespaces: tbs1, tbs2, tbs3, tbs4, and tbs5. This USER_TABLESPACES clause includes the tbs1, tbs4, and tbs5 tablespaces, but excludes the tbs2 and tbs3 tablespaces.

USER_TABLESPACES=('tbs1','tbs4','tbs5')
Example 5-6 USER_TABLESPACES Clause That Includes All Tablespaces Except for Listed Ones

Assume that the non-CDB or PDB from which a PDB is being created includes the following tablespaces: tbs1, tbs2, tbs3, tbs4, and tbs5. This USER_TABLESPACES clause includes the tbs2 and tbs3 tablespaces, but excludes the tbs1, tbs4, and tbs5 tablespaces.

USER_TABLESPACES=ALL EXCEPT('tbs1','tbs4','tbs5')
Example 5-7 USER_TABLESPACES in a Different Creation Mode

This example shows a full CREATE PLUGGABLE DATABASE statement that plugs in a non-CDB and only includes the tbs3 user tablespace from the non-CDB. The example copies the files for Oracle-supplied tablespaces (such as SYSTEM and SYSAUX) to a new location, but moves the files of the tbs3 user tablespace.

CREATE PLUGGABLE DATABASE ncdb USING '/disk1/oracle/ncdb.xml'
  COPY
  FILE_NAME_CONVERT = ('/disk1/oracle/dbs/', '/disk2/oracle/ncdb/')
  USER_TABLESPACES=('tbs3') MOVE;


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 支持支持 反对反对
回复

使用道具 举报

沙发
 楼主| 发表于 2021-8-18 22:49:12 | 只看该作者
可以用来从其他PDB中,或者NON_CDB中创建PDB时,指定表空间,或者排除表空间,是 SYSTEM, SYSAUX, or TEMP tablespaces 之外的表空间。所以,从SEED PDB 复制时,使用这个 USER_TABLESPACES就没有意义了。
回复 支持 反对

使用道具 举报

板凳
 楼主| 发表于 2021-8-18 22:55:06 | 只看该作者
可以用来从其他PDB中,或者NON_CDB中创建PDB时,指定表空间,或者排除表空间,是 SYSTEM, SYSAUX, or TEMP tablespaces 之外的表空间。所以,从SEED PDB 复制时,使用这个 USER_TABLESPACES就没有意义了。
回复 支持 反对

使用道具 举报

地板
 楼主| 发表于 2021-8-18 23:14:17 | 只看该作者
郑全 发表于 2021-8-18 22:49
可以用来从其他PDB中,或者NON_CDB中创建PDB时,指定表空间,或者排除表空间,是 SYSTEM, SYSAUX, or TEMP  ...

从ORCLPDB复制一个PDB, ORCLPDB 包含多个业务表空间,我们只复制 TBS_PDB.
SQL> alter session set container=orclpdb;

Session altered.

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         3 ORCLPDB                        READ WRITE NO
SQL> select * from v$tablespace;

       TS# NAME                           INC BIG FLA ENC     CON_ID
---------- ------------------------------ --- --- --- --- ----------
         0 SYSTEM                         YES NO  YES              3
         1 SYSAUX                         YES NO  YES              3
         2 UNDOTBS1                       YES NO  YES              3
         3 TEMP                           NO  NO  YES              3
         5 USERS                          YES NO  YES              3
         8 TSP_RESUME                     YES NO  YES              3
         6 TBS_PDB                        YES NO  YES              3
         7 TEMP_ORCLPDB                   NO  NO  YES              3

8 rows selected.

--开始复制PDB
SQL> conn / as sysdba
Connected.
SQL> create pluggable database pdb_user from orclpdb
  2     user_tablespaces=('tbs_pdb');

Pluggable database created.

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 ORCLPDB                        READ WRITE NO
         4 PDB2                           READ WRITE NO
         5 PDB1                           READ WRITE NO
         6 PDB_USER                       MOUNTED
SQL> alter pluggable database pdb_user open;

Pluggable database altered.

SQL> alter session set container=pdb_user;

Session altered.

--看到所有表空间
SQL> select *from v$tablespace;

       TS# NAME                           INC BIG FLA ENC     CON_ID
---------- ------------------------------ --- --- --- --- ----------
         0 SYSTEM                         YES NO  YES              6
         1 SYSAUX                         YES NO  YES              6
         2 UNDOTBS1                       YES NO  YES              6
         3 TEMP                           NO  NO  YES              6
         5 USERS                          YES NO  YES              6
         6 TBS_PDB                        YES NO  YES              6
         7 TEMP_ORCLPDB                   NO  NO  YES              6
         8 TSP_RESUME                     YES NO  YES              6

8 rows selected.

但有文件的只有TBS_PDB。

SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
+DATA/ORCLCDB/C9D71BF3B3C325FBE0538685A8C0EB07/DATAFILE/system.295.1080944313
+DATA/ORCLCDB/C9D71BF3B3C325FBE0538685A8C0EB07/DATAFILE/sysaux.296.1080944313
+DATA/ORCLCDB/C9D71BF3B3C325FBE0538685A8C0EB07/DATAFILE/undotbs1.302.1080944313
+DATA/ORCLCDB/C9D71BF3B3C325FBE0538685A8C0EB07/DATAFILE/tbs_pdb.294.1080944313


从DBA_TABLESPACES中,只看到 TBS_PDB表空间。

SQL> select tablespace_name,status,CONTENTS from dba_tablespaces where contents='PERMANENT';

TABLESPACE_NAME                STATUS    CONTENTS
------------------------------ --------- ---------------------
SYSTEM                         ONLINE    PERMANENT
SYSAUX                         ONLINE    PERMANENT
TBS_PDB                        ONLINE    PERMANENT


回复 支持 反对

使用道具 举报

5#
 楼主| 发表于 2021-8-18 23:33:55 | 只看该作者
排除所有的表空间,除 SYSTEM,UNDO,TEMP外:

从ORCLPDB中复制一个PDB,但排除所有业务表表空间:

SQL> alter session set container=orclpdb;

Session altered.

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         3 ORCLPDB                        READ WRITE NO
SQL> select * from v$tablespace;

       TS# NAME                           INC BIG FLA ENC     CON_ID
---------- ------------------------------ --- --- --- --- ----------
         0 SYSTEM                         YES NO  YES              3
         1 SYSAUX                         YES NO  YES              3
         2 UNDOTBS1                       YES NO  YES              3
         3 TEMP                           NO  NO  YES              3
         5 USERS                          YES NO  YES              3
         8 TSP_RESUME                     YES NO  YES              3
         6 TBS_PDB                        YES NO  YES              3
         7 TEMP_ORCLPDB                   NO  NO  YES              3

8 rows selected.


SQL> conn / as sysdba
Connected.
SQL> create pluggable database pdb_exclude from orclpdb
  2    user_tablespaces=('none');

Pluggable database created.

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 ORCLPDB                        READ WRITE NO
         4 PDB2                           READ WRITE NO
         5 PDB1                           READ WRITE NO
         6 PDB_USER                       READ WRITE NO
         7 PDB_EXCLUDE                    MOUNTED
SQL> alter pluggable database pdb_exclude open;

Pluggable database altered.

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 ORCLPDB                        READ WRITE NO
         4 PDB2                           READ WRITE NO
         5 PDB1                           READ WRITE NO
         6 PDB_USER                       READ WRITE NO
         7 PDB_EXCLUDE                    READ WRITE NO
SQL> alter session set container=pdb_exclude;

Session altered.

SQL> select * from v$tablespace;

       TS# NAME                           INC BIG FLA ENC     CON_ID
---------- ------------------------------ --- --- --- --- ----------
         0 SYSTEM                         YES NO  YES              7
         1 SYSAUX                         YES NO  YES              7
         2 UNDOTBS1                       YES NO  YES              7
         3 TEMP                           NO  NO  YES              7
         5 USERS                          YES NO  YES              7
         6 TBS_PDB                        YES NO  YES              7
         7 TEMP_ORCLPDB                   NO  NO  YES              7
         8 TSP_RESUME                     YES NO  YES              7

8 rows selected.

SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
+DATA/ORCLCDB/C9D73C10628B27A2E0538685A8C0B956/DATAFILE/system.312.1080944851
+DATA/ORCLCDB/C9D73C10628B27A2E0538685A8C0B956/DATAFILE/sysaux.310.1080944851
+DATA/ORCLCDB/C9D73C10628B27A2E0538685A8C0B956/DATAFILE/undotbs1.311.1080944851

SQL> select tablespace_name ,contents from dba_tablespaces;

TABLESPACE_NAME                CONTENTS
------------------------------ ---------------------
SYSTEM                         PERMANENT
SYSAUX                         PERMANENT
UNDOTBS1                       UNDO
TEMP                           TEMPORARY
TEMP_ORCLPDB                   TEMPORARY


回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|手机版|小黑屋|重庆思庄Oracle、Redhat认证学习论坛 ( 渝ICP备12004239号-4 )

GMT+8, 2024-4-29 22:47 , Processed in 0.083618 second(s), 18 queries .

重庆思庄学习中心论坛-重庆思庄科技有限公司论坛

© 2001-2020

快速回复 返回顶部 返回列表