1. 程式人生 > >轉 深入解析:一主多備DG環境,failover的實現過程詳解 以及 11g 容災庫可以線上新增tempfile.

轉 深入解析:一主多備DG環境,failover的實現過程詳解 以及 11g 容災庫可以線上新增tempfile.

https://yq.aliyun.com/articles/229600

 

核心,就是11g通過datafille_scn 號來追日誌,而不是日誌序列號來追日誌。

 

摘要: 在DG中,switchover和failover是兩個重要的概念,也是DG實現的核心。根據不同的DG配置,switchover和failover也是有差異的。當主庫被crash之後,如何進行DG foilover的操作?概述本文是針對在DG災備環境進行failover操作以及後續恢復的報告。

在DG中,switchover和failover是兩個重要的概念,也是DG實現的核心。根據不同的DG配置,switchover和failover也是有差異的。當主庫被crash之後,如何進行DG foilover的操作?

概述

本文是針對在DG災備環境進行failover操作以及後續恢復的報告。

1




驗證過程

1、A庫異常關閉

A庫:

SQL>shutdown abort

2、B庫進行failover切換為新主庫

failover 標準步驟如下:

#取消DG應用
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
#重啟下資料庫(建議)
shutdown immediate;
startup
#操作不可逆,確定實際情況需要failover
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE FINISH force;
SELECT OPEN_MODE, DATABASE_ROLE, SWITCHOVER_STATUS, FORCE_LOGGING, DATAGUARD_BROKER, GUARD_STATUS FROM V$DATABASE;
#嘗試常規切換為主庫
ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY WITH SESSION SHUTDOWN;

如果這一步的常規切換失敗,提示需要介質恢復,那麼:

1)恢復備庫 recover standby database until cancel;
 2)啟用備庫 alterdatabaseactivatestandbydatabase;
#最後重新啟動資料庫
shutdownimmediate;
startup

檢視此時B庫的資訊:

SQL>selectname, database_role, open_mode fromgv$database;


2

可以看到,目前B庫已成為新的主庫,redo日誌的sequence重新開始。

3、要求C庫成為新主庫的備庫

現在要求C庫成為新主庫的備庫。是否需要重建C庫呢?答案是不需要。下面具體來看下驗證過程。

C庫的alert日誌:

3

可以看到,在A庫crash之後,C庫收到網路無法連線到A庫的告警,說明C庫目前沒有新的操作。

接下來想要C庫成為B庫(新主庫)的備庫,就需要嘗試在B庫上配置DG引數,使得B庫的歸檔可以傳輸到C庫。

4

同時在B庫的tnsnames.ora檔案中增加到C庫的連線:

#StandbySingle Instance
JYZHAO_S=
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.111)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = jyzhao_s))  )

在B庫設定完成後,觀察B庫的告警:


5

然後返回C庫操作,將C庫開啟實時日誌應用:

SQL>alter database recover managed standby database cancel;
Databasealtered.
SQL>alter database recover managed standby database using current logfile disconnect from session;
Databasealtered.

此時再觀察C庫的告警日誌:

6

 

上面這個資料檔案頭的檢查點是0,說明資料檔案沒有正確獲取到,實際上是由於OMF的名字有變化,直接將資料檔案路徑catalog到備份集中,再switch即可。
catalogstartwith'+DATA1/jyzhao/datafile/';
switchdatabase to copy;

再次查詢:


7

此時在mount狀態下開啟日誌應用:

alter database recover managed standby database disconnect from session;

從告警日誌觀察,確認應用到最新時,取消日誌應用:

alter database recover managed standby database cancel;

開啟資料庫,開啟實時應用:

alter database recover managed standby database USING CURRENT LOGFILE disconnect from session;

最終查詢可以正常實時應用。


結論

一般來說,在A庫crash之後,B庫failover成為新的主庫,那麼原來設定為延遲1小時應用的C 庫是可以直接配置成為新主庫的備庫。A庫修復後,也可以通過failover之前的現有備份集來恢復到failover之前的狀態,而不需要在新主庫重新去備份。

原文釋出時間為:2017-11-1
本文作者:趙靖宇
本文來自雲棲社群合作伙伴“資料和雲”,瞭解相關資訊可以關注“資料和雲”微信公眾號

 

 

########11g 容災庫可以線上新增tempfile.

Data Guard Physical Standby - Managing temporary tablespace tempfiles (文件 ID 1514588.1)


3.
Verify Primary and Standby tempfiles match and all datafiles are ONLINE

SQL> SELECT TMP.NAME FILENAME, BYTES/1024/1024 "M", TS.NAME TABLESPACE
FROM V$TEMPFILE TMP, V$TABLESPACE TS WHERE TMP.TS#=TS.TS#;

4. 11.2 DG 可以在DG Active Data Guard 狀態下 新增臨時檔案。10G 無法做到。

You must add the new tempfile to the new primary site manually after the switchover is complete. This will ensure you maintain the same tempfile structures across the Primary and Standby sites.

 

5As this an 11.2 environment Active Data Guard can be running while this file is built into the standby sites structure. Managed recovery is started in this demonstration.

New Standby Site

To demonstrate the Standby will be opened read only and the tempfile added manually to the sites configuration.

SQL> select open_mode from v$database;

OPEN_MODE
--------------------
MOUNTED

SQL> recover managed standby database cancel;
Media recovery complete.
SQL> alter database open;

Database altered.

As this an 11.2 environment Active Data Guard can be running while this file is built into the standby sites structure. Managed recovery is started in this demonstration.

SQL> recover managed standby database disconnect using current logfile;
Media recovery complete.
The new 20M tempfile that was added to the Primary has not been replicated, is not a part of the standby sites structure and must be added manually if we want both sites tempfile configuration to be the same.

SQL> select name from v$tempfile;

NAME
--------------------------------------------------------------------------------
+DATA/rs1/tempfile/temp.264.800115667
+DATA/rs1/tempfile/temp.273.802356687

SQL> alter tablespace temp add tempfile '+DATA' size 20M;

Tablespace altered.

SQL> select name from v$tempfile;

NAME
--------------------------------------------------------------------------------
+DATA/rs1/tempfile/temp.264.800115667
+DATA/rs1/tempfile/temp.273.802356687
+DATA/rs1/tempfile/temp.274.802357821