11g主庫歸檔自動刪除的小問題分析

jeanron100發表於2016-02-06

最近在無疑中檢視一個資料庫的日誌的時候,發現裡面有這麼一段內容。

Sat Feb 06 10:07:25 2016
Deleted Oracle managed file +ARCH/testdb2/archivelog/2016_01_13/thread_1_se
q_4566.261.901038877
Archived Log entry 9262 added for thread 1 sequence 4678 ID 0x26b3e123 dest 1:
Sat Feb 06 14:04:52 2016
Thread 1 advanced to log sequence 4680 (LGWR switch)
  Current log# 1 seq# 4680 mem# 0: +DATA/testdb2/onlinelog/group_1.261.815382013
Sat Feb 06 14:04:52 2016
LNS: Standby redo logfile selected for thread 1 sequence 4680 for destination LOG_ARCHIVE_DEST_2
Sat Feb 06 14:04:52 2016
Deleted Oracle managed file +ARCH/testdb2/archivelog/2016_01_13/thread_1_seq_4567.258.901058415
Archived Log entry 9264 added for thread 1 sequence 4679 ID 0x26b3e123 dest 1:

這段日誌的亮點就在於"Deleted Oracle managed file"
這是一個11gR2的主庫,使用了ASM作為資料儲存。如果看到這段自動刪除歸檔的內容,很可能和一個特性聯絡起來,那就是閃回區的自動刪除歸檔的閥值 80%,在11g ADG中會有這樣的而一個特性,閃回區使用率達到80%以上的時候,會幫助清理一些過期的歸檔日誌檔案。同時出現這個問題和另外一個引數有關,那就是閃回 區的大小設定,如果太小了,使用率馬上就會達到80%,所以這個引數db_recovery_file_dest_size也值得關注。
目前的引數配置為:

SQL> show parameter reco

NAME                                 TYPE        VALUE

------------------------------------ ----------- ---------------

control_file_record_keep_time        integer     7

db_recovery_file_dest                string      +ARCH

db_recovery_file_dest_size           big integer 100G

db_unrecoverable_scn_tracking        boolean     TRUE

recovery_parallelism                 integer     0

那麼這個問題中,先不說主備庫是否都使用哪個特性,先看看主庫閃回區使用率到底是多少呢?

SQL>select *from v$flash_recovery_area_usage;

FILE_TYPE            PERCENT_SPACE_USED PERCENT_SPACE_RECLAIMABLE NUMBER_OF_FILES

-------------------- ------------------ ------------------------- ---------------

CONTROL FILE                        .01                         0               1

REDO LOG                              0                         0               0

ARCHIVED LOG                       3.92                      3.89             112

BACKUP PIECE                          0                         0               0

IMAGE COPY                            0                         0               0

FLASHBACK LOG                         0                         0               0

FOREIGN ARCHIVED LOG                  0                         0               0

所以這個問題就比較奇怪了,使用率遠遠沒有達到80%的閥值,怎麼會自動刪除呢,當然檢視了MOS也發現了一些相關的bug,4911954),有的可能是v$flash_recovery_area_usageV$RECOVERY_FILE_DEST的資料情況會有較大出入,會有這種情況,不過我的這個環境從版本的日誌來看,是沒有關係的。

FILE_TYPE            PERCENT_SPACE_USED PERCENT_SPACE_RECLAIMABLE NUMBER_OF_FILES

-------------------- ------------------ ------------------------- ---------------

CONTROL FILE                        .01                         0               1

REDO LOG                              0                         0               0

ARCHIVED LOG                       3.92                      3.89             112

BACKUP PIECE                          0                         0               0

IMAGE COPY                            0                         0               0

FLASHBACK LOG                         0                         0               0

FOREIGN ARCHIVED LOG                  0                         0               0

然後繼續找可能的情況,從日誌中發現了一個特別的情況,也是規律,那就是刪除的歸檔是24天以前的,切一次日誌,刪除一次24天以前的舊歸檔。
可以透過rman中的操作 crosscheck archivelog all觀察和分析日誌得出。

RMAN>crosscheck archivelog all;
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=1668 device type=DISK
validation succeeded for archived log
archived log file name=+ARCH/testdb2/archivelog/2016_01_14/thread_1_seq_4568.369.901073863 RECID=9042 STAMP=901073862
validation succeeded for archived log
archived log file name=+ARCH/testdb2/archivelog/2016_01_14/thread_1_seq_4569.262.901095119 RECID=9043 STAMP=901095118
validation succeeded for archived log
archived log file name=+ARCH/testdb2/archivelog/2016_01_14/thread_1_seq_4570.259.901095121 RECID=9045 STAMP=901095121

關於歸檔的刪除策略,其實從rman中也可以做一些配置。如果配置是這樣的情況,刪除策略就是保留24天。
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 24 DAYS;
不過我這個問題的情況還不是,rman的配置都是取預設,只有一條新增的配置。
CONFIGURE ARCHIVELOG DELETION POLICY TO APPLIED ON ALL STANDBY;
這個時候,怎麼透過sql語句來檢視rman中的相關設定呢,主要可以透過下面的方式來看。
SELECT NAME,VALUE FROM V$RMAN_CONFIGURATION

當然裡面只有一條自定義的配置

NAME                           VALUE
------------------------------ ------------------------------
ARCHIVELOG DELETION POLICY     TO APPLIED ON ALL STANDBY

我們這個時候來簡單測試一下這個配置的影響。取消自定義的配置。取預設值。

RMAN> CONFIGURE ARCHIVELOG DELETION POLICY clear;
old RMAN configuration parameters:
CONFIGURE ARCHIVELOG DELETION POLICY TO APPLIED ON ALL STANDBY;
RMAN configuration parameters are successfully reset to default value

然後手工切換一次日誌。得到的日誌如下,又看到了一些額外的資訊。

Sat Feb 06 22:16:30 2016
Thread 1 advanced to log sequence 4683 (LGWR switch)
  Current log# 7 seq# 4683 mem# 0: +DATA/testdb2/onlinelog/group_7.271.817297835
Sat Feb 06 22:16:30 2016
Trying to expand controlfile section 11 for Oracle Managed Files
Expanded controlfile section 11 from 224 to 448 records
Requested to grow by 224 records; added 8 blocks of records
LNS: Standby redo logfile selected for thread 1 sequence 4683 for destination LOG_ARCHIVE_DEST_2
Sat Feb 06 22:16:30 2016
Archived Log entry 9270 added for thread 1 sequence 4682 ID 0x26b3e123 dest 1:

對於看起來有些陌生的日誌,當然也是集各家之言。
有一個老外的建議非常專業,我就直接貼出來了,對於這些日誌的說明,他的解釋如下:

this is nothing to worry about.
the following is an extract from metalink

Starting in Oracle8 the controlfile is automatically expanded.
A new datafile is added beyond the maxdatafiles limited specified
in the control file.

This also happens if new records are added to the "log_history" section of
the control files and there are no entries that could be replaced.

The routine that performs the expansion writes this message to the alert log.
The messages specifies the section that was expanded and the amount of
the expansion. Please note that this message cannot be turned off.

好了,看到這裡,我們還是很有必要去看一下涉及的檢視 v$controlfile_record_section

修改rman配置之後的檢視內容如下,只顯示了alert日誌中說明的部分section 11相關的記錄。

TYPE         RECORD_SIZE RECORDS_TOTAL RECORDS_USED FIRST_INDEX LAST_INDEX LAST_RECID

------------ ----------- ------------- ------------ ----------- ---------- ----------

LOG HISTORY           56           292          292          12         11       4683

所以這個問題又指向了控制檔案,對於控制檔案,我們有一個資料庫引數相關。

SQL> show parameter control_file_record_keep_time

NAME                                 TYPE        VALUE

------------------------------------ ----------- ---------

control_file_record_keep_time        integer     7
所以透過日誌中的一條資訊,逐步測試最後發現了一些意料之外的情況,還是需要好好琢磨琢磨這些內容。


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

相關文章