2025年9月26日 星期五

6. Data Guard on Multitenant Database

Multitenant Database 的 Data Guard 建置方式與傳統 Non-CDB 的建置方式無異,在 Oracle 12c 至 19c 的

版本只能於 CDB 層級來建置 Data Guard ,自 Oracle 21c 之後就可以只在 PDB 層級建置 Data Guard 。


在 CDB 層級建立 Data Guard 之後需要探討的問題是,未來在此 CDB 上建立新的 PDB 是否會同步到 standby 

端 ? 以下分別說明同步與不會同步的兩種情境 :

  • PDB 自動同步至 Standby 的情境

有兩個情境在 Primary 建立新 PDB 時會自動同步到 Standby :

1. Create PDB from seed

於 Primary 使用 seed 建立新的 PDB 時,所有的操作會自動同步到 Standby 端,例如在 Primary 建立 pdb3 

會自動同步到 Standby :

SQL> create pluggable database pdb3 admin user pdbadmin identified by welcome1 file_name_convert=('pdbseed','pdb3');


在 Standby 的 alter log 可以看到新的 PDB3 自動被建立出來 :

A screenshot of a computer program

AI-generated content may be incorrect.

如果這個情境下反而不想同步到 Standby 端,那麼在 create pluggable 的語法當中加上 STANDBYS=NONE 

就不會同步了。


2. Clone PDB from Read-Only PDB

如果是以 clone 的方式建立 PDB ,則來源端 PDB 必須為 Read-Only 才能夠自動同步到 Standby ,

例如 Create PDB4 from Local PDB3 ,此時 PDB4 會自動同步到 Standby :

SQL> alter pluggable database pdb3 close immediate;

SQL> alter pluggable database pdb3 open read only;

SQL> create pluggable database pdb4 from pdb3 file_name_convert=('pdb3','pdb4');


在 Standby 的 alter log 可以看到新的 PDB4 自動被建立出來 :

A screenshot of a computer program

AI-generated content may be incorrect.


如果是 Clone from Remote PDB 則限制較多,除了要求 Remote PDB 必須為 Read only 之外, 

Standby Database 必須為 ADG 且設定參數 standby_pdb_source_file_dblink 才會自動同步,

例如 Create rpdb from Remote Clone :

Enable ADG on Standby :

SQL> shutdown immediate

SQL> startup mount

SQL> alter database open read only

SQL> alter database recover managed standby database disconnect;

SQL> alter system set standby_pdb_source_file_dblink='rcdb';


Create PDB from Remote on Primary :

SQL> create pluggable database rpdb from rpdb@rcdb file_name_convert=('SQLMGMT/rpdb','ORAPDB/rpdb');


在這個情境下比較特殊, Standby 實際上是透過 DB Link 直接去 Remote Source PDB 拉 datafile 

而非從 Primary 拉,standby_pdb_source_file_dblink 設定的是連線到 Source Database 的 DB Link 名稱

,而且此 DB Link 必須要能夠連線成功,如果設定都沒錯的話 Standby 就會自動同步建立此 PDB :

A screenshot of a computer program

AI-generated content may be incorrect.


如果此時 Standby 沒有啟用 ADG ,則會因為無法使用 DB Link 來 restore datafile 造成 MRP crash :

A screenshot of a computer program

AI-generated content may be incorrect.

此時必須先將新建的 PDB disable recovery 才能夠重新啟用 MRP :

SQL> alter session set container=rpdb;

SQL> alter pluggable database disable recovery;

SQL> exit;

$ sqlplus / as sysdba

SQL> alter database recover managed standby database disconnect;



  • PDB 不會同步至 Standby 的情境

使用 Clone 的方式建立 PDB 不論是從 Local Clone 或是 Remote Clone ,只要 Source PDB 不是 Read Only 的情況下

,新建的 PDB 就不會自動同步至 Standby ,此時必須手動針對新的 PDB 進行 restore 並且 enable recovery ,

例如 Create wpdb from Read Write pdb :

SQL> create pluggable database wpdb from wpdb@rcdb file_name_convert=('SQLMGMT/wpdb','ORAPDB/wpdb');

SQL> alter pluggable database wpdb open;


此時 Standby 端只會建立 Metadata 不會 restore datafile ,也就是此時 Standby 端只有 wpdb 的空殼而已 :

A screenshot of a computer screen

AI-generated content may be incorrect.

此時必須於 Standby 端進行 restore pluggable database :

$ rman target /

RMAN>  run {

set newname for datafile 112 to '/u01/oradata/ORAPDBS/wpdb/system01.dbf';

set newname for datafile 113 to '/u01/oradata/ORAPDBS/wpdb/sysaux01.dbf';

set newname for datafile 114 to '/u01/oradata/ORAPDBS/wpdb/undotbs01.dbf';

restore pluggable database wpdb from service orapdb;

switch datafile 112 to copy;

switch datafile 113 to copy;

switch datafile 114 to copy;

}


Restore 結束後必須再 enable recovery 才能夠同步 :

$ sqlplus / as sysdba

SQL> alter database recover managed standby database cancel;

SQL> alter session set container=wpdb;

SQL> alter pluggable database enable recovery;

SQL> exit;

$ sqlplus / as sysdba

SQL> alter database recover managed standby database disconnect;


 

除此之外,如果在 Primary 針對 PDB 進行 flashback 的操作, Standby 端也會同步針對這個 PDB 進行 flashback ,

例如於 Primary 端針對 PDB2 進行 flashback ,首先必須於 Standby 端確認 Standby 有啟用 flashback 功能 :

A black screen with white text

AI-generated content may be incorrect.

從 Primary 針對 PDB2 進行 flashback 的操作 :

SQL> alter pluggable database pdb2 close immediate;

SQL> flashback pluggable database pdb2 to restore point rp;

SQL> alter pluggable database pdb2 open resetlogs;


在 pdb2 open resetlogs 的同時可以看到 Standby 端同步進行了 flashback 的動作 :

A screenshot of a computer

AI-generated content may be incorrect.

Data Guard 在有 CDB/PDB 的情況下較為複雜, DBA 在日常維運上必須要非常了解這些情境。



沒有留言:

張貼留言