環境:
OS:rhel63_64bit
DB: Oracle10gR2
主備切換 切換的順序: 先從主庫到備用,再從備庫到主庫
Switchover Switchover:
無損轉換,通常是使用者手動觸發或者有計劃的讓其自動觸發,比如硬體升級啦,軟體升級啦之類的。
通常它給你帶來的工作量非常小並且都是可預計的。其執行分兩個階段,第一步,primary 資料庫轉換為standby 角色,第二步,standby 資料庫(之一)轉換為 primary 角色,primary 和 standby 只是簡單的角色互換,這也印證了我們前面關於角色轉換是 primary/standby 互動的猜測。
Failover Failover:
不可預知原因導致 primary 資料庫故障並且短期內不能恢複就需要 failover。如果是這種切換那你就要小心點了,有可能只是虛驚一場,甚至連你可能損失的腦細胞的數量都能預估,但如果運氣不好又沒有完備的備份恢複策略而且 primary 資料並非處於最大資料保護或最高可用性模式地話
SWITCHOVER_STATUSVARCHAR2(18)Indicates whether switchover is allowed:
■NOT ALLOWED - Either this is a standby database and the primary
database has not been switched first or this is a primary database
and there are no standby databases.
■SESSIONS ACTIVE - Indicates that there are active SQL sessions
attached to the primary or standby database that need to be
disconnected before the switchover operation is permitted. Query
theV$SESSIONviewtoidentifythespecificprocessesthatneedto
be terminated.
■SWITCHOVER PENDING - This is a standby database and the
primary database switchover request has been received but not
processed.
■SWITCHOVER LATENT - The switchover was in pending mode,
but did not complete and went back to the primary database.
■TOPRIMARY-Thisisastandbydatabaseandisallowedtoswitch
over to a primary database.
■TOSTANDBY-Thisisaprimarydatabaseandisallowedtoswitch
over to a standby database.
■RECOVERY NEEDED - This is a standby database that has not
received the switchover request.
主庫操作
SQL> select process,pid,status,client_process from v$managed_standby;
PROCESS PID STATUS CLIENT_P
--------- ---------- ------------ --------
ARCH 7913 CONNECTED ARCH
ARCH 7915 CONNECTED ARCH
ARCH 7917 CLOSING ARCH
ARCH 7919 CONNECTED ARCH
ARCH 7921 CONNECTED ARCH
ARCH 7923 CONNECTED ARCH
ARCH 7925 CONNECTED ARCH
ARCH 7927 CONNECTED ARCH
ARCH 7929 CONNECTED ARCH
ARCH 7931 CONNECTED ARCH
LGWR 7893 WRITING LGWR
11 rows selected.
SQL> select DATABASE_ROLE,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
---------------- --------------------
PRIMARY SESSIONS ACTIVE
SQL>
sys@ORA> SELECT COUNT(*) FROM V$SESSION WHERE USERNAME IS NOT NULL;
COUNT(*)
----------
1
SQL> startup force
ORACLE instance started.
Total System Global Area 213909504 bytes
Fixed Size 2095152 bytes
Variable Size 88082384 bytes
Database Buffers 117440512 bytes
Redo Buffers 6291456 bytes
Database mounted.
Database opened.
SQL> select DATABASE_ROLE,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
---------------- --------------------
PRIMARY SESSIONS ACTIVE
SQL> SELECT COUNT(*) FROM V$SESSION WHERE USERNAME IS NOT NULL;
COUNT(*)
----------
1
沒有其他的會話,直接切換
SQL> select sequence#,applied from dba_logstdby_log;
no rows selected
SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY WITH SESSION SHUTDOWN;
Database altered.
SQL> alter database commit to switchover to standby;
Database altered.
SQL> select instance_name,status from v$instance;
INSTANCE_NAME STATUS
---------------- ------------
ora STARTED
SQL> shutdown immediate
ORA-01507: database not mounted
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.
Total System Global Area 213909504 bytes
Fixed Size 2095152 bytes
Variable Size 92276688 bytes
Database Buffers 113246208 bytes
Redo Buffers 6291456 bytes
Database mounted.
sys@ORA> select DATABASE_ROLE,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
---------------- --------------------
PHYSICAL STANDBY TO PRIMARY
SQL> select process,pid,status,client_process from v$managed_standby;
PROCESS PID STATUS CLIENT_P
--------- ---------- ------------ --------
ARCH 8126 CONNECTED ARCH
ARCH 8128 CONNECTED ARCH
ARCH 8130 CONNECTED ARCH
ARCH 8132 CONNECTED ARCH
ARCH 8134 CONNECTED ARCH
ARCH 8136 CONNECTED ARCH
ARCH 8138 CONNECTED ARCH
ARCH 8140 CONNECTED ARCH
ARCH 8142 CONNECTED ARCH
ARCH 8144 CONNECTED ARCH
10 rows selected.
更多詳情見請繼續閱讀下一頁的精彩內容:
推薦閱讀:
使用RMAN的Duplicate功能建立物理DataGuard
Oracle基礎教程之通過RMAN複製資料庫
RMAN備份策略制定參考內容
RMAN備份學習筆記
OracleDatabase Backup加密 RMAN加密
通過RMAN備份duplicate建立DataGuard