Oracle關於ARCHIVELOG DELETION POLICY的配置解釋以及RMAN-08137/RMAN-08591的原因探究
前言
關於ARCHIVELOG DELETION POLICY的配置和解釋,百度答案存在很多的問題,大部分都描述不准確甚至是錯誤的。
於是花了將近3天在官網尋找答案並邊做實驗,整理如下的資料來說明歸檔刪除策略。
整理By PiscesCanon,2021-03-01至2021-03-03。
幾個RMAN的報錯
- RMAN-08137: WARNING: archived log not deleted, needed for standby or upstream capture process
- RMAN-08137: WARNING: archive log not deleted as it is still needed
In newer versions, the error may be:
RMAN-08120:WARNING: archived log not deleted, not yet applied by standby
- RMAN-08591: WARNING: invalid archivelog deletion policy
誤區和感慨
以前一直以為歸檔刪除策略就只是限制歸檔日志被誤刪除。
但是其實即便是設置TO NONE,那么如果歸檔日志沒有被備份過且(且?)歸檔日志均已傳輸至所指定的所需遠程目標LOG_ARCHIVE_DEST_
n
的話,那么也是沒有辦法被刪除的。
以前還一直以為TO NONE就是隨意刪除歸檔日志。
另外歸檔刪除策略對於BACKUP
... DELETE INPUT
,DELETE
ARCHIVELOG
或DELETE OBSOLETE
命令均生效。在10G中,如DELETE ARCHIVELOG或DELETE INPUT不遵守這個配置(參考文檔 ID 1577382.1,文檔描述不太明確,自己沒驗證)
另外,對於在FRA里邊的歸檔日志,Oracle會根據策略自動刪除。
總結就不總結了,詳細看下邊 。
歸檔刪除策略的持久配置的描述
來源(有引用修改):RMAN CONFIGURE,11gR2。以下是谷歌瀏覽器右鍵翻譯后如下。
特別需要注意有的字眼和前提條件。
語法元素 | 描述 |
ARCHIVELOG DELETION POLICY | 確定何時可以刪除已歸檔的重做日志文件。 歸檔的日志刪除策略適用於所有日志歸檔目標,包括快速恢復區域。該策略不適用於備份集中的歸檔重做日志文件。 數據庫僅自動刪除快速恢復區域中的已歸檔重做日志文件。您可以執行 在恢復區域中,數據庫會盡可能長地保留符合刪除條件的日志。需要磁盤空間時,數據庫將首先刪除最早的日志。當恢復區域處於磁盤壓力下時,數據庫可能會刪除Oracle Streams所需的存檔重做日志文件。 注意:刪除策略不適用於外部歸檔的重做日志文件,這些文件是邏輯備用數據庫為LogMiner會話接收的日志。 這些日志是從主數據庫傳輸的,但是與普通的歸檔重做日志文件不同,它們具有不同的DBID。 無法在邏輯備用數據庫上備份或還原外部歸檔的重做日志文件。
其他地方的說明:Configuring an Archived Redo Log Deletion Policy(11gR2) |
TO APPLIED ON [ALL] STANDBY |
指定如果同時滿足以下兩個條件,則可以刪除已歸檔的重做日志文件:
考慮哪些遠程目標取決於以下條件:
注意: 另請參見: Oracle Data Guard概念和管理以獲取詳細信息 |
TO NONE |
禁用存檔的日志刪除策略。這是默認設置。 歸檔的重做日志文件可以位於快速恢復區域的內部或外部。可以通過手動命令刪除任何位置的日志。數據庫只能自動刪除快速恢復區域中的日志。 如果將刪除策略設置為
例如,假設已將已歸檔的重做日志文件傳輸到所需的遠程目標。 根據恢復窗口保留策略,日志已過時,但尚未備份。 在這種情況下,日志可以刪除。 或者,假設日志已過時並且已備份到SBT,但尚未傳輸到所需的遠程目標。 在這種情況下,日志不符合刪除條件。 如果刪除策略設置為 |
|
指定如果同時滿足以下兩個條件,則可以刪除已歸檔的重做日志文件:
考慮哪些遠程目標取決於以下條件:
注意: 另請參見: Oracle Data Guard概念和管理以獲取詳細信息 |
關於MANDATORY
的含義,參考:Specifying Mandatory and Optional Destinations(11gR2)
在10gR2中關於歸檔日志刪除策略的描述,貌似是在基於Fast Recovery Area的前提下來進行的。
語法:ARCHIVELOG
DELETION
POLICY
TO
( APPLIED ON STANDBY
| NONE
| CLEAR
)
FRA前提處:Flash Recovery Area中歸檔的重做日志文件的刪除策略
PDF文檔(引用如下):10g RMAN-Data Guard
The following CONFIGURE commands should be issued, after connecting to the primary database and recovery catalog:
- CONFIGURE ARCHIVELOG DELETION POLICY TO APPLIED ON STANDBY
By setting this configuration at the primary database, it will enable automatic deletion of archived logs on the primary database that have been applied to remote standby destinations. By default, this configuration requires that at least one remote destination is set to mandatory.
Note: Mandatory standby destination can impact the primary database if the standby destination cannot be reached. To enable this feature without using mandatory standby destination, refer to Metalink Note 331924.1 (RMAN backups in Max Performance/Max Availability Data Guard Environment).
The following commands should be issued, after connecting to the standby database server where backups are made, and the recovery catalog:
- CONFIGURE ARCHIVELOG DELETION POLICY TO NONE
This will enable automatic deletion of archived logs on the standby database (where backups are being taken) that are outside of the retention period or have already been backed up to tape, if additional space is needed for new backups or archived logs.
The following commands should be issued, after connecting to each of the other standby database servers, and the recovery catalog:
- CONFIGURE ARCHIVELOG DELETION POLICY TO APPLIED ON STANDBY
By setting this configuration on each of the other standby databases (where backups are not being taken), it will enable automatic deletion of archived logs on this standby database that have been applied to all other remote standby destinations. By default, this configuration requires that at least one remote destination is set to mandatory.
Archived logs are deleted if space in the Flash Recovery Area needs to be reclaimed for new files.Note: Mandatory standby destination can impact the primary database if the standby destination cannot be reached. To enable this feature without using mandatory standby destination, refer to Metalink Note 331924.1 (RMAN backups in Max Performance/Max Availability Data Guard Environment).
因此,若是手工刪除,如果違反歸檔刪除策略,就會報錯RMAN-08137,更高版本為RMAN-08120(沒有驗證過)。
另外,對於子句TO APPLIED ON
[ALL] STANDBY
和子句TO SHIPPED TO
[ALL] STANDBY
在設置歸檔刪除策略的時候,報錯RMAN-08591: WARNING: invalid archivelog deletion policy。
原因是因為默認情況下,歸檔刪除策略是基於mandatory的,有隱含參數"_log_deletion_policy"控制。
SQL> create or replace view h$parameter as 2 select a.ksppinm name, 3 a.ksppdesc description, 4 b.ksppstvl session_value, 5 c.ksppstvl system_value 6 from x$ksppi a, x$ksppcv b, x$ksppsv c 7 where a.indx = b.indx 8 and a.indx = c.indx; View created. SQL> set line 500 SQL> col name for a25 SQL> col DESCRIPTION for a70 SQL> col SESSION_VALUE for a15 SQL> col SYSTEM_VALUE for a15 SQL> select * from h$parameter where name='_log_deletion_policy'; NAME DESCRIPTION SESSION_VALUE SYSTEM_VALUE ------------------------- ---------------------------------------------------------------------- --------------- --------------- _log_deletion_policy archivelog deletion policy for mandatory/all destination mandatory mandatory
關於RMAN-08591,我測試了如下兩條語句(測試版本為11.2.0.4.0):
CONFIGURE ARCHIVELOG DELETION POLICY TO APPLIED ON STANDBY; CONFIGURE ARCHIVELOG DELETION POLICY TO APPLIED ON ALL STANDBY;
前提條件log_archive_dest_N為optional,並且對應的log_archive_dest_state_N為enable。
如果不帶'ALL',報錯RMAN-08591。如果帶'ALL',那就不會報錯。
因為根據上邊TO APPLIED ON
[ALL] STANDBY
的說明,帶有'ALL'的時候,確定遠程目標囊括了optional和mandatory。不帶'ALL'則只包含mandatory。
那么如何解決RMAN-08591?
3種方法:
- 設置遠程目標log_archive_dest_N的時候加上mandatory參數
- 使用如下語句來配置歸檔刪除策略:
CONFIGURE ARCHIVELOG DELETION POLICY TO APPLIED ON ALL STANDBY;
- 修改參數_log_deletion_policy為ALL(文檔 ID 1577382.1,文檔 ID 1602424.1表示修改此參數需要重啟DB,但是實際可以動態修改並生效):
alter system set "_log_deletion_policy"='ALL' scope=both;;
建議使用第2,3種方法,第1種在FRA空間緊張的時候會導致無法對redolog做歸檔。
參考
RMAN-08137 on Primary Database although Archive Destination to Standby is deferred (文檔 ID 1380368.1)
RMAN-08137/RMAN-08120: Warning: Archive Log Not Deleted (文檔 ID 374421.1)
配置RMAN清除已應用到備庫的歸檔日志 (文檔 ID 1577382.1)
最大性能/最大可用性 Data Guard 環境中的 RMAN 備份 (文檔 ID 1602424.1)
RMAN "Applied On Standby" Throws RMAN-08591 And Archivelog Files Deleted Too Soon From Standby (文檔 ID 1082886.1)