My .bashrc

A RAC DBA needs to keep at least two sets of environment variables handy: one for the Grid/ASM home, and one for the database home. Here’s how I set up my .bashrc to make that easy.

Typing ‘DB’ sets up the environment to use the database instance, and ‘CRS’ sets up the environment for Grid and ASM. (CRS because before Grid was “Grid”, it was “Cluster Ready Services”.) Instead of hard-coding the SID on each node, I use grep and awk to pick up the SID for the currently running instance on that node.

umask 022
HOST=`hostname|cut -d. -f1`
export MANPATH=/usr/man:/usr/local/man:/usr/openwin/man
export EDITOR=/usr/bin/vim
export TERM=xterm
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
export CRS_HOME=/u01/app/11.2.0/grid
export DB_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
export OH=$ORACLE_HOME
export CH=$CRS_HOME
export OB=$ORACLE_BASE
export DH=$DB_HOME
export PBASE=/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/ccs/bin:/usr/sbin:/etc:/usr/openwin/bin:/usr/proc/bin:/home/oracle/bin
export PATH=$PBASE:$CRS_HOME/bin:$ORACLE_HOME/bin:.
export PS1='[${LOGNAME}@ ${HOST}:$ORACLE_SID]$PWD> '
#export SQLPATH=${HOME}/scripts
unset LD_LIBRARY_PATH
#this alias sets ORACLE_SID to the sid of currently running instance with name like "orcl"
alias getsid="export ORACLE_SID=`ps -ef | grep pmon | grep -i orcl | awk {'print $NF'} | sed s/ora_pmon_//g`"
#this alias sets ORACLE_SID to the sid of currently running instance with name like "ASM"
alias getasm="export ORACLE_SID=`ps -ef | grep pmon | grep -i asm | awk {'print $NF'} | awk -F_ {'print $NF'}`"
alias DB="export ORACLE_HOME=$DH;export OH=$ORACLE_HOME;export PATH=$DH/bin:$DH/OPatch:$CH/bin:$PBASE;getsid"
alias CRS="export ORACLE_HOME=$CH;export OH=$ORACLE_HOME;export PATH=$CH/bin:$CH/OPatch:$DH/bin:$PBASE;getasm"
alias cdo='cd $ORACLE_HOME'
alias sqi="sqlplus '/ as sysdba'"
alias sqa="sqlplus '/ as sysasm'"
alias ll="ls -lhtr"

What shell aliases, tricks or shortcuts do you use to make RAC administration easier? Leave your answer in the comments.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.