If Source/Non-CDB is 11.2.0.3/11.2.0.4:
1) FULL-TTS
2) Datapump Export/Import
If Source/Non-CDB is already a 12c version:
1) FULL-TTS
2) DBMS_PDB.DESCRIBE
3) Datapump Export/Import
Using FULL-TTS:
1. Verify whether the Platforms are supported for transport?
2. Verify whether the Platforms differ by endian format? (for conversion)
3. Verify the National and Database Character Set.
4. Create an empty PDB in the Target CDB
5. Pre-create the 'Source Database Users' in the Target PDB or use REMAP_SCHEMA.
6. Make the user-defined and application tablespaces to READ-ONLY in Source.
7. Perform the FULL-TTS Export in Source.
8. Transport the FULL-TTS Dumpfile to the PDB Target location.
9. Transport the Datafiles to the PDB Target location. If endianness are different, Conversion of datafiles to Target Platform Endian is necessary.
10. Perform the FULL-TTS Import in Target.
11. When the FULL-TTS Import is complete, the tablespaces are automatically put into READ WRITE mode in Target.
12. Open the Source Tablespaces to READ WRITE upon successful completion of import. (this step can be after Step 9 as well)
以下是使用 DBMS_PDB.DESCRIBE 方法将12c非CDB转换为PDB的完整步骤:
1) Shutdown the 12c non-cdb database gracefully (shutdown immediate)
2) Now Open the 12c non-cdb database in Read-Only Mode
3) In the 12c non-CDB database, execute the "DBMS_PDB.DESCRIBE" package, which will create an XML file containing the description about the non-cdb database datafiles.
4) Shutdown the 12c non-cdb database
5) Connect to the target root CDB and check the compatibility of the 12c non-cdb database using "DBMS_PDB.CHECK_PLUG_COMPATIBILITY" package
6) If this package returns FALSE/NO, then check for violations in "PDB_PLUG_IN_VIOLATIONS" view and correct the errors and warnings.
7) If the above package returns TRUE/YES, then plug the 12c non-cdb as a PDB to the target cdb using the "CREATE PLUGGABLE DATABASE USING <xml>" command
8) Now switch or connect to the pdb using "ALTER SESSION SET CONTAINER=pdbname" and execute "$ORACLE_HOME/rdbms/admin/noncdb_to_pdb.sql" script
9) Now open the PDB in read write mode using "ALTER PLUGGABLE DATABASE pdbname OPEN" command.
10) Now, the non-CDB has been converted to a PDB.
Non-CDB创建测试用户、测试数据
create user testuser identified by Aa123456;
grant dba to testuser;
conn testuser/Aa123456
CREATE TABLE area
(area_no CHAR(2) NOT NULL PRIMARY KEY,
area_name VARCHAR2(60),
DHQ VARCHAR2(20) DEFAULT 'ShenZhen' NOT NULL);
INSERT INTO area VALUES ('01','华东','Shanghai');
INSERT INTO area VALUES ('02','华西','Chengdu');
INSERT INTO area VALUES ('03','华南','Guangzhou');
INSERT INTO area VALUES ('04','华北','Beijing');
INSERT INTO area VALUES ('05','华中','Wuhan');
commit;
Non-CDB:
SQL> select name, dbid, cdb from v$database;
NAME DBID CDB
--------- ---------- ---
ORCL 1655557394 NO
目标数据库:
SQL> select name, dbid, cdb from v$database;
NAME DBID CDB
--------- ---------- ---
CDB1 1101218947 YES
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDB1 MOUNTED
把Non-CDB设置为只读模式
shutdown immediate
startup mount
alter database open read only;
连接到Non-CDB并使用存储过程dbms_pdb.describe来创建描述Non-CDB的XML文件
exec dbms_pdb.describe(pdb_descr_file=>'/tmp/orcl.xml');
使用dbms_pdb.check_plug_compatibility检查Non-CDB与目标CDB是否兼容:
pdb_name:指定CDB中新的PDB的名字。
set serverout on
declare
compatible constant varchar2(3) := case
dbms_pdb.check_plug_compatibility(
pdb_descr_file => '/tmp/orcl.xml',
pdb_name => 'orclpdb')
when true then 'yes' else 'no' end;
begin
dbms_output.put_line(compatible);
end;
/
关闭源库Non-CDB:orcl
shutdown immediate;
将Non-CDB:orcl插入到CDB:ora12c中,且命名为orclpdb。
指定 COPY 参数,将文件复制到 CDB 的相应目录下,如果已经复制到特定目录,则可以指定 NOCOPY 选项,就无需再复制一次。
因为源数据库在 192.168.11.11,而目标数据库在 192.168.11.10,故而需要创建 /data/oradata/orcl 目录,并复制文件
scp /data/oradata/orcl/dbf 192.168.11.10:/data/oradata/orcl/
create pluggable database orclpdb using '/tmp/orcl.xml' nocopy tempfile reuse;
show pdbs
select pdb_id, pdb_name, dbid, status, con_id from cdb_pdbs;
执行 noncdb_to_pdb.sql 脚本
alter session set container=orclpdb;
@$ORACLE_HOME/rdbms/admin/noncdb_to_pdb.sql
以读写模式打开新PDB
alter pluggable database orclpdb open;
show pdbs
alter session set container=orclpdb;
create table t as select * from dba_objects;
查看迁移之前创建的数据
SQL> col area_name for a20
SQL> select * from testuser.area;
AR AREA_NAME DHQ
-- -------------------- --------------------
01 华东 Shanghai
02 华西 Chengdu
03 华南 Guangzhou
04 华北 Beijing
05 华中 Wuhan