Thursday, August 19, 2010

Environment setup at Oracle RAC Database Server on Linux o/s (oraenv)

I have a RAC database named “TEST”, with instances TEST1 and TEST2. The default entry in the oratab looks something like this:
TEST:/u01/app/oracle/product/11.2.0/dbhome_1:N

[oracle@oscqadb02 ~]$ . oraenv
ORACLE_SID = [QAERIE1] ? TEST --- sets the *home* correctly, but does not set the instance.

I have to do it manually

#export ORACLE_SID=TEST1

The below alias does not work because main folder depends upon database name not the instance name

alias alog='/bin/vi $ORACLE_BASE/admin/$ORACLE_SID/bdump/alert_$ORACLE_SID.log'

Here is the workaround:

Login as root

Copy the existing oraenv file to oraenvrac (whatever name) and change the owner of this file.

For example:

[root@oscqadb02 oracle]# cp /usr/local/bin/oraenv /usr/local/bin/oraenvrac

[root@oscqadb02 oracle]# chown oracle /usr/local/bin/oraenvrac

oracle@oscqadb02 ~]$ ll /usr/local/bin/oraenvrac
-rwxr-xr-x 1 oracle root 3094 Aug 18 14:14 /usr/local/bin/oraenvrac

Add the below lines at bottom of the oraenvrac file:

#To get database name:

export DB_NAME=$ORACLE_SID

#To get instance number:

len=`hostname
wc -c`
len1=`expr $len - 1`
nodenum=`hostname
cut -c$len1-$len`

#To get instance name:

export ORACLE_SID=$ORACLE_SID$nodenum

You can use following alias for view and tail the alert.log file

alias alog='/bin/vi $ORACLE_BASE/admin/$DB_NAME/bdump/alert_$ORACLE_SID.log'

alias alogt='/bin/tail -f $ORACLE_BASE/admin/$DB_NAME/bdump/alert_$ORACLE_SID.log'

# [oracle@oscqadb02 ~]$. oraenvrac
ORACLE_SID = [ABC2] ? TEST
[oracle@oscqadb02 ~]$ sid
TEST2
[oracle@oscqadb02~]

You are all set now.

1 comment:

  1. The code of getting instance number does not work for me on Linux. Can you suggest the solution

    ReplyDelete