Finding Oracle Homes which Oracle instances are using on Linux

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.

Comments

  1. ANDREJS says:

    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.

  2. Gokhan Atil says:

    #!/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.

  3. Tanel Poder says:

    @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…

  4. Dimitre Radoulov says:

    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_}" )"
      done
  5. Simon says:

    At last… after you took a month off from blogging! ;-)

  6. Tanel Poder says:

    @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 :-)

  7. Tanel Poder says:

    @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)

  8. Dimitre Radoulov says:

    @Tanel Poder

    Hi Tanel,
    yes, that code won’t work for installations that don’t use oratab (i.e. non-standard installations).

  9. Simon says:

    @Tanel Poder

    Excellent. Looking forward to that!

  10. pfiles? man pwdx

  11. Tanel Poder says:

    @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…

Trackbacks

  1. [...] which ORACLE_HOME, so it was fun to see Tanel Poder’s recent posted on how to do this on LINUX and SOLARIS. Here is a quick summary of LINUX and SOLARIS plus HPUX and AIX as [...]

Speak Your Mind

*