Oracle Data Guard 主库归档文件删除策略

对于Oracle Data Guard 的Maximum Availability和 Maximum Performance 两种模式下的主库归档文件的删除,必须是在归档文件在备库应用以后才可以删除。

  对于Maximum Protection 模式,这种模式的日志是同时写到主库和备库的,所以这种模式下的主库删除归档,没有限制。 可以直接删除。

  那么在Maximum Availability和 Maximum Performance下,RMAN 备份归档文件的时候,如果我们加上delete input,那么如何确定归档问及爱你该不该删除。

在10g之前的版本,只能通过操作系统脚本的方式,在删除归档文件之前,首先对Standby端数据库的归档文件应用状态作判断,应用之后才能在Primary端执行正常删除。

如下为在9i中执行删除归档的脚本:

#!/bin/sh
#########################################################################
#         This shell is for primary and standby database                #
#         to rm applied archivelog that before some day ago.            #
#                                                                       #
#       You can define "some day" in variables ${day_before}            #
#            This shell can be put in crontab for auto run              #
#                                                                       #
#########################################################################
 
## load profile file
. /oracle/.bash_profile
 
## Path Define
main_path=/oracle/del_appl_arc      <
----------------部署的主路径
bin_path=${main_path}/bin     
log_path=${main_path}/log     
arc_path=/oracle/arch     
 
cd ${bin_path}
 
## Initial script
touch app_arc_name.sh
chmod +x app_arc_name.sh
 
## rm applied archivelog that before ${day_before} day ago
day_before=1      1天前已经规定的日志,这个变量设置为1,你可以设置成其他。  
 
## Db info
dbuser=test
dbpwd=test
dbsid=primary
 
########## Main shell start here ##########
## load exisit archlog list to db      sqlldr将arch文件列表load到数据库中。
sqlplus ${dbuser}/${dbpwd}@${dbsid}</dev/null
drop table ${dbuser}.arc_log_list;
CREATE TABLE ${dbuser}.arc_log_list (arc_name VARCHAR2(2000));
exit;
EOF
 
ls -l ${arc_path}|awk '{print $9}' |grep arc >arc_log_list.tmp
 
echo "load data">>arc_log.ctl
echo "infile 'arc_log_list.tmp'">>arc_log.ctl
echo "replace into table arc_log_list">>arc_log.ctl
echo "fields terminated by X'09'">>arc_log.ctl
echo "(arc_name)">>arc_log.ctl
 
sqlldr ${dbuser}/${dbpwd}@${dbsid} control=arc_log.ctl log=sqlldr_run.log bad=sqlldr_badfile.bad
 
### Create shell for rm applied archive that before some day ago
sqlplus -s ${dbuser}/${dbpwd}@${dbsid}</dev/null      load数据库中的arch列表和
set feedback off         v$archived_log,找出符合条件可以删除的arch,同时生成删除脚本。
set pages 0
set head off
set timing off
set echo off
spool app_arc_name.tmp
select 'rm -f '||'${arc_path}/'||arc_name from test.arc_log_list 
intersect
select 'rm -f '||name from v\$archived_log 
where DEST_ID=1 and name like '%.arc' 
and SEQUENCE# and COMPLETION_TIME<=sysdate-${day_before};
spool
exit
EOF
 
## Exec the shell in background mode
cat app_arc_name.tmp |grep -v spooling>app_arc_name.sh
./app_arc_name.sh
mv app_arc_name.sh rm_appl_arc_`date +"%Y%m%d%H%M"`.log
 
mv rm_appl_arc*.log ${log_path}
rm app_arc_name.tmp arc_log.ctl sqlldr_run.log arc_log_list.tmp

在Oracle 10g 后,RMAN提供了配置归档文件删除策略:    configure archivelog deletion policy

该策略对应两个值:

APPLIED ON STANDBY 设置为该值时,当通过附加的 DELETE INPUT 子句删除Standby数据库仍需要的日志时,会提示RMAN-08137错误。不过仍然可以手动地通过 DELETE ARCHIVELOG 方式删除。

NONE 设置为该值时,则不启用归档文件的删除策略。默认情况下就是NONE。

  

我们配置一下:

RMAN> configure archivelog deletion policy to applied on standby;

   

old RMAN configuration parameters:

CONFIGURE ARCHIVELOG DELETION POLICY TO APPLIED ON STANDBY;

new RMAN configuration parameters:

CONFIGURE ARCHIVELOG DELETION POLICY TO APPLIED ON STANDBY;

new RMAN configuration parameters are successfully stored

RMAN-08591: WARNING: invalid archivelog deletion policy

 

这里有个警告, 解决方法,执行如下命令:

SQL>alter system set "_log_deletion_policy"=ALL scope=spfile sid='*';

 

设置该参数以后,DB 需要重启。

 

修改之后,我们在设置:

RMAN> configure archivelog deletion policy to applied on standby;

 

using target database control file instead of recovery catalog

old RMAN configuration parameters:

CONFIGURE ARCHIVELOG DELETION POLICY TO APPLIED ON STANDBY;

new RMAN configuration parameters:

CONFIGURE ARCHIVELOG DELETION POLICY TO APPLIED ON STANDBY;

new RMAN configuration parameters are successfully stored

 

RMAN> configure archivelog deletion policy to none;

 

old RMAN configuration parameters:

CONFIGURE ARCHIVELOG DELETION POLICY TO APPLIED ON STANDBY;

new RMAN configuration parameters:

CONFIGURE ARCHIVELOG DELETION POLICY TO NONE;

new RMAN configuration parameters are successfully stored

 

修改之后成功修改RMAN 的归档文件删除策略。

 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29339097/viewspace-1073327/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/29339097/viewspace-1073327/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值