Oracle Data Guard主庫備庫角色切換(Switchovers)

forrest_itpub發表於2017-04-11

步驟1:驗證主庫能否進行角色切換,TO STANDBY表示可以進行
SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE;
SWITCHOVER_STATUS
-----------------
TO STANDBY
1 row selected

The TO STANDBY value in the SWITCHOVER_STATUS column indicates that it is
possible to switch the primary database to the standby role. If the TO STANDBY value
is not displayed, then verify the Data Guard configuration is functioning correctly (fo
example, verify all LOG_ARCHIVE_DEST_n parameter values are specified correctly).
If the value in the SWITCHOVER_STATUS column is SESSIONS ACTIVE, perform. the
steps described in SectionA.4, "Problems Switching Over to a Standby Database" on
pageA-4 to identify and terminate active user or SQL sessions that might prevent a

switchover from being processed. If, after performing these steps, the SWITCHOVER_
STATUS column still displays SESSIONS ACTIVE, you can successfully perform. a
switchover by appending the WITH SESSION SHUTDOWN clause to the ALTER
DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY statement
described in Step 2.
See Oracle Database Reference for information about other valid values for the
SWITCHOVER_STATUS column of the V$DATABASE view.

步驟2:在主庫上執行角色切換到從庫角色
SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY;

After this statement completes, the primary database is converted into a standby
database. The current control file is backed up to the current SQL session trace file
before the switchover. This makes it possible to reconstruct a current control file, if
necessary.

步驟3:關閉並重新啟動之前的主庫例項
SQL> SHUTDOWN IMMEDIATE;
SQL> STARTUP MOUNT;

At this point in the switchover process, both databases are configured as standby
databases.

步驟4:在備庫的V$DATABASE檢視中檢視備庫的切換狀態
SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE;
SWITCHOVER_STATUS
-----------------
TO_PRIMARY
1 row selected

If the value in the SWITCHOVER_STATUS column is SESSIONS ACTIVE, perform. the
steps described in SectionA.4, "Problems Switching Over to a Standby Database" on
pageA-4 to identify and terminate active user or SQL sessions that might prevent a
switchover from being processed. If, after performing these steps, the SWITCHOVER_
STATUS column still displays SESSIONS ACTIVE, you can proceed to Step 5, and
append the WITH SESSION SHUTDOWN clause to the switchover statement. See Oracle
Database Reference for information about other valid values for the SWITCHOVER_
STATUS column of the V$DATABASE view

步驟5:切換備庫到主庫角色
You can switch a physical standby database from the standby role to the primary role
when the standby database instance is either mounted in Redo Apply mode or open
for read-only access. It must be in one of these modes so that the primary database
switchover request can be coordinated. After the standby database is in an appropriate
mode, issue the following SQL statement on the physical standby database that you
want to change to the primary role:


SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;

步驟6:完成備庫到主庫的切換
1. 如果備庫沒有以只讀模式開啟,直接執行以下語句開啟到新的主庫。
SQL> ALTER DATABASE OPEN;

2. 如果備庫以只讀模式開啟,先關閉資料,然後再重新啟動。
SQL> SHUTDOWN IMMEDIATE;
SQL> STARTUP;

步驟7:如果有必要,重新啟動一下新的備庫上的重做日誌應用服務
For the new physical standby database and for each other physical or logical standby
database in the Data Guard configuration, if log apply services were not previously
configured to continue operating through a switchover, use an appropriate command
to restart log apply services. See Chapter6, "Log Apply Services" for more information
about how to configure and start log apply services.
SQL> alter database recover managed standby database disconnect from session;

(注:可以透過select message from v$dataguard_status;檢視當前備庫應用重做日誌的狀態)

步驟8:開始傳送重做資料到備庫上
Issue the following statement on the new primary database:
SQL> ALTER SYSTEM SWITCH LOGFILE;

v$database Switchover_Status值的含義

NOT ALLOWED

當前的資料庫不是帶有備用資料庫的主資料庫

PREPARING DICTIONARY

該邏輯備用資料庫正在向一個主資料庫和其他備用資料庫傳送它的重做資料,以便為切換做準備

PREPARING SWITCHOVER

接受用於切換的重做資料時,邏輯備用配置會使用它

RECOVERY NEEDED

備用資料庫還沒有接收到切換請求

SESSIONS ACTIVE

在主資料庫中存在活動的SQL會話;在繼續執行之前必須斷開這些會話

SWITCHOVER PENDING

適用於那些已收到主資料庫切換請求但是還沒有處理該請求的備用資料庫

SWITCHOVER LATENT

切換沒有完成並返回到主資料庫

TO LOGICAL STANDBY

主資料庫已經收到了來自邏輯備用資料庫的完整的字典

TO PRIMARY

該備用資料庫可以轉換為主資料庫

TO STANDBY

該主資料庫可以轉換為備用資料庫

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

相關文章