可以通过查询 v$archived_log的字段 applied 字段来判断,同时加上 REGISTRAR 和 name的限制条件, REGISTRAR=’RFS’ 表示 是 Remote File Server process 进程,别外加上 name is not null 是因为,通过rman crosscheck 并删除 expired的 archivelog 后 name 字段会被置空,
–sql 如下
1 2 3 4 5 6
SELECTname, SEQUENCE#, FIRST_TIME, REGISTRAR, APPLIED, NEXT_TIME, status FROM V$ARCHIVED_LOG where applied = 'YES' and REGISTRAR = 'RFS' andnameisnotnull ORDERBYSEQUENCE#;
------- 功能:删除备机被 applied 的归档日志,同时也到主库上删除这个归档日志。 #!/bin/bash #Author Francs.tan #Date 2010-12-20 ################################################ #Set Result Flag #0-Successful #1-No Archived log that have been applied by standby database #2-ERROR:Excute file clear_primary.sh #3-ERROR: File clear_primary.sh delete error #initialize variable RESULT_FLAG=0 file_num='0' export ORACLE_HOME=/opt/oracle/product/10.2.0/db_1 export PATH=${ORACLE_HOME}/bin:${PATH} export ORACLE_SID=orasid export script_dir=/home/oracle/script/clear_arch export log_dir=/home/oracle/script/clear_arch/log DATE=`date +%Y%m%d` ## Select the earliest archived log file that have been applied by standby database sqlplus -s "/as sysdba"<<EOF setecho off set head off set linesize 200 set feedback off; col name format a50; col REGISTRAR format a10; col APPLIED format a10; spool ${script_dir}/archivelog_list.txt select 'file_num=' || name from (SELECT nvl(name, '0') as name FROM V$ARCHIVED_LOG where applied = 'YES' and REGISTRAR = 'RFS' and name is not null ORDER BY SEQUENCE#) where rownum = 1; spool off; exit EOF ##Delete earliest archived log file that applied by standby database control_file=${script_dir}/archivelog_list.txt . ${control_file} if [ ${file_num} == '0' ] then echo"WARNING: No Archived log that have been applied by standby database !" | tee -a ${log_file} RESULT_FLAG=1 echo"Result Flag:${RESULT_FLAG}" | tee -a ${log_file} exit${RESULT_FLAG} fi log_file=${log_dir}/clear_log_${DATE}.log echo" begin rm archivelog file = ${file_num} * " | tee -a ${log_file} rm -f ${file_num} ##Crosscheck archivelog echo"* begin Crosscheck archivelog * " | tee -a ${log_file} . ${script_dir}/check_arc.sh >> ${log_file} ## Delete primary archived log echo"* Delete primary archived log * " | tee -a ${log_file} echo"rm -f ${file_num}" > ${script_dir}/clear_primary.sh scp ${script_dir}/clear_primary.sh [oracle@xxx.xxx.xxx.xx:${script_dir](mailto:oracle@xxx.xxx.xxx.xx:${script_dir)} ssh [oracle@xxx.xxx.xxx.xx](mailto:oracle@xxx.xxx.xxx.xx) chmod u+x ${script_dir}/clear_primary.sh ssh [oracle@xxx.xxx.xxx.xx](mailto:oracle@xxx.xxx.xxx.xx) ${script_dir}/clear_primary.sh if [ $? -ne 0 ] ####如果前一条命令执行成功,则返回非0,否则为0 then echo"*" | tee -a ${log_file} echo"ERROR:Excute file clear_primary.sh ,please check it! " | tee -a ${log_file} echo"*" | tee -a ${log_file} RESULT_FLAG=2 echo"Result Flag:${RESULT_FLAG}" | tee -a ${log_file} exit${RESULT_FLAG} fi ##rm temp files echo"* Remove temp files * " | tee -a ${log_file} rm -f ${control_file} rm -f ${script_dir}/clear_primary.sh ssh [oracle@xxx.xxx.xxx.xx](mailto:oracle@xxx.xxx.xxx.xx) rm -f ${script_dir}/clear_primary.sh if [ $? -ne 0 ] ####如果前一条命令执行成功,则返回非0,否则为0 then echo"*" | tee -a ${log_file} echo"ERROR: File clear_primary.sh delete error ,please check it! " | tee -a ${log_file} echo"*" | tee -a ${log_file} RESULT_FLAG=3 echo"Result Flag:${RESULT_FLAG}" | tee -a ${log_file} exit${RESULT_FLAG} fi echo" Remove archivelog of Primary and Standby database successfully ! *" | tee -a ${log_file} exit #end
##Clear archivelog that have been applied by standby database
05 5 * * * /home/oracle/script/clear_arch/clear_arc_orasid.sh >> /home/oracle/script/clear_arch/log/clear.log 2>&1