Home >Database >Mysql Tutorial >Oracle 12C 将Non-PDB插入到CDB中
使用dbms_pdb包进行迁移,dbms_pdb是12c新增加的,为了方便迁移用的。可以用desc dbms_pdb查看下具体参数。将Non-CDB数据库迁移到
进入到非CDB数据库中
查看数据文件的位置
[Oracle@shuang ~]$ sqlplus / as sysdba
SQL*Plus: Release 12.1.0.1.0 Production on Wed Feb 26 13:17:45 2014
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area 1060585472 bytes
Fixed Size 2296472 bytes
Variable Size 704644456 bytes
Database Buffers 348127232 bytes
Redo Buffers 5517312 bytes
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/SHUANG/datafile/o1_mf_system_9jckkfwg_.dbf
/u01/app/oracle/oradata/SHUANG/datafile/o1_mf_sysaux_9jckdvs6_.dbf
/u01/app/oracle/oradata/SHUANG/datafile/o1_mf_undotbs1_9jckpbno_.dbf
/u01/app/oracle/oradata/SHUANG/datafile/o1_mf_users_9jckp97s_.dbf
查看数据库为Non-CDB数据库
SQL> select name ,cdb from v$database;
NAME CDB
--------- ---
SHUANG NO
建立测试用户以及表
SQL> conn a/a
Connected.
SQL> select count(*) from a;
COUNT(*)
----------
1024
使用dbms_pdb包进行迁移,dbms_pdb是12c新增加的,为了方便迁移用的。可以用desc dbms_pdb查看下具体参数。
将Non-CDB数据库迁移到CDB数据库,得先将Non-CDB数据库设置为只读数据库,,再进行进一步操作。
SQL> shut immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
[oracle@shuang ~]$ sqlplus / as sysdba
SQL*Plus: Release 12.1.0.1.0 Production on Wed Feb 26 13:17:45 2014
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup mount
ORACLE instance started.
Total System Global Area 1060585472 bytes
Fixed Size 2296472 bytes
Variable Size 704644456 bytes
Database Buffers 348127232 bytes
Redo Buffers 5517312 bytes
Database mounted
SQL>alter database open read only;
Database altered.
SQL> exec dbms_pdb.describe(PDB_DESCR_FILE=>'/u01/app/oracle/oradata/SHUANG/datafile/shuang12c.xml');
PL/SQL procedure successfully completed.
SQL> host ls -l /u01/app/oracle/oradata/SHUANG/datafile/shuang12c.xml
-rw-r--r-- 1 oracle oinstall 4123 2月 26 12:50 /u01/app/oracle/oradata/SHUANG/datafile/shuang12c.xml
SQL> shut immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
在CDB中执行PLUG,就可以将这个Non-CDB插入CDB中,指定COPY参数,将文件复制到CDB的相应目录下,如果已经复制到特定目录,则可以指定NOCOPY选项,就无需再复制一遍。
进入到CDB数据库中。
SQL>create pluggable database shuang using '/u01/app/oracle/oradata/SHUANG/datafile/shuang12c.xml' copy ;
PL/SQL procedure successfully completed.
SQL> select name,open_mode from v$pdbs;
NAME OPEN_MODE
------------------------------ ----------
PDB$SEED READ ONLY
PDBORCL MOUNTED
SHUANG READ WRITE
SQL> alter session set container=shuang;
Session altered.
SQL> select count(*) from a.a;
COUNT(*)
----------
1024