签到成功

知道了

CNDBA社区CNDBA社区

Orcle 12c 新特性---PDB Refresh

2017-08-07 17:30 3360 0 原创 Oracle 12C
作者: Expect-乐

说明

Customers want to periodically propagate changes from a source pluggable database (PDB) to its cloned copy. In such cases, we say that the cloned PDB is a refreshable copy of the source PDB. A refreshable cloned PDB can only be opened in read-only mode and propagating changes from the source PDB can be performed manually (on demand) or automatically.

12.2开始,周期性的从源PDB更新变化的数据到目标克隆PDB中,可以手动更新,也可以自动更新,这种就叫作PDB Refresh

这就相当于增量备份和应用增量备份一样。大大减少了重新克隆PDB的时间。不过,目标PDB只能是read only.

注意:

A refreshable PDB and its source must be in different CDBs. Therefore, a refreshable PDB must be created at a CDB that is remote from the source CDB, and a database link must be specified during the creation.http://www.cndba.cn/Expect-le/article/2073

必须是在不同的CDB中,意思是必须是远端的PDB

A PDB that is not refreshable cannot be changed into a refreshable PDB. However, a PDB that is refreshable can be changed into a PDB that is not refreshable by running an ALTER PLUGGABLE DATABASE statement with REFRESH MODE NONE for the PDB.

本性难移,普通PDB是不能被改为refresh pdb的。refresh pdb可以修改为普通pdb,通过ALTER PLUGGABLE DATABASE 设置REFRESH MODE NONE

When you create a refreshable PDB, you can set the REMOTE_RECOVERY_FILE_DEST initialization parameter in the PDB. This initialization parameter specifies a directory from which to read archive log files during refresh operations if the source PDB is not available over its database link.

REMOTE_RECOVERY_FILE_DEST存放归档日志,防止dblink不可用。

If new data files are created in the source PDB, then the PDB_FILE_NAME_CONVERT initialization parameter must be set in the CDB to convert the data file paths from the source PDB to the clone PDB.

如果源pdb新增数据文件,那么必须要指定PDB_FILE_NAME_CONVERT参数,来转换数据文件路径。

实验

源端PDB192.168.1.55  CNDBA_PDB

目标端克隆PDB:192.168.1.110 CNDBA_PDB_REF

2.1   创建dblink

指向源PDB

create public database link cndba_pdb connect to SYSTEM identified by oracle using 'CNDBA_PDB';

2.2   创建手动refreshPDB

SQL> CREATE PLUGGABLE DATABASE cndba_pdb_ref FROM cndba_pdb@cndba_pdb
file_name_convert=('/u01/app/oracle/oradata/cndba_pdb/','/u01/app/oracle/oradata/orcl/cndba_pdb_ref/')
REFRESH MODE MANUAL;  2    3  
CREATE PLUGGABLE DATABASE cndba_pdb_ref FROM cndba_pdb@cndba_pdb
*

ERROR at line 1:
ORA-17628: Oracle error 65035 returned by remote Oracle server
ORA-65035: unable to create pluggable database from

http://www.cndba.cn/Expect-le/article/2073

报错了,查看错误信息

SQL> !oerr ora 65035
65035, 00000, "unable to create pluggable database from %s"
// *Cause:  An attempt was made to clone a pluggable database that did not have
//          local undo enabled.
// *Action: Enable local undo for the PDB and and retry the operation.
//

源库必须是local undo才行。查看源库undo模式,PDB有自己的undo表空间。

2.2.1  share undo改为local undo

CDBupgrade模式启动

SQL> shutdown immediate;

SQL> startup upgrade
ORACLE instance started.
Database mounted.
Database opened.

SQL> alter database local undo on;
Database altered.

--重启cdb即可

http://www.cndba.cn/Expect-le/article/2073

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> startup
ORACLE instance started.
Database mounted.
Database opened.

查看日志可以发现,Oracle自动创建了undo表空间

CNDBA_PDB(4):Opening pdb with no Resource Manager plan active

CNDBA_PDB(4):CREATE SMALLFILE UNDO TABLESPACE undo_1 DATAFILE '/u01/app/oracle/oradata/cndba_pdb/system01_i1_undo.dbf' SIZE 279969792 AUTOEXTEND ON NEXT 1572864 MAXSIZE 10307919872 ONLINE

2017-08-07T16:51:54.241448+08:00

CNDBA_PDB(4):[24648] Successfully onlined Undo Tablespace 6.http://www.cndba.cn/Expect-le/article/2073

CNDBA_PDB(4):Completed: CREATE SMALLFILE UNDO TABLESPACE undo_1 DATAFILE '/u01/app/oracle/oradata/cndba_pdb/system01_i1_undo.dbf' SIZE 279969792 AUTOEXTEND ON NEXT 1572864 MAXSIZE 10307919872 ONLINEhttp://www.cndba.cn/Expect-le/article/2073

Pluggable database CNDBA_PDB opened read write

 

2.2.2  再次来克隆refresh PDB

SQL> CREATE PLUGGABLE DATABASE cndba_pdb_ref FROM cndba_pdb@cndba_pdb
file_name_convert=('/u01/app/oracle/oradata/cndba_pdb/','/u01/app/oracle/oradata/orcl/cndba_pdb_ref/')
REFRESH MODE MANUAL;  2    3  

Pluggable database created.

http://www.cndba.cn/Expect-le/article/2073

妥了, 成功了。

SQL> show pdbs;
 
    CON_ID CON_NAME	  OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
 2 PDB$SEED	  READ ONLY  NO
 3 LEI1   READ WRITE NO
 4 LEI2   MOUNTED
 5 SIHONG	  MOUNTED
 6 CNDBA_PDB_REF	  MOUNTED

2.3   将克隆pdb启动到read only

http://www.cndba.cn/Expect-le/article/2073

SQL> alter pluggable database CNDBA_PDB_REF open read only;
Pluggable database altered.


SQL> col name for a20
SQL> SELECT name, open_mode FROM v$pdbs WHERE name = 'CNDBA_PDB_REF';

NAME	     OPEN_MODE
-------------------- --------------------
CNDBA_PDB_REF	     READ ONLY

2.4   PDB新建表

SQL> conn lei/lei@cndba_pdb
Connected.

SQL> create table cndba as select * from dba_tables;
Table created.

http://www.cndba.cn/Expect-le/article/2073

2.5   手动刷新PDB

--刷新之前查看,没有该表

SQL> select * from lei.cndba;
select * from lei.cndba
                  *
ERROR at line 1:
ORA-00942: table or view does not exist

--手动刷新

SQL> alter session set container=CNDBA_PDB_REF;
Session altered.

SQL> ALTER PLUGGABLE DATABASE CLOSE IMMEDIATE;
Pluggable database altered.

SQL> ALTER PLUGGABLE DATABASE REFRESH;
Pluggable database altered.

SQL> ALTER PLUGGABLE DATABASE OPEN READ ONLY;
Pluggable database altered.

2.6   查看数据

--PDB

http://www.cndba.cn/Expect-le/article/2073

SQL> conn lei/lei@cndba_pdb
SQL> select count(*) from cndba;

  COUNT(*)
----------
      2130

--目标PDB

SQL> select count(*) from lei.cndba;

  COUNT(*)
----------
      2130

2.7   查看PDB刷新模式

SQL> COLUMN pdb_name FORMAT A30
SELECT pdb_id, pdb_name, refresh_mode, refresh_interval
FROM   dba_pdbs
ORDER BY 1;SQL> SQL>   2    3  

    PDB_ID PDB_NAME	  REFRESH_MODE REFRESH_INTERVAL
---------- ------------------------------ ------------ ----------------
 2 PDB$SEED	  NONE
 3 LEI1   NONE
 4 LEI2   NONE
 5 SIHONG	  NONE
 6 CNDBA_PDB_REF MANUAL

2.8   更多刷新方式

--每隔60分钟自动刷新一次http://www.cndba.cn/Expect-le/article/2073

REFRESH MODE EVERY 60 MINUTES

--不刷新,这和普通克隆pdb一样

REFRESH MODE NONE

也可以通过ALTER PLUGGABLE DATABASE pdb3 REFRESH MODE EVERY 60 MINUTES;来修改刷新方式,但是必须是可刷新的pdb。普通克隆的pdb无法修改。

 

版权声明:本文为博主原创文章,未经博主允许不得转载。

PDB Refresh

用户评论
* 以下用户言论只代表其个人观点,不代表CNDBA社区的观点或立场
Expect-乐

Expect-乐

关注

Without the continuous bitter cold, there can be no fragrant plum blossom

  • 336
    原创
  • 6
    翻译
  • 100
    转载
  • 41
    评论
  • 访问:1569908次
  • 积分:1957
  • 等级:核心会员
  • 排名:第4名
精华文章
    最新问题
    查看更多+
    热门文章
      热门用户
      推荐用户
        Copyright © 2016 All Rights Reserved. Powered by CNDBA · 皖ICP备2022006297号-1·

        QQ交流群

        注册联系QQ