檢測SOLARIS上的ORACLE PROCESSES的記憶體使用量
這篇文章是翻譯的,加入了一些我的例子和解釋。看原文的到直接到文章最後
目的
-------------------------
檢測SOLARIS上的ORACLE PROCESSES的記憶體使用量。
适用的範圍
--------------------------
本篇文章介紹給系統管理者或資料庫管理者,如何對ORACLE在SOLARIS系統上的記憶體使用進行監控。
對ORACLE程序類型的了解
----------------------------------------
首先需要了解的是ORACLE背景程序。
ORACLE背景程序同INSTANCE一起建立,在作業系統上的命名規則是“ora_ProcessName_SID”。SID是ORACLE_SID。例如:SID是ora817的PROCESS MONITOR背景程序的名稱是“ora_pmon_ora817”。
另外需要注意的類型是使用者或用戶端的程序。它們的命名規則同啟動程式的名稱相同。例如SQLPLUS程式的名稱就是“sqlplus”。
另一種程序類型是ORACLE的伺服器程序(server processes) 或叫影子程序(shadow processes)。server processes 接受使用者程序的請求,通路資料庫執行個體完成請求。在dedicated模式和MTS模式下,分别對應一個或多個使用者程序。命名規則是“oracleSID”,例如“oracleORA817”是ORACLE_SID為ora817的伺服器程序名。 複制内容到剪貼闆
代碼:
# ps -ef|grep ora
oracle 6372 1 0 Aug 06 ? 0:00 ora_arc1_ora817
………….
oracle 365 1 0 Jul 25 ? 0:00 ora_pmon_ora817
oracle 367 1 0 Jul 25 ? 0:01 ora_dbw0_ora817
oracle 369 1 0 Jul 25 ? 0:01 ora_lgwr_ora817
oracle 371 1 0 Jul 25 ? 0:01 ora_ckpt_ora817
oracle 373 1 0 Jul 25 ? 0:01 ora_smon_ora817
oracle 375 1 0 Jul 25 ? 0:00 ora_reco_ora817
oracle 377 1 0 Jul 25 ? 0:12 ora_snp0_ora817
oracle 379 1 0 Jul 25 ? 0:01 ora_arc0_ora817
oracle 470 463 0 Jul 25 ? 0:01 dtwm
oracle 481 1 0 Jul 25 ? 0:00 /bin/ksh /usr/dt/bin/sdtvolcheck -d -z 5 cdrom,zip,jaz,dvdrom,rmdisk
oracle 500 499 0 Jul 25 ?? 0:00 /usr/dt/bin/dtterm -C -ls
oracle 498 481 0 Jul 25 ? 0:00 /bin/cat /tmp/.removable/notify481
oracle 502 500 0 Jul 25 pts/5 0:00 -sh
oracle 7151 7150 0 10:07:03 ? 0:00 oracleora817 (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
oracle 7150 7143 0 10:07:02 pts/6 0:00 sqlplus system/manager
oracle 7152 7150 0 10:07:05 pts/6 0:00 /bin/sh
oracle 7143 7139 0 10:06:54 pts/6 0:00 -sh
oracle 6346 1 0 Aug 06 ? 0:00 /export/oracle/app/oracle/product/8.1.7/bin/tnslsnr LISTENER -inherit
root 7154 7153 0 10:07:20 pts/6 0:00 grep ora
了解ORACLE的記憶體使用
ORACLE的記憶體使用有兩種基本的使用方式:私有或共享(shared或privated)。私有類型同時隻能被單一程序所使用,而共享記憶體則可以同時被多個程序所使用(存在争用)。
最大的共享記憶體段是SGA。SGA被映射到一塊虛拟位址空間供所有背景程序和伺服器程序使用。 大多數顯示記憶體使用的程式,如“top”或“ps -lf”都不能差別共享和私有記憶體,也不能顯示出每個背景程序和伺服器程序的SGA使用。它顯示的數值可能是ORACLE使用了多次的數量,其總和可能已經大于實際通路的實體記憶體量。
為了正确檢測ORACLE的記憶體使用,我們可以利用“/usr/proc/bin/pmap”。同它相關的一個腳本是“omemuse”,即Oracle Memory Usage的意思。這個腳本調用pmap來檢測ORACLE的記憶體使用。我們可以打“omemuse h”來看詳細的介紹。腳本跟蹤指定的ORACLE程序并報告相應的私有和共享記憶體的使用大小。
背景程序使用私有記憶體的大小基本相同,因為所有的背景程序實際上隻是在對“$ORACLE_HOME/bin/oracle”的不同調用請求而已。
檢測伺服器程序的記憶體使用複雜了些,因為不同時間上的記憶體使用可能大不相同。為了得到近似的數值,我們可以在資料庫運作高峰期進行平均采樣後取均值。
ORACLE背景程序和伺服器程序使用記憶體的塊照值可以通過“omemuse SB”來獲得。此指令将顯示ORACLE所有的伺服器程序使用的私有記憶體總大小,ORACLE所有背景程序使用私有記憶體的總大小,ORACLE背景程序和伺服器程序所使用的共享記憶體的總和。最後,給出INSTANCE使用記憶體的總大小。 複制内容到剪貼闆
代碼:
$ sqlplus system/manager
SQL*Plus: Release 8.1.7.0.0 - Production on Tue Jul 30 13:04:09 2002
(c) Copyright 2000 Oracle Corporation. All rights reserved.
Connected to:
Oracle8i Enterprise Edition Release 8.1.7.0.0 – Production
With the Partitioning option
JServer Release 8.1.7.0.0 - Production
SQL> select spid,username,terminal from v$process;
SPID USERNAME TERMINAL
--------- --------------- ------------------------------
365 oracle UNKNOWN
…(details about background processes)
4141 oracle pts/2
10 rows selected.
# su - oracle
Sun Microsystems Inc. SunOS 5.8 Generic February 2000
$ cd /
$ ./memcheck S
Total Shadow (bytes) : 958464
-----
Grand Total (bytes) : 958464
$ ./memcheck B
Total Private (bytes) : 13332480
Total Shared (bytes) : 145223680
-----
Grand Total (bytes) : 158556160
$ ./memcheck SB
Total Shadow (bytes) : 958464
Total Private (bytes) : 13332480
Total Shared (bytes) : 145223680
-----
Grand Total (bytes) : 159514624
$ ./memcheck P 4141
Total Private (bytes) : 1028096
Total Shared (bytes) : 145223680
-----
Grand Total (bytes) : 146251776
關于使用pmap和檢測程序記憶體使用的更詳細資訊請參閱:
http://www.itworld.com/Comp/2402/UIR980301perf
http://www.sun.com/sun-on-net/performance/vmsizing.pdf
附錄:對應腳本 複制内容到剪貼闆
代碼:
#!/usr/bin/sh
#
# Copyright 2001 Oracle Corporation
#
# program: omemuse (Oracle MEMory USagE)
# by Richard Gulledge
#
# modification history:
# date by comments
# ---------- -------- ----------------
# 11/15/1999 rgulledg original program
# 04/16/2001 rgulledg minor usage check mods
#
usage()
{
echo "Usage: $0 [ SB ]"
echo "Usage: $0 [ P <pid> ]"
echo "Usage: $0 [ h ]"
echo " "
echo "specify 'S' for Oracle shadow processes"
echo "specify 'B' for Oracle background processes (includes shared memory SGA)"
echo "specify 'h' for help"
echo " "
}
echo " "
#
# check usage
#
if [ $# = "0" ];then
usage;exit 1
fi
Parm1=$1
if [ $Parm1 = "h" ];then
echo "This script uses the Sun Solaris pmap command to determine memory usage"
echo "for Oracle server [B]ackground processes and/or [S]hadow processes."
echo "An individual [P]rocess can also be specified."
echo " "
echo "Although the Oracle server background processes memory usage should"
echo "remain fairly constant, the memory used by any given shadow process"
echo "can vary greatly. This script shows only a snapshot of the current"
echo "memory usage for the processes specified."
echo " "
echo "The 'B' option shows the sum of memory usage for all Oracle server"
echo "background processes, including shared memory like the SGA."
echo " "
echo "The 'S' option shows the sum of private memory usage by all"
echo "shadow processes. It does not include any shared memory like the"
echo "SGA since these are part of the Oracle server background processes."
echo " "
echo "The 'P' option shows memory usage for a specified process, broken"
echo "into two categories, private and shared. If the same executable"
echo "for this process was invoked again, only the private memory"
echo "would be allocated, the rest is shared with the currently running"
echo "process."
echo " "
usage;exit 1
fi
echo $Parm1|grep '[SBP]' > /dev/null
ParmFound=$?
if [ $ParmFound != "0" ];then
usage;exit 1
fi
echo $Parm1|grep P > /dev/null
ParmFound=$?
if [ $ParmFound = "0" ];then
if [ $Parm1 != "P" ];then
usage;exit 1
fi
if [ "X$2" = "X" ];then
usage;exit 1
fi
Parm2=$2
echo $Parm2|grep '[^0-9]' > /dev/null
ParmFound=$?
if [ $ParmFound = "0" ];then
usage;exit 1
fi
PidOwner=`ps -ef | grep -v grep | grep $Parm2 | grep -v $0 | awk '{print $1}'`
CurOwner=`/usr/xpg4/bin/id -un`
if [ "X$PidOwner" != "X$CurOwner" ];then
echo "Not owner of pid $Parm2, or pid $Parm2 does not exist"
echo " "
usage;exit 1
fi
else
if [ "X${ORACLE_SID}" = "X" ];then
echo "You must set ORACLE_SID first"
usage;exit1
fi
fi
#
# initialize variables
#
Pmap="/usr/proc/bin/pmap"
SharUse="/tmp/omemuseS$$"
PrivUse="/tmp/omemuseP$$"
ShadUse="/tmp/omemuseD$$"
PidPUse="/tmp/omemusePP$$"
PidSUse="/tmp/omemusePS$$"
TotalShad=0
TotalShar=0
TotalPriv=0
PidPriv=0
PidShar=0
#
# shadow processes
#
echo $Parm1|grep S > /dev/null
ParmFound=$?
if [ $ParmFound = "0" ];then
ShadPrc="`ps -ef|grep -v grep|grep oracle$ORACLE_SID|awk '{print $2}'`"
echo "" > $ShadUse
for i in $ShadPrc;do
$Pmap $i | grep "read/write" | grep -v shared | /
awk '{print $2}' | awk -FK '{print $1}' >> $ShadUse
done
for i in `cat $ShadUse`;do
TotalShad=`expr $TotalShad + $i`
done
TotalShad=`expr $TotalShad "*" 1024`
echo "Total Shadow (bytes) : $TotalShad"
/bin/rm $ShadUse
fi
#
# non-shared portion of background processes
#
echo $Parm1|grep B > /dev/null
ParmFound=$?
if [ $ParmFound = "0" ];then
OrclPrc="`ps -ef|grep -v grep|grep ora_|grep $ORACLE_SID|awk '{print $2}'`"
BkgdPrc="`echo $OrclPrc|awk '{print $1}'`"
echo "" > $PrivUse
for i in $OrclPrc;do
$Pmap $i | grep "read/write" | grep -v shared | /
awk '{print $2}' | awk -FK '{print $1}' >> $PrivUse
done
for i in `cat $PrivUse`;do
TotalPriv=`expr $TotalPriv + $i`
done
TotalPriv=`expr $TotalPriv "*" 1024`
echo "Total Private (bytes) : $TotalPriv"
#
# shared portion of background processes
#
echo "" > $SharUse
$Pmap $BkgdPrc | grep "read/exec" | /
awk '{print $2}' | awk -FK '{print $1}' >> $SharUse
$Pmap $BkgdPrc | grep "shared" | /
awk '{print $2}' | awk -FK '{print $1}' >> $SharUse
for i in `cat $SharUse`;do
TotalShar=`expr $TotalShar + $i`
done
TotalShar=`expr $TotalShar "*" 1024`
echo "Total Shared (bytes) : $TotalShar"
/bin/rm $SharUse $PrivUse
fi
#
# non-shared portion of pid
#
echo $Parm1|grep P > /dev/null
ParmFound=$?
if [ $ParmFound = "0" ];then
echo "" > $PidPUse
$Pmap $Parm2 | grep "read/write" | grep -v shared | /
awk '{print $2}' | awk -FK '{print $1}' >> $PidPUse
for i in `cat $PidPUse`;do
PidPriv=`expr $PidPriv + $i`
done
PidPriv=`expr $PidPriv "*" 1024`
echo "Total Private (bytes) : $PidPriv"
#
# shared portion of pid
#
echo "" > $PidSUse
$Pmap $Parm2 | grep "read/exec" | awk '{print $2}' | /
awk -FK '{print $1}' >> $PidSUse
$Pmap $Parm2 | grep "shared" | awk '{print $2}' | /
awk -FK '{print $1}' >> $PidSUse
for i in `cat $PidSUse`;do
PidShar=`expr $PidShar + $i`
done
PidShar=`expr $PidShar "*" 1024`
echo "Total Shared (bytes) : $PidShar"
/bin/rm $PidPUse $PidSUse
fi
#
# Display grand total
#
Gtotal="`expr $TotalShad + $TotalPriv + $TotalShar + $PidPriv + $PidShar`"
echo " -----"
echo "Grand Total (bytes) : $Gtotal"
echo " "
----------------------
btw:我是ITPUB上的TOPXU。很高興看到另外一個ORACLE技術人員組成的論壇。CHAO_PING斑竹可能是吸引我來這裡的一個原因。翻出來以前翻譯的一篇文章,看原文請到這裡:
HTTP://METALINK.ORACLE.COM/ 文章編号:Note:153655.1