目标
将源端的non-CDB 迁移到目标端的CDB中
参考文档
https://docs.oracle.com/database/121/ADMIN/cdb_plug.htm#ADMIN-GUID-60C23F96-6EF3-4BE3-B8CF-5AD6EC29954F
38.6 Creating a PDB Using a Non-CDB
环境信息
| 源端 | 目标端 |
实例名 | orcl | root:oracdb pdb:ncdb |
版本 | 12.2.0.1 | 12.2.0.1 |

实施过程
利用DBMS_PDB.DESCRIBE存储过程来插入non-CDB,实现将non-CDB数据库插入到CDB中
制作pdbxml文件
以只读方式打开non-CDB
SQL*Plus: Release 12.2.0.1.0 Production on Mon Mar 22 10:24:08 2021 Copyright (c) 1982, 2016, Oracle. All rights reserved. Connected to: Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production SQL> shutdown immediate; Database closed. Database dismounted. ORACLE instance shut down. SQL> startup open read only ORACLE instance started. Total System Global Area 763363328 bytes Fixed Size 8625368 bytes Variable Size 557843240 bytes Database Buffers 192937984 bytes Redo Buffers 3956736 bytes Database mounted. Database opened. |
运行DBMS_PDB.DESCRIBE生成xml文件
BEGIN DBMS_PDB.DESCRIBE( pdb_descr_file => '/home/oracle/orcl.xml'); END; / |
查看xml文件
[oracle@oracle12c ~]$ ll *.xml -rw-r--r-- 1 oracle oinstall 6525 Mar 22 10:36 orcl.xml |
兼容性检查
在CDB中进行兼容性检查
SET SERVEROUTPUT ON DECLARE compatible CONSTANT VARCHAR2(3) := CASE DBMS_PDB.CHECK_PLUG_COMPATIBILITY( pdb_descr_file => '/home/oracle/orcl.xml', pdb_name => 'NCDB') WHEN TRUE THEN 'YES' ELSE 'NO' END; BEGIN DBMS_OUTPUT.PUT_LINE(compatible); END; / |
返回YES即兼容性无问题
关闭non-CDB
[oracle@oracle12c ~]$ export ORACLE_SID=orcl [oracle@oracle12c ~]$ sqlplus as sysdba SQL*Plus: Release 12.2.0.1.0 Production on Mon Mar 22 11:10:24 2021 Copyright (c) 1982, 2016, Oracle. All rights reserved. Connected to: Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production SQL> shutdown immediate; Database closed. Database dismounted. ORACLE instance shut down. |
创建pdb
使用生成的non-CDB xml创建pdb
CREATE PLUGGABLE DATABASE ncdb USING '/home/oracle/orcl.xml' COPY FILE_NAME_CONVERT = ('/oradata/orcl', '/oradata/oracdb/') USER_TABLESPACES=('USERS'); |

SQL> show pdbs CON_ID CON_NAME OPEN MODE RESTRICTED ---------- --------------- ---------- ---------- 2 PDB$SEED READ ONLY NO 5 NCDB MOUNTED |
pdb已经建完并启动到mount状态
继续执行脚本@$ORACLE_HOME/rdbms/admin/noncdb_to_pdb.sql
SQL> alter session set container=ncdb; Session altered. SQL> @$ORACLE_HOME/rdbms/admin/noncdb_to_pdb.sql |
启动pdb
SQL> show pdbs; CON_ID CON_NAME OPEN MODE RESTRICTED ---------- --------------- ---------- ---------- 3 NCDB MOUNTED SQL> startup; Pluggable Database opened. |
验证数据
以scott用户连接到pdb
[oracle@oracle12c ~]$ sqlplus scott/tiger@192.168.106.10/ncdb SQL*Plus: Release 12.2.0.1.0 Production on Mon Mar 22 13:33:45 2021 Copyright (c) 1982, 2016, Oracle. All rights reserved. Last Successful login time: Mon Mar 22 2021 13:31:01 +08:00 Connected to: Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production SQL> select count(*) from tab; COUNT(*) ---------- 194 SQL> select count(*) from emp; COUNT(*) ---------- 14 |
查看原库数据
[oracle@oracle12c ~]$ sqlplus scott/tiger@192.168.106.10/orcl SQL*Plus: Release 12.2.0.1.0 Production on Mon Mar 22 13:32:27 2021 Copyright (c) 1982, 2016, Oracle. All rights reserved. Last Successful login time: Tue Mar 16 2021 14:16:03 +08:00 Connected to: Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production SQL> select count(*) from tab; COUNT(*) ---------- 194 SQL> select count(*) from emp; COUNT(*) ---------- 14 |
至此non-CDB插入CDB完成