Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3561809
  • 博文数量: 715
  • 博客积分: 1860
  • 博客等级: 上尉
  • 技术积分: 7745
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-07 08:51
个人简介

偶尔有空上来看看

文章分类

全部博文(715)

文章存档

2023年(75)

2022年(134)

2021年(238)

2020年(115)

2019年(11)

2018年(9)

2017年(9)

2016年(17)

2015年(7)

2014年(4)

2013年(1)

2012年(11)

2011年(27)

2010年(35)

2009年(11)

2008年(11)

最近访客

分类: Oracle

2021-07-07 20:39:51


应对归档突增情况,当达到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!
阅读(7636) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~