1、源端环境准备
为本次实验克隆一个PDB
克隆步骤可参考https://blog.csdn.net/ogdkevin/article/details/83107092
2、源端拔出PDB[问题1]
在CDB中操作,关闭PDB后,拔出PDB生成XML文件
SQL> alter pluggable database pdb2 close immediate;
Pluggable database altered.
SQL> alter pluggable database pdb2 unplug into '/home/oracle/pdb2.xml';
Pluggable database altered.
SQL> drop pluggable database pdb2 keep datafiles;
Pluggable database dropped.
3、目标端创建PDB的datafile目录
#oracle用户运行
[oracle@oracle12c ~]$ mkdir /u01/app/oracle/oradata/pdb2
4、传输源端datafile和xml文件到目标端
源端datafile位置可以查看unplug生成的xml文件
5、验证待插入PDB的兼容性
SQL> SET SERVEROUTPUT ON
SQL> DECLARE
2 v_result BOOLEAN;
3 BEGIN
4 v_result := DBMS_PDB.check_plug_compatibility(
5 pdb_descr_file => '/home/oracle/pdb2.xml',
6 pdb_name => 'PDB2');
7
8 IF v_result THEN
9 DBMS_OUTPUT.PUT_LINE('compatible');
10 ELSE
11 DBMS_OUTPUT.PUT_LINE('incompatible');
12 END IF;
13 END;
14 /
compatible
PL/SQL procedure successfully completed.
6、插入PDB[问题2]
--PDB名称可以和原来的不同
--如果datafile都在同一个目录,只需要指定目录
SQL> create pluggable database pdb2 as clone using '/home/oracle/pdb2.xml'
2 source_file_directory = '/u01/app/oracle/oradata/pdb2'
3 file_name_convert=NONE NOCOPY tempfile reuse;
Pluggable database created.
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDB1 READ WRITE NO
4 PDB2 MOUNTED
7、打开PDB并检查插入的PDB是否有问题,查看PDB_PLUG_IN_VIOLATIONS表[问题3]
--查看DB的trace log也能看到相关提示
***************************************************************
WARNING: Pluggable Database PDB2 with pdb id - 4 is
altered with errors or warnings. Please look into
PDB_PLUG_IN_VIOLATIONS view for more details.
***************************************************************
SQL> set lin 200
SQL> col name for a10
SQL> col cause for a20
SQL> col message for a100
SQL> select name,cause,type,message,status from pdb_plug_in_violations order by name;
NAME CAUSE TYPE MESSAGE STATUS
---------- -------------------- --------- ---------------------------------------------------------------------------------------------------- ---------
PDB2 OPTION WARNING Database option RAC mismatch: PDB installed version 12.1.0.2.0. CDB installed version NULL. PENDING
PDB2 Parameter WARNING CDB parameter sga_max_size mismatch: Previous 2G Current 1584M RESOLVED
PDB2 Parameter WARNING CDB parameter memory_target mismatch: Previous 2G Current 1584M RESOLVED
PDB2 Parameter WARNING CDB parameter memory_max_target mismatch: Previous 2G Current 1584M RESOLVED
PDB2 Parameter WARNING CDB parameter cluster_database mismatch: Previous TRUE Current FALSE RESOLVED
PDB2 Oracle Opatch WARNING Oracle opatch mismatch: opatch 19769480 is missing in the CDB. RESOLVED
PDB2 Oracle Opatch WARNING Oracle opatch mismatch: opatch 20299023 is missing in the CDB. RESOLVED
PDB2 Oracle Opatch WARNING Oracle opatch mismatch: opatch 20831110 is missing in the CDB. RESOLVED
PDB2 Oracle Opatch WARNING Oracle opatch mismatch: opatch 21359755 is missing in the CDB. RESOLVED
PDB2 Oracle Opatch WARNING Oracle opatch mismatch: opatch 21948354 is missing in the CDB. RESOLVED
PDB2 Oracle Opatch WARNING Oracle opatch mismatch: opatch 22291127 is missing in the CDB. RESOLVED
NAME CAUSE TYPE MESSAGE STATUS
---------- -------------------- --------- ---------------------------------------------------------------------------------------------------- ---------
PDB2 Oracle Opatch WARNING Oracle opatch mismatch: opatch 23054246 is missing in the CDB. RESOLVED
PDB2 Oracle Opatch WARNING Oracle opatch mismatch: opatch 24006101 is missing in the CDB. RESOLVED
PDB2 Oracle Opatch WARNING Oracle opatch mismatch: opatch 24732082 is missing in the CDB. RESOLVED
PDB2 Oracle Opatch WARNING Oracle opatch mismatch: opatch 25171037 is missing in the CDB. RESOLVED
PDB2 Oracle Opatch WARNING Oracle opatch mismatch: opatch 25755742 is missing in the CDB. RESOLVED
PDB2 Oracle Opatch WARNING Oracle opatch mismatch: opatch 26609783 is missing in the CDB. RESOLVED
PDB2 Oracle Opatch WARNING Oracle opatch mismatch: opatch 26713565 is missing in the CDB. RESOLVED
PDB2 Oracle Opatch WARNING Oracle opatch mismatch: opatch 26925311 is missing in the CDB. RESOLVED
PDB2 Oracle Opatch WARNING Oracle opatch mismatch: opatch 27338020 is missing in the CDB. RESOLVED
PDB2 Oracle Opatch WARNING Oracle opatch mismatch: opatch 27338041 is missing in the CDB. RESOLVED
21 rows selected.
STATUS状态RESOLVED的不用处理,只要看状态为PENDING,这里只有一条为OPTIN的问题。
因为是从RAC环境插拔过来的,目标环境不是RAC,注意只需要把这个RAC选项关掉。
8、切换到PDB2,关掉RAC选项
SQL> alter session set container=pdb2;
Session altered.
SQL> exec dbms_registry.OPTION_OFF('RAC');
PL/SQL procedure successfully completed.
9、重新关闭和启动,再检查是否还有问题
SQL> alter pluggable database pdb2 close immediate;
Pluggable database altered.
SQL> alter pluggable database pdb2 open;
Pluggable database altered.
SQL> select name,cause,type,message,status from pdb_plug_in_violations order by name;
NAME CAUSE TYPE MESSAGE STATUS
---------- -------------------- --------- ---------------------------------------------------------------------------------------------------- ---------
PDB2 OPTION WARNING Database option RAC mismatch: PDB installed version 12.1.0.2.0. CDB installed version NULL. RESOLVED
PDB2 Parameter WARNING CDB parameter sga_max_size mismatch: Previous 2G Current 1584M RESOLVED
PDB2 Parameter WARNING CDB parameter memory_target mismatch: Previous 2G Current 1584M RESOLVED
PDB2 Parameter WARNING CDB parameter memory_max_target mismatch: Previous 2G Current 1584M RESOLVED
PDB2 Parameter WARNING CDB parameter cluster_database mismatch: Previous TRUE Current FALSE RESOLVED
PDB2 Oracle Opatch WARNING Oracle opatch mismatch: opatch 19769480 is missing in the CDB. RESOLVED
PDB2 Oracle Opatch WARNING Oracle opatch mismatch: opatch 20299023 is missing in the CDB. RESOLVED
PDB2 Oracle Opatch WARNING Oracle opatch mismatch: opatch 20831110 is missing in the CDB. RESOLVED
PDB2 Oracle Opatch WARNING Oracle opatch mismatch: opatch 21359755 is missing in the CDB. RESOLVED
PDB2 Oracle Opatch WARNING Oracle opatch mismatch: opatch 21948354 is missing in the CDB. RESOLVED
PDB2 Oracle Opatch WARNING Oracle opatch mismatch: opatch 22291127 is missing in the CDB. RESOLVED
NAME CAUSE TYPE MESSAGE STATUS
---------- -------------------- --------- ---------------------------------------------------------------------------------------------------- ---------
PDB2 Oracle Opatch WARNING Oracle opatch mismatch: opatch 23054246 is missing in the CDB. RESOLVED
PDB2 Oracle Opatch WARNING Oracle opatch mismatch: opatch 24006101 is missing in the CDB. RESOLVED
PDB2 Oracle Opatch WARNING Oracle opatch mismatch: opatch 24732082 is missing in the CDB. RESOLVED
PDB2 Oracle Opatch WARNING Oracle opatch mismatch: opatch 25171037 is missing in the CDB. RESOLVED
PDB2 Oracle Opatch WARNING Oracle opatch mismatch: opatch 25755742 is missing in the CDB. RESOLVED
PDB2 Oracle Opatch WARNING Oracle opatch mismatch: opatch 26609783 is missing in the CDB. RESOLVED
PDB2 Oracle Opatch WARNING Oracle opatch mismatch: opatch 26713565 is missing in the CDB. RESOLVED
PDB2 Oracle Opatch WARNING Oracle opatch mismatch: opatch 26925311 is missing in the CDB. RESOLVED
PDB2 Oracle Opatch WARNING Oracle opatch mismatch: opatch 27338020 is missing in the CDB. RESOLVED
PDB2 Oracle Opatch WARNING Oracle opatch mismatch: opatch 27338041 is missing in the CDB. RESOLVED
21 rows selected.
全部的状态都是RESOLVED,检查trace log也没用了相关警告!
至此,PDB迁移完成!
可能存在问题及解决办法:
问题1、unplug出错:
SQL> alter pluggable database pdb2 unplug into '/home/oracle/pdb2.xml'; alter pluggable database pdb2 unplug into '/home/oracle/pdb2.xml' * ERROR at line 1: ORA-65025: Pluggable database PDB2 is not closed on all instances.
解决办法:需要先关闭PDB才可以unplug。
问题2、如果datafile不在同一目录,或者要对datafile重新命名的,使用source_file_name_convert指定每一个datafile
create pluggable database pdb2 as clone using '/home/oracle/pdb2.xml' source_file_name_convert = ( '+DG_DATA/RACDB/783C262E9F5EC362E0531F05160A3313/DATAFILE/system.278.989576727', '/u01/app/oracle/oradata/pdb1/system.278.989576727', '+DG_DATA/RACDB/783C262E9F5EC362E0531F05160A3313/DATAFILE/sysaux.271.989576727', '/u01/app/oracle/oradata/pdb1/sysaux.271.989576727', '+DG_DATA/RACDB/783C262E9F5EC362E0531F05160A3313/DATAFILE/users.276.989576727', '/u01/app/oracle/oradata/pdb1/users.276.989576727', '+DG_DATA/RACDB/783C262E9F5EC362E0531F05160A3313/TEMPFILE/temp.279.989576733', '/u01/app/oracle/oradata/pdb1/temp.276.989576727') file_name_convert=NONE NOCOPY tempfile reuse;
问题3、如果不想出现补丁或者参数这些warning出现,可以修改xml文件才进行插入操作。
解决办法:
- 修改参数值和目标设置的参数值一样,如下
processes=300 sga_max_size=2147483648 memory_target=2147483648 memory_max_target=2147483648 db_block_size=8192 compatible='12.1.0.2.0' cluster_database=TRUE open_cursors=300 enable_pluggable_database=TRUE
- 删除目标端不存在的补丁集,如下:
19769480 20299023 20831110 21359755 21948354 22291127 23054246 24006101 24732082 25171037 25755742 26609783 26713565 26925311 27338020 27338041
参考: