Re: Map database to running instance from oratab?

  • From: "Radoulov, Dimitre" <cichomitiko@xxxxxxxxx>
  • To: post.ethan@xxxxxxxxx
  • Date: Thu, 19 Jul 2012 14:58:43 +0200

On 19/07/2012 10.10, Radoulov, Dimitre wrote:
> 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.
[...]

Corrected and improved.


unset _crs_managed_dbs _gi_home _not_crs_managed
# set if databases managed
# by crs exist, otherwise leave
# empty
_gi_home=/u01/app/11.2.0/grid


# databases managed by crs
[[ $_gi_home ]] &&
   _crs_managed_dbs=(
     $(
       "$_gi_home"/bin/crsctl stat res |
         fgrep .db |
           cut -d. -f2
           )
         )
# crs managed instances running on this host
for _db in "${_crs_managed_dbs[@]}"; do
   _inst_running=$(
     "$_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
     _crs_managed_inst=(
       "${_crs_managed_inst[@]}"
       "$_inst_running"
       )
     }
done

# use ps -ef ... if pgrep is not available
_not_crs_managed=(
   $(
      grep -xvf <( printf '%s\n' "${_crs_managed_inst[@]}") <( pgrep -lf 
ora_smon_ | cut -d_ -f3 )
      )
   )

for _inst in "${_not_crs_managed[@]}"; do
   # assuming dbname == inst_name if not crs managed
   printf 'database %s: instance %s is running on %s\n' "$_inst" 
"$_inst" "$HOSTNAME"
done

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


Other related posts: