I had a question about how to quickly identify which Oracle process runs out of which ORACLE_HOME on Linux.
I have uploaded a little script for that – it’s basically looking up all PMON process IDs and then using /proc/PID/exe link to find out where is the oracle binary of a running process located.
You may have to run this as root (as on some Linux versions I get “ls: cannot read symbolic link: Permission denied” error even when running this command as the owner of all Oracle homes (it seems to happen when your users UID and primary GID are different than thet setuid/setgid bits on the oracle binary):
oracle@linux03:~$ sudo ./findhomes.sh PID NAME ORACLE_HOME 4421 asm_pmon_+ASM /u01/app/oracle/product/11.2.0/db_1/ 4545 ora_pmon_demo112 /u01/app/oracle/product/11.2.0/dbhome_1/ 4547 ora_pmon_test112 /u01/app/oracle/product/11.2.0/dbhome_1/
You can use a similar approach on other Unixes too where the executable location or current working directory (CWD) is externalized in the /proc filesystem – or just use pmap to get this info instead.




Thanks, working under oracle user on RHEL4.
[oracle@lv-test ~]$ ./findhomes.sh
PID NAME ORACLE_HOME
7112 ora_pmon_SET2 /opt/oracle/920/
7294 ora_pmon_CL2 /opt/oracle/112/product/11.2.0/dbhome_1/
All ORACLE homes under one user.
#!/bin/bash
printf “%6s %-20s %-80s\n” “PID” “NAME” “ORACLE_HOME”
pgrep -lf _pmon_ |
while read pid pname y ; do
if [ `uname` = "SunOS" ]; then
printf “%6s %-20s %-70s\n” $pid $pname `pfiles $pid | grep dbs | sed ‘s/dbs.*//’ | uniq`
else
printf “%6s %-20s %-80s\n” $pid $pname `ls -l /proc/$pid/exe | awk -F’>’ ‘{ print $2 }’ | sed ‘s/bin\/oracle$//’ | sort | uniq`
fi
done
I have added Solaris support and a simple if-then-else structure. This should work on both Linux and Solaris 10. Unfortunately I couldn’t tested it on Linux.
@Gokhan Atil
Cool, thanks. I’ve used pmap on Solaris so far, but pfiles can do this too…
People who are copying & pasting Gokhan’s script – you probably need to replace the “fancy” quotes which WordPress put in place with regular single quotes…
Alternatively, one could use the script dbhome that Oracle provides:
pgrep -lf ora_smon | while read p a; do printf '%s %-15s => %s\n' "$p" "$a" \ "$( dbhome "${a#ora_smon_}" )" doneAt last… after you took a month off from blogging! ;-)
@Simon
Yeah, it has been very hard to find time for blogging lately – but at least I am writing something – my part of the Expert Oracle Exadata book :-)
@Dimitre Radoulov
Dimitre,
If I recall correctly then the dbhome script just greps the instance name from /etc/oratab – which may not be correct in some cases or not used at all if the DBAs use some other standard for starting/stopping instances (clusterware etc)
@Tanel Poder
Hi Tanel,
yes, that code won’t work for installations that don’t use oratab (i.e. non-standard installations).
@Tanel Poder
Excellent. Looking forward to that!
pfiles? man pwdx
@Laurent Schneider
Yep that would also work on Solaris. just like /proc/pid/cwd on Linux… Might even be faster than running pmaps or pfiles commands…
Hello Experts,
Thanks a lot, I was looking for exactly this one.
Regards,
Vallish
Thanks Vallish, I had even forgotten that I had written such an article and had such a script :-)
I did used the proc command to generate the lsinventory logs, which we always needed to upload to SR guys, The script will become handy now. Thanks for the blog
#!/bin/ksh
# Script Name — lsinventory.ksh
# Partho, Dated 14-09-2012
# Setting the env variable
# ————————————————————————————————————
## ASM / Grid lsinventory log is created automatically and is default
## Run this script as root user !
## The ASM and the db instance should be running !
## Call this Script by passing one arguments, ORACLE_SID — database name, e.g sudo ./lsinventory.ksh ABCPRD1
## lsinventory logs for both ASM and Dd are generated in the /tmp dir.
# ————————————————————————————————————
# ———————
# User Input
# ———————
if [[ $1 = "" ]]
then
print “Please Enter – ORACLE_SID”
exit 0
else
export ORACLE_SID=$1
fi
# —————————————————————————
# Determine the user which is executing this script.
# —————————————————————————
CUSER=`id |cut -d”(” -f2 | cut -d “)” -f1`
if [ "$CUSER" != "root" ]
then
print “The Script has to be executed as Root user !”
exit 0
fi
#### Grid Logfile
Grid_lsinventory=/tmp/lsinventory_grid_ASM.log
if [ -f "$Grid_lsinventory" ]
then
rm -f “$Grid_lsinventory”
fi
#### Oracle db logfile
Oracle_db_lsinventory=/tmp/lsinventory_db_$ORACLE_SID.log
if [ -f "$Oracle_db_lsinventory" ]
then
rm -f “$Oracle_db_lsinventory”
fi
### For Grid
guser_name=`ps -ef | grep pmon | grep -v perl | egrep -v grep | grep +ASM | awk ‘{print $1}’`
gpid=`ps -ef | grep pmon | grep -v perl | egrep -v grep | grep +ASM | awk ‘{print $2}’`
gohome=`ls -l /proc/$gpid/exe | awk -F’>’ ‘{ print $2 }’ | sed ‘s/bin\/oracle$//’ | sort | uniq`
# Initiate the command string
echo “Grid Home — $gohome”
if [ "$CUSER" = "root" ]
then
su – $guser_name -c “$gohome/OPatch/opatch lsinventory” >> $Grid_lsinventory
GRSTAT=$?
else
print “The Script has to be executed as Root user !”
GRSTAT=$?
fi
# —————————————————————————
# Grid Log the completion of this script.
# —————————————————————————
if [ "$GRSTAT" = "0" ]
then
GLOGMSG=”ended successfully”
else
GLOGMSG=”ended in error”
fi
#echo Script $0 >> $Grid_lsinventory
echo ==== $GLOGMSG on `date` ==== >> $Grid_lsinventory
echo >> $Grid_lsinventory
### For Oracle Db
duser_name=`ps -ef | grep pmon | grep -v perl | egrep -v grep | grep -i _pmon_$ORACLE_SID | awk ‘{print $1}’ | uniq`
dpid=`ps -ef | grep pmon | grep -v perl | egrep -v grep | grep -i _pmon_$ORACLE_SID | awk ‘{print $2}’| uniq`
dohome=`ls -l /proc/$dpid/exe | awk -F’>’ ‘{ print $2 }’ | sed ‘s/bin\/oracle$//’ | sort | uniq`
# Initiate the command string
echo “Oracle Db Home — $dohome”
if [ "$CUSER" = "root" ]
then
su – $duser_name -c “$dohome/OPatch/opatch lsinventory” >> $Oracle_db_lsinventory
DRSTAT=$?
else
print “The Script has to be executed as Root user !”
DRSTAT=$?
fi
# —————————————————————————
# Db Log the completion of this script.
# —————————————————————————
if [ "$DRSTAT" = "0" ]
then
DLOGMSG=”ended successfully”
else
DLOGMSG=”ended in error”
fi
#echo Script $0 >> $Oracle_db_lsinventory
echo ==== $DLOGMSG on `date` ==== >> $Oracle_db_lsinventory
echo >> $Oracle_db_lsinventory