日常会涉及到oracle19C的pdb复制到新环境,又不想影响现有环境的PDB运行。我总结了2个方案。
一、拷贝数据文件方式
1、拷贝源库到一个新库
create pluggable database test_new from test;
2、拔出新库
alter pluggable database test_new unplug into ‘/app/expdp/test_new.xml’;
3、查看新库的con_id
show pdbs;
4、查看新库的数据文件地址
set lines 1999
col name for a100
select name from v$datafile where con_id=5;
5、移动新库数据文件到xml文件夹,方便一起拷贝
mv /app/xxxx/o1_mf_system_mnx7m7r5_.dbf /app/expdp/
6、拷贝xml与数据文件到新环境
scp * xxxxx:/app/exp_dir
7、移动数据文件到正确目录
mkdir -p /app/xxxxx/datafile/
mv /app/exp_dir/*.dbf /app/xxxxx/datafile/
8、新环境创建源库
create pluggable database test using ‘/app/exp_dir/test_new.xml’;
alter pluggable database test open;
此处我有些报错,因为我新环境补丁版本高于旧环境
Warning: PDB altered with errors.
用下面语句查看错误信息
set lines 1999
col name for a20
col MESSAGE for a50
col CAUSE for a20
select NAME,CAUSE,ERROR_NUMBER,MESSAGE,STATUS from PDB_PLUG_IN_VIOLATIONS where CON_ID=7;
以下命令刷新下patch,pdb处于开启状态。
$ORACLE_HOME/OPatch/datapatch --verbose
@?/rdbms/admin/utlrp.sql
9、拷贝过来的库,服务可能么启动。手动启动下
BEGIN
------DBMS_SERVICE.create_service(‘paypf_upgradeserv’,‘paypf_upgradeserv’);
DBMS_SERVICE.start_service(‘paypf_upgradeserv’);
END;
/
二、在线拷贝PDB
1、源端 cdb 执行
grant connect,resource,create pluggable database to system container=all;
alter user system identified by xxxx;
2、目标端 执行
create public database link db_link connect to system identified by “xxxxx” using ‘//xxxxxx:1521/xxxxx’;
alter system set db_create_file_dest=’/app/oracle/oradata/ORCL’ scope=both sid=’*’;
create pluggable database test from test@db_link parallel 8;
alter pluggable database test open ;
如果启动报错,参考上面步骤。




