通过non-cdb数据库创建pdb
目录结构
一、说明
二、测试环境
三、创建准备
四、启动非cdb库到read only状态
五、创建新的pdb
六、在non-cdb上使用DBMS_PDB包创建pdb
一、说明
从 12c 版本 1 开始可以通过克隆一个非 cdb 得数据库创建 pdb
Both the CDB and the non-CDB must be running Oracle Database 12c Release 1 (12.1.0.2) or later
If your current non-CDB uses an Oracle Database release before Oracle Database 12c
Release 1 (12.1.0.2), then you must upgrade the non-CDB to Oracle Database 12c Release 1 (12.1.0.2)
to use this technique
Use Oracle Data Pump export/import(You export the data from the non-CDB and import it into a PDB)
Use GoldenGate replication.
Use the DBMS_PDB package to generate an XML metadata file. The XML metadata file describes the database files of the non-CDB
so that you can plug it into a CDB
from后使用NON$CDB代表非cdb库。
二、测试环境
1、非cdb信息 数据库名cdb 文件名路径 /opt/oracle/oradata/cdb/
SQL> select name,cdb,open_mode from v$database;
NAME CDB OPEN_MODE
--------- --- --------------------
CDB NO READ WRITE
2、cdb信息 主机 192.168.5.40 端口1521 cdb: mycdb
pdb数据文件存放路径 /opt/oracle/oradata/mycdb/
三、创建准备
1、在非cdb中创建链接用户
SQL> create user conadmin identified by dhhzdhhz;
User created.
grant dba to conadmin;
grant CREATE PLUGGABLE DATABASE to conadmin;
2、创建链接
SQL> create public database link admincdb connect to conadmin identified by dhhzdhhz using '192.168.5.41/cdb';
Database link created.
SQL> select * from dual@admincdb;
D
-
X
四、启动非cdb库到read only状态
SQL> startup mount;
ORACLE instance started.
Total System Global Area 1073740616 bytes
Fixed Size 8665928 bytes
Variable Size 671088640 bytes
Database Buffers 385875968 bytes
Redo Buffers 8110080 bytes
Database mounted.
SQL> alter database open read only;
Database altered.
SQL> select name,cdb,open_mode from v$database;
NAME CDB OPEN_MODE
--------- --- --------------------
CDB NO READ ONLY
五、创建新的pdb
1、执行创建语句
SQL> CREATE PLUGGABLE DATABASE mypdb5 FROM NON$CDB@admincdb FILE_NAME_CONVERT=('/opt/oracle/oradata/cdb/','/opt/oracle/oradata/mycdb/mypdb5/');
Pluggable database created.
SQL> show pdbs;
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 MYPDB1 READ WRITE NO
4 MYPDB2 READ WRITE NO
5 YOUPDB MOUNTED
6 MYPDB3 READ WRITE NO
7 MYPDB4 READ WRITE NO
8 MYPDB5 MOUNTED
2、切换容器到新创建的pdb
alter session set container=mypdb5;
3、执行noncdb_to_pdb.sql脚本
@?/rdbms/admin/noncdb_to_pdb.sql
4、打开新创建的pdb
SQL> alter pluggable database mypdb5 open;
六、在non-cdb上使用DBMS_PDB包创建pdb
6.1、说明
1、You run the DBMS_PDB.DESCRIBE procedure on the non-CDB to generate the XML file
that describes the database files of the non-CDB
2、To use this technique, the non-CDB must be an Oracle Database 12c non-CDB
6.2、确保 non-cdb 处于一致性状态,并重新打开数据库到只读状态
SQL> startup mount;
ORACLE instance started.
Total System Global Area 1073740616 bytes
Fixed Size 8665928 bytes
Variable Size 671088640 bytes
Database Buffers 385875968 bytes
Redo Buffers 8110080 bytes
Database mounted.
SQL> alter database open read only;
6.3、以 sysdba 用户登陆 non-cdb 数据库执行DBMS_PDB.DEXCRIBE过程生成非cdb 数据库的xml 文件
BEGIN
DBMS_PDB.DESCRIBE(
pdb_descr_file => '/backup/ncdb.xml');
END;
/
exec DBMS_PDB.DESCRIBE('/backup/ncdb.xml');
6.4、在cdb机器上创建非cdb的数据文件路径并拷贝xml和数据文件
[oracle@oracle18c1 backup]$ scp ncdb.xml [email protected]:/backup/
[email protected]'s password:
ncdb.xml 100% 6792 3.2MB/s 00:00
[oracle@oracle18c1 backup]$ scp -r /opt/oracle/oradata/cdb/* [email protected]:/opt/oracle/oradata/cdb/
[email protected]'s password:
control01.ctl 100% 18MB 44.0MB/s 00:00
redo01.log 100% 100MB 50.0MB/s 00:02
redo02.log 100% 100MB 33.3MB/s 00:03
redo03.log 100% 100MB 50.0MB/s 00:02
sysaux01.dbf 100% 550MB 30.5MB/s 00:18
system01.dbf 100% 700MB 34.9MB/s 00:20
temp01.dbf 100% 20MB 33.9MB/s 00:00
undotbs01.dbf 100% 220MB 44.0MB/s 00:05
users01.dbf 100% 500MB 38.5MB/s 00:13
usertbs01.dbf 100% 200MB 33.3MB/s 00:06
6.5、在cdb上运行 兼容性检测(DBMS_PDB.CHECK_PLUG_COMPATIBILITY)
1、注意事项
pdb_descr_file:设置XML元数据文件的完整路径。
pdb_name:指定新PDB名字
2、检测语句
set serveroutput on
declare
compatible constant varchar2(3) :=
case dbms_pdb.check_plug_compatibility(
pdb_descr_file => '/backup/ncdb.xml',
pdb_name => 'mypdb5')
when true then 'yes'
else 'no'
end;
begin
dbms_output.put_line(compatible);
end;
/
3、如果返回结果为no 则查询语句纠正错误
select con_id,cause,message from pdb_plug_in_violations;
6.6、创建新的pdb
CREATE PLUGGABLE DATABASE mypdb5 USING '/backup/ncdb.xml' NOCOPY tempfile reuse;
6.7、执行noncdb_to_pdb.sql脚本
@?/rdbms/admin/noncdb_to_pdb.sql
6.8、打开新创建的pdb
alter pluggable database mypdb5 open;