通过克隆本地现有 pdb 创建新的 pdb
目录结构
一、创建说明
二、创建选项
三、新pdb创建语句
四、执行创建过程
五、指定NO DATA子句,克隆时不复制数据。
一、创建说明
1、执行创建的用户必须具有CREATE PLUGGABLE DATABASE 系统权限
2、源pdb不能被关闭
3、如果cdb不是 local undo 模式, 则源pdb必须启动到read-only 状态
4、如果cdb非归档, 则源pdb必须启动到read-only 状态
二、创建选项
1、如果STORAGE UNLIMITED被设定,或者没有存储选项被设定,则pdb没有存储限制。常用设置如下:
STORAGE (MAXSIZE 2G) STORAGE (MAXSIZE UNLIMITED) storage(MAX_AUDIT_SIZE xxx) storage(MAX_DIAG_SIZE)
2、通过 DEFAULT TABLESPACE子句 指定pdb的默认表空间
3、通过FILE_NAME_CONVERT 指定pdb被创建时,数据文件的存放位置
用法1 FILE_NAME_CONVERT = ('/oracle/dbs/', '/oracle/pdb5/')
用法2 'string1' , 'string2' , 'string3' , 'string4' , ... string2路径替换string1路径,string4路径替换string3路径
4、如果FILE_NAME_CONVERT和CREATE_FILE_DEST同时被指定,则FILE_NAME_CONVERT指定pdb被创建时文件的位置,CREATE_FILE_DEST指定pdb创建后,新建数据文件的路径。
5、指定NO DATA子句,克隆时不复制数据。
三、新pdb创建语句
1、登陆源pdb查询数据文件路径
SQL> alter session set container=mypdb1;
Session altered.
SQL> select name from v$datafile;
NAME
------------------------------------------------------------
/opt/oracle/oradata/mycdb/mypdb1/system01.dbf
/opt/oracle/oradata/mycdb/mypdb1/sysaux01.dbf
/opt/oracle/oradata/mycdb/mypdb1/undotbs01.dbf
/opt/oracle/oradata/mycdb/mypdb1/users01.dbf
2、待创建pdb mypdb3的创建语句
create pluggable database mypdb3 from mypdb1 FILE_NAME_CONVERT = ('/opt/oracle/oradata/mycdb/mypdb1/','/opt/oracle/oradata/mycdb/mypdb3/');
四、执行创建过程
1、切换到根容器
SQL> show pdbs;
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 MYPDB1 READ WRITE NO
4 MYPDB2 READ WRITE NO
5 YOUPDB MOUNTED
SQL> show con_name;
CON_NAME
------------------------------
CDB$ROOT
2、执行创建语句
SQL> create pluggable database mypdb3 from mypdb1 FILE_NAME_CONVERT = ('/opt/oracle/oradata/mycdb/mypdb1/','/opt/oracle/oradata/mycdb/mypdb3/');
Pluggable database created.
3、启动新创建的mypdb3
SQL> show pdbs;
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 MYPDB1 READ WRITE NO
4 MYPDB2 READ WRITE NO
5 YOUPDB MOUNTED
6 MYPDB3 MOUNTED
SQL> alter pluggable database mypdb3 open;
Pluggable database altered.
SQL> show pdbs;
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 MYPDB1 READ WRITE NO
4 MYPDB2 READ WRITE NO
5 YOUPDB MOUNTED
6 MYPDB3 READ WRITE NO
SQL> alter session set container=mypdb3;
Session altered.
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/opt/oracle/oradata/mycdb/mypdb3/system01.dbf
/opt/oracle/oradata/mycdb/mypdb3/sysaux01.dbf
/opt/oracle/oradata/mycdb/mypdb3/undotbs01.dbf
/opt/oracle/oradata/mycdb/mypdb3/users01.dbf
SQL> select name from v$tempfile;
NAME
--------------------------------------------------------------------------------
/opt/oracle/oradata/mycdb/mypdb3/temp01.dbf
五、指定NO DATA子句,克隆时不复制数据。
1、注意事项
需要把源pdb打开的read only 状态,否则报如下错误
[oracle@cydbcs ~]$ oerr ora 65359;
65359, 00000, "unable to create pluggable database with no data"
// *Cause: An attempt was made to clone a pluggable database that was opened
// in read/write mode.
// *Action: Retry the clone operation after the source pluggable database is
// in read-only mode.
2、pdb源库数据查询
SQL> alter session set container=democdb2;
Session altered.
SQL> show pdbs;
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
48 DEMOCDB2 READ ONLY NO
SQL> select count(*) from bfpub10.bfsystem;
COUNT(*)
----------
3
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/oradata/DEVCDB/DEMOCDB2/system01.dbf
/oradata/DEVCDB/DEMOCDB2/sysaux01.dbf
/oradata/DEVCDB/DEMOCDB2/undotbs01.dbf
/oradata/DEVCDB/DEMOCDB2/BF_DATA.dbf
3、创建
SQL> create pluggable database demodb from democdb2 FILE_NAME_CONVERT = ('/oradata/DEVCDB/DEMOCDB2/','/oradata/DEVCDB/demodb/') NO DATA;
Pluggable database created.
4、验证
SQL> alter pluggable database demodb open;
Pluggable database altered.
SQL> alter session set container=demodb;
Session altered.
SQL> select count(*) from bfpub10.bfsystem;
COUNT(*)
----------
0