DG中3種保護模式之間的切換

skyin_1603發表於2016-10-20
對於生成當中的資料庫,不同公司不同業務需求或者不同時間,對主庫與備庫的保護模式需求不一樣,
這樣,就需要切換主資料庫與備用資料庫之間的保護模式。以下是模式之間的切換過程。

--檢視主庫的保護模式:
SQL> select open_mode,protection_mode,switchover_status,database_role from v$database;
OPEN_MODE            PROTECTION_MODE      SWITCHOVER_STATUS    DATABASE_ROLE
-------------------- -------------------- -------------------- ----------------
READ WRITE           MAXIMUM PERFORMANCE  TO STANDBY           PRIMARY

--檢視備庫的保護模式:
SQL> select open_mode,protection_mode,switchover_status,database_role from v$database;
OPEN_MODE            PROTECTION_MODE      SWITCHOVER_STATUS    DATABASE_ROLE
-------------------- -------------------- -------------------- ----------------
READ ONLY            MAXIMUM PERFORMANCE  NOT ALLOWED          PHYSICAL STANDBY

----Data Guard三種保護模組式之間的轉換:
--最大效能轉換至最大可用:
--關閉主庫,重啟到mount狀態:
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.

Total System Global Area  835104768 bytes
Fixed Size                  2257840 bytes
Variable Size             683674704 bytes
Database Buffers          146800640 bytes
Redo Buffers                2371584 bytes
Database mounted.

--在主庫修改引數資訊:
SQL> alter system set 
  2  LOG_ARCHIVE_DEST_2='SERVICE=PROD LGWR SYNC AFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=PROD';
System altered.

--SQL> alter database set standby database to maximize availability;
Database altered.

--開啟主庫並驗證:
SQL> alter database open;
Database altered.

--驗證主庫:
SQL> select open_mode,protection_mode,switchover_status,database_role from v$database;
OPEN_MODE            PROTECTION_MODE      SWITCHOVER_STATUS    DATABASE_ROLE
-------------------- -------------------- -------------------- ----------------
READ WRITE           MAXIMUM AVAILABILITY TO STANDBY           PRIMARY

--確認備庫:
SQL> select open_mode,protection_mode,switchover_status,database_role from v$database;
OPEN_MODE            PROTECTION_MODE      SWITCHOVER_STATUS    DATABASE_ROLE
-------------------- -------------------- -------------------- ----------------
READ ONLY WITH APPLY MAXIMUM AVAILABILITY NOT ALLOWED          PHYSICAL STANDBY
備庫也已經把模式改變到最大可用模式。

--將主庫與備庫調至最大保護模式:
--由於最大保護模式與最大可用模式的重做歸檔程式、網路傳輸與磁碟寫選項是一樣的
--所以可以直接更改模式就可以了,不需要先修改引數資訊:

--把主庫與備庫調至最大保護模式:
--直接修改到maximize protection模式:
SQL> alter database set standby database to maximize protection;
Database altered.
--驗證主庫:
SQL> select open_mode,protection_mode,switchover_status,database_role from v$database;
OPEN_MODE            PROTECTION_MODE      SWITCHOVER_STATUS    DATABASE_ROLE
-------------------- -------------------- -------------------- ----------------
READ WRITE           MAXIMUM PROTECTION   TO STANDBY           PRIMARY

--確認備庫:
SQL> select open_mode,protection_mode,switchover_status,database_role from v$database;
OPEN_MODE            PROTECTION_MODE      SWITCHOVER_STATUS    DATABASE_ROLE
-------------------- -------------------- -------------------- ----------------
READ ONLY WITH APPLY MAXIMUM PROTECTION   NOT ALLOWED          PHYSICAL STANDBY
可以看到主庫與備庫都調至到最大保護模式。

--把資料庫重新調至回到最大效能模式:
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.

Total System Global Area  835104768 bytes
Fixed Size                  2257840 bytes
Variable Size             687869008 bytes
Database Buffers          142606336 bytes
Redo Buffers                2371584 bytes
Database mounted.
SQL> 
SQL> alter system set
  2  LOG_ARCHIVE_DEST_2='SERVICE=PROD ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=PROD';
System altered.

SQL> alter database set standby database to maximize performance;
Database altered.

--驗證主庫:
SQL> select open_mode,protection_mode,switchover_status,database_role from v$database;
OPEN_MODE            PROTECTION_MODE      SWITCHOVER_STATUS    DATABASE_ROLE
-------------------- -------------------- -------------------- ----------------
MOUNTED              MAXIMUM PERFORMANCE  NOT ALLOWED          PRIMARY

--確認備庫:
SQL> select open_mode,protection_mode,switchover_status,database_role from v$database;
OPEN_MODE            PROTECTION_MODE      SWITCHOVER_STATUS    DATABASE_ROLE
-------------------- -------------------- -------------------- ----------------
MOUNTED              MAXIMUM PERFORMANCE  NOT ALLOWED          PRIMARY

---最後開啟主庫:
SQL> alter database open;
Database altered.

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

相關文章