19c+將NONCDB轉換爲PDB

可以使用拔出插入的方式將一個非CDB庫轉換爲PDB.還可以使用克隆的方式.

NONCDB轉換爲PDB的的條件:

1.NONCDB和CDB的版本必須在12.1.0.2以上

2.字節順序必須一致

下面測試這兩種方法

一.插入NONCDB

1.檢查數據庫兼容性

1)在NONCDB創建xml文件

 

SQL> begin
dbms_pdb.describe(
pdb_descr_file=>'/home/oracle/nonecdb.xml');
end;
/  2    3    4    5  

 
PL/SQL procedure successfully completed

創建完成之後將xml文件拷貝到CDB系統中.

2)在CDB中進行兼容性檢查

 

set serveroutput on
declare
    compatible constant varchar2(3):=
    case DBMS_PDB.CHECK_PLUG_COMPATIBILITY(
        pdb_descr_file=>'/home/oracle/nonecdb.xml',
        pdb_name=>'nonecdb')
    WHEN TRUE THEN 'YES'
    ELSE 'NO'
end;
begin dbms_output.put_line(compatible);
end;
/

 
PL/SQL procedure successfully completed.

運行上面的代碼檢查是否有問題或者違反約束

3)查看錶PDB_PLUG_IN_VIOLATIONS查看檢查結果.

 

SQL> select message,action from pdb_plug_in_violations where name='NONECDB';

 
MESSAGE                                      ACTION
-------------------------------------------------------------------------------- --------------------------------------------------
PDB plugged in is a non-CDB, requires noncdb_to_pdb.sql be run.          Run noncdb_to_pdb.sql.
CDB parameter sga_target mismatch: Previous 1552M Current 908M           Please check the parameter in the current CDB
CDB parameter open_cursors mismatch: Previous 300 Current 400            Please check the parameter in the current CDB
CDB parameter pga_aggregate_target mismatch: Previous 448M Current 303M      Please check the parameter in the current CDB

 

如上面的結果提示了需要運行nocdb_to_pdb.sql,還有一些參數由於PDB中會被CDB覆蓋.

 

2.重新生成xml文件,並關閉原庫

爲了SCN和目標端的CDB一致.必須將原庫打開到read only,再生成xml文件.生成完成之後就可以關閉原庫了

 

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup read only;
SP2-0714: invalid combination of STARTUP options
SQL> startup mount;
ORACLE instance started.

 
Total System Global Area 1627386464 bytes
Fixed Size          8897120 bytes
Variable Size         385875968 bytes
Database Buffers     1224736768 bytes
Redo Buffers            7876608 bytes
Database mounted.
SQL> alter database open read only;

 
Database altered.

 
SQL>  begin
dbms_pdb.describe(
pdb_descr_file=>'/home/oracle/nonecdb.xml');
end;
/   2    3    4    5  

 
PL/SQL procedure successfully completed.

 
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

 

將生成的xml文件拷貝到目標端.

 

3.拷貝數據文件

將源端的數據文件目錄拷貝到目標端指定位置:

 

[oracle@ora19c ORA19C]$ pwd
/u01/app/oracle/oradata/ORA19C
[oracle@ora19c ORA19C]$ scp -r ora19c2:/oradata/NONECDB .
oracle@ora19c2's password: 
control01.ctl                 100%   10MB  35.6MB/s   00:00    
control02.ctl                 100%   10MB  40.4MB/s   00:00    
redo01.log                    100%  200MB  46.5MB/s   00:04    
redo02.log                    100%  200MB  45.8MB/s   00:04    
redo03.log                    100%  200MB  43.8MB/s   00:04    
system01.dbf                  100%  700MB  31.5MB/s   00:22    
sysaux01.dbf                  100%  550MB  43.8MB/s   00:12    
undotbs01.dbf                 100%  230MB  42.8MB/s   00:05    
temp01.dbf                    100%   20MB  43.9MB/s   00:00    
users01.dbf                   100% 5128KB  41.8MB/s   00:00    

 

源端數據文件存放在/oradata/NONECDB,目標端存放在/u01/app/oracle/oradata/ORA19C/NONECDB

4.插入數據庫

插入的語法如下:

 

SQL> create pluggable database nonecdb using '/home/oracle/nonecdb.xml'
source_file_name_convert=('/oradata/NONECDB','/u01/app/oracle/oradata/ORA19C/NONECDB') nocopy tempfile reuse;  2  

 
Pluggable database created.

 

特別說明一下:

1.這裏指定了source_file_name_convert指定xml文件中數據文件的路徑和我們實際存放數據文件的路徑

2.這裏使用了nocopy而沒有指定file_name_convert這是因爲數據文件我們是通過手工進行拷貝的,所以不需要oracle再來幫我們拷貝了,所以不需要中file_name_convert,而是使用了nocopy

3.這裏設置了tempfile reuse,如果不設置oracle會自動嘗試創建tempfile,但是此tempfile已經手工拷貝了,就會報錯:

 

SQL> create pluggable database nonecdb using '/home/oracle/nonecdb.xml'
source_file_name_convert=('/oradata/NONECDB','/u01/app/oracle/oradata/ORA19C/NONECDB') nocopy;  2  
create pluggable database nonecdb using '/home/oracle/nonecdb.xml'
*
ERROR at line 1:
ORA-27038: created file already exists
ORA-01119: error in creating database file
'/u01/app/oracle/oradata/ORA19C/NONECDB/temp01.dbf'

因此需要指定tempfile reuse.

 

5.執行轉換腳本

正如兼容性檢查的提示,需要執行noncdb_to_pdb.sql

 

alter session set container=nonecdb;
@?/rdbms/admin/noncdb_to_pdb.sql

執行完成之後就可以打開數據庫使用了:

 

SQL> alter pluggable database open;

 
Pluggable database altered.

 

 

二.克隆非CDB

克隆的方法更簡單,同樣需要執行兼容性檢查.

1.創建到源端NONECDB的數據庫鏈接

 

SQL> create database link tononecdb connect to system identified by manager using 'ora19c2/nonecdb';

 
Database link created.

 
SQL> select CDB from v$database@tononecdb;

 
CDB
---
NO

 

 

2.執行數據庫克隆

執行數據庫克隆:

 

SQL> create pluggable database nonecdb2 from NON$CDB@tononecdb 
file_name_convert=('/oradata/NONECDB','/u01/app/oracle/oradata/ORA19C/NONECDB2');  2  

 
Pluggable database created.

這裏的注意點:

1.PDB指定NON$CDB這個特殊的PDB名字

2.遠程克隆會拷貝數據文件,因此需要指定文件名的轉換

你可能會遇到ORA-01031的錯誤:

 

ORA-17628: Oracle error 1031 returned by remote Oracle server
ORA-01031: insufficient privileges

需要在源端執行如下賦權:

 

SQL> grant cdb_dba to system;

 
Grant succeeded.

 
SQL> grant create session,connect,resource,cdb_dba,sysoper to system;

 
Grant succeeded.

 
SQL> grant  CREATE PLUGGABLE DATABASE to system;

 
Grant succeeded.

 

 

3.執行noncdb_to_pdb.sql

 

SQL> alter session set container=nonecdb2;

 
Session altered.

 
SQL> @?/rdbms/admin/noncdb_to_pdb.sql

 

 

4.打開pdb

執行完成之後就可以打開PDB了

 

SQL> alter pluggable database open;

 
Pluggable database altered.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章