How to Delete Archive logs from Standby/DR databases.
Standby / DR has 3 node RAC .Below script can be run to delete applied archive logs at Standby/DR site.
Script name: stdby_applied_archive_delete.sh
## Delete Archive logs from Standby/DR
#!/bin/ksh
PATH=$PATH:/usr/local/bin
export sid=$1
export thrd1=$2
export thrd2=$3
export thrd3=$4
export ORACLE_SID=$sid
export ORAENV_ASK=NO;
. /usr/local/bin/oraenv > /dev/null
logs=/u01/app/oracle/backups/logs/remove_arch_${sid}_$(date “+%m%d%y_%R”).log
seq=$($ORACLE_HOME/bin/sqlplus -s / as sysdba <<EOF
set heading off feedback off
select max(SEQUENCE#) from gv\$archived_log where REGISTRAR=’RFS’ and APPLIED=’YES’ and DELETED=’NO’ and thread#=$thrd1; select max(SEQUENCE#) from gv\$archived_log where REGISTRAR=’RFS’ and APPLIED=’YES’ and DELETED=’NO’ and thread#=$thrd2;
select max(SEQUENCE#) from gv\$archived_log where REGISTRAR=’RFS’ and APPLIED=’YES’ and DELETED=’NO’ and thread#=$thrd3;
EOF
)
seq1=`echo $seq | awk ‘{ print $1 }’`
seq2=`echo $seq | awk ‘{ print $2 }’`
seq3=`echo $seq | awk ‘{ print $3 }’`
seq1=$(($seq1- 500))
seq2=$(($seq2- 500))
seq3=$(($seq3- 500))
if [ $seq1 > 0 ] && [ $seq2 > 0 ] ; then
(
rman target / << EOF
list archivelog until SEQUENCE = $seq1 thread $thrd1;
list archivelog until SEQUENCE = $seq2 thread $thrd2;
list archivelog until SEQUENCE = $seq3 thread $thrd3;
delete noprompt archivelog until SEQUENCE = $seq1 thread $thrd1;
delete noprompt archivelog until SEQUENCE = $seq2 thread $thrd2;
delete noprompt archivelog until SEQUENCE = $seq3 thread $thrd3;
exit
EOF
) > $logs
fi |
No. of Parameters passed
4
First parameter is DBname, remaining 3 are instance numbers.
Parameter values:
- parameter1= ORCLP
- Parameter2=1
- Parameter3=2
- parameter4=3
How to run Manually?
sh stdby_applied_archive_delete.sh ORCLP 1 2 3
How to schedule from crontab?
15 * * * * stdby_applied_archive_delete.sh ORCLP 1 2 3 >/dev/null
see also