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

教程发布:风哥 教程分类:ITPUX技术网 更新日期:2022-02-12 浏览学习:439

[backcolor=rgb(239, 239, 239)]对于[color=rgb(142, 3, 0)]http://www.linuxidc.com/topicnews.aspx?tid=12]Oracle Data Guard 的Maximum Availability和 Maximum Performance 两种模式下的主库归档文件的删除,必须是在归档文件在备库应用以后才可以删除。[backcolor=rgb(239, 239, 239)]  对于Maximum Protection 模式,这种模式的日志是同时写到主库和备库的,所以这种模式下的主库删除归档,没有限制。 可以直接删除。[backcolor=rgb(239, 239, 239)]  那么在Maximum Availability和 Maximum Performance下,RMAN 备份归档文件的时候,如果我们加上delete input,那么如何确定归档问及爱你该不该删除。[backcolor=rgb(239, 239, 239)]在10g之前的版本,只能通过操作系统脚本的方式,在删除归档文件之前,首先对Standby端数据库的归档文件应用状态作判断,应用之后才能在Primary端执行正常删除。[backcolor=rgb(239, 239, 239)]如下为在9i中执行删除归档的脚本:[backcolor=rgb(239, 239, 239)]#!/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#<(select max(SEQUENCE#) from v\$archived_log where applied='YES') 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[backcolor=rgb(239, 239, 239)][backcolor=rgb(239, 239, 239)]在Oracle 10g 后,RMAN提供了配置归档文件删除策略: configure archivelog deletion policy[backcolor=rgb(239, 239, 239)]该策略对应两个值:[backcolor=rgb(239, 239, 239)]APPLIED ON STANDBY :设置为该值时,当通过附加的 DELETE INPUT 子句删除Standby数据库仍需要的日志时,会提示RMAN-08137错误。不过仍然可以手动地通过 DELETE ARCHIVELOG 方式删除。[backcolor=rgb(239, 239, 239)]NONE :设置为该值时,则不启用归档文件的删除策略。默认情况下就是NONE。[backcolor=rgb(239, 239, 239)] [backcolor=rgb(239, 239, 239)]我们配置一下:[backcolor=rgb(239, 239, 239)]RMAN> configure archivelog deletion policy to applied on standby;[backcolor=rgb(239, 239, 239)] [backcolor=rgb(239, 239, 239)]old RMAN configuration parameters:[backcolor=rgb(239, 239, 239)]CONFIGURE ARCHIVELOG DELETION POLICY TO APPLIED ON STANDBY;[backcolor=rgb(239, 239, 239)]new RMAN configuration parameters:[backcolor=rgb(239, 239, 239)]CONFIGURE ARCHIVELOG DELETION POLICY TO APPLIED ON STANDBY;[backcolor=rgb(239, 239, 239)]new RMAN configuration parameters are successfully stored[backcolor=rgb(239, 239, 239)]RMAN-08591: WARNING: invalid archivelog deletion policy[backcolor=rgb(239, 239, 239)] [backcolor=rgb(239, 239, 239)]这里有个警告, 解决方法,执行如下命令:[backcolor=rgb(239, 239, 239)]SQL>alter system set "_log_deletion_policy"=ALL scope=spfile sid='*';[backcolor=rgb(239, 239, 239)] [backcolor=rgb(239, 239, 239)]设置该参数以后,DB 需要重启。[backcolor=rgb(239, 239, 239)] 修改之后,我们在设置:[backcolor=rgb(239, 239, 239)]RMAN> configure archivelog deletion policy to applied on standby;[backcolor=rgb(239, 239, 239)] [backcolor=rgb(239, 239, 239)]using target database control file instead of recovery catalog[backcolor=rgb(239, 239, 239)]old RMAN configuration parameters:[backcolor=rgb(239, 239, 239)]CONFIGURE ARCHIVELOG DELETION POLICY TO APPLIED ON STANDBY;[backcolor=rgb(239, 239, 239)]new RMAN configuration parameters:[backcolor=rgb(239, 239, 239)]CONFIGURE ARCHIVELOG DELETION POLICY TO APPLIED ON STANDBY;[backcolor=rgb(239, 239, 239)]new RMAN configuration parameters are successfully stored[backcolor=rgb(239, 239, 239)] [backcolor=rgb(239, 239, 239)]RMAN> configure archivelog deletion policy to none;[backcolor=rgb(239, 239, 239)] [backcolor=rgb(239, 239, 239)]old RMAN configuration parameters:[backcolor=rgb(239, 239, 239)]CONFIGURE ARCHIVELOG DELETION POLICY TO APPLIED ON STANDBY;[backcolor=rgb(239, 239, 239)]new RMAN configuration parameters:[backcolor=rgb(239, 239, 239)]CONFIGURE ARCHIVELOG DELETION POLICY TO NONE;[backcolor=rgb(239, 239, 239)]new RMAN configuration parameters are successfully stored[backcolor=rgb(239, 239, 239)] [backcolor=rgb(239, 239, 239)]修改之后成功修改RMAN 的归档文件删除策略。

本文标签:
网站声明:本文由风哥整理发布,转载请保留此段声明,本站所有内容将不对其使用后果做任何承诺,请读者谨慎使用!
【上一篇】
【下一篇】