1. 程式人生 > >基於主庫SCN恢復物理DG

基於主庫SCN恢復物理DG

模擬環境:

主庫歸檔丟失,備庫未接收到主庫已丟失的日誌,導致產生gap

主庫 備庫
db_name orcl orcl
instance_name orcl

 orclstd

版本號 11.2.0.4 11.2.0.4

 開始實驗:

一、模擬歸檔丟失

1、在主庫建立新表,並切換日誌,檢視日誌應用狀態

create table test_dg as select * from all_objects;

alter system switch logfile;

select recid,name,sequence#,archived,applied from v$archived_log order by sequence#;

2、關閉實時應用

alter database recover managed standby database cancel;

3、關閉實時傳輸日誌

alter system set log_archive_dest_state_2=defer;

4、在主庫新建表並切換日誌

create table test_dg01 as select * from all_objects;

alter system switch logfile;

alter system switch logfile;

alter system switch logfile;

5、刪除新生成的部分歸檔日誌

6、開啟實時傳輸日誌

alter system set log_archive_dest_state_2=enable;

7、開啟實時應用

alter database recover managed standby database using current logfile disconnect from session;

8、檢視alert日誌發現存在gap,也可以通過v$archive_gap檢視查詢

select * from v$archive_gap;

二、開始恢復

1、查詢最小SCN號

兩種方法

      1、select FIRST_CHANGE#  from v$archived_log where SEQUENCE#  = 丟失的第一個歸檔號;--試驗成功

      2、SELECT (SELECT MIN(d.CHECKPOINT_CHANGE#) FROM v$datafile d) datafile_scn,        (SELECT MIN(d.CHECKPOINT_CHANGE#)         FROM   v$datafile_header d         WHERE  rownum = 1) datafile_header_scn,        (SELECT current_scn FROM v$database) current_scn,        (SELECT b.NEXT_CHANGE#         FROM   v$archived_log b         WHERE  b.SEQUENCE# = 丟失的第一個歸檔號         AND    resetlogs_change# =                (SELECT d.RESETLOGS_CHANGE# FROM v$database d)         AND    rownum = 1) NEXT_CHANGE# FROM   dual;--試驗失敗

2、根據scn號啟動主庫的增量備份

假設上步得到的scn是2241214

backup as compressed backupset incremental from SCN 2241214 database format '/u05/oracle/oracle_bk/ORADG11G/standby_%d_%T_%U.bak' include current controlfile for standby filesperset=5  tag 'FOR STANDBY';

3、將備份檔案傳到備庫

4、儲存備庫datafile絕對路徑

select name from v$datafile;

5、啟動備庫到nomount狀態,恢復控制檔案

restore standby controlfile from ‘’;

6、啟動備庫到mount狀態,增量恢復資料檔案

recover database noredo;

7、開啟實時應用日誌

alter database recover managed standby database using current logfile disconnect from session;

8、檢視日誌應用效果

select recid,name,sequence#,archived,applied from v$archived_log order by sequence#;

9、啟動備庫到open狀態

10、測試主備是否實時同步