Oracle 12c系列(五)|PDB Refresh

shilei1發表於2018-05-13

沃趣科技資料庫技術專家 楊禹航




PDB Refresh12c推出的特性,具有對源端PDB進行增量同步的功能,每次重新整理會將源端PDB中的任何更改同步到目標PDB(在此環境中目標PDB被稱作Refreshable PDB)中,目前增量同步方式有兩種:手動方式自動方式


REFRESH MODE語句:

在使用CREATE PLUGGABLE DATABASE建立PDB時指定REFRESH MODE子句用來控制是否開啟重新整理機制。

該子句目前只在"CREATE PLUGGABLE DATABASE ... FROM"中支援,可以使用此語句指定如下選項:

1.指定REFRESH MODE NONE,這是預設方式,在建立PDB時不開啟刷機機制。

2.指定REFRESH MODE MANUAL子句,建立手動重新整理的PDB

3.指定REFRESH MODE EVERY number_of_minutes MINUTES子句,建立以週期性重新整理的PDB

另外值得一提的是Oracle 18cRefreshable PDB進行了進一步的增強,增強為Refreshable PDB Switchover(可重新整理PDB的切換),在12.2.1中源PDB只能作為源端PDB,而在18c中可對源PDB和目標PDB進行角色轉換,該功能類似Active Dataguard的主備切換,只不過OraclePDB Refresh中再次實現了該功能。

目前refreshable PDB只能在只讀模式下開啟,當Refreshable PDB進行重新整理時,Refreshable PDB必須處於關閉狀態,只讀模式開啟時會停止重新整理,當再次關閉Refreshable PDB時繼續上次的重新整理,也可以將Refreshable PDB更改為REFRESH MODE NONE模式,更改之後你無法在將PDB改為Refreshable PDB

另外也可以使用ALTER PLUGGABLE DATABASE命令將Refreshable PDB從手動重新整理更改為自動重新整理,也可以從自動重新整理更改為手動重新整理,同樣透過語句ALTER PLUGGABLE DATABASE + REFRESH MODE更改為非Refreshable PDB,但是非Refreshable PDB不可以被更改為Refreshable PDB

同時需要注意的是Refreshable PDB和源PDB必須屬於不同的CDB,因此Refreshable PDB需要使用遠端的CDB中的PDB來建立,在建立期間必須使用dblink,但實際情況是Source PDBRefreshable PDB可以屬於同一個CDB,只不過在建立Refreshable PDB時必須指定dblinkdblink指向自己所在的CDB,否則語法無法透過。

Refreshable PDB應用場景可以用在開發和測試環境的搭建過程中, 因為資料是採用增量同步的方式,這樣就減少了對源資料庫的影響,也可以作為online備份庫。

Clone源端的PDB前期注意事項:

1.如果PDBClone的到的CDB的字符集不是AL32UTF8,那麼源與目標字符集必須相容。

2.源端與目標端的位元組順序必須相同。

3.連線的使用者在CDB中必須擁有'CREATE PLUGGABLE DATABASE'的許可權。

4.PDB不可以是關閉狀態。

5.源端PDB必須為歸檔模式。

6.源端PDB必須是local undo模式。

7.Refreshable PDB建立後,如果源端需要建立相應表空間,那麼目標端需要配置PDB_FILE_NAME_CONVERT引數或使用OMF目錄管理方式(OMF級別高於PDB_FILE_NAME_CONVERT),否正會導致目標端PDB重新整理失敗。

8.目標端採用OMF目錄管理方式後,CREATE PLUGGABLE DATABASE子句中不能指定file_name_convert做顯示目錄轉換,否正報ORA-01276錯誤。

9.在使用重新整理目標PDB與源PDB同步資料時,是透過dblink從源PDB訪問redo,但有些時候,當需要更新重新整理副本時,源PDB或源PDB所屬的CDB可能無法訪問,在這種情況下,設定REMOTE_RECOVERY_FILE_DEST引數,將嘗試從此引數指定的目錄中讀取歸檔日誌檔案。

10.重新整理與切換命令均需在目標PDB中執行。

PDB Refresh測試:

如下將源端PDBwoqupdb透過refresh方式克隆到本地,且命名為qdatapdb

(1)建立目標端到源端庫的DBLINKorcl12c

sys. ora12c>CREATE DATABASE LINK orcl12c CONNECT TO system IDENTIFIED BY oracle USING 'orcl12c';

Database link created.

Elapsed: 00:00:00.15

sys. ora12c>


克隆源端WOQUPDB

sys. orcl12c>show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED

---------- ------------------------------ ---------- ----------

         2 PDB$SEED                       READ ONLY  NO

         4 WOQUPDB                        READ WRITE NO

sys. orcl12c>


(2)
目標端配置OMF目錄管理方式

sys. ora12c>alter system set db_create_file_dest='/u01/app/oracle/oradata';

System altered.

Elapsed: 00:00:00.04

sys. ora12c>


(3)
在目標端使用CREATE PLUGGABLE DATABASE + REFRESH MODE MANUAL語句建立qdatapdb

sys. ora12c>CREATE PLUGGABLE DATABASE qdatapdb FROM woqupdb@orcl12c REFRESH MODE MANUAL;

Pluggable database created.

Elapsed: 00:00:14.20

sys. ora12c>


(4)
檢查克隆完成的QDATAPDB

sys. ora12c>show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED

---------- ------------------------------ ---------- ----------

         2 PDB$SEED                       READ ONLY  NO

         4 QDATAPDB                       MOUNTED

sys. ora12c>select pdb_id, pdb_name, status, refresh_mode, refresh_interval from cdb_pdbs;

    PDB_ID PDB_NAME                       STATUS     REFRES REFRESH_INTERVAL

---------- ------------------------------ ---------- ------ ----------------

         2 PDB$SEED                       NORMAL     NONE

         4 QDATAPDB                       REFRESHING MANUAL

Elapsed: 00:00:00.07

sys. ora12c>

透過檢視我們可以看到狀態為REFRESHING,重新整理模式為MANUAL手工重新整理。


(5)
在源PDB建立表空間tbs1,及測試表t

sys. orcl12c>create tablespace tbs1 datafile size 100M;

Tablespace created.

Elapsed: 00:00:00.30

sys. orcl12c>create user yyh identified by yyh;

User created.

Elapsed: 00:00:00.09

sys. orcl12c>drop user yyh ;

User dropped.

Elapsed: 00:00:01.34

sys. orcl12c>create user yyh default tablespace tbs1 identified by yyh;

User created.

Elapsed: 00:00:00.05

sys. orcl12c>grant dba to yyh;

Grant succeeded.

Elapsed: 00:00:00.04

sys. orcl12c>conn yyh/yyh@woqupdb

Connected.

yyh. woqupdb>create table t as select * from dba_objects;

Table created.

Elapsed: 00:00:02.18

yyh. woqupdb>select count(*) from t;

  COUNT(*)

----------

     72714

Elapsed: 00:00:00.03

yyh. woqupdb>


  (6)
在目標端重新整理qdatapdb

sys. ora12c>alter pluggable database qdatapdb refresh;

alter pluggable database qdatapdb refresh

*

ERROR at line 1:

ORA-65118: operation affecting a pluggable database cannot be performed from another pluggable database

Elapsed: 00:00:00.04

sys. ora12c>conn sys/oracle@qdatapdb as sysdba

Connected.

21:55:00 sys. qdatapdb>set time off

sys. qdatapdb>alter pluggable database qdatapdb refresh;

Pluggable database altered.

Elapsed: 00:00:01.84

sys. qdatapdb>


日誌資訊:

2018-03-10T21:55:06.187494-05:00

QDATAPDB(4):alter pluggable database qdatapdb refresh

2018-03-10T21:55:06.975492-05:00

Applying media recovery for pdb-4099 from SCN 2800296 to SCN 2802347

Remote log information: count-1

thr-1, seq-5, logfile-/u01/app/oracle/fast_recovery_area/orcl12c/ORCL12C/foreign_archivelog/WOQUPDB/2018_03_10/o1_mf_1_5_1212300924_.arc, los-2791634, nxs-18446744073709551615

QDATAPDB(4):Media Recovery Start

2018-03-10T21:55:06.977285-05:00

QDATAPDB(4):Serial Media Recovery started

2018-03-10T21:55:07.061801-05:00

QDATAPDB(4):Media Recovery Log /u01/app/oracle/fast_recovery_area/orcl12c/ORCL12C/foreign_archivelog/WOQUPDB/2018_03_10/o1_mf_1_5_1212300924_.arc

2018-03-10T21:55:07.503582-05:00

QDATAPDB(4):Successfully added datafile 51 to media recovery

QDATAPDB(4):Datafile #51: '/u01/app/oracle/oradata/ORA12C/671B0AC55A3F2870E0535138A8C0026E/datafile/o1_mf_tbs1_fb96ncby_.dbf'

2018-03-10T21:55:07.998822-05:00

QDATAPDB(4):Incomplete Recovery applied until change 2802347 time 03/10/2018 21:55:06

2018-03-10T21:55:08.006177-05:00

QDATAPDB(4):Media Recovery Complete (ora12c)

QDATAPDB(4):Completed: alter pluggable database qdatapdb refresh

(7)目標端開啟qdatapdb, 檢查重新整理完成後的資料

sys. qdatapdb>alter database open read only;

Database altered.

Elapsed: 00:00:01.54

sys. qdatapdb>select count(*) from yyh.t;

  COUNT(*)

----------

     72714

Elapsed: 00:00:00.04

sys. qdatapdb>select t.name tablespace_name, d.name from v$tablespace t, v$datafile d where d.ts#=t.ts#;

TABLESPACE_NAME NAME

--------------- ---------------------------------------------------------------------

SYSTEM          /u01/app/oracle/oradata/ORA12C/671B/datafile/o1_mf_system_fbjv_.dbf

SYSAUX          /u01/app/oracle/oradata/ORA12C/671B/datafile/o1_mf_sysaux_fbk6_.dbf

UNDOTBS1        /u01/app/oracle/oradata/ORA12C/671B/datafile/o1_mf_undotbs1_fbhk7_.dbf

TBS1            /u01/app/oracle/oradata/ORA12C/671B/datafile/o1_mf_tbs1_fbcby_.dbf

Elapsed: 00:00:00.01

sys. qdatapdb>

這裡已經重新整理完畢,資料同步到本地目標qdatapdb中。


(8)
目標庫修改為自動重新整理模式,每分鐘重新整理一次

sys. qdatapdb>ALTER PLUGGABLE DATABASE qdatapdb REFRESH MODE EVERY 1 MINUTES;

Pluggable database altered.

Elapsed: 00:00:00.09

sys. qdatapdb>select pdb_id, pdb_name, status, refresh_mode, refresh_interval from cdb_pdbs;

    PDB_ID PDB_NAME                       STATUS     REFRES REFRESH_INTERVAL

---------- ------------------------------ ---------- ------ ----------------

         4 QDATAPDB                       REFRESHING AUTO                  1

Elapsed: 00:00:00.05

sys. qdatapdb>

透過檢視我們可以看到重新整理模式已經被更改為AUTO,間隔時間為1分鐘。


(9)
PDB刪除測試表

yyh. woqupdb>drop table t;

Table dropped.

Elapsed: 00:00:00.31

yyh. woqupdb>


日誌:

2018-03-10T22:01:49.537240-05:00

QDATAPDB(4):ALTER PLUGGABLE DATABASE pdb1 REFRESH MODE EVERY 1 MINUTES

QDATAPDB(4):ORA-65118 signalled during: ALTER PLUGGABLE DATABASE pdb1 REFRESH MODE EVERY 1 MINUTES...

2018-03-10T22:02:21.179776-05:00

QDATAPDB(4):ALTER PLUGGABLE DATABASE qdatapdb REFRESH MODE EVERY 1 MINUTES

QDATAPDB(4):Completed: ALTER PLUGGABLE DATABASE qdatapdb REFRESH MODE EVERY 1 MINUTES

2018-03-10T22:02:21.357524-05:00

QDATAPDB(4):alter pluggable database refresh

QDATAPDB(4):Completed: alter pluggable database refresh

2018-03-10T22:03:21.502428-05:00

QDATAPDB(4):alter pluggable database refresh

QDATAPDB(4):Completed: alter pluggable database refresh

2018-03-10T22:04:21.680468-05:00

QDATAPDB(4):alter pluggable database refresh

QDATAPDB(4):Completed: alter pluggable database refresh

透過日誌可以觀察到目標端每分鐘自動重新整理一次。


(10)
檢查目標端資料同步情況

sys. qdatapdb>select count(*) from yyh.t;

  COUNT(*)

----------

     72714

Elapsed: 00:00:00.03

sys. qdatapdb>select open_mode from v$database;

OPEN_MODE

--------------------

READ ONLY

Elapsed: 00:00:00.03

sys. qdatapdb>shutdown immediate

Pluggable Database closed.

sys. qdatapdb>

因目標庫在OPEN狀態下,雖然日誌中顯示每分鐘重新整理,但是資料實際並未正真同步。


(11)1
分鐘後再次檢查資料同步情況

sys. qdatapdb>alter database open read only;

Database altered.

Elapsed: 00:00:01.89

sys. qdatapdb>select count(*) from yyh.t;

select count(*) from yyh.t

                         *

ERROR at line 1:

ORA-00942: table or view does not exist

Elapsed: 00:00:00.01

sys. qdatapdb>

資料已經同步完成。


(12)
轉換為目標PDB:qdatapdb為非none PDB

sys. ora12c>select pdb_id, pdb_name, status, refresh_mode, refresh_interval from cdb_pdbs;

    PDB_ID PDB_NAME                       STATUS     REFRES REFRESH_INTERVAL

---------- ------------------------------ ---------- ------ ----------------

         2 PDB$SEED                       NORMAL     NONE

         4 QDATAPDB                       REFRESHING AUTO                  1

Elapsed: 00:00:00.03

sys. ora12c>alter pluggable database qdatapdb close;

Pluggable database altered.

Elapsed: 00:00:00.19

sys. ora12c>alter session set container=qdatapdb;

Session altered.

Elapsed: 00:00:00.00

sys. qdatapdb>ALTER PLUGGABLE DATABASE qdatapdb REFRESH MODE NONE;

Pluggable database altered.

Elapsed: 00:00:04.01

sys. ora12c>ALTER PLUGGABLE DATABASE qdatapdb REFRESH MODE manual;

ALTER PLUGGABLE DATABASE qdatapdb REFRESH MODE manual

*

ERROR at line 1:

ORA-65261: pluggable database QDATAPDB not enabled for refresh

Elapsed: 00:00:00.00

sys. ora12c>

Note:

 禁用PDB refresh功能後,就不能再轉換為refresh pdb


(13)
檢查qdatapdb狀態

sys. ora12c>conn /as sysdba

Connected.

sys. ora12c>select pdb_id, pdb_name, status, refresh_mode, refresh_interval from cdb_pdbs;

    PDB_ID PDB_NAME                       STATUS     REFRES REFRESH_INTERVAL

---------- ------------------------------ ---------- ------ ----------------

         2 PDB$SEED                       NORMAL     NONE

         4 QDATAPDB                       NEW        NONE

Elapsed: 00:00:00.00

sys. ora12c>alter pluggable database qdatapdb open;

Pluggable database altered.

Elapsed: 00:00:05.02

sys. ora12c>select pdb_id, pdb_name, status, refresh_mode, refresh_interval from cdb_pdbs;

    PDB_ID PDB_NAME                       STATUS     REFRES REFRESH_INTERVAL

---------- ------------------------------ ---------- ------ ----------------

         2 PDB$SEED                       NORMAL     NONE

         4 QDATAPDB                       NORMAL     NONE

Elapsed: 00:00:00.00

sys. ora12c>

QDATAPDB的狀態已經由自動重新整理轉換成為了普通的PDB


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/196700/viewspace-2154403/,如需轉載,請註明出處,否則將追究法律責任。

相關文章