Oracle 資料表空間的監控

來源:互聯網
上載者:User

現在所有業務系統上面都部署了各種類型針對各方面的監控,那麼咱們Oracle也不例外,也需要做關於oracle方面的監控,比如執行個體的存活狀況,監聽器的存活狀況,系統的運行情況(包括,磁碟使用率,進程數,登陸系統使用者數,系統負載情況,各類型資料表空間的使用率等等)基於系統運行情況的監視軟體很多,比如nagios之類的,在此就不做使用和監控方法。但是要監控oracle執行個體的運行情況,就得一直觀察oracle的警示日誌,那麼我們可以通過使用指令碼來監控oracle執行個體的運行情況,當警示日誌中出現ORA錯誤時,立即將警示日誌中的錯誤資訊提取使用郵件和簡訊的方式發送給咱們DBA工程師。至於資料表空間的監控,由於需要瞭解資料表空間的使用率,必須使用sql語句查詢來看,僅僅依靠指令碼是不夠的,那麼我們就可以通過指令碼+sql語句來監控oracle的資料表空間。下面我分別說下監控oracle警示日誌和資料表空間的方法。
監控oracle警示日誌的方法:

1.建立profile檔案。
vim /etc/oracle.profile

#######################################################################
## oracle.profile ##
#######################################################################
EDITOR=vi;export EDITOR
ORACLE_BASE=/u01/app/oracle; export
ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1; export
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib64:/usr/lib64; export
LD_LIBRARY_PATH TNS_ADMIN=$ORACLE_HOME/network/admin;export
TNS_ADMIN NLS_LANG='American_China.ZHS16GBK'; export
NLS_LANG NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'; export
NLS_DATE_FORMAT RATAB=/etc/oratab;export
#ORATAB PATH=$PATH:$ORACLE_HOME:$ORACLE_HOME/bin:/usr/ccs/bin:/bin:/usr/bin:/usr/sbin:/
#sbin:/usr/openwin/bin:/opt/bin:.; export
PATH=$ORACLE_HOME/bin:$PATH:$HOME/bin
DBALIST="xujinhua@uniits.com,xujinhua@cbc.cn";export DBALIST
2. 編寫檢查oracle alter日誌指令碼(oracle使用者)
#!/bin/ksh
source /etc/oracle.profile
#for SID in `cat $ORACLE_HOME/sidlist`
for SID in 'orcl'
do
cd /u01/app/oracle/diag/rdbms/orcl/orcl/trace
if [ -f alert_${SID}.log ]
then
mv alert_${SID}.log alert_work.log
touch alert_${SID}.log
cat alert_work.log >> alert_${SID}.hist
grep ORA- alert_work.log > alert.err
fi
if [ `cat alert.err|wc -l` -gt 0 ]
then
mailx -s "mobile-testdb${SID} ORACLE ALERT ERRORS" $DBALIST < alert.err
fi
rm -f alert.err
rm -f alert_work.log
done
3.oracle使用者下使用crontab定期運行檢查oracle alter日誌的指令碼,即可。

監控資料表空間的方法:
由於現在資料表空間都使用自動擴充模式,在規劃資料庫的時候,都是根據業務一段時間啟動並執行資料量作參考規劃資料檔案的大小,從而決定資料檔案的個數以及初始每個資料檔案的初始大小和每次擴充的大小。那麼咱們要監控資料表空間的利用率是沒意義的,因為運行資料增長一段時間就會達到初始設定的大小,此時就會觸發警示資料表空間不足,但是事實上它會自動擴充。但是也不能說就不監控了,咱們可以定期瞭解資料表空間的使用方式,看跟咱們預估的資料檔案的大小有多少,這樣也能起到監控資料表空間的效果。 【幫客之家 http://www.bkjia.com 】

1)編寫如下指令碼:
[root@woodpecker oracle]# cat tbs_monitor.sh
#!/bin/sh
#this is a script. of monitor
#login
su - oracle -c "sqlplus / as sysdba" <<EOF

start /home/oracle/tb_check/spool.sql
exit;
EOF
#out
export ORACLE_SID=orcl
export TODAY=`date '+%Y%m%d'`
MONITOR=monitor$TODAY.lst
#mail for user
mail -s "$ORACLE_SID TABLESPACE $MONITOR" xujinhua@uniits.com < $MONITOR -- -f xujinhua@uniits.com

2)編寫如下sql:
[root@woodpecker oracle]# cat /home/oracle/tb_check/spool.sql
spool on;
set echo off
set feedback off;
set termout off;
set heading on;
set term off
column dat new_value date;
select to_char(sysdate,'yyyymmdd') dat from dual;
spool monitor&&date;

set linesize 80;
select d.tablespace_name,space sum_space,
       space-nvl(free_space,0) used_space,
       round((1-nvl(free_space,0)/space)*100,2) used_rate,
       free_space free_space
      from (select tablespace_name,
                   round(sum(bytes)/(1024*1024),2) space,
                   sum(blocks) blocks
           from dba_data_files
                  group by tablespace_name) d,
           (select tablespace_name,
                  round(sum(bytes)/(1024*1024),2) free_space
           from dba_free_space
                  group by tablespace_name) f
           where d.tablespace_name = f.tablespace_name(+);

spool off;
exit;

3)通過系統的crontab定時每天調度一次指令碼即可每天告訴給dba資料庫的所有資料表空間的使用方式。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.