1 说明

An administrator can now create a clone of a pluggable database only with the data model definition. The dictionary data in the source is copied as is but all user-created table and index data from the source is discarded.

从12.1.0.2开始,在克隆源PDB时,可以通过该特性只复制源pdb的数据字典里的数据,而忽略用户创建的表和索引数据

可以通过CREATE PLUGGABLE DATABASE语句中指定NO DATA来排除对象数据。从而会非常快的创建一个PDB。
注意:

  • 使用该特性,必须使用CREATE PLUGGABLE DATABASE …FROM语句。
  • 该特性不会对SYSTEM,SYSAUX生效,如果用户在这两个表空间中创建对象,那么这些对象会被完整的克隆,包括数据。

在使用该特性时,源PDB不能包含以下类型的表:

  • Advanced Queue (AQ) tables
  • Clustered tables
  • Table clusters

2 实验

2.1 查看当前PDB

SQL> show pdbs;

CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO

3 LEI1 READ WRITE YES

2.2 源库PDB创建测试数据

SQL> conn lei/lei@lei1;
Connected.

SQL> create table test_t(id number,name varchar2(50)) tablespace cndba;
Table created.


SQL> insert into test_t values(1,'sihong');
1 row created.


SQL> commit;
Commit complete.

2.3 克隆LEI1为SIHONG

SQL> CREATE PLUGGABLE DATABASE sihong FROM lei1
FILE_NAME_CONVERT = ('/u01/app/oracle/oradata/orcl/lei1/','/u01/app/oracle/oradata/orcl/sihong/',
'/u01/app/oracle/oradata/orcl/lei1/o1_mf_cndba_dr8kfogo_.dbf','/u01/app/oracle/oradata/orcl/sihong/cndba01.dbf',
'/u01/app/oracle/product/11.2.0.4/db_1/dbs/file','/u01/app/oracle/oradata/orcl/sihong/file') NO DATA; 2 3 4

Pluggable database created.

备注:

创建期间出些错,仅供参考:

  • 临时表空间其中一个数据文件在另一个目录下,报错如下:
SQL> CREATE PLUGGABLE DATABASE sihong FROM lei1
FILE_NAME_CONVERT = ('/u01/app/oracle/oradata/orcl/lei1/', '/u01/app/oracle/oradata/orcl/sihong/') NO DATA; 2
CREATE PLUGGABLE DATABASE sihong FROM lei1
*
ERROR at line 1:
ORA-65005: missing or invalid file name pattern for file -
/u01/app/oracle/product/11.2.0.4/db_1/dbs/file

解决办法:手动指定文件名

'/u01/app/oracle/product/11.2.0.4/db_1/dbs/file','/u01/app/oracle/oradata/orcl/sihong/file'
  • OMF管理的数据文件
SQL> CREATE PLUGGABLE DATABASE sihong FROM lei1
FILE_NAME_CONVERT = ('/u01/app/oracle/oradata/orcl/lei1/','/u01/app/oracle/oradata/orcl/sihong/',
'/u01/app/oracle/product/11.2.0.4/db_1/dbs/file','/u01/app/oracle/oradata/orcl/sihong/file') NO DATA; 2 3
CREATE PLUGGABLE DATABASE sihong FROM lei1
*

ERROR at line 1:
ORA-01276: Cannot add file
/u01/app/oracle/oradata/orcl/sihong/o1_mf_cndba_dr8kfogo_.dbf. File has an
Oracle Managed Files file name.
SQL> !oerr ora 01276
01276, 00000, "Cannot add file %s. File has an Oracle Managed Files file name."
// *Cause: An attempt was made to add to the database a datafile, log file,
// control file, snapshot control file, backup control file,
// datafile copy, control file copy or backuppiece with an Oracle
// Managed Files file name.
// *Action: Retry the operation with a new file name.

解决方法:

'/u01/app/oracle/oradata/orcl/lei1/o1_mf_cndba_dr8kfogo_.dbf','/u01/app/oracle/oradata/orcl/sihong/cndba01.dbf'

2.4 验证数据

SQL> alter session set container=sihong;

Session altered.

–数据没有克隆过来

SQL> select * from lei.test_t;
no rows selected

参考文档:​​http://docs.oracle.com/database/121/SQLRF/statements_6010.htm#SQLRF57032​