本文主要是介绍每日一记:Oracle Dataguard定时清理从库已归档日志,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
作为一个合格的DBA,每次部署完DG,都应该考虑到后果,想想如果从库的归档满了该怎么办?
如果可以每天登陆服务器检查,那也是可以的。往往很多时候都会因没有及时清理归档,导致数据库出错。
那么,你需要以下这个脚本来帮你解决这个问题:
#!/bin/bash
oracle_sid=$1
applied_days=$2
dest_id=$3
export ORACLE_SID=${oracle_sid}
cd /home/oracle/xxx/rman_scripts
cat /dev/null>applied_arch_${oracle_sid}.lst
sqlplus -s "/ as sysdba"<<EOF >/dev/null
set feedback off
set pages 0
set head off
set timing off
set echo off
spool applied_arch_${oracle_sid}.lst
select 'rm -f '||name from v\$archived_log
where DEST_ID=${dest_id} and name like '%.dbf'
and SEQUENCE#<(select max(SEQUENCE#) from v\$archived_log where applied='YES')
and COMPLETION_TIME<=sysdate-${applied_days};
spool off;
exit
EOF## Exec the shell
cat /dev/null>applied_arch_${oracle_sid}.sh
cat applied_arch_${oracle_sid}.lst |grep -v spooling>applied_arch_${oracle_sid}.sh
chmod u+x applied_arch_${oracle_sid}.sh
sh applied_arch_${oracle_sid}.sh
chmod -x applied_arch_${oracle_sid}.sh
mv applied_arch_${oracle_sid}.sh ./log/rm_appl_arc_${oracle_sid}_`date +"%Y%m%d%H%M"`.logrm -f applied_arch_${oracle_sid}.lst##remove expired archive log from database
/u01/oracle/app/11.2.0/bin/rman target / nocatalog<<EOF >/dev/null
crosscheck archivelog all;
delete noprompt expired archivelog all;
exit
EOF
以上脚本参考自各路大神,本人稍稍做了修改,支持传参!
以下是在linux的crontab配置的定时任务:
[oracle@localhost rman_scripts]$ crontab -l
00 00 * * * /home/oracle/xxx/rman_scripts/delete_archived_log.sh orcl1 1 3
30 00 * * * /home/oracle/xxx/rman_scripts/delete_archived_log.sh orcl2 1 3
00 01 * * * /home/oracle/xxx/rman_scripts/delete_archived_log.sh orcl3 1 5
这篇关于每日一记:Oracle Dataguard定时清理从库已归档日志的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!