經過non-cdb數據庫建立pdbsql
目錄結構數據庫
1、說明session
2、測試環境oracle
3、建立準備ide
4、啓動非cdb庫到read only狀態測試
5、建立新的pdbthis
6、在non-cdb上使用DBMS_PDB包建立pdbspa
1、說明server
從 12c 版本 1 開始能夠經過克隆一個非 cdb 得數據庫建立 pdbxml
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庫。
2、測試環境
一、非cdb信息 數據庫名cdb 文件名路徑 /opt/oracle/oradata/cdb/
SQL> select name,cdb,open_mode from v$database;
NAME CDB OPEN_MODE
--------- --- --------------------
CDB NO READ WRITE
二、cdb信息 主機 192.168.5.40 端口1521 cdb: mycdb
pdb數據文件存放路徑 /opt/oracle/oradata/mycdb/
3、建立準備
一、在非cdb中建立連接用戶
SQL> create user conadmin identified by dhhzdhhz;
User created.
grant dba to conadmin;
grant CREATE PLUGGABLE DATABASE to conadmin;
二、建立連接
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
4、啓動非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
5、建立新的pdb
一、執行建立語句
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
二、切換容器到新建立的pdb
alter session set container=mypdb5;
三、執行noncdb_to_pdb.sql腳本
@?/rdbms/admin/noncdb_to_pdb.sql
四、打開新建立的pdb
SQL> alter pluggable database mypdb5 open;
6、在non-cdb上使用DBMS_PDB包建立pdb
6.一、說明
一、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
二、To use this technique, the non-CDB must be an Oracle Database 12c non-CDB
6.二、確保 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.三、以 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.四、在cdb機器上建立非cdb的數據文件路徑並拷貝xml和數據文件
[oracle@oracle18c1 backup]$ scp ncdb.xml oracle@192.168.5.40:/backup/
oracle@192.168.5.41's password:
ncdb.xml 100% 6792 3.2MB/s 00:00
[oracle@oracle18c1 backup]$ scp -r /opt/oracle/oradata/cdb/* oracle@192.168.5.40:/opt/oracle/oradata/cdb/
oracle@192.168.5.40'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.五、在cdb上運行 兼容性檢測(DBMS_PDB.CHECK_PLUG_COMPATIBILITY)
一、注意事項
pdb_descr_file:設置XML元數據文件的完整路徑。
pdb_name:指定新PDB名字
二、檢測語句
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;
/
三、若是返回結果爲no 則查詢語句糾正錯誤
select con_id,cause,message from pdb_plug_in_violations;
6.六、建立新的pdb
CREATE PLUGGABLE DATABASE mypdb5 USING '/backup/ncdb.xml' NOCOPY tempfile reuse;
6.七、執行noncdb_to_pdb.sql腳本
@?/rdbms/admin/noncdb_to_pdb.sql
6.八、打開新建立的pdb
alter pluggable database mypdb5 open;