Purge Archived Logs in Standby Database

#!/bin/ksh

. /scripts/dba/bin/SetOracleEnv

export script=`basename $0`

export tmpf=/tmp/”${script}_${vdate}.tmp”

export logtokeep=5

### Get Max sequence # applied from Primary database ###

applied_sequence=`sqlplus -silent /nolog <<EOSQL

connect / as sysdba

whenever sqlerror exit sql.sqlcode

set pagesize 0 feedback off verify off heading off echo off

select max(sequence#) from v\\$archived_log where applied = ‘YES’ and REGISTRAR=’RFS’;

exit;

EOSQL`

### Calculate the archive log # to delete ###

arch_to_del=$(($applied_sequence-$logtokeep))

#echo “applied_sequence: ” $applied_sequence

#echo “arch_to_del: “$arch_to_del

if [ -z “$arch_to_del” ]; then

echo “No rows returned from database” >> ${tmpf}

exit 0

fi

#delete old logs – current applied -5

#

rman << EORMAN >> ${tmpf}

connect target ;

#delete noprompt archivelog all completed before ‘SYSDATE-1′ ;

delete noprompt archivelog until sequence = $arch_to_del;

exit

EORMAN

echo

find /tmp/$script*.tmp -mtime +30 | xargs /bin/rm -f >> ${tmpf}

du -hs /u04/oradata/TS2PRD/flash_recovery_area/TS2STB/* >> ${tmpf}

exit

https://anargodjaev.wordpress.com/2013/10/15/script-to-delete-arch-logs-from-dataguard-when-archivelog-backups-are-taken-from-primary-database/

=====

cd
. ./setdb
applied_sequence=`sqlplus -silent /nolog <<EOSQL
connect / as sysdba
whenever sqlerror exit sql.sqlcode
set pagesize 0 feedback off verify off heading off echo off
select max(sequence#)-35 from v\\$archived_log where applied = ‘YES’ and REGISTRAR=’RFS’;
exit;
EOSQL`
export applied_sequence

tmpf=/tmp/”delete_archive_logs.tmp”
export tmpf
echo “” > $tmpf

rman << EORMAN >> ${tmpf}
connect target ;
delete noprompt archivelog until sequence = $applied_sequence;
change archivelog all crosscheck;
delete noprompt expired archivelog all;
exit
EORMAN

msub=”List of archive logs deleted from STANDBY SERVER are @”`date`
export msub

tolist=”NallapaReddy.Arveti@abc.com,somireddy.tetali@abc.com,nageswararao.macherla@abc.com”
export tolist

mailx -r noreply@abc.com -s “$msub” ${tolist} < /tmp/delete_archive_logs.tmp

=================

https://somireddy.wordpress.com/2012/07/24/how-to-purge-applied-archive-logs-from-standby-server/

PRE="set pagesize 0 \n set feedback off \n"; SS="$ORACLE_HOME/bin/sqlplus -L -S / as sysdba"
ROLE=$(echo -e “$PRE select database_role from v\$database;" | $SS)
[[ “$ROLE" != “PHYSICAL STANDBY" ]] && { echo “ERROR: database not a physical standby"; exit 1; }
THREADS=$(echo -e “$PRE select distinct thread# from v\$archived_log;" | $SS)
for THREAD in $THREADS; do
MAX_APPLIED=$(echo -e “$PRE select max(sequence#) from v\$archived_log where applied=’YES’ and thread#=$THREAD;" | $SS)
echo “delete noprompt archivelog until sequence $MAX_APPLIED thread $THREAD;"|rman target /
done

http://www.oaktable.net/content/delete-archived-logs-standby