I use this script to delete archivelog for dataguard database running RAC.
example: /path/this_script SID
#!/bin/bash
export PATH=/bin:/usr/bin:/usr/local/bin:/usr/sbin:.:/usr/ccs/bin:/usr/ucb:/usr/openwin/bin:/u01/oracle/dba
#. $HOME/.profile
ORACLE_SID=$1
export ORAENV_ASK=NO
. /usr/local/bin/oraenv
SCRIPT_HOME=/u01/dba/bin
DATE=`date +%d%m%y_%H%M`
LOG=${SCRIPT_HOME}/logs/archive_cleanup_${ORACLE_SID}.log
rm -rf ${LOG}
cd ${SCRIPT_HOME}
touch ${LOG}
echo $PATH >${LOG}
$ORACLE_HOME/bin/sqlplus -S / as sysdba <<EOF
set pagesize 0
set feedback off
spool ${SCRIPT_HOME}/$SID_tmp.lst
select database_role from v\$database;
spool off ;
EOF
DB_ROLE=`grep -i "PHYSICAL STANDBY" ${SCRIPT_HOME}/$SID_tmp.lst |wc -l`
echo $DB_ROLE
if [ "$DB_ROLE" -eq '1' ];
then
$ORACLE_HOME/bin/sqlplus -S / as sysdba <<EOF
set pagesize 0
set feedback off
spool ${SCRIPT_HOME}/$SID_tmp.lst
select 'delete noprompt archivelog until sequence '||max(sequence#)||' thread '||thread#||';' from v\$archived_log where applied='YES' group by thread#;
spool off;
EOF
#MAX_APPLIED=`cat $SCRIPT_HOME/$SID_tmp.lst|tr -d ' '`
#echo ${MAX_APPLIED}
#MAX_APPLIED=`expr ${MAX_APPLIED} - 20`
rman target / cmdfile=$SCRIPT_HOME/$SID_tmp.lst log=${LOG}
fi
rm -rf ${SCRIPT_HOME}/$SID_tmp.lst
exit;
example: /path/this_script SID
#!/bin/bash
export PATH=/bin:/usr/bin:/usr/local/bin:/usr/sbin:.:/usr/ccs/bin:/usr/ucb:/usr/openwin/bin:/u01/oracle/dba
#. $HOME/.profile
ORACLE_SID=$1
export ORAENV_ASK=NO
. /usr/local/bin/oraenv
SCRIPT_HOME=/u01/dba/bin
DATE=`date +%d%m%y_%H%M`
LOG=${SCRIPT_HOME}/logs/archive_cleanup_${ORACLE_SID}.log
rm -rf ${LOG}
cd ${SCRIPT_HOME}
touch ${LOG}
echo $PATH >${LOG}
$ORACLE_HOME/bin/sqlplus -S / as sysdba <<EOF
set pagesize 0
set feedback off
spool ${SCRIPT_HOME}/$SID_tmp.lst
select database_role from v\$database;
spool off ;
EOF
DB_ROLE=`grep -i "PHYSICAL STANDBY" ${SCRIPT_HOME}/$SID_tmp.lst |wc -l`
echo $DB_ROLE
if [ "$DB_ROLE" -eq '1' ];
then
$ORACLE_HOME/bin/sqlplus -S / as sysdba <<EOF
set pagesize 0
set feedback off
spool ${SCRIPT_HOME}/$SID_tmp.lst
select 'delete noprompt archivelog until sequence '||max(sequence#)||' thread '||thread#||';' from v\$archived_log where applied='YES' group by thread#;
spool off;
EOF
#MAX_APPLIED=`cat $SCRIPT_HOME/$SID_tmp.lst|tr -d ' '`
#echo ${MAX_APPLIED}
#MAX_APPLIED=`expr ${MAX_APPLIED} - 20`
rman target / cmdfile=$SCRIPT_HOME/$SID_tmp.lst log=${LOG}
fi
rm -rf ${SCRIPT_HOME}/$SID_tmp.lst
exit;
Comments
Post a Comment