物理備庫failover實驗

duduyey發表於2014-08-18
系統資訊:Linux localhost.localdomain 2.6.18-164.el5 #1 SMP Thu Sep 3 03:33:56 EDT 2009 i686 i686 i386 GNU/Linux
資料庫版本:Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production

主庫資訊:

SQL> select NAME,DB_UNIQUE_NAME,DATABASE_ROLE,SWITCHOVER_STATUS,PRIMARY_DB_UNIQUE_NAME,PROTECTION_MODE from v$database;

NAME      DB_UNIQUE_NAME                 DATABASE_ROLE    SWITCHOVER_STATUS    PRIMARY_DB_UNIQUE_NAME         PROTECTION_MODE
--------- ------------------------------ ---------------- -------------------- ------------------------------ --------------------
PHYPRIMA  phyprimary                     PRIMARY          TO STANDBY           phystandby                     MAXIMUM AVAILABILITY

備庫資訊:

SQL> select NAME,DB_UNIQUE_NAME,DATABASE_ROLE,SWITCHOVER_STATUS,PRIMARY_DB_UNIQUE_NAME,PROTECTION_MODE from v$database;

NAME      DB_UNIQUE_NAME                 DATABASE_ROLE    SWITCHOVER_STATUS    PRIMARY_DB_UNIQUE_NAME         PROTECTION_MODE
--------- ------------------------------ ---------------- -------------------- ------------------------------ --------------------
PHYPRIMA  phystandby                     PHYSICAL STANDBY NOT ALLOWED          phyprimary                     MAXIMUM AVAILABILITY

實驗前準備:

1. 確保沒有沒有redo transport errors 或者 redo gap存在(備庫操作).

SQL> SELECT STATUS, GAP_STATUS FROM V$ARCHIVE_DEST_STATUS where status!='INACTIVE';  

STATUS    GAP_STATUS
--------- ------------------------
VALID
VALID     NO GAP
VALID     NO GAP

同時確保歸檔檔案是否連線

SQL> select thread#, low_sequence#, high_sequence# from v$archive_gap;

no rows selected

如果存在的話,如果主庫伺服器允許,將列出的歸檔檔案靠備考備庫,並通過如下語句註冊:

alter database register physical logfile 'filespec1';

2. 確保備庫存在於主庫想對應的臨時檔案

主庫:

SQL> select file_name,tablespace_name, bytes/1024/1024, status from dba_temp_files;

FILE_NAME                                                    TABLESPACE_NAME                BYTES/1024/1024 STATUS
------------------------------------------------------------ ------------------------------ --------------- -------
/data/oracle/oradata/phyprimary/temp01.dbf                   TEMP                                        20 ONLINE

備庫:

SQL> select file_name,tablespace_name, bytes/1024/1024, status from dba_temp_files;

FILE_NAME                                                    TABLESPACE_NAME                BYTES/1024/1024 STATUS
------------------------------------------------------------ ------------------------------ --------------- -------
/data/oracle/oradata/phystandby/temp01.dbf                   TEMP                                        20 ONLINE

3. 確保主庫與備庫是在最優效能模式下,如果不是,改為最優效能模式

SQL> alter database set standby database to maximize performance;


開始試驗:

4. 模擬主庫出現意外當機

SQL> shutdown abort;
ORACLE instance shut down.

5. 在需要failover的備庫上進行failover切換(備庫操作)

5.1 停止redo apply(可選項)

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;

Database altered.

5.2 停止接受redo log(可選項)

SQL>  ALTER DATABASE RECOVER MANAGED STANDBY DATABASE FINISH;

Database altered.


6 進行資料庫failover

SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE;

SWITCHOVER_STATUS
--------------------
TO PRIMARY


SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY WITH SESSION SHUTDOWN;

Database altered.

SQL> alter database open;  

Database altered.

SQL> select database_role from v$database;

DATABASE_ROLE
----------------
PRIMARY

SQL> select open_mode from v$database;

OPEN_MODE
--------------------
READ WRITE

如果是 READ ONLY狀態,則需要重啟資料庫到READ WRITE狀態

7 立即備份新的主庫,備份終於一切
























來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28719055/viewspace-1252931/,如需轉載,請註明出處,否則將追究法律責任。

相關文章