您好,登錄后才能下訂單哦!
這篇文章給大家分享的是有關單個腳本如何監控主機上所有實例的表空間利用率的內容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。
借助一個文件,存放ps –ef | grep pmon的輸出
[test]:/orasw/dba>more /orasw/dba/scripts/ db_running.log
oracle 8922 1 0 Dec 17 ? 10:48 ora_pmon_spw2005p
oracle 13535 1 0 Dec 17 ? 10:00 ora_pmon_mstrmd1p
oracle 28599 1 0 Dec 19 ? 10:39 ora_pmon_tsr2008p
oracle 7561 1 0 Dec 17 ? 11:57 ora_pmon_asa2p
oracle 6756 1 0 Dec 17 ? 11:53 ora_pmon_tsr2009p
oracle 12041 1 0 Dec 17 ? 11:01 ora_pmon_spw06p
oracle 6737 1 0 Dec 17 ? 10:57 ora_pmon_spw2003p
oracle 16046 1 0 Dec 17 ? 12:32 ora_pmon_crs2007t
oracle 5002 1 0 Dec 19 ? 10:04 ora_pmon_smart3p
shell腳本
1 遍歷該文件,將sid取出
2 遍歷sid 列表,分別執行檢查表空間sql腳本,并將結果發送給相關人員
#!/bin/ksh
db_name=`cat /orasw/dba/scripts/ db_running.log|awk 'BEGIN { FS = "_" } ; { print $3 }'|sed '/^$/d'`
echo $db_name
for k in $db_name
do
h=`ps -ef | grep pmon | grep -c $k`
echo $k
ORACLE_SID=$k; export ORACLE_SID
ORAENV_ASK=NO
. oraenv
#. oraenv
export ORACLE_HOME
# Set threshhold limit for tablespace to send alert
#
export threshold=70
export script_dir=/orasw/dba/scripts/
rm -rf $script_dir/${k}_ts.rpt
rm -rf $script_dir/${k}_chk_ts.out
cut_of_pt=$threshold
tmp_file=$script_dir/${k}_chk_ts.out
ts_stat_rpt=$script_dir/${k}_ts.rpt
sqlplus -s '/ as sysdba' @$script_dir/chk_ts.sql >> $ts_stat_rpt <<-EOF
exit
EOF
echo "TABLESPACE_NAME PCT_USED(%)" > $tmp_file
echo "-----------------------------" >> $tmp_file
cat $ts_stat_rpt | awk '{
if (int($2) > int("'$cut_of_pt'"))
print $0
}' >> $tmp_file
echo "----------------------------------" >> $ts_stat_rpt
if test -s $tmp_file
then
subject="Below TableSpaces crossed threshold limits of $cut_of_pt in $k. Please take immediate action."
echo $subject
mailx -s "$subject" ***@***.com < $tmp_file
fi
done
相應sql腳本
bash-3.2$ more chk_ts.sql
set lines 120
set pages 100
set echo off
set feedback off
set head off
col PCT_USED format a10
col tablespace_name format a20
(select t.tablespace_name tablespace_name,TO_CHAR((1 - DECODE(tsf.bytes, NULL, tsa.bytes, tsf.bytes) / tsa.bytes) * 100, '990') PCT_USED
from sys.dba_tablespaces t, sys.sm$ts_avail tsa, sys.sm$ts_free tsf
where t.tablespace_name = tsa.tablespace_name and t.tablespace_name = tsf.tablespace_name (+)
)
union
(SELECT D.TABLESPACE_NAME TABLESPACE_NAME, TO_CHAR(DECODE(A.SUM_ALLOCATE, NULL, 0, NVL(T.SUM_USED, 0) / A.SUM_ALLOCATE * 100), '990') PCT_USED
FROM DBA_TABLESPACES D,
(SELECT TABLESPACE_NAME, SUM(BYTES) SUM_ALLOCATE FROM DBA_TEMP_FILES GROUP BY TABLESPACE_NAME) A,
(SELECT TABLESPACE_NAME, SUM(BYTES_CACHED) SUM_USED FROM V$TEMP_EXTENT_POOL GROUP BY TABLESPACE_NAME) T
WHERE D.TABLESPACE_NAME = A.TABLESPACE_NAME(+)
AND D.TABLESPACE_NAME = T.TABLESPACE_NAME(+)
AND D.EXTENT_MANAGEMENT = 'LOCAL' AND D.CONTENTS = 'TEMPORARY'
)
/
感謝各位的閱讀!關于“單個腳本如何監控主機上所有實例的表空間利用率”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。