Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

 
 Home
 E-mail Us
 Oracle Articles
New Oracle Articles


 Oracle Training
 Oracle Tips

 Oracle Forum
 Class Catalog


 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Analysis
 Design
 Implementation
 Oracle Support


 SQL Tuning
 Security

 Oracle UNIX
 Oracle Linux
 Monitoring
 Remote s
upport
 Remote plans
 Remote
services
 Application Server

 Applications
 Oracle Forms
 Oracle Portal
 App Upgrades
 SQL Server
 Oracle Concepts
 Software Support

 Remote S
upport  
 Development  

 Implementation


 Consulting Staff
 Consulting Prices
 Help Wanted!

 


 Oracle Posters
 Oracle Books

 Oracle Scripts
 Ion
 Excel-DB  

Don Burleson Blog 


 

 

 


 

 

 
 

Change Oracle environment in UNIX/Linux

Oracle Database Tips by Donald BurlesonApril 28, 2015

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.

 

 

Burleson is the American Team

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals.  Feel free to ask questions on our Oracle forum.

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise. All legitimate Oracle experts publish their Oracle qualifications.

Errata?  Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:  

and include the URL for the page.


                    









Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

Remote DBA Services


 

Copyright © 1996 -  2020

All rights reserved by Burleson

Oracle ® is the registered trademark of Oracle Corporation.

 

 

��  
 
 
Oracle Training at Sea
 
 
 
 
oracle dba poster
 

 
Follow us on Twitter 
 
Oracle performance tuning software 
 
Oracle Linux poster