1. 程式人生 > >Oracle資料庫主備切換

Oracle資料庫主備切換

主備庫切換原因: 1. switch:使用者主動切換; 2. failover:主庫出現故障,強行切換;   switch切換過程:先主庫再備庫   主庫 1. 檢視switchover_status:select database_role, switchover_status from v$database; 如果switchover_status為:to standby 則: ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY 否則用:ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY WITH SESSION SHUTDOWN;   2. 重啟資料庫: shutdown immediate; startup nomount;   3. 以備庫mount alter database mount standby database;   備庫 1. 應用redo:alter database recover managed standby database disconnect from session;   2. 檢視switchover_status:select database_role, switchover_status from v$database; 如果switchover_status為:to primary 則:ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY 否則用:ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY WITH SESSION SHUTDOWN;   3.  重啟資料庫 shutdown immediate; startup;   failover 主備庫切換 1.. 停止日誌應用 
alter database recover managed standby database cancel; 
2. 關閉standby日誌傳輸 
alter database recover managed standby database finish force;   3. 切換到primary 
alter database commit to switchover to primary with session shutdown;  做這一步的時候,若存在gap,則會報ORA-16139:Switchover: Media recovery required - standby not in limbo 錯誤。 做測試的時候,若先起主庫再起備庫,且未等待備庫相關日誌傳輸完畢,就會出現這個問題。此時需要強制切換 
alter database activate physical standby database;    4. 重啟資料庫到open狀態