一、克隆/迁移准备
前提:源库启动归档模式
1、源数据库配置
$ sqlplus / as sysdba
SQL> alter session set container=MESPROD;
SQL> grant connect, create pluggable database to system;
2、目标数据库配置
2.1 配置TNS,增加源库CDB的解析:
MESPROD_CDB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 源库IP)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
2.2 创建DB Link:
在目标库CBD中创建连接源库CDB的dblink。
$ sqplus / as sysdba
SQL> create database link cp_link connect to system identified by xxxxxx using 'MESPROD_CDB';
2.3 检查dblink是否可用
SQL> select count(*) from all_users@cp_link;
2.4 创建目标库数据文件目录
$ mkdir -p /u19/app/oracle/oradata/
设置db_create_file_dest参数
SQL> alter system set db_create_file_dest='/u19/app/oracle/oradata';
二、克隆PDB
1、删除目标数据库原PDB
$ sqlplus / as sysdba
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 TESTPDB READ WRITE NO
4 MESTEST READ WRITE NO
SQL> alter pluggable database MESTEST close;
Pluggable database altered.
SQL> drop pluggable database MESTEST including datafiles;
Pluggable database dropped.
SQL> show pdbs;
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 TESTPDB READ WRITE NO
2、运行在线克隆
# su - oracle
$ sqlplus / as sysdba
SQL> create pluggable database mestest from mesprod@cp_link;
Pluggable database created.
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 TESTPDB READ WRITE NO
4 MESTEST MOUNTED
SQL> alter pluggable database MESTEST open;
Pluggable database altered.
SQL> alter pluggable database MESTEST save state;
Pluggable database altered.
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 TESTPDB READ WRITE NO
4 MESTEST READ WRITE NO
至此,PDB克隆/迁移完成。