Note:153655.1
PURPOSE -------To determine the amount of memory being used by Oracle processes on a Solaris system.SCOPE & APPLICATION -------------------This article is intended for Solaris system administrators andDBAs working on Solaris systems, but can be used by anyone whowould like to monitor memory used by Oracle on a Solaris system.UNDERSTANDING ORACLE PROGRAM TYPES ---------------------------------- The first program type you should be aware of are the Oracleuser or client processes.These processes are created when you start aprogram which will work with an Oracle database.Common examplesof Oracle user processes are sqlplus, imp, exp, and sqlldr, butmay include many others. User processesare usually named the same asthe command you used to start the program.For example, the sqlplususer process would be named "sqlplus". The second program type you should be aware of are the Oracle shadowor server processes.Shadow processes work directly with the databaseinstance to carry out the requests from the user processes.Shadow processes may be dedicated to a single user process or partof a multi-threaded server (MTS) configuration.The shadow processesare named oracleSID, where SID is the value of ORACLE_SID.For example, any shadow process connected to the database instance"DEV" would be named "oracleDEV".The third program type you should be aware of are the Oracle background processes.These processes are created when you start a database instance.Common examples of Oracle background processes are log writer (lgwr), database writer (dbw0), system monitor (smon), process monitor (pmon), recovery (reco), and check point (ckpt), but may include others.These processes run with the name ora_ProcessName_SID, where ProcessName is the name of the background process and SID is the value of ORACLE_SID.For example, the process monitor background process for a database instance named DEV would be "ora_pmon_DEV". UNDERSTANDING ORACLE MEMORY USAGE ---------------------------------Oracle memory usage can be broken down into 2 basic types, private and shared.Private memory is used only by a single process.In contrast, shared memory is used by more than 1 process and this is where most confusion over memory usage happens.When determining how much memory Oracle is using, the shared memory segments should only be counted once for all processes sharing a given memory segment.The largest segment of shared memory with Oracle is usually the Shared Global Area (SGA).The SGA is mapped into the virtual address space for all background and shadow processes.Many programs which display memory usage, like "top" or "ps -lf" do not distinguish between shared and private memory and show the SGA usage in each background and shadow process.Subsequently, it may appear as though Oracle is using several times more memory than what is actually installed on the system.To properly determine how much memory Oracle is using, you must use a tool which separates private and shared memory.One such tool is "/usr/proc/bin/pmap".This program can be located on the Sun Solaris cdrom as part of the Solaris Extended System Utilities package SUNWesu (32-bit) or SUNWesxu (64-bit). Use the "pkgadd" command to add this package if desired.A bourne shell script (omemuse), which relies on "/usr/proc/bin/pmap", has been included below that will help simplify the process of determining Oracle memory usage for background and shadow processes.For help with invocation options, run the script with the "h" parameter: % omemuse hThe script will run pmap against Oracle processes that you specify, then report how much and what type of memory (private/shared) is being used.The amount of memory used can fluctuate greatly from one moment to the next. The value for memory returned with the omemuse script is only a snapshot and the value will change if the instance is active.To get a good estimate of memory used by the instance, you should run the omemuse script repeatedly at regular intervals while the process is under peak load to get an average value.You can now take this value and multiply it by the peak number of expected users to estimate how much memory will be needed on the system.To see a snapshot of memory usage for all Oracle background and shadow processes, invoke omemuse as follows: % omemuse SBThis will display the total private memory for all Oracle shadow processes, then the total private memory for all Oracle background processes, followed by the total shared memory used by all Oracle shadow and background processes, and finally, the grand total of all memory used by this Oracle instance.For more information about the pmap command and determining process memory usage, please refer to the following articles from Sun... http://docs.sun.com/db/doc/816-0210/6m6nb7mhj?q=pmap&a=viewhttp://www.sun.com/sun-on-net/itworld/UIR980301perf.htmlhttp://www.sun.com/sun-on-net/performance/vmsizing.pdfNote: There have been several changes made by Sun to the pmap command, including changes to the output and the meaning of some columns/options. Due to these changes the script below has been reported not to work with Solaris9.It should work for most Solaris8 systems.This script has not been tested with versions prior to Solaris8 and the results may be incorrect. === begin "omemuse" script === #!/usr/bin/sh # # Copyright 2003 Oracle Corporation # # program: omemuse (Oracle MEMory USagE) # by Richard Gulledge # # modification history: # datebycomments # ---------------------------------- # 11/15/1999rgulledgoriginal program # 04/16/2001rgulledgminor usage check mods # 03/10/2003rgulledguse "pmap -x" # 03/25/2003rgulledgallow ORACLE_SID override, show examples in help # 03/27/2003rgulledgcheck DLM shared mem mapped into lmon for OPS/RAC #usage() { echo "Usage: $0 S [ ORACLE_SID ]" echo "Usage: $0 B [ ORACLE_SID ]" echo "Usage: $0 SB [ ORACLE_SID ]" echo "Usage: $0 P processID" 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 'P' and a process ID for a specific process" echo "specify 'h' for help" echo " " echo "The 'S' and 'B' parameters can be used together or separately, but cannot" echo "be used with the 'P' option.The 'P' parameter requires a process ID." echo "The 'S' and 'B' parameters can use the optional ORACLE_SID parameter" echo "to override the setting of the environment variable ORACLE_SID." echo " " }echo " "# # initialize variables # Ps="/usr/bin/ps" Awk="/usr/bin/awk" Grep="/usr/bin/grep" Cat="/usr/bin/cat" Rm="/usr/bin/rm" Wc="/usr/bin/wc" Pmap="/usr/proc/bin/pmap -x" Id="/usr/xpg4/bin/id" PrivUse="/tmp/omemuseP$$" ShadUse="/tmp/omemuseD$$" TotalShad=0 TotalShar=0 TotalPriv=0 PidPriv=0 PidShar=0 ShadNum=0 BkgdNum=0# # check usage # if [ $# = "0" ];then usage;exit 1 fi Parm1=$1 if [ $Parm1 = "h" ];then echo "This script uses the Sun Solaris pmap command (/usr/proc/bin/pmap)" echo "to determine memory usage for Oracle Server [B]ackground processes" echo "and/or [S]hadow processes.An individual [P]rocess can also be" echo "specified." echo " " echo "The memory used by any given process can vary greatly.This script" echo "shows only a snapshot of the current memory usage for the process" echo "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 "Note that all of the background and shadow process are just" echo "different invocations of the same ORACLE_HOME/bin/oracle executable" echo "file." echo " " echo "The 'P' option shows memory usage for the 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 " " echo "Examples:" echo " " echo "To display memory usage for Oracle background processes..." echo "omemuse B" echo " " echo "To display memory usage for Oracle shadow processes..." echo "omemuse S" echo " " echo "To display memory usage for Oracle shadow and background processes..." echo "omemuse SB" echo " " echo "To display memory usage for processID 45678..." echo "omemuse P 45678" echo " " echo "To display memory usage for Oracle shadow and background processes for" echo "the database instance named \"DEVL\"..." echo "omemuse SB DEVL" echo " " exit 2 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 | $Awk '{print $1" "$2}' \
| $Grep $Parm2 | $Grep -v $0 | $Awk '{print $1}'` CurOwner=`$Id -un` CurUID=`$Id -u` if [ "X$PidOwner" = "X" ];then usage echo " " echo "pid $Parm2 does not exist" echo " " exit 1 fi if [ $CurUID != 0 ];then if [ "X$PidOwner" != "X$CurOwner" ];then usage echo " " echo "Not owner of pid $Parm2" echo " " exit 1 fi fi else if [ $# -gt 1 ];then ORACLE_SID=$2 fi if [ "X${ORACLE_SID}" = "X" ];then usage echo " " echo "You must set the ORACLE_SID environment variable, or specify the" echo "optional database instance name parameter." echo " " exit 1 else InstRunning=`$Ps -ef | $Grep ora_pmon_$ORACLE_SID | $Grep -v grep | $Wc -l` if [ $InstRunning -lt 1 ];then usage echo " " echo "The database instance \"$ORACLE_SID\" is not running" echo " " exit 1 fi InstOwner=`$Ps -ef | $Grep ora_pmon_$ORACLE_SID | $Grep -v grep \
| $Awk '{print $1}'` CurUID=`$Id -u` CurOwner=`$Id -un` if [ $CurUID != 0 ];then if [ "X$InstOwner" != "X$CurOwner" ];then usage echo " " echo "Not owner of database instance \"$ORACLE_SID\"" echo " " exit 1 fi fi fi fi# # shadow processes private # 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 "total Kb" | $Awk '{print $6}' >> $ShadUse ShadNum=`expr $ShadNum + 1` done for i in `$Cat $ShadUse`;do TotalShad=`expr $TotalShad + $i` done echo "Total Shadow (Kb) : $TotalShad (processes: $ShadNum)" $Rm $ShadUse fi# # private 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 "total Kb" | $Awk '{print $6}' >> $PrivUse BkgdNum=`expr $BkgdNum + 1` done for i in `cat $PrivUse`;do TotalPriv=`expr $TotalPriv + $i` done echo "Total Private(Kb) : $TotalPriv (processes: $BkgdNum)" $Rm $PrivUse# # shared portion of background processes # LmonPrc="`$Ps -ef | $Grep -v grep | $Grep ora_lmon_$ORACLE_SID \
| $Awk '{print $2}'`" if [ "X${LmonPrc}" != "X" ];then BkgdPrc=$LmonPrc fi TotalShar=`$Pmap $BkgdPrc | $Grep "total Kb" | $Awk '{print $5}'` echo "Total Shared (Kb) : $TotalShar" fi# # private and shared portion of pid # echo $Parm1 | $Grep P > /dev/null ParmFound=$? if [ $ParmFound = "0" ];then PidPriv=`$Pmap $Parm2 | $Grep "total Kb" | $Awk '{print $6}'` echo "Total Private(Kb) : $PidPriv" PidShar=`$Pmap $Parm2 | $Grep "total Kb" | $Awk '{print $5}'` echo "Total Shared (Kb) : $PidShar" fi# # display grand total # Gtotal="`expr $TotalShad + $TotalPriv + $TotalShar + $PidPriv + $PidShar`" echo " -----" echo "Grand Total(Kb) : $Gtotal" echo " " === end "omemuse" script ===------------------------------------------------------------------------ Accessibility of Links to External Web Sites This documentation may contain links to Web sites of other companies or organizations that Oracle Corporation does not own or control.Oracle Corporation neither evaluates nor makes any representations regarding the accessibility of these Web sites. ------------------------------------------------------------------------ RELATED DOCUMENTS -----------------http://docs.sun.com/db/doc/816-0210/6m6nb7mhj?q=pmap&a=view http://www.sun.com/sun-on-net/itworld/UIR980301perf.html http://www.sun.com/sun-on-net/performance/vmsizing.pdf
.
|