归档空间使用率达到90时,及时清理脚本

5810阅读 0评论2021-07-07 brjl
分类:Oracle


应对归档突增情况,当达到90%时就强制删除(只保留最近20个)

  1. #!/bin/bash
  2. # clear older archivelog when archive file space used% > 90
  3. # crontab example: */5 * * * * sh /home/oracle/scripts/clear_arch.sh

  4. . ~/.bash_profile
  5. # .~/.profile

  6. # get arch space used

  7. getArchUsed(){
  8. sqlplus -S "/as sysdba" <<EOF
  9. set head off
  10. set feedback off
  11. set time off
  12. set timing off
  13. set echo off
  14. select round((total_mb-free_mb)/total_mb*100,2) used_percent from v\$asm_diskgroup where name ='ARCHDG';
  15. exit
  16. EOF
  17. }
  18. archUsed=$(getArchUsed)

  19. # export arch_dest='/home/ora/fast_recovery_area'
  20. # archUsed=` df -P $arch_dest |grep /|awk '{print $5}'|sed 's/\%//g' `

  21. if [ "${archUsed}" < 90 ]; then
  22. exit
  23. fi

  24. getsql(){
  25. sqlplus -S "/as sysdba" <<EOF
  26. set head off
  27. set feedback off
  28. set time off
  29. set timing off
  30. set echo off
  31. select 'delete force noprompt archivelog from sequence 0 until sequence '||max(sequence# - 20)|| ' thread ' || thread# ||';'
  32.   from v\$archived_log group by thread#;
  33. exit
  34. EOF
  35. }

  36. delOldArch(){
  37. sql=$(getsql)
  38. echo "begin deleting standby archivelog"
  39. rman target / log=${logfile} append <<EOF
  40. $sql
  41. exit;
  42. EOF
  43. }

  44. getrole() {
  45. sqlplus -S "/as sysdba" <<EOF
  46. set head off
  47. set feedback off
  48. set echo off
  49. set time off
  50. set timing off
  51. select database_role from v\$database;
  52. exit
  53. EOF
  54. }

  55. role=$(getrole)
  56. role=`echo ${role} |sed 's/ //g'`
  57. echo $role
  58. if [ "${role}" = "PRIMARY" ]; then
  59. delOldArch;
  60. else
  61. echo "error, unable to connect to the database, try again later"
  62. fi
Good Luck!
上一篇:win下自动获取一些文件
下一篇:duplicate 各项参数的含义