Oracle 12C 新特性之 PDB熱克隆(本地克隆、遠端異機克隆)

張衝andy發表於2017-05-17

說明:版本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

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31383567/viewspace-2139221/,如需轉載,請註明出處,否則將追究法律責任。

相關文章