Oracle DataGuard 主備切換 (switchover) oracle11g
Oracle DataGuard主備切換(switchover)
首先確認現在的dataguard是否正確
主庫
SQL> SELECT OPEN_MODE, DATABASE_ROLE, SWITCHOVER_STATUS,protection_level FROM V$DATABASE; OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS PROTECTION_LEVEL -------------------- ---------------- -------------------- -------------------- READ WRITE PRIMARY TO STANDBY MAXIMUM PERFORMANCE
備庫
SQL> SELECT OPEN_MODE, DATABASE_ROLE, SWITCHOVER_STATUS,protection_level FROM V$DATABASE; OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS PROTECTION_LEVEL -------------------- ---------------- -------------------- -------------------- READ ONLY WITH APPLY PHYSICAL STANDBY NOT ALLOWED MAXIMUM PERFORMANCE
備庫為以下狀態,說明現階段dataguard正常
READ ONLY WITH APPLY
(一)將主庫切換為物理備庫
STEP1:檢視主庫狀態
SQL> SELECT OPEN_MODE, DATABASE_ROLE, SWITCHOVER_STATUS,protection_level FROM V$DATABASE; OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS PROTECTION_LEVEL -------------------- ---------------- -------------------- -------------------- READ WRITE PRIMARY TO STANDBY MAXIMUM PROTECTION
注意:需要檢查SWITCHOVER_STATUS引數,如果值為"SESSION ACTIVE"或者"TO STANDBY", 則主資料庫角色可以切換為備庫角色。
STEP2:將其切換到備庫,切換後,資料庫會關閉
SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY [WITH SESSION SHUTDOWN];
注意:如果上一步的SWITCH_STATUS引數值為"TO STANDBY",則 WITH SESSION SHUTDOWN 可以省略。
STEP3:啟動到mount狀態
SQL> STARTUP MOUNT
注意:11.2.0.4版本及其以上版本不需要執行"SHUTDOWN ABORT",因為資料庫已經在STEP2命令中關閉了。
(二) 將備庫切換成主庫並啟動到open
STEP1:檢視備庫狀態
SQL> SELECT OPEN_MODE, DATABASE_ROLE, SWITCHOVER_STATUS,protection_level FROM V$DATABASE; OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS PROTECTION_LEVEL -------------------- ---------------- -------------------- -------------------- READ ONLY PHYSICAL STANDBY RECOVERY NEEDED MAXIMUM PROTECTION
注意:需要檢查SWITCH_STATUS引數,如果值為"SESSION ACTIVE"或"TO PRIMARY",則備庫可以切換為主庫。
此處SWITCH_STATUS引數為 RECOVERY NEEDED,或者NOT ALLOWED 需要執行
SQL> RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION; Media recovery complete. SQL>
再次檢查備庫狀態
SQL> SELECT OPEN_MODE, DATABASE_ROLE, SWITCHOVER_STATUS,protection_level FROM V$DATABASE; OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS PROTECTION_LEVEL -------------------- ---------------- -------------------- -------------------- READ ONLY WITH APPLY PHYSICAL STANDBY TO PRIMARY MAXIMUM PROTECTION
此時已經是TO PRIMARY
STEP2: 切換到主庫
SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY [WITH SESSION SHUTDOWN];
注意:如果上一步的SWITCH_STATUS引數值為"TO PRIMARY",則 WITH SESSION SHUTDOWN 可以省略。
STEP3: 此時資料庫為mount狀態,需開啟資料庫
SQL> SELECT OPEN_MODE, DATABASE_ROLE, SWITCHOVER_STATUS, FORCE_LOGGING, DATAGUARD_BROKER, GUARD_STATUS FROM V$DATABASE; OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS FOR DATAGUAR GUARD_S -------------------- ---------------- -------------------- --- -------- ------- MOUNTED PRIMARY NOT ALLOWED YES DISABLED NONE SQL> ALTER DATABASE OPEN ; SQL> SELECT OPEN_MODE, DATABASE_ROLE, SWITCHOVER_STATUS, FORCE_LOGGING, DATAGUARD_BROKER, GUARD_STATUS FROM V$DATABASE; OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS FOR DATAGUAR GUARD_S -------------------- ---------------- -------------------- --- -------- ------- READ WRITE PRIMARY TO STANDBY YES DISABLED NONE
(三)新的備庫開啟日誌應用
SQL> ALTER DATABASE OPEN; SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT ;
或者
SQL> alter database recover managed standby database disconnect from session;
###################兩種注意點#########################################################################
啟動redo 應用
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
啟動實時應用
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;
提示:disconnect from session子句並非必須,該子句用於指定啟動完應用後自動退出到命令運算子前,
如果不指定的話,當前session 就會一直停留處理redo 應用,如果想做其它操作,就只能新建一個連線。
兩者切換需要用到語句
SQL> alter database recover managed standby database cancel;
如果是啟動的實時應用,主庫插入一條語句,備庫就能查詢到
如果是啟用的redo應用,備庫需要過一會才會查詢到。
#######################################################################################################
檢視備庫狀態
SQL> SELECT OPEN_MODE, DATABASE_ROLE, SWITCHOVER_STATUS,protection_level FROM V$DATABASE; OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS PROTECTION_LEVEL -------------------- ---------------- -------------------- -------------------- READ ONLY WITH APPLY PHYSICAL STANDBY NOT ALLOWED MAXIMUM PROTECTION
參考文件:https://www.cnblogs.com/lijiaman/p/13335406.html
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/70004783/viewspace-2789023/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- oracle11g dataguard切換Oracle
- openGauss主備切換之switchover與failoverAI
- 【DG】Data Guard主備庫Switchover切換
- DataGuard---->物理StandBy的角色切換之switchover
- 【DATAGUARD】Oracle Dataguard物理備庫切換最佳實踐(sqlplus)OracleSQL
- Oracle 11.2.0.4 physical dataguard和snapshot dataguard切換Oracle
- Oracle 單機切換為主備Oracle
- ORACLE 12C DATAGUARD環境搭建和主從切換Oracle
- Oracle 11g dg switchover切換操作流程Oracle
- Oracle 11g 一主多備切換方案Oracle
- DATAGUARD失敗切換
- DATAGUARD強行切換
- oracle 19c使用dgmgrl來執行switchover和failover切換OracleAI
- oracle 11g datagurd主從切換Oracle
- 【DG】Data Guard主備庫Failove切換AI
- Mysql 5.6 Master和Slave 主備切換MySqlAST
- MySQL高可用之MHA切換測試(switchover & failover)MySqlAI
- 基於單機的DataGuard切換文件
- Oracle:DG 的 switchoverOracle
- 基於多種場景DataGuard切換方案
- 【PG流複製】Postgresql流複製主備切換SQL
- mysql主備切換canal出現的問題解析MySql
- 【ARCH】留存,Oracle11g之前Dataguard環境刪除歸檔指令碼Oracle指令碼
- (九)主題切換
- Redis主從切換Redis
- 【DG】Oracle11g異構平臺之Linux To Windows DataGuard安裝配置--duplicateOracleLinuxWindows
- 12c data guard 使用 sqlplus 主備切換最佳實踐SQL
- 手工切換MySQL主從MySql
- Redis sentinel主從切換Redis
- 【DATAGUARD】Oracle Dataguard nologging 塊修復Oracle
- oracle dg切換操作示例Oracle
- 【dgmgrl】使用dgmgrl做switchover切換報錯ORA-16501, ORA-16625等
- Spring Boot中自定義註解+AOP實現主備庫切換Spring Boot
- SQLServer2012映象主庫掛掉如何切換到映象備庫SQLServer
- oracle rman備份歸檔日誌需要先切換日誌嗎Oracle
- keepalived配置redis主從切換Redis
- 小程式切換主題配色
- ostgreSQL主從切換-手動SQL