oracle 日常检查脚本

[plain]  view plain copy
  1. #!/bin/bash  
  2. sqlplus -s / as sysdba <<EOF  
  3. spool /tmp/oraclecheck/dbcheck.log  
  4. set echo off  
  5. whenever sqlerror continue;  
  6. prompt ##################################################################################################################################  
  7. prompt Database status:  
  8. col host_name for a45  
  9. col instance_name for a10  
  10. col status for a10  
  11. select  INSTANCE_NAME,host_name,status,active_state,STARTUP_TIME from  gv\$instance;  
  12. prompt  
  13. prompt ##################################################################################################################################  
  14. prompt Asm_diskgroup status and usage:  
  15. col name for a10  
  16. col state for a15  
  17. col pt_free for a5  
  18. select name,state,total_mb,free_mb,round(free_mb/total_mb,3)*100||'%' pt_free from v\$asm_diskgroup;  
  19. prompt  
  20. prompt ##################################################################################################################################  
  21. prompt Session number:  
  22. select INST_ID,count(*) from  gv\$session  group by INST_ID;  
  23. prompt  
  24. prompt ##################################################################################################################################  
  25. prompt Datafile status invalid:  
  26. col file_name for a50  
  27. select file_name,status from dba_data_files where status='INVALID';  
  28. prompt  
  29. prompt ##################################################################################################################################  
  30. prompt Tablespace usage:  
  31. col tablespace_name for a15  
  32. select  
  33. f.tablespace_name,  
  34. a.total,  
  35. f.free,  
  36. round((f.free/a.total)*100) "% Free"  
  37. from  
  38. (select tablespace_name, sum(bytes/(1024*1024)) total from dba_data_files group by tablespace_name) a,  
  39. (select tablespace_name, round(sum(bytes/(1024*1024))) free from dba_free_space group by tablespace_name) f  
  40. WHERE a.tablespace_name = f.tablespace_name(+)  
  41.       order by "% Free";  
  42. prompt  
  43. prompt ###################################################################################################################################  
  44. prompt Top 5 wait event:  
  45. col event for a60  
  46. col wait_class for a30  
  47. select *  
  48.   from (select case when event is null then 'cpu time'  
  49.                else event end enent, round(sum(wait_time + time_waited)/1000000,1) wait_time, wait_class  
  50.           from gv\$active_session_history active_session_history  
  51.          where sample_time between sysdate - 60 / 2880 and sysdate  
  52.          group by case when event is null then 'cpu time'  
  53.                else event end, wait_class  
  54.          order by 2 desc)  
  55.  where rownum <= 5  
  56.  order by 2 desc;  
  57. prompt  
  58. prompt ###################################################################################################################################  
  59. prompt If exits table lock:  
  60. col username for a10  
  61. col MACHINE for a35  
  62. col PROGRAM for a46  
  63. col owner for a10  
  64. col object_name for a30  
  65. col object_type for a10  
  66. select sid,serial#,username,MACHINE,PROGRAM,owner,object_name,object_type  
  67. from dba_objects o,  
  68. v\$locked_object l,  
  69. v\$session s  
  70. where o.object_id=l.object_id  
  71. and s.sid=l.session_id;  
  72. prompt  
  73. prompt ###################################################################################################################################  
  74. prompt If exits zombie process:  
  75. select spid from v\$process where addr not in (select paddr from v\$session);  
  76. prompt  
  77. prompt ###################################################################################################################################  
  78. prompt Objects invalid:  
  79. col owner for a15  
  80. col object_name for a30  
  81. SELECT owner, object_name, object_type FROM dba_objects WHERE status= 'INVALID';  
  82. prompt  
  83. prompt####################################################################################################################################  
  84. prompt Constraint invalid:  
  85. SELECT owner, constraint_name, table_name, constraint_type, status FROM dba_constraints WHERE status ='DISABLE';  
  86. prompt  
  87. prompt####################################################################################################################################  
  88. prompt Triggers invalid:  
  89. SELECT owner, trigger_name, table_name, status FROM dba_triggers WHERE status = 'DISABLED';  
  90. prompt  
  91. prompt####################################################################################################################################  
  92. prompt Archivelog Increate:  
  93. set numf '9999999.99'  
  94. SELECT TRUNC(FIRST_TIME) day,  
  95.        TRUNC(SUM(BLOCKS * BLOCK_SIZE) / 1024 / 1024 / 1024, 2) "size(GB/DAY)"  
  96.   FROM V\$ARCHIVED_LOG  
  97.  where TRUNC(FIRST_TIME) > sysdate - 8  
  98.    and TRUNC(FIRST_TIME) <> TRUNC(sysdate)  
  99.  GROUP BY TRUNC(FIRST_TIME)  
  100.  ORDER BY 1 DESC;  
  101. prompt  
  102. prompt  
  103. spool off  
  104. exit  
  105. EOF  
  106.   
  107.   
  108. echo "####################################################################################################################################">>/tmp/oraclecheck/dbcheck.log  
  109.   
  110. echo "The localhost disk Check:" >>/tmp/oraclecheck/dbcheck.log  
  111. df -h>>/tmp/oraclecheck/dbcheck.log  
  112.   
  113. echo " ">>/tmp/oraclecheck/dbcheck.log  
  114.   
  115. echo "The 500 line from the bottom of rac2 Alert.log abnormal Check:" >>/tmp/oraclecheck/dbcheck.log  
  116. tail -500 /opt/oracle/admin/STATRAC/bdump/alert_STATRAC2.log| egrep -i "Error|Fail|WARNING|Invalid|Global Enqueue Services|dead|ORA-" >>/tmp/oraclecheck/dbcheck.log  
  117.   
  118. echo "####################################################################################################################################">>/tmp/oraclecheck/dbcheck.log  
  119.   
  120. echo "The 500 line from the bottom of rac2 Listener.log abnormal Check:" >>/tmp/oraclecheck/dbcheck.log  
  121. tail -500 /opt/oracle/product/10.2.0/db_1/network/log/listener.log|egrep -i "Error|WARNING|Invalid|Global Enqueue Services|dead|ORA-" >>/tmp/oraclecheck/dbcheck.log  
  122.   
  123. echo "####################################################################################################################################">>/tmp/oraclecheck/dbcheck.log  
  124.   
  125. echo "The rac1 disk Check:" >>/tmp/oraclecheck/dbcheck.log  
  126. ssh rac1 'df -h'>>/tmp/oraclecheck/dbcheck.log  
  127.   
  128. echo " ">>/tmp/oraclecheck/dbcheck.log  
  129.   
  130. echo "The 500 line from the bottom of rac1 Alert.log abnormal Check" >>/tmp/oraclecheck/dbcheck.log  
  131. ssh rac1 'tail -500 /opt/oracle/admin/STATRAC/bdump/alert_STATRAC1.log| egrep -i "Error|Fail|WARNING|Invalid|Global Enqueue Services|dead|ORA-"' >> /tmp/oraclecheck/dbcheck.log  
  132.   
  133. echo "####################################################################################################################################">>/tmp/oraclecheck/dbcheck.log  
  134.   
  135. echo "The 500 line from the bottom of rac1 Listener.log abnormal Check:" >>/tmp/oraclecheck/dbcheck.log  
  136. ssh rac1 'tail -500 /opt/oracle/product/10.2.0/db_1/network/log/listener.log| egrep -i "Error|WARNING|Invalid|Global Enqueue Services|dead|ORA-"' >> /tmp/oraclecheck/dbcheck.log  
  137.   
  138.   
  139. echo "####################################################################################################################################">>/tmp/oraclecheck/dbcheck.log  
  140.   
  141. echo "The local standby disk Check:" >>/tmp/oraclecheck/dbcheck.log  
  142. ssh standby1 'df -h'>>/tmp/oraclecheck/dbcheck.log  
  143.   
  144. echo " ">>/tmp/oraclecheck/dbcheck.log  
  145.   
  146. echo "The local standby logsync Check:" >>/tmp/oraclecheck/dbcheck.log  
  147. ssh standby1 '/opt/cron/logsyncchk.sh'>>/tmp/oraclecheck/dbcheck.log  
  148.   
  149. echo "####################################################################################################################################">>/tmp/oraclecheck/dbcheck.log  
  150.   
  151. echo "The remote standby disk Check:" >>/tmp/oraclecheck/dbcheck.log  
  152. ssh standby2 'df -h'>>/tmp/oraclecheck/dbcheck.log  
  153.   
  154. echo " ">>/tmp/oraclecheck/dbcheck.log  
  155.   
  156. echo "The remote standby logsync Check:" >>/tmp/oraclecheck/dbcheck.log  
  157. ssh standby2 '/opt/cron/logsyncchk.sh'>>/tmp/oraclecheck/dbcheck.log  
  158.   
  159.   
  160. egrep -v 'SQL|Copyright|Connected to:|Oracle Database|With the Partitioning|prompt|set|whenever|col|spool off' /tmp/oraclecheck/dbcheck.log >/tmp/oraclecheck/dbcheckdone.log  
  161. mv /tmp/oraclecheck/dbcheckdone.log /tmp/oraclecheck/dbcheck.log  
  162.   
  163. echo " ">>/tmp/oraclecheck/dbcheck.log  
  164. echo "Check date: `date +"%F.%T"`" >>/tmp/oraclecheck/dbcheck.log  

 

logsyncchk.sh:

[plain]  view plain copy
  1. #!/bin/bash  
  2. export ORACLE_HOME=/opt/oracle/product/10.2.0/db_1  
  3. export ORACLE_SID=STATDG  
  4. export PATH=$ORACLE_HOME/bin:$PATH  
  5.   
  6. sqlplus / as sysdba <<EOF  
  7. set linesize 150  
  8. col name for a45  
  9. SELECT   
  10. ARCH.THREAD# "Thread",name,   
  11. ARCH.SEQUENCE# "Last Sequence Received",   
  12. APPL.SEQUENCE# "Last Sequence Applied",   
  13. (ARCH.SEQUENCE# - APPL.SEQUENCE#) "Difference"   
  14. FROM   
  15. (SELECT THREAD# ,SEQUENCE#,name FROM V\$ARCHIVED_LOG WHERE (THREAD#,FIRST_TIME ) IN (SELECT THREAD#,MAX(FIRST_TIME)     FROM V\$ARCHIVED_LOG GROUP BY THREAD#)) ARCH,  
  16. (SELECT THREAD# ,SEQUENCE# FROM V\$LOG_HISTORY WHERE (THREAD#,FIRST_TIME ) IN (SELECT THREAD#,MAX(FIRST_TIME)  
  17.       FROM V\$LOG_HISTORY GROUP BY THREAD#)) APPL   
  18. WHERE ARCH.THREAD# = APPL.THREAD#   
  19. ORDER BY 1;  
  20.   
  21. select * from v\$archive_gap;  
  22.   
  23. exit  
  24. EOF  


单独sql检查脚本:

[sql]  view plain copy
  1. <pre name="code" class="sql">set echo off  
  2. whenever sqlerror continue;  
  3. prompt #######################################################################################  
  4. prompt Database status:  
  5. col host_name for a45  
  6. col instance_name for a10  
  7. col status for a10  
  8. select  INSTANCE_NAME,host_name,status,active_state,STARTUP_TIME from  gv$instance;  
  9. prompt  
  10. prompt ########################################################################################  
  11. prompt Session number:  
  12. select INST_ID,count(*) from  gv$session  group by INST_ID;  
  13. prompt  
  14. prompt #########################################################################################  
  15. prompt Datafile status invalid:  
  16. col file_name for a50  
  17. select file_name,status from dba_data_files where status='INVALID';  
  18. prompt  
  19. prompt ##########################################################################################  
  20. prompt Tablespace usage:  
  21. col tablespace_name for a15  
  22. select  
  23. f.tablespace_name,  
  24. a.total||'M' "totol",  
  25. f.free||'M' "free",  
  26. round((f.free/a.total)*100) "% Free"  
  27. from  
  28. (select tablespace_name, sum(bytes/(1024*1024)) total from dba_data_files group by tablespace_name) a,  
  29. (select tablespace_name, round(sum(bytes/(1024*1024))) free from dba_free_space group by tablespace_name) f  
  30. WHERE a.tablespace_name = f.tablespace_name(+)  
  31.       order by "% Free";  
  32. prompt  
  33. prompt ###########################################################################################  
  34. prompt Top 5 wait event:  
  35. col event for a60  
  36. col wait_class for a30  
  37. select *  
  38.   from (select case when event is null then 'cpu time'  
  39.                else event end enent, round(sum(wait_time + time_waited)/1000000,1) wait_time, wait_class  
  40.           from v$active_session_history active_session_history  
  41.          where sample_time between sysdate - 60 / 2880 and sysdate  
  42.          group by case when event is null then 'cpu time'  
  43.                else event end, wait_class  
  44.          order by 2 desc)  
  45.  where rownum <= 5  
  46.  order by 2 desc;  
  47. prompt  
  48. prompt ############################################################################################  
  49. prompt Log file check:  
  50. col member for a50  
  51. col size for a5  
  52. select l.GROUP#,  
  53.        lf.MEMBER,  
  54.        l.SEQUENCE#,  
  55.        l.BYTES / 1024 / 1024 || 'M' "size",  
  56.        l.STATUS  
  57.   from v$log l, v$logfile lf  
  58.  where l.GROUP# = lf.GROUP#;  
  59. prompt  
  60. prompt ##############################################################################################  
  61. prompt Top 5 io SQL:  
  62. col sql for a60  
  63. SELECT sql, disk_reads, executions  
  64.   FROM (SELECT sql_text sql,  
  65.                disk_reads,  
  66.                executions,  
  67.                disk_reads / executions "Reads/Exec",  
  68.                hash_value,  
  69.                address  
  70.           FROM V$SQLAREA  
  71.          WHERE disk_reads > 1000  
  72.          ORDER BY disk_reads DESC)  
  73.  WHERE rownum <= 5;  
  74. prompt  
  75. prompt ################################################################################################  
  76. col sql for a60  
  77. select sql, cpu_time, elapsed_time  
  78.   from (select sql_text sql,  
  79.                round(cpu_time / 1000000) cpu_time,  
  80.                round(elapsed_time / 1000000) elapsed_time,  
  81.                disk_reads,  
  82.                buffer_gets,  
  83.                rows_processed  
  84.           from v$sqlarea  
  85.          order by cpu_time desc, disk_reads desc)  
  86.  where rownum < = 5;  
  87. prompt  
  88. prompt ##################################################################################################  
  89. prompt Top 10 io dbfile:  
  90. col name for a60  
  91. select *  
  92.   from (select df.name, phyrds, phywrts  
  93.           from v$filestat fs, v$dbfile df  
  94.          where fs.file# = df.file#  
  95.          order by fs.phyrds desc)  
  96.  where rownum < 11;   
  97. prompt  
  98. prompt ##################################################################################################  
  99. prompt If exits table lock:  
  100. col username for a10  
  101. col MACHINE for a35  
  102. col PROGRAM for a46  
  103. col owner for a10  
  104. col object_name for a30  
  105. col object_type for a10  
  106. select sid,serial#,username,MACHINE,PROGRAM,owner,object_name,object_type  
  107. from dba_objects o,  
  108. v$locked_object l,  
  109. v$session s  
  110. where o.object_id=l.object_id  
  111. and s.sid=l.session_id;  
  112. prompt  
  113. prompt #################################################################################################  
  114. prompt If exits zombie process:  
  115. select spid from v$process where addr not in (select paddr from v$session);  
  116. prompt    
  117. prompt   
  118. </pre><br>  
  119. <br>  
  120. <p></p>  
  121. <pre></pre>  
  122. <p></p>  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值