RMAN 配置归档日志删除策略

        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

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏刘君君

使用Spring Event解耦业务开发

Spring 事件是观察者模式的一种体现,对象间的一对多关系,被观察者发出信号时候会通知监听该事件的观察者;而发布-订阅模型往往需要一个调度中心,如消息队列等

23530
来自专栏北京马哥教育

Vim自动补全神器:YouCompleteMe

第一次听说这个插件还是在偶然的情况下看到别人的博客,听说了这个插件的大名。本来打算在实训期间来完成安装的,无奈网实在不给力,也就拖到了回家的时候。在开始准备工作...

91360
来自专栏安恒网络空间安全讲武堂

赛前福利①最新2018HITB国际赛writeup

FIRST 距离“西湖论剑杯”全国大学生网络空间安全技能大赛只有10天啦! 要拿大奖、赢offer,那必须得来点赛前练习定定心啊~这不,讲武堂就拿到了2018H...

47750
来自专栏salesforce零基础学习

salesforce 零基础学习(六十)Wizard样式创建数据

项目中表之间关联关系特别多,比如三个表中A,B,C  C作为主表,A,B作为从表,有时候C表需要创建数据时,同时需要创建A,B两个表的数据,这种情况下,使用Wi...

27890
来自专栏移动端开发

iOS 测试三方 KIF 的那些事

一: KIF 三方库的配置       今天的广州天气还不错,原本想试试UI测试的,前几天也了解到很多公司都在用 KIF 这这三方框架!!今天也就试着做做,可就...

24560
来自专栏杨建荣的学习笔记

一天内碰到的3个rac节点问题 (r6笔记第36天)

说到问题,真是层出不穷,自己也算搭建了也不少的rac环境的,但是在本地试验的时候总是会碰到一些问题,昨晚铲掉旧环境,搭建了两遍rac环境,终于在凌晨搭建好了环境...

35170
来自专栏一个爱瞎折腾的程序猿

Swashbuckle.AspNetCore3.0的二次封装与使用

之前写过一篇Swashbuckle.AspNetCore-v1.10 的使用,现在 Swashbuckle.AspNetCore 已经升级到 3.0 了,正好开...

15340
来自专栏Java帮帮-微信公众号-技术文章全总结

Web-第二十三天 Web商城实战三【悟空教程】

<a href="${pageContext.request.contextPath}/OrderServlet?method=findByUid">我的订单<...

19110
来自专栏Kubernetes

Kubernetes ReplicationController源码分析

虽然在Kubernetes v1.2中,Kubernetes推出了Deployments特性,Deployment通过创建ReplicaSet来管理Pod,R...

76680
来自专栏全栈架构

Elasticsearch Java API 搜索之Scrolls(四)

首先需要阅读 [scroll documentation](https://www.elastic.co/guide/en/elasticsearch/refe...

58040

扫码关注云+社区

领取腾讯云代金券