您好,登錄后才能下訂單哦!
如何實現Oracle Data Guard主庫備庫角色切換,很多新手對此不是很清楚,為了幫助大家解決這個難題,下面小編將為大家詳細講解,有這方面需求的人可以來學習下,希望你能有所收獲。
步驟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;
NOT ALLOWED | 當前的數據庫不是帶有備用數據庫的主數據庫 |
PREPARING DICTIONARY | 該邏輯備用數據庫正在向一個主數據庫和其他備用數據庫發送它的重做數據,以便為切換做準備 |
PREPARING SWITCHOVER | 接受用于切換的重做數據時,邏輯備用配置會使用它 |
RECOVERY NEEDED | 備用數據庫還沒有接收到切換請求 |
SESSIONS ACTIVE | 在主數據庫中存在活動的SQL會話;在繼續執行之前必須斷開這些會話 |
SWITCHOVER PENDING | 適用于那些已收到主數據庫切換請求但是還沒有處理該請求的備用數據庫 |
SWITCHOVER LATENT | 切換沒有完成并返回到主數據庫 |
TO LOGICAL STANDBY | 主數據庫已經收到了來自邏輯備用數據庫的完整的字典 |
TO PRIMARY | 該備用數據庫可以轉換為主數據庫 |
TO STANDBY | 該主數據庫可以轉換為備用數據庫 |
v$database Switchover_Status值的含義
看完上述內容是否對您有幫助呢?如果還想對相關知識有進一步的了解或閱讀更多相關文章,請關注億速云行業資訊頻道,感謝您對億速云的支持。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。