Oracle 11g中对于归档日志的删除,除了遵循RMAN保留策略外,也可以通过RMAN来配置归档日志的删除策略,也就是归档日志何时可以被删除。归档日志删除策略适用于所有归档位置(使用快速闪回区FRA/不使用FRA)。本文主要描述归档日志删除策略并给出了具体的演示。
1、关于归档日志删除策略
也就是哪些归档日志符合删除策略能够被删除,如前所述,归档位置适用于所有归档位置(使用快速闪回区FRA/不使用FRA)
当启用该策略后,如归档日志存在于FRA中,则Oracle会尽可能根据保留他们,一旦FRA空间告急,则Oracle会根据归档日志删除策略自动删除
对于不在FRA中的归档日志,需要手动使用delete obsolete或delete archivelog方式来删除日志
无论归档日志存在于FRA内或外,都可以通过BACKUP ... DELETE INPUT or DELETE ARCHIVELOG方式来删除
该策略不适用于使用LogMiner方式从主数据库传送到逻辑standby生成的外部归档日志文件,因为这些日志文件不能够在逻辑standy上备份或恢复
2、配置归档日志删除策略
使用下面的方式来配置归档日志删除策略
configure archivelog deletion policy to backed up 2 times to sbt;
configure archivelog deletion policy to backed up 1 times to device type disk;
configure archivelog deletion policy to applied on standby;
configure archivelog deletion policy to shipped on standby;
configure archivelog deletion policy clear;
对于Oracle 10g没有该特性,但有一个类似的用于配置归档日志被备份次数,如下;
configure archivelog backup copies for device type disk to ${archiveretention};
3、禁用归档日志删除策略
缺省情况下,该策略被设置为none。也就是说根据RMAN备份保留策略,对于FRA中的归档日志,被备份过一次(到磁盘或磁带)即符合条件被删除
如果Oracle不再需要当前的归档日志用于保证数据库时点恢复或数据库闪回,则RMAN备份保留策略认为当前日志为obsolete
在SYSDATE-'DB_FLASHBACK_RETENTION_TARGET'之后创建的归档日志是需要被保留的
4、启用归档日志删除策略
一旦启用该策略,则指定的归档日志被备份数量达到设定值后,这些归档日志能够被删除
BACKUP ARCHIVELOG 会在未超出指定备份数的情况下(比如设置为2)备份归档日志到指定位置,如超出2次,则RMAN会跳过这些备份过2次的归档日志
对于上述的情形,可以为BACKUP ARCHIVELOG适用force选项来强制备份归档日志
如果启用该策略且配置为APPLIED ON STANDBY子句,则所有强制standby位置被apply后,这些归档日志会被RMAN删除
如果启用该策略且配置为SHIPPED ON STANDBY子句,则所有强制standby位置被成功传送后,这些归档日志会被RMAN删除
5、演示归档日志删除策略
[oracle@linux1 ~]$ rman target / Recovery Manager: Release 11.2.0.1.0 - Production on Tue Nov 12 15:10:17 2013 --查看当前数据库保留策略 RMAN> show retention policy; RMAN configuration parameters for database with db_unique_name USBO are: CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default --查看当前数据库保归档日志留策略 RMAN> show archivelog deletion policy; RMAN configuration parameters for database with db_unique_name USBO are: CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default --查看过时的备份 RMAN> report obsolete; RMAN retention policy will be applied to the command RMAN retention policy is set to redundancy 1 no obsolete backups found --列出copy副本 RMAN> list copy; specification does not match any datafile copy in the repository specification does not match any control file copy in the repository List of Archived Log Copies for database with db_unique_name USBO ===================================================================== Key Thrd Seq S Low Time ------- ---- ------- - ------------------- 124 1 121 A 2013/11/12 15:34:15 Name: /u03/database/usbo/fr_area/USBO/archivelog/2013_11_12/o1_mf_1_121_983pm3gp_.arc --当前的归档日志 --修改当前的归档日志保留策略为2个备份副本 RMAN> configure archivelog deletion policy to backed up 2 times to device type disk; new RMAN configuration parameters: CONFIGURE ARCHIVELOG DELETION POLICY TO BACKED UP 2 TIMES TO DISK; new RMAN configuration parameters are successfully stored --备份归档日志,并删除已经备份的归档日志 RMAN> backup archivelog all delete input; Starting backup at 2013/11/12 15:37:25 current log archived using channel ORA_DISK_1 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=121 RECID=124 STAMP=831310563 input archived log thread=1 sequence=122 RECID=125 STAMP=831310645 channel ORA_DISK_1: starting piece 1 at 2013/11/12 15:37:26 channel ORA_DISK_1: finished piece 1 at 2013/11/12 15:37:27 piece handle=/u03/database/usbo/fr_area/USBO/backupset/2013_11_12/o1_mf_annnn_TAG20131112T153726_983pop3p_.bkp tag=TAG20131112T153726 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 channel ORA_DISK_1: deleting archived log(s) RMAN-08138: WARNING: archived log not deleted - must create more backups --->出现警告提示,日志当前不能被删除,更多的备份需要创建 archived log file name=/u03/database/usbo/fr_area/USBO/archivelog/2013_11_12/o1_mf_1_121_983pm3gp_.arc thread=1 sequence=121 RMAN-08138: WARNING: archived log not deleted - must create more backups archived log file name=/u03/database/usbo/fr_area/USBO/archivelog/2013_11_12/o1_mf_1_122_983pooxb_.arc thread=1 sequence=122 Finished backup at 2013/11/12 15:37:27 --从os层面查看归档日志,当前已备份的两个归档日志没有删除 sys@USBO> ho ls -hltr /u03/database/usbo/fr_area/USBO/archivelog/2013_11_12/* -rw-r----- 1 oracle asmadmin 3.0K Nov 12 15:36 /u03/database/usbo/fr_area/USBO/archivelog/2013_11_12/o1_mf_1_121_983pm3gp_.arc -rw-r----- 1 oracle asmadmin 4.5K Nov 12 15:37 /u03/database/usbo/fr_area/USBO/archivelog/2013_11_12/o1_mf_1_122_983pooxb_.arc --从视图查询也可以获得其状态 sys@USBO> select name,status from v$archived_log where STATUS='A'; NAME STA -------------------------------------------------------------------------------- --- /u03/database/usbo/fr_area/USBO/archivelog/2013_11_12/o1_mf_1_121_983pm3gp_.arc A /u03/database/usbo/fr_area/USBO/archivelog/2013_11_12/o1_mf_1_122_983pooxb_.arc A --第二次备份归档日志 -- Author : Leshami -- Blog : http://blog.csdn.net/leshami RMAN> backup archivelog all delete input tag=arc_2nd; Starting backup at 2013/11/12 15:41:58 current log archived using channel ORA_DISK_1 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=121 RECID=124 STAMP=831310563 --sequence 121与122依旧被备份 input archived log thread=1 sequence=122 RECID=125 STAMP=831310645 input archived log thread=1 sequence=123 RECID=126 STAMP=831310918 channel ORA_DISK_1: starting piece 1 at 2013/11/12 15:41:58 channel ORA_DISK_1: finished piece 1 at 2013/11/12 15:41:59 piece handle=/u03/database/usbo/fr_area/USBO/backupset/2013_11_12/o1_mf_annnn_ARC_2ND_983py6mv_.bkp tag=ARC_2ND comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 channel ORA_DISK_1: deleting archived log(s) --sequence 121与122被删除 archived log file name=/u03/database/usbo/fr_area/USBO/archivelog/2013_11_12/o1_mf_1_121_983pm3gp_.arc RECID=124 STAMP=831310563 archived log file name=/u03/database/usbo/fr_area/USBO/archivelog/2013_11_12/o1_mf_1_122_983pooxb_.arc RECID=125 STAMP=831310645 RMAN-08138: WARNING: archived log not deleted - must create more backups --->出现警告提示,日志123不能被删除,更多的备份需要创建 archived log file name=/u03/database/usbo/fr_area/USBO/archivelog/2013_11_12/o1_mf_1_123_983py6gh_.arc thread=1 sequence=123 --再次查看,只有sequence 123存在,121与122已经被删除 RMAN> list copy; specification does not match any datafile copy in the repository specification does not match any control file copy in the repository List of Archived Log Copies for database with db_unique_name USBO ===================================================================== Key Thrd Seq S Low Time ------- ---- ------- - ------------------- 126 1 123 A 2013/11/12 15:37:25 Name: /u03/database/usbo/fr_area/USBO/archivelog/2013_11_12/o1_mf_1_123_983py6gh_.arc Finished backup at 2013/11/12 15:41:59 --配置新的归档日志删除策略 RMAN> configure archivelog deletion policy to backed up 1 times to device type disk; old RMAN configuration parameters: CONFIGURE ARCHIVELOG DELETION POLICY TO BACKED UP 2 TIMES TO DISK; new RMAN configuration parameters: CONFIGURE ARCHIVELOG DELETION POLICY TO BACKED UP 1 TIMES TO DISK; new RMAN configuration parameters are successfully stored --第三次备份归档日志 RMAN> backup archivelog all tag=arc_3rd; Starting backup at 2013/11/12 15:44:11 current log archived using channel ORA_DISK_1 --下面是skip的提示信息,因为根据新的策略,sequence 123已经被备份过一次了 skipping archived log file /u03/database/usbo/fr_area/USBO/archivelog/2013_11_12/o1_mf_1_123_983py6gh_.arc; already backed up 1 time(s) 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=124 RECID=127 STAMP=831311051 channel ORA_DISK_1: starting piece 1 at 2013/11/12 15:44:12 channel ORA_DISK_1: finished piece 1 at 2013/11/12 15:44:13 piece handle=/u03/database/usbo/fr_area/USBO/backupset/2013_11_12/o1_mf_annnn_ARC_3RD_983q2d34_.bkp tag=ARC_3RD comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 Finished backup at 2013/11/12 15:44:13 --清除策略 RMAN> configure archivelog deletion policy clear; old RMAN configuration parameters: CONFIGURE ARCHIVELOG DELETION POLICY TO BACKED UP 1 TIMES TO DISK; RMAN configuration parameters are successfully reset to default value --列出所有归档日志的备份信息 RMAN> list backup of archivelog all; List of Backup Sets =================== BS Key Size Device Type Elapsed Time Completion Time ------- ---------- ----------- ------------ ------------------- 24 8.00K DISK 00:00:00 2013/11/12 15:37:26 BP Key: 24 Status: AVAILABLE Compressed: NO Tag: TAG20131112T153726 Piece Name: /u03/database/usbo/fr_area/USBO/backupset/2013_11_12/o1_mf_annnn_TAG20131112T153726_983pop3p_.bkp List of Archived Logs in backup set 24 Thrd Seq Low SCN Low Time Next SCN Next Time ---- ------- ---------- ------------------- ---------- --------- 1 121 3090437 2013/11/12 15:34:15 3090507 2013/11/12 15:36:03 1 122 3090507 2013/11/12 15:36:03 3090591 2013/11/12 15:37:25 BS Key Size Device Type Elapsed Time Completion Time ------- ---------- ----------- ------------ ------------------- 25 37.50K DISK 00:00:00 2013/11/12 15:41:58 BP Key: 25 Status: AVAILABLE Compressed: NO Tag: ARC_2ND Piece Name: /u03/database/usbo/fr_area/USBO/backupset/2013_11_12/o1_mf_annnn_ARC_2ND_983py6mv_.bkp List of Archived Logs in backup set 25 Thrd Seq Low SCN Low Time Next SCN Next Time ---- ------- ---------- ------------------- ---------- --------- 1 121 3090437 2013/11/12 15:34:15 3090507 2013/11/12 15:36:03 1 122 3090507 2013/11/12 15:36:03 3090591 2013/11/12 15:37:25 1 123 3090591 2013/11/12 15:37:25 3090746 2013/11/12 15:41:58 BS Key Size Device Type Elapsed Time Completion Time ------- ---------- ----------- ------------ ------------------- 26 2.50K DISK 00:00:00 2013/11/12 15:44:12 BP Key: 26 Status: AVAILABLE Compressed: NO Tag: ARC_3RD Piece Name: /u03/database/usbo/fr_area/USBO/backupset/2013_11_12/o1_mf_annnn_ARC_3RD_983q2d34_.bkp List of Archived Logs in backup set 26 Thrd Seq Low SCN Low Time Next SCN Next Time ---- ------- ---------- ------------------- ---------- --------- 1 124 3090746 2013/11/12 15:41:58 3090839 2013/11/12 15:44:11
相关参考
RMAN 配置保留策略
Oracle 闪回区(Oracle Flash recovery area)
Oracle 快照控制文件(snapshot control file)
基于RMAN的异机数据库克隆(rman duplicate)
基于RMAN从活动数据库异机克隆(rman duplicate from active DB)
RMAN duplicate from active 时遭遇 ORA-17627 ORA-12154
Oracle 基于备份控制文件的恢复(unsing backup controlfile)
Oracle 基于 RMAN 的不完全恢复(incomplete recovery by RMAN)
rman 还原归档日志(restore archivelog)