参考文章:Oracle NON-CDB转换为PDB几种方式
DBMS_PDB.DESCRIBE方式从12C后开始支持。
测试环境安装过程忽略,可参考:
30分钟!一键部署Oracle 19C单机CDB+PDB
noncdb19c:
cd /soft
./OracleShellInstall.sh -i 10.211.55.100 `#Public ip`\
-n noncdb19c `# hostname`\
-o noncdb19c `# oraclesid`\
-op oracle `# oracle user password`\
-b /u01/app `# install basedir`\
-s AL32UTF8 `# characterset`\
-opa 32545013 `# oracle RU number`
cdb19c:
cd /soft
./OracleShellInstall.sh -i 10.211.55.101 `#Public ip`\
-n cdb19c `# hostname`\
-o cdb19c `# oraclesid`\
-c TRUE `# cdb`\
-op oracle `# oracle user password`\
-b /u01/app `# install basedir`\
-s AL32UTF8 `# characterset`\
-opa 32545013 `# oracle RU number`
脚本使用和下载可参考Github:https://github.com/pc-study/InstallOracleshell
节点 | 主机版本 | 主机名 | 实例名 | Oracle版本 | IP地址 |
源库 | redhat 7.9 | noncdb19c | noncdb19c | 19.3.0.0(补丁 32441092) | 10.211.55.100 |
目标库 | redhat 7.9 | cdb19c | cdb19c | 19.3.0.0(补丁 32441092) | 10.211.55.101 |
注意:源库为生产环境,目标库为升级环境,保留生产环境用于失败回退。
1.正常关闭on-cdb数据库,以只读模式打开on-cdb数据库。
SELECT NAME,cdb FROM v$database;
shutdown IMMEDIATE;
startup mount;
ALTER DATABASE OPEN READ ONLY;
2.在on-cdb数据库中,执行BMS_PDB.DESCRIBE包,将创建一个ML文件,其中包含有关非db数据库数据文件的描述。
exec dbms_pdb.describe(pdb_descr_file => '/soft/noncdb.xml');
shutdown IMMEDIATE
拷贝数据文件目录和ml文件拷贝到目标端
scp /soft/noncdb.xml 10.211.55.101:/soft/
scp -r /oradata/NONCDB19C 10.211.55.101:/oradata/
3.连接到目标db库,执行BMS_PDB.CHECK_PLUG_COMPATIBILITY包,检查on-cdb数据库兼容性。
SELECT NAME,cdb FROM v$database;
select name, open_mode, restricted, open_time, inst_id, con_id, dbid, con_uid from gv$pdbs;
select pdb_id, pdb_name, dbid, con_uid, con_id, status from cdb_pdbs;
set serveroutput on
DECLARE
compatible CONSTANT VARCHAR2(3) := CASE dbms_pdb.check_plug_compatibility(pdb_descr_file => '/soft/noncdb.xml',
pdb_name => 'lucifer')
WHEN TRUE THEN
'YES'
ELSE
'NO'
END;
BEGIN
dbms_output.put_line(compatible);
END;
/
4.如果此程序包返回ALSE/NO,则在DB_PLUG_IN_VIOLATIONS视图中检查违规情况,并更正错误和警告。
col time format a30
col cause format a40
col action format a120
col message format a120
col error format 999999
set lines 200 pages 20000 long 2000000000 longchunksize 2000000
select time, name, type, error_number error, status, line, message, cause, action from pdb_plug_in_violations order by time desc;
5.如果程序包返回RUE/YES,则使用REATE PLUGGABLE DATABASE USING
--1.通过file_name_convert+copy来创建
chown -R oracle:oinstall /oradata/NONCDB19C/
CREATE pluggable DATABASE lucifer USING '/soft/noncdb.xml' COPY FILE_NAME_CONVERT=('/oradata/NONCDB19C/','/oradata/CDB19C/lucifer/');
--2.通过source_file_name_convert+nocopy创建
chown -R oracle:oinstall /oradata/NONCDB19C/
create pluggable database nonecdb using '/soft/noncdb.xml' source_file_name_convert=('/oradata/NONCDB19C/','/oradata/CDB19C/lucifer/') nocopy tempfile reuse;
6.使用LTER SESSION SET CONTAINER = pdbname 切换或连接到db并执行?/rdbms/admin/noncdb_to_pdb.sql 脚本。
alter session set container=lucifer;
@?/rdbms/admin/noncdb_to_pdb.sql
执行时间较久,根据数据库大小而定。
7.使用LTER pluggable DATABASE pdbname OPEN 命令以读写模式打开DB。
select name, open_mode, restricted, open_time, inst_id, con_id, dbid, con_uid from gv$pdbs;
ALTER pluggable DATABASE ALL OPEN;
ALTER pluggable DATABASE ALL SAVE state;
select name, open_mode, restricted, open_time, inst_id, con_id, dbid, con_uid from gv$pdbs;
至此,non-cdb转换pdb成功。
设置TNSNAMES.ORA,测试连接pdb:
cat <>$TNS_ADMIN/tnsnames.ora
lucifer =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = cdb19c)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = lucifer)
)
)
EOF
##创建测试用户
alter session set container=lucifer;
create user lucifer identified by oracle;
grant dba to lucifer;
转载至https://blog.csdn.net/m0_50546016/article/details/117022079?spm=1001.2014.3001.5501