Oracle 12c Refreshable Clone

这个例子将介绍通过克隆一个远程PDB(jypdb)来创建一个目标PDB(ycpdb)。这种克隆是对源PDB的一种可以刷新的副本,它意味着对源PDB所执行的任何改变都可以通过刷新来对目标PDB进行更新。这里假设满足以下条件:
.连接到远程PDB(jypdb)的dblink为jypdb_link
.不使用path_prefix子句
.不使用file_name_convert与create_file_dest子句,如果启用了OMF,或者设置了pdb_file_name_convert参数。那么基于OMF或参数设置
文件将会被复制到新指定的目录中
.对PBD不使用存储限制。因此不使用storage子句
.这里没有与新temp文件同名的文件存在,因此新的temp文件会创建到目标目录中。因此不用指定tempfile reuse子句。
.刷新克隆将会每隔10分钟自动刷新。记住,为了创建一个可刷新的PDB,源PDB必须启用archivelog模式与本地undo模式。

1.在目标数据库CDB(jy)中创建指向源PBD(jypdb)的dblink

SQL> create public database link  jypdb_link
  2    connect to system identified by "cs"
  3    using '(DESCRIPTION =
  4      (ADDRESS_LIST =
  5        (ADDRESS = (PROTOCOL = TCP)(HOST =10.10.13.17)(PORT = 1521))
  6      )
  7      (CONNECT_DATA =
  8        (SERVER = DEDICATED)
  9        (SERVICE_NAME =jypdb)
 10      )
 11    )';
Database link created

2.检查源pdb是否启用arachivelog与本地undo

SQL> col PROPERTY_NAME for a25;
SQL> col PROPERTY_VALUE for a25;
SQL> select PROPERTY_NAME,PROPERTY_VALUE from database_properties where property_name='LOCAL_UNDO_ENABLED';

PROPERTY_NAME             PROPERTY_VALUE
------------------------- -------------------------
LOCAL_UNDO_ENABLED        TRUE

SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            +DATA/arch
Oldest online log sequence     251
Next log sequence to archive   253
Current log sequence           253

3.在目标数据库CDB(jy)执行下面的语句来克隆可刷新的PDB

SQL> create pluggable database ycpdb from jypdb@jypdb_link refresh mode every 10 minutes;

Pluggable database created.

4.在源数据库中对表jy.jy_test与jy.test插入数据与删除数据

SQL> select * from jy.jy_test;

   USER_ID
----------
         2
         1

SQL> select * from jy.test;

   USER_ID
----------
         2
         1


SQL> insert into jy.jy_test values(3);

1 row created.

SQL> commit;

Commit complete.

SQL> delete from jy.test where rownum<2;

1 row deleted.

SQL> commit;

Commit complete.

SQL> host date
Fri Aug 25 01:58:40 CST 2017

5.十分钟后我们在目标数据库ycpdb中来查询数据是否被刷新到目标数据库ycpdb中
5.1先将pdb(ycpdb)以read only模式打开

SQL> select name,open_mode from v$pdbs;

NAME
--------------------------------------------------------------------------------
OPEN_MODE
----------
YCPDB
MOUNTED


SQL> alter  pluggable database ycpdb open read only;

Pluggable database altered.

5.2再来查看数据是否被刷新,从下面的结果可以看到数据已经被刷新了。

SQL> select * from jy.jy_test;

   USER_ID
----------
         2
         3
         1

SQL> select * from jy.test;

   USER_ID
----------
         1

6.为了与源pdb(jypdb)进行同步我们需要将目标pdb设置为close状态

SQL> alter  pluggable database ycpdb close immediate;

Pluggable database altered.

SQL> select name,open_mode from v$pdbs;


NAME
--------------------------------------------------------------------------------
OPEN_MODE
----------
YCPDB
MOUNTED

我们还可以手动刷新目标pdb

SQL> alter  pluggable database ycpdb close immediate;

Pluggable database altered.

SQL> alter pluggable database refresh;

Pluggable database altered.

Leave a Reply

Your email address will not be published.

Proudly powered by WordPress | Indrajeet by Sus Hill.