比如 在一个CDB DEVCDB中,创建一个PDB hotclone_pdb1,来自于另外一个CDB PRODCDB中的PDB pdbprod1,每5分钟刷新一次,最后,可以SWITHOVER
source: prodcdb -->prdprod1
destion:devcdb -->hotclone_pdb1
步骤如下:
1. 前提条件:
源和目标:
archivelog
local undo
2. 在源 prodcdb ,授权给SYSTEM用户 create pluggable database 权限
sql>conn sys/oracle_4U@prodcdb as sysdba
SYS@prodcdb> grant create pluggable database to system container=all;
SYS@prodcdb> alter pluggable database pdbprod1 open;
3. 在目标库 devcdb 创建DBLINK LINK_PRODCDB指向 源 prodcdb
sql>conn sys/oracle_4U@devcdb as sysdba
SYS@devcdb> create database link link_prodcdb
connect to system identified by oracle_4U
using 'prodcdb';
4. 在目标库创建 PDB,使用热克隆方式,每5分钟刷新一次
sql>conn sys/oracle_4U@devcdb as sysdba
sql>create pluggable database hotclone_pdb1 from pdbprod1@link_prodcdb
refresh mode every 5 minutes
create_file_dest='/u01/app/oracle/oradata/';
5.验证
SYS@devcdb> select pdb_name,status,REFRESH_MODE,REFRESH_INTERVAL from cdb_pdbs
PDB_NAME STATUS REFRES REFRESH_INTERVAL
------------------------------ ---------- ------ ----------------
PDB$SEED NORMAL NONE
HOTCLONE_PDB1 REFRESHING AUTO 5
在源端创建一个表,并插入数据
SYS@prodcdb> create table hr.ref(test_id number);
SYS@prodcdb> insert into hr.ref values(100);
SYS@prodcdb> commit;
SYS@prodcdb> select systimestamp from dual;
SYSTIMESTAMP
---------------------------------------------------------------------------
10-SEP-23 03.38.49.356125 PM +08:00
在目标端 DEVCDB,确认是否数据同步
SYS@devcdb> select systimestamp from dual;
SYSTIMESTAMP
---------------------------------------------------------------------------
10-SEP-23 03.43.59.229046 PM +08:00
SYS@devcdb> alter session set container=HOTCLONE_PDB1;
SYS@devcdb> alter database open read only;
SYS@devcdb> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
5 HOTCLONE_PDB1 READ ONLY NO
SYS@devcdb> select * from hr.ref;
TEST_ID
----------
100
6. 如果要做SWITCHOVER 需要几个地方注意
1.权限上,需要有SYSOPER权限
grant sysoper to system container=all
2.在源库,也需要创建DBLINK 到目标库
3. 需要在源和目标启用 "_exadata_feature_on"=true 参数
4.execute switchover at source pdb pdbprod1
ALTER PLUGGABLE DATABASE
REFRESH MODE every 5 minutes
FROM hotclone_pdb1@link_devcdb
SWITCHOVER;
|