RE: AW: Query on Linux 'top' command for oracle user

  • From: "Herring Dave - dherri" <Dave.Herring@xxxxxxxxxx>
  • To: <yong321@xxxxxxxxx>, <karlarao@xxxxxxxxx>
  • Date: Fri, 31 Dec 2010 09:47:33 -0600

I know this thread is old, but I finally got around to reviewing it and I 
thought I'd share a tip related to it, at least under Linux bash.  Having to 
lookup each pid with "ps ... -p <pid>..." is pretty slow, so I changed it 
around to be one long stream, then through the commands into 1 script to 
quickly get total memory used and the top 10 memory users:

USER=<oracle schema>
PASS=<automated lookup of schema pass>
SGA=`echo "CONNECT $USER/$PASS
SHOW SGA
EXIT" | sqlplus -s /nolog | grep "^Total System" | awk '{print $5}'`

((SGA/=1024))
# get the RSS (which is in KB) for each Oracle-owned process and remove 
SGA-shared space.

echo -n "Total memory used by $ORACLE_SID database processes: "
ps -u oracle -o rss,cmd | grep $ORACLE_SID | grep -vE '(PID|grep)' | sed -e 
's/^ *//' | awk '{SUMRSS+=($1-SGA)} END {print SUMRSS/1048576"GB\n"}' SGA=$SGA

echo "Top 10 by memory"
echo "PID   MB   COMMAND"
ps -u oracle -o pid,rss,cmd | grep $ORACLE_SID | grep -v grep | awk 
'{printf("%-5s %-4d %s\n", $1, ($2-SGA)/1024, $3)}' SGA=$SGA | sort -nr -k2,2 | 
head -10

DAVID HERRING
DBA
Acxiom Corporation
EML   dave.herring@xxxxxxxxxx
TEL   630.944.4762
MBL   630.430.5988 
1501 Opus Pl, Downers Grove, IL 60515, USA
WWW.ACXIOM.COM  

The information contained in this communication is confidential, is intended 
only for the use of the recipient named above, and may be legally privileged. 
If the reader of this message is not the intended recipient, you are hereby 
notified that any dissemination, distribution or copying of this communication 
is strictly prohibited. If you have received this communication in error, 
please resend this communication to the sender and delete the original message 
or any copy of it from your computer system. Thank you.

-----Original Message-----
From: oracle-l-bounce@xxxxxxxxxxxxx [mailto:oracle-l-bounce@xxxxxxxxxxxxx] On 
Behalf Of Yong Huang
Sent: Friday, October 22, 2010 12:08 PM
To: karlarao@xxxxxxxxx
Cc: oracle-l@xxxxxxxxxxxxx
Subject: Re: AW: Query on Linux 'top' command for oracle user

> Yes too bad it's not available on <RHEL5,

I don't know if this command can help you:

#Red Hat 4, sum of Oracle $ORACLE_SID instance process resident memory 
(supposedly private)
SGA=<number from `show sga' sqlplus command>
(for i in `ps -fu oracle | grep $ORACLE_SID | grep -v grep | awk '{print $2}'`; 
do  echo "`ps -orss= -p $i`*1024-$SGA" | bc; done) | awk '{sumrss+=$1} END 
{print sumrss}'

If the above is messed up, go to
http://yong321.freeshell.org/osnotes/FreqCmds.txt

> the same way I'm feeling  for iotop here 
> http://people.redhat.com/jolsa/iotop/ which is a very useful tool

For older Linux, just use atop:
http://www.atoptool.nl

I thought iotop was written by Guillaume Chazarain at
http://guichaz.free.fr/iotop/
But maybe they somehow work together.

Ever since kernel 2.6.18-164 added /proc/<pid>/io, it's a simple matter 
of reading and sorting. Even I can write a program to do it, called topio:
http://yong321.freeshell.org/freeware/pio.html#linux
and it's just two simple Perl scripts. No RPM is needed. Slightly before 
kernel 2.6.18-164, you may be able to have /proc/<pid>/io by configuring 
TASK_DELAY_ACCT and TASK_IO_ACCOUNTING in kernel and rebuild.

Yong Huang


      
--
//www.freelists.org/webpage/oracle-l


--
//www.freelists.org/webpage/oracle-l


Other related posts: