Re: Map database to running instance from oratab?

From: Radoulov, Dimitre <>
Date: Thu, 19 Jul 2012 10:10:34 +0200
Message-ID: <>

On 18/07/2012 22.27, Ethan Post wrote:
> Anyone know of a simpler way to map the database name to the running
> instance ID? Assume we could have a non-rac database called FOO1, and a rac
> database called FOO with instance FOO2 running on the same server. Below
> fails in this case because it will find FOO1 for rac database FOO before it
> finds FOO2. Not a big deal because that is really an edge case but perhaps
> there is a single file I could grab this from someplace that I don't know
> about.
> # ASM smon process begins with asm so this script will not find an instance
> for ASM.

Hi Ethan,
definitely not simpler, but something like this may work. The code should work with bash, ksh93 and zsh. Tested with bash on Linux and RAC 11.2.

unset _crs_managed_dbs _gi_home

# set if databases managed
# by crs exist, otherwise leave
# empty


# databases managed by crs
[[ $_gi_home ]] &&


       "$_gi_home"/bin/crsctl stat res |
         fgrep .db |
           cut -d. -f2

# crs managed instances running on this host for _db in "${_crs_managed_dbs[_at_]}"; do


     "$_gi_home"/bin/srvctl status instance -d "$_db" -n "$HOSTNAME" |
       sed -n 's/Instance \(.*\) is running.*/\1/p'
   [[ $_inst_running ]] && {
     printf 'database %s: instance %s is running on %s\n' "$_db" 
"$_inst_running" "$HOSTNAME"
     # use += if avaliable


# use ps -ef ... if pgrep is not available pgrep -lf ora_smon_ |

   cut -d_ -f3 |

     while read; do
       # use -q instead of /dev/null if available
       # assuming dbname == inst_name if not crs managed
       grep "$REPLY" <( printf '%s\n' "${_crs_managed_inst[_at_]}") > 
/dev/null ||
         printf 'database %s: instance %s is running on %s\n' "$REPLY" 

Received on Thu Jul 19 2012 - 03:10:34 CDT

Original text of this message