应对归档突增情况,当达到90%时就强制删除(只保留最近20个)
-
#!/bin/bash
-
# clear older archivelog when archive file space used% > 90
-
# crontab example: */5 * * * * sh /home/oracle/scripts/clear_arch.sh
-
-
. ~/.bash_profile
-
# .~/.profile
-
-
# get arch space used
-
-
getarchused(){
-
sqlplus -s "/as sysdba" <<eof
-
set head off
-
set feedback off
-
set time off
-
set timing off
-
set echo off
-
select round((total_mb-free_mb)/total_mb*100,2) used_percent from v\$asm_diskgroup where name ='archdg';
-
exit
-
eof
-
}
-
archused=$(getarchused)
-
-
# export arch_dest='/home/ora/fast_recovery_area'
-
# archused=` df -p $arch_dest |grep /|awk '{print $5}'|sed 's/\%//g' `
-
-
if [ "${archused}" < 90 ]; then
-
exit
-
fi
-
-
getsql(){
-
sqlplus -s "/as sysdba" <<eof
-
set head off
-
set feedback off
-
set time off
-
set timing off
-
set echo off
-
select 'delete force noprompt archivelog from sequence 0 until sequence '||max(sequence# - 20)|| ' thread ' || thread# ||';'
-
from v\$archived_log group by thread#;
-
exit
-
eof
-
}
-
-
deloldarch(){
-
sql=$(getsql)
-
echo "begin deleting standby archivelog"
-
rman target / log=${logfile} append <<eof
-
$sql
-
exit;
-
eof
-
}
-
-
getrole() {
-
sqlplus -s "/as sysdba" <<eof
-
set head off
-
set feedback off
-
set echo off
-
set time off
-
set timing off
-
select database_role from v\$database;
-
exit
-
eof
-
}
-
-
role=$(getrole)
-
role=`echo ${role} |sed 's/ //g'`
-
echo $role
-
if [ "${role}" = "primary" ]; then
-
deloldarch;
-
else
-
echo "error, unable to connect to the database, try again later"
-
fi
good luck!
阅读(7486) | 评论(0) | 转发(0) |