Question: How do I change my Oracle
environment in UNI/Linux? I want to change from one
instance to another instance with a Linux command.
Answer: A typical problem on any
UNIX server is quickly setting the many Oracle environment
variables necessary to change the Oracle environment to a
different database.
Oracle provides a command
script called oraenv to reset the Oracle environment, but it
often does not work properly, and most experienced DBAs know
that the following commands must be issued to change from
one ORACLE_SID to another:
export ORAENV_ASK=NO;\
export ORACLE_SID='$DB';\
.TEMPHOME/bin/oraenv;\
export ORACLE_HOME;\
export ORACLE_BASE=\
`echo ORACLE_HOME | sed -e 's:/product/.*::g'`;\
export DBA=$ORACLE_BASE/admin;\
export SCRIPT_HOME=$DBA/scripts;\
export PATH=$PATH:$SCRIPT_HOME;\
export LIB_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/lib:/usr/lib '
Most DBAs create a UNIX alias with the same name as the
ORACLE_SID. When the ORACLE_SID is entered at the
command prompt, all of the required commands are executed by
means of a shell script. Below is the login profile
code to perform this function.
*****************************************************************
# For every Oracle_SID in
/var/opt/oracle/oratab,
# create an alias using
the SID name.
# Now, entering the ORACLE_SID at the UNIX prompt will
completely set the
# UNIX environment for
that SID
#*****************************************************************
for DB
in `cat /var/opt/oracle/oratab| \
grep -v \#|grep -v \*|cut
-d":" -f1`
do
alias $DB='export ORAENV_ASK=NO; export ORACLE_SID='$DB'; .
TEMPHOME/bin/oraenv;
export ORACLE_HOME; export ORACLE_BASE=`echo
ORACLE_HOME | sed -e
's:/product/.*::g'`; export DBA=$ORACLE_BASE/admin;
xport SCRIPT_HOME=$DBA/scripts;
export PATH=$PATH:$SCRIPT_HOME; export
IB_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/lib:/usr/lib
'
done
Next, examine how this works.
First there is a FOR loop in UNIX. Decompose this
command and see what it is doing:
for DB in `cat
/var/opt/oracle/oratab|\
grep -v \#|grep -v \*|cut -d":" -f1`
The for DB in command means that the script will loop
once for each value of $DB. The argument to the for DB
in command is enclosed in graves (pronounced "gra-vees"),
which is the back-tick character (directly above the tab key
on a PC keyboard). Arguments enclosed in graves tell
UNIX to execute the command enclosed in the graves and
return the result set to UNIX. In this case, the command in
the graves does the following:
cat the
var/opt/oracle/oratab file (/etc/oratab in AIX). This
lists all databases defined on the UNIX server:
root>cat /var/opt/oracle/oratab
test9i:/u01/app/oracle/product/8.1.7_64:Y
testc1:/u01/app/oracle/product/8.1.7_64:Y
#testc2:/u01/app/oracle/product/8.1.7_64:Y
testman:/u01/app/oracle/product/8.1.7_64:Y
Next, notice the grep –v \# and the grep –v \* commands.
These ignores any lines in the oratab file that are
commented-out:
root>cat /var/opt/oracle/oratab|grep –v \#|grep –v \*
test9i:/u01/app/oracle/product/8.1.7_64:Y
testc1:/u01/app/oracle/product/8.1.7_64:Y
testman:/u01/app/oracle/product/8.1.7_64:Y
Then issue the cut -d":" -f1 command. This extracts
the first column in the oratab file using the colon ":" as
the column delimiter:
root>cat /var/opt/oracle/oratab|grep –v \#|grep –v \*|cut
–d":" –f1
test9i
testc1
testman
There
is now a list of valid $ORACLE_SID values. Inside the
for loop, create an alias with the value of $DB (The
$ORACLE_SID name), and perform all of the required changes
to reset the UNIX environment for that database.
Now
turn to the processes of dissecting complex UNIX commands.
An Oracle DBA must be able to interpret complex UNIX
commands.
|
|
Get the Complete
Oracle SQL Tuning Information
The landmark book
"Advanced Oracle
SQL Tuning The Definitive Reference" is
filled with valuable information on Oracle SQL Tuning.
This book includes scripts and tools to hypercharge Oracle 11g
performance and you can
buy it
for 30% off directly from the publisher.
|