通過RMAN設定standby接收日誌後主庫歸檔日誌才可刪除

guocun09發表於2020-05-13

因為Oracle archivelog會不斷生產,一般會設定定期清理archivelog的排程,類似下面。

但DG環境中因為某些原因導致主庫事務沒有即使傳到standby,而這時如果主庫的archivelog也被清理掉了,主備庫就產生了日誌GAP

export  ORACLE_SID=abc
export  ORACLE_HOME=/u01/product/oracle/
export  PATH=$ORACLE_HOME/bin:$PATH
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
rman target / <<EOF
run 
{
crosscheck archivelog all;
DELETE NOPROMPT ARCHIVELOG until time 'sysdate-7';
}
exit;
EOF


如何能夠確保standby日誌接收到了,主庫archivelog才會被刪除呢?

11G 後提供了RMAN的archivelog刪除策略

CONFIGURE ARCHIVELOG DELETION POLICY TO APPLIED ON STANDBY;

注:這裡是說archivelog在standby目錄中接收生產了,並不是被實際應用了。

因為這樣說?一種情況standby正常開啟,但MPR不開啟應用redo,其實standby也能接收主庫傳遞過來的archivelog但並沒有被應用,這時主庫的archivelog是可以被清理的


預設 CONFIGURE ARCHIVELOG DELETION POLICY TO APPLIED ON NONE;

SHOW ALL 命令能看到


實驗

1.關閉standby DB,模擬standby無法接受archivelog


2. 主庫rman中配置

CONFIGURE ARCHIVELOG DELETION POLICY TO APPLIED ON STANDBY;


3. 主庫切換生成新log,模擬gap

SQL> alter system switch logfile;

SQL> /


4.因為standby未接收到archivelog,對主庫備份archivelog同時加了DELETE INPUT清理歸檔報錯RMAM-08120

RMAN> backup format '/data/exp/arch_%T_%s_%U' ARCHIVELOG ALL DELETE INPUT;
Starting backup at 13-MAY-20
current log archived
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=9 device type=DISK
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=12585 RECID=25142 STAMP=1040319318
input archived log thread=1 sequence=12586 RECID=25144 STAMP=1040319532
input archived log thread=1 sequence=12587 RECID=25146 STAMP=1040319628
input archived log thread=1 sequence=12588 RECID=25147 STAMP=1040320146
channel ORA_DISK_1: starting piece 1 at 13-MAY-20
channel ORA_DISK_1: finished piece 1 at 13-MAY-20
piece handle=/data/exp/arch_20200513_10_0av041ki_1_1 tag=TAG20200513T174906 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/data/epodb/arch/1_12585_893259821.arc RECID=25142 STAMP=1040319318
archived log file name=/data/epodb/arch/1_12586_893259821.arc RECID=25144 STAMP=1040319532
RMAN-08120: WARNING: archived log not deleted, not yet applied by standby
archived log file name=/data/epodb/arch/1_12587_893259821.arc thread=1 sequence=12587
RMAN-08120: WARNING: archived log not deleted, not yet applied by standby
archived log file name=/data/epodb/arch/1_12588_893259821.arc thread=1 sequence=12588
Finished backup at 13-MAY-20


5.因為standby未接收到archivelog,對主庫delete archivelog報錯RMAM-08120

RMAN> delete archivelog until time 'sysdate' ;
released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=9 device type=DISK
RMAN-08120: WARNING: archived log not deleted, not yet applied by standby
archived log file name=/data/epodb/arch/1_12587_893259821.arc thread=1 sequence=12587
RMAN-08120: WARNING: archived log not deleted, not yet applied by standby
archived log file name=/data/epodb/arch/1_12588_893259821.arc thread=1 sequence=12588

注:如果帶上FORCE引數可以忽略 RMAM-08120直接刪除archivelog, delete FORCE archivelog until time 'sysdate' ;

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

相關文章