Data Guard主從庫之間的角色切換分為以下兩種
Swithchover通常都是人為的有計劃的進行角色互換
Failover是指由於Primary故障無法短時間恢復
下面分別演示物理Standby的Switchover和Failover(邏輯Standby的切換類似)
PRIMARY>select switchover_status from v$database;
SWITCHOVER_STATUS
TO STANDBY
PRIMARY>alter database commit to switchover to physical standby;
此時原primary就是以standby身份在運行了
STANDBY>select switchover_status from v$database;
SWITCHOVER_STATUS
TO PRIMARY
STANDBY>alter database commit to switchover to primary;
Database altered
STANDBY>alter database open;
Database altered
PRIMARY>select database_role from v$database;
DATABASE_ROLE
PHYSICAL STANDBY
STANDBY>select database_role from v$database;
DATABASE_ROLE
PRIMARY
可以看到原來的primary現在變成standby
檢查新的primary的log_archive_dest參數的設置是否正確
STANDBY>show parameter log_archive_dest_
NAME TYPE VALUE
log_archive_dest_
=(ONLINE_LOGFILES
) DB_UNIQUE_NAME=O
STANDBY>show parameter log_archive_dest_state_
NAME TYPE VALUE
log_archive_dest_state_
在新primary端做log switch:
STANDBY>alter system switch logfile;
System altered
STANDBY>select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
在新standby端查看
PRIMARY>select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
兩邊的歸檔日志的最大序號吻合
STANDBY>SELECT THREAD#
no rows selected
這一步很重要
如果上述語句有返回結果
STANDBY>alter database register physical logfile
STANDBY>SELECT UNIQUE THREAD# AS THREAD
d#) AS LAST from V$ARCHIVED_LOG;
THREAD LAST
通過上述語句可以查出standby目前序號最大的歸檔日志為
STANDBY>alter database register physical logfile
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE FINISH FORCE;
ALTER DATABASE OPEN;STANDBY>select database_role from v$database;DATABASE_ROLE
From:http://tw.wingwit.com/Article/program/Oracle/201311/19104.html