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.

Advertisements

About deepakguptadba

10 years of experience in Database Administrator for Oracle Database 10g//9i/8i/7.x with total 15 years’ comprehensive experience in IT , Pharma / Biotech , Manufacturing, Construction , Auto & Electronics.
This entry was posted in Uncategorized and tagged , , . Bookmark the permalink.

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

  1. Vish says:

    Here is what my .profile and .profile_setdb profiles look like.

    ==============================================

    $$cat .profile

    ##———– Manual Fill-In variables ————-

    IS_RAC=NO #YES/NO
    RAC_NODE_NO=1 #1/2/3
    ORACLE_SID=TESTDB #Instance_name if RAC for eg. DB_NAME1.

    ##———– Standard Oracle Env Variables ————-

    export ORACLE_SID
    export ORACLE_HOME=`grep “^${ORACLE_SID}:” /etc/oratab|cut -d: -f2 -s`
    export ORACLE_BASE=`echo $ORACLE_HOME|cut -dp -f1 | sed ‘s/[ /]*$//’`
    export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/lib32
    export ORAENV_ASK=YES

    #echo “Enter the database name that you want to connect to ”
    if [ $IS_RAC = “YES” ]
    then
    cat /etc/oratab | awk -F: ‘{print $1}’ | grep -v ^”#” |grep $RAC_NODE_NO > /dev/null
    else
    cat /etc/oratab | awk -F: ‘{print $1}’ | grep -v ^”#” > /dev/null
    fi

    export SCRIPTS=/u01/home/scripts
    export NLS_LANG=AMERICAN_AMERICA.WE8ISO8859P1
    export PATH=$PATH:$ORACLE_HOME/bin:/etc:/usr/local/bin:
    export ADMIN=$ORACLE_BASE/admin
    export ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
    export SHLIB_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/lib32
    export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/lib32

    ##———– Aliases ————-

    alias c=’clear’
    alias l=’ls -l|more’
    alias ll=’ls -ltr’
    alias oraup=’ps -ef|grep pmon|grep -v grep; ps -ef|grep pmon|grep -v grep|wc -l’
    alias pm=’ps -ef|grep pmon|grep -v grep; ps -ef|grep pmon|grep -v grep|wc -l’
    alias dbs=”cd $ORACLE_HOME/dbs;pwd”
    alias admin=”cd ${ORACLE_BASE}/admin;pwd”
    alias tns=”cd ${ORACLE_HOME}/network/admin;pwd”
    alias scripts=” cd ${SCRIPTS};pwd”
    alias sql=”sqlplus / as sysdba”
    alias setdb=”. ~/.profile_setdb”
    alias oh=”echo $ORACLE_HOME”
    alias sshto=”ssh camrschoralxd02″

    ##———– Aliases for Backup scripts/logfiles ————-
    alias nbs=”cd /usr/openv/netbackup/ext/db_ext/oracle/scripts;pwd”
    alias nbl=”cd /usr/openv/netbackup/logs/user_ops/dbext/oracle;pwd”

    ##———– Aliases, if RAC ————-
    if [ $IS_RAC = “YES” ]
    then
    export ASM_HOME=`cat /etc/oratab|grep -i asm|grep -v ^”#”|cut -d: -f2`
    export CRS_HOME=$ORACLE_BASE/product/crs
    export ins_len=`echo $ORACLE_SID |wc -c`
    export db_len=`expr $ins_len – 2`
    export DB_NAME=”$(echo “$ORACLE_SID” | cut -c1-$db_len)”
    export PATH=$PATH:$CRS_HOME/bin
    alias adump=”cd ${ORACLE_BASE}/admin/${DB_NAME}/adump;pwd”
    alias bdump=”cd ${ORACLE_BASE}/admin/${DB_NAME}/bdump;pwd”
    alias cdump=”cd ${ORACLE_BASE}/admin/${DB_NAME}/cdump;pwd”
    alias udump=”cd ${ORACLE_BASE}/admin/${DB_NAME}/udump;pwd”
    alias diag=”cd ${ORACLE_BASE}/admin/diag/rdbms/*/$ORACLE_SID/trace;pwd”
    alias crs=”cd ${CRS_HOME}/bin;pwd”
    alias evmd=”cd ${CRS_HOME}/log/*/evmd;pwd”
    alias crsd=”cd ${CRS_HOME}/log/*/crsd;pwd”
    alias cssd=”cd ${CRS_HOME}/log/*/cssd;pwd”
    else
    alias bdump=”cd ${ORACLE_BASE}/admin/${ORACLE_SID}/bdump;pwd”
    alias udump=”cd ${ORACLE_BASE}/admin/${ORACLE_SID}/udump;pwd”
    alias cdump=”cd ${ORACLE_BASE}/admin/${ORACLE_SID}/cdump;pwd”
    alias adump=”cd ${ORACLE_BASE}/admin/${ORACLE_SID}/adump;pwd”
    fi

    ##———– Standard Unix Env Variables ————-

    export HN=`hostname| cut -d. -f1`
    export EDITOR=vi
    export PS1='[$ORACLE_SID@$HN ] $’
    stty erase ‘^?’
    umask 022

    ##———– Standard Banner for Aliases ————-
    printf “\n\n”
    echo “Use the alias setdb to set your environment”
    echo “Aliases for adump/bdump/cdump/udump/diag/dbs/scripts/admin/tns/nbs/nbl are all set”
    printf “\n\n”
    ##——————————————————————————————

    ===========================================

    $$cat .profile_setdb

    ##———– Manual Fill-In variables ————-

    IS_RAC=NO #YES/NO
    RAC_NODE_NO=1 #1/2/3
    ORACLE_SID=TESTDB #Instance_name if RAC for eg. DB_NAME1.

    ##———– Standard Oracle Env Variables ————-

    export ORACLE_SID
    export ORACLE_HOME=`grep “^${ORACLE_SID}:” /etc/oratab|cut -d: -f2 -s`
    export ORACLE_BASE=`echo $ORACLE_HOME|cut -dp -f1 | sed ‘s/[ /]*$//’`
    export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/lib32
    export ORAENV_ASK=YES

    echo “Enter the database name that you want to connect to ”
    if [ $IS_RAC = “YES” ]
    then
    cat /etc/oratab | awk -F: ‘{print $1}’ | grep -v ^”#” |grep $RAC_NODE_NO
    else
    cat /etc/oratab | awk -F: ‘{print $1}’ | grep -v ^”#”
    fi

    . oraenv

    export SCRIPTS=/u01/home/oracle/sql_scripts
    export NLS_LANG=AMERICAN_AMERICA.WE8ISO8859P1
    export PATH=$PATH:$ORACLE_HOME/bin:/etc:/usr/local/bin:
    export ADMIN=$ORACLE_BASE/admin
    export ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
    export SHLIB_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/lib32
    export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/lib32

    ##———– Aliases ————-

    alias c=’clear’
    alias l=’ls -l|more’
    alias ll=’ls -ltr’
    alias oraup=’ps -ef|grep pmon|grep -v grep; ps -ef|grep pmon|grep -v grep|wc -l’
    alias pm=’ps -ef|grep pmon|grep -v grep; ps -ef|grep pmon|grep -v grep|wc -l’
    alias dbs=”cd $ORACLE_HOME/dbs;pwd”
    alias admin=”cd ${ORACLE_BASE}/admin;pwd”
    alias tns=”cd ${ORACLE_HOME}/network/admin;pwd”
    alias scripts=” cd ${SCRIPTS};pwd”
    alias sql=”sqlplus / as sysdba”
    alias setdb=”. ~/.profile_setdb”
    alias oh=”echo $ORACLE_HOME”
    alias sshto=”ssh camrschoralxd02″
    alias crsh=”cd /u01/home/oracle/product/crs;pwd”

    ##———– Aliases for Backup ————-
    alias nbs=”cd /usr/openv/netbackup/ext/db_ext/oracle/scripts;pwd”
    alias nbl=”cd /usr/openv/netbackup/logs/user_ops/dbext/oracle;pwd”

    ##———– Aliases, if RAC ————-
    if [ $IS_RAC = “YES” ]
    then
    export ASM_HOME=`cat /etc/oratab|grep -i asm|grep -v ^”#”|cut -d: -f2`
    export CRS_HOME=$ORACLE_BASE/product/crs
    export ins_len=`echo $ORACLE_SID |wc -c`
    export db_len=`expr $ins_len – 2`
    export DB_NAME=”$(echo “$ORACLE_SID” | cut -c1-$db_len)”
    export PATH=$PATH:$CRS_HOME/bin
    alias adump=”cd ${ORACLE_BASE}/admin/${DB_NAME}/adump;pwd”
    alias bdump=”cd ${ORACLE_BASE}/admin/${DB_NAME}/bdump;pwd”
    alias cdump=”cd ${ORACLE_BASE}/admin/${DB_NAME}/cdump;pwd”
    alias udump=”cd ${ORACLE_BASE}/admin/${DB_NAME}/udump;pwd”
    alias diag=”cd ${ORACLE_BASE}/admin/diag/rdbms/*/$ORACLE_SID/trace;pwd”
    alias crs=”cd ${CRS_HOME}/bin;pwd”
    alias evmd=”cd ${CRS_HOME}/log/*/evmd;pwd”
    alias crsd=”cd ${CRS_HOME}/log/*/crsd;pwd”
    alias cssd=”cd ${CRS_HOME}/log/*/cssd;pwd”
    else
    alias bdump=”cd ${ORACLE_BASE}/admin/${ORACLE_SID}/bdump;pwd”
    alias udump=”cd ${ORACLE_BASE}/admin/${ORACLE_SID}/udump;pwd”
    alias cdump=”cd ${ORACLE_BASE}/admin/${ORACLE_SID}/cdump;pwd”
    alias adump=”cd ${ORACLE_BASE}/admin/${ORACLE_SID}/adump;pwd”
    fi

    ##———– Standard Unix Env Variables ————-

    export HN=`hostname| cut -d. -f1`
    export EDITOR=vi
    export PS1='[$ORACLE_SID@$HN ] $’
    stty erase ‘^?’
    umask 022

    ##———– Standard Banner for Aliases ————-
    printf “\n\n”
    echo “Use the alias setdb to set your environment”
    echo “Aliases for adump/bdump/cdump/udump/diag/dbs/scripts/admin/tns/nbs/nbl are all set”
    printf “\n\n”
    printf “Your environment variables are set as below\n”
    echo “ORACLE_SID : $ORACLE_SID”
    echo “ORACLE_HOME : $ORACLE_HOME”
    printf “\n\n”
    ##——————————————————————————————

    So, whenever I login to my server, I use setdb. That will read my .profile_setdb profile, reads my oratab and gives me a list of database/Instance(if rac). I can then choose the database/instance. Makes life easier.

    — Vish.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s