Oracle12C新特性之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 模式切换可以参考 blog.csdn/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>
clonecol 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 ,
参考blog.csdn/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

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。