生産環境中,可能會有各種各樣的原因導緻資料庫不能提供服務,例如資料庫庫的硬體故障,作業系統故障或軟體bug,人為的失誤(例如rm -rf /)等,在這種情況下,dataguard顯得尤為重要,當主庫不可用的時候,可以将備庫failover成主庫繼續提供服務,failover和switchover不同的是,執行failover後,原有的dataguard配置将會失效且有可能會丢失部分資料,是以在生産環境中能用switchover解決的問題則應盡量采用switchover!
一:使用sql指令執行failover
1:檢視目前的主庫是dg1,實體備庫為dg2,将主庫關閉,模拟主庫故障
[oracle@dg2 ~]$ dgmgrl /
DGMGRL for Linux: Version 11.2.0.3.0 - 64bit Production
Copyright (c) 2000, 2009, Oracle. All rights reserved.
Welcome to DGMGRL, type "help" for information.
Connected.
DGMGRL> show configuration;
Configuration - DG_BROKER_CONFIG
Protection Mode: MaxAvailability
Databases:
dg1 - Primary database
dg2 - Physical standby database
Fast-Start Failover: DISABLED
Configuration Status:
SUCCESS
SQL> select open_mode,database_role,db_unique_name,flashback_on from v$database;
OPEN_MODE DATABASE_ROLE DB_UNIQUE_NAME FLASHBACK_ON
-------------------- ---------------- -------------------- ------------------
READ WRITE PRIMARY dg1 NO
SQL> shutdown abort
ORACLE instance shut down.
2:在備庫dg2上執行failover過程,failover執行的指令和switchover類似,隻是在這個過程中,主庫已經不可用
READ ONLY WITH APPLY PHYSICAL STANDBY dg2 NO
SQL> alter database recover managed standby database cancel;
Database altered.
READ ONLY PHYSICAL STANDBY dg2 NO
出現這個錯誤說明日志并未完全的應用
SQL> alter database commit to switchover to primary;
alter database commit to switchover to primary
*
ERROR at line 1:
ORA-16139: media recovery required
SQL> alter database recover managed standby database using current logfile disconnect from session;
SQL> alter database recover managed standby database finish;
MOUNTED PRIMARY dg2 NO
SQL> alter database open;
READ WRITE PRIMARY dg2 NO
二:使用datagurad broker進行failover
1:開啟主庫和備庫的閃回功能,主要用于主庫恢複後的reinstate操作,目前主庫為dg2,備庫為dg1
READ WRITE PRIMARY dg2 YES
READ ONLY WITH APPLY PHYSICAL STANDBY dg1 YES
[oracle@dg1 ~]$ dgmgrl sys/123456@dg1
dg2 - Primary database
dg1 - Physical standby database
SUCCESS
2:關閉主庫dg2,模拟主庫故障
ORACLE instance shut down.
ORA-01034: ORACLE not available
ORA-16625: cannot reach database "dg2"
DGM-17017: unable to determine configuration status
3:執行failover
DGMGRL> failover to dg1;
Performing failover NOW, please wait...
Failover succeeded, new primary is "dg1"
Warning: ORA-16629: database reports a different protection level from the protection mode
dg2 - Physical standby database (disabled)
ORA-16661: the standby database needs to be reinstated
WARNING
4:重新啟動原主庫dg2
SQL> startup
ORACLE instance started.
Total System Global Area 417546240 bytes
Fixed Size 2228944 bytes
Variable Size 352324912 bytes
Database Buffers 54525952 bytes
Redo Buffers 8466432 bytes
Database mounted.
ORA-16649: possible failover to another database prevents this database from
being opened
MOUNTED PRIMARY dg2 YES
5:執行reinstate操作
DGMGRL> reinstate database dg2;
Reinstating database "dg2", please wait...
Operation requires shutdown of instance "dg" on database "dg2"
Shutting down instance "dg"...
ORA-01109: database not open
Database dismounted.
Operation requires startup of instance "dg" on database "dg2"
Starting instance "dg"...
Unable to connect to database
ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
Failed.
Warning: You are no longer connected to ORACLE.
Please complete the following steps and reissue the REINSTATE command:
start up and mount instance "dg" of database "dg2"
SQL> conn /as sysdba
Connected to an idle instance.
Database opened.
READ ONLY PHYSICAL STANDBY dg2 YES
DGMGRL> enable database dg2;
Error: ORA-16661: the standby database needs to be reinstated
Reinstatement of database "dg2" succeeded
總結
1:非到萬不得已的情況,不使用failover,優先考慮switchover
2:若執行failover,則考慮使用sql指令完成
3:執行failover後,應及時備份資料,并重構dg環境
本文轉自東方之子736651CTO部落格,原文連結: http://blog.51cto.com/ecloud/1381881,如需轉載請自行聯系原作者