所以在创建pdb时,你必须要通过REFRESH MODE MANUAL或REFRESH MODE EVERY minutes语句。
创建可刷新的克隆pdb
1 2 3
sys@ORA12C> create pluggable database pdb3new from pdb3@to_remote refresh mode manual;
Pluggable database created.
打开新建的pdb,这里可刷新的pdb只能打开成read-only模式
1 2 3 4 5 6 7 8 9 10
sys@ORA12C> alter pluggable database pdb3new open; alter pluggable database pdb3new open * ERROR at line 1: ORA-65341: cannot open pluggable database in read/write mode
sys@ORA12C> alter pluggable database pdb3new open read only;
Pluggable database altered.
在源pdb上创建点数据
1 2 3 4 5 6 7 8 9 10
create tablespace tbs1 datafile size 10m autoextend on ;
create user xb identified by xb default tablespace tbs1;
sys@ORA12C> select * from xb.t1; select * from xb.t1 * ERROR at line 1: ORA-00942: table or view does not exist
sys@ORA12C> alter pluggable Database close immediate;
Pluggable database altered.
sys@ORA12C> alter pluggable Database refresh;
Pluggable database altered.
sys@ORA12C> alter pluggable Database open read only;
Pluggable database altered.
sys@ORA12C> select * from xb.t1;
ID NAME ---------- ---------- 1 xb
表空间也同步过来了
1 2 3 4 5 6 7 8 9
sys@ORA12C> select tablespace_name from dba_tablespaces;
TABLESPACE_NAME ------------------------------ SYSTEM SYSAUX UNDOTBS1 TEMP TBS1
刷新模式,总共包含三种
REFRESH MODE MANUAL 手动刷新
REFRESH MODE EVERY 60 MINUTES 每60分钟自动刷新
REFRESH MODE NONE 不刷新
也可以通过ALTER的方式来调整刷新模式。
swithover克隆pdb
可以切换源pdb和可刷新pdb的角色
1
ALTER PLUGGABLE DATABASE refresh_mode FROM clonepdb@dblink SWITCHOVER;
这里的refresh_mode不允许为NONE模式,切换完毕后,源pdb就变成了只读的可刷新pdb
前提条件:
必须连到源pdb去执行命令
如果源和目标端是两个不同的CDB,则数据链里指定的用户需要在源端和目标端pdb有相同的用户名和密码
源端也建一个同样的数据链
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
# 建用户 GRANT CREATE SESSION, RESOURCE, CREATE ANY TABLE, UNLIMITED TABLESPACE TO c#xb CONTAINER=ALL; GRANT CREATE PLUGGABLE DATABASE TO c#xb CONTAINER=ALL; GRANT SYSOPER TO c#xb CONTAINER=ALL;
# 数据链 drop public database link to_test;
create public database link to_test connect to c#xb identified by xb using '(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = testyum)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = ora12c) ) )';
做swithover
1 2 3 4 5 6 7
sys@CDB1> alter session set container=pdb3;
Session altered.
sys@CDB1> alter pluggable database refresh mode manual from pdb3new@to_test switchover;
CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 4 PDB3 MOUNTED sys@CDB1> alter pluggable database open ; alter pluggable database open * ERROR at line 1: ORA-65341: cannot open pluggable database in read/write mode
sys@CDB1> alter pluggable database open read only;
CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 2 PDB$SEED READ ONLY NO 3 PDB12C READ WRITE NO 4 PDB4 READ WRITE NO 6 PDB3NEW READ WRITE NO sys@ORA12C> alter session set container=pdb3new;
Session altered.
sys@ORA12C> insert into xb.t1 values(2,'test');
1 row created.
sys@ORA12C> commit;
Commit complete.
sys@ORA12C> select * from xb.t1;
ID NAME ---------- ---------- 1 xb 2 test
刷新源pdb库
1 2 3 4 5 6 7 8 9 10 11 12 13
sys@CDB1> alter session set container=pdb3;
Session altered.
ALTER PLUGGABLE DATABASE REFRESH; ALTER PLUGGABLE DATABASE OPEN READ ONLY;