Oracle 12C 新特性之 PDB热克隆(本地克隆、远端异机克隆)

说明:版本12.2.0.1

12c r1版本中 clone 一份PDB源库需要打开在read only只读模式 , 在12c r2版本中引入了local undo mode, 源PDB在read/write 读写模式也可以 clone 。  local undo mode 也是oracle推崇的模式。

说明: shared undo 与 Local undo 模式切换 可以参考 http://blog.csdn.net/zhang123456456/article/details/71374528

要求:
1、 Archive Log Enabled  
2、 Local Undo Enabled 
3、 destination CDB must have a public database link to the source CDB,have sufficient privileges to use the database link.

一、  克隆本地pdb

[oracle@12c ~]$ sqlplus / as sysdba
-- 检查是否开启 local undo
SQL> 
col PROPERTY_NAME for a25;
col PROPERTY_VALUE for a25;
select PROPERTY_NAME,PROPERTY_VALUE from database_properties where property_name='LOCAL_UNDO_ENABLED';
PROPERTY_NAME  PROPERTY_VALUE
------------------------- -------------------------
LOCAL_UNDO_ENABLED  TRUE

SQL> show pdbs
    CON_ID CON_NAME  OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED  READ ONLY  NO
3 PDB01  READ WRITE NO
SQL> show parameter pdb_file_name_convert
NAME     TYPE VALUE
------------------------------------ ----------- ------------------------------
pdb_file_name_convert     string
-- clone pdb 数量为一  , 注意这里 pdb_file_name_convert 参数生效级别设置的是 session , 如有需要,自行设置为全局
SQL> alter session set pdb_file_name_convert='pdb01','pdb02';
Session altered.
SQL> create pluggable database pdb02 from pdb01;
Pluggable database created.
SQL> alter pluggable database pdb02 open;
Pluggable database created.
SQL> alter pluggable database pdb02 close immediate;
Pluggable database altered.
-- clone pdb 数量为多
SQL> alter session set pdb_file_name_convert='pdb01','pdb02,pdb03';
Session altered.
SQL> create pluggable database pdb03 from pdb01;
Pluggable database created.
SQL> show pdbs
    CON_ID CON_NAME  OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED  READ ONLY  NO
3 PDB01  READ WRITE NO
4 PDB02  MOUNTED
5 PDB03  MOUNTED
SQL> alter pluggable database pdb02 open;
Pluggable database altered.
SQL> alter pluggable database pdb03 open;
Pluggable database altered.
SQL> show pdbs
    CON_ID CON_NAME  OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED  READ ONLY  NO
3 PDB01  READ WRITE NO
4 PDB02  READ WRITE NO

5 PDB03  READ WRITE NO

二、  克隆远程pdb
--源端
SQL> create user c##andy identified by andy container=all;
User created.
SQL> grant dba to c##andy container=all;
Grant succeeded.
-- 目标端cdb执行

SQL> create database link clonePdb connect to c##andy  identified by andy using '(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = 10.219.24.17)(PORT = 1521))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = pdb01)))';
Database link created.

-- 源端
SQL> show pdbs
    CON_ID CON_NAME  OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED  READ ONLY  NO
3 PDB01  READ WRITE NO

-- 目标端cdb
SQL> show pdbs
    CON_ID CON_NAME  OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED  READ ONLY  NO
3 PDB01  READ WRITE NO
4 PDB02  READ WRITE NO
5 PDB03  READ WRITE NO

SQL> alter session set pdb_file_name_convert='pdb01','pdb04';
Session altered.
-- 通过 dblink 克隆源端的 pdb 
SQL> create pluggable database pdb04 from pdb01@clonePdb;
Pluggable database created.
SQL> show pdbs
    CON_ID CON_NAME  OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED  READ ONLY  NO
3 PDB01  READ WRITE NO
4 PDB02  READ WRITE NO
5 PDB03  READ WRITE NO
6 PDB04  MOUNTED
SQL> alter pluggable database pdb04 open;
alter pluggable database pdb04 open
*
ERROR at line 1:
ORA-14694: database must in UPGRADE mode to begin MAX_STRING_SIZE migration
SQL> ho oerr ora 14694
14694, 00000, "database must in UPGRADE mode to begin MAX_STRING_SIZE migration"
// *Cause:  An attempt was made to update the MAX_STRING_SIZE parameter
//          to EXTENDED when the database was not in UPGRADE mode.
//* Action: Restart the database in UPGRADE mode, modify the parameter, 
//          run the utl32k.sql script in $ORACLE_HOME/rdbms/admin, and
//          restart the database in normal mode.

说明: 这个报错的原因是目标端使用了12c的新特性extended data type ,源端没有使用这个新特性,从源端克隆过来的pdb需要扩展 extended data type 新特性与目标端保持一致。有关新特性extended data type ,
参考http://blog.csdn.net/zhang123456456/article/details/71713201
-- 新克隆的pdb拓展 extended data type 新特性
SQL> alter session set container=pdb04;
Session altered.
SQL>  startup upgrade;
Pluggable Database opened.
SQL> show parameter max_string_size
NAME     TYPE VALUE
------------------------------------ ----------- ------------------------------
max_string_size     stringEXTENDED
SQL> @$ORACLE_HOME/rdbms/admin/utl32k.sql
SQL> shutdown immediate;
Pluggable Database closed.
SQL> startup;
Pluggable Database opened.
SQL> alter session set container=cdb$root;
Session altered.
SQL> show pdbs
    CON_ID CON_NAME  OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED  READ ONLY  NO
3 PDB01  READ WRITE NO
4 PDB02  READ WRITE NO
5 PDB03  READ WRITE NO
6 PDB04  READ WRITE NO

posted on 2017-05-17 13:59  张冲andy  阅读(1940)  评论(0编辑  收藏  举报

导航