Oracle7 Administrator's Reference for UNIX

Contents Index Home Previous Next

Setting the Environment

The following sections explain the use of environment variables.

See Also: Chapter 6, "Environment Variables for UNIX".

Displaying and Setting Environment Variables

To display the value of an environment variable, use the echo command. For example, to display the value of ORACLE_SID, enter:

$ echo $ORACLE_SID

To set and export the value of a variable in your current session, enter:

For the Bourne or Korn shell:

$ ORACLE_SID=test
$ export ORACLE_SID

For the C shell:

% setenv ORACLE_SID test

where test is the value of the variable.

Setting a Common Environment

Oracle7 enables a DBA to set a common environment for all users and allows easy movement between databases.

The oraenv Command File

The oraenv (coraenv for the C shell) command file is created during installation. It contains values for Oracle environment variables and provides:

A common environment makes it easier for system administrators and database administrators to make changes to the physical Oracle Server system.

For example, you may need to move a database from /usr/oracle to /usr1/oracle. Without a common environment-setting routine for all users, you would have to change each user's startup file to reflect the change. With oraenv, each user profile calls the oraenv command file and the changes are made automatically.

Local bin Directory

Placing oraenv (or coraenv) and dbhome in the local bin directory, separate from the Oracle software home directory, ensures that these files are accessible to all users. It also ensures that oraenv (coraenv) continues to work even if you change the path to point to a different $ORACLE_HOME.

User Startup Files

Sample user startup files are created automatically in the $ORACLE_HOME directory during installation. These files, .login or .cshrc for the C shell, and .profile for the Bourne or Korn shell, automatically set the ORACLE_SID, ORACLE_HOME, PATH, and TERM variables for the oracle software owner. The DBA puts the oraenv or coraenv command line manually in the startup file of all other users.

Moving Between Databases

To switch from one database or instance to another, call the oraenv routine, and reply to the prompt with the sid of the desired database. Always provide the full path of the oraenv command file. For example:

$ . /usr/lbin/oraenv
ORACLE_SID= [default]? sid

Database Examples

In the following examples, it is assumed your local bin directory is called /usr/lbin and your production database is called PROD. If you prefer not to be prompted for the $ORACLE_SID at startup, set the ORAENV_ASK environment variable to no.

Note: In the examples below, ORAENV_ASK is reset to the default, yes, after oraenv is executed, to ensure that you will be prompted for a different $ORACLE_SID when you execute oraenv subsequently.

Single Instance

For the Bourne or Korn shell, replace the following line in the .profile file:

. local_bin_directory/oraenv

with the following lines:

PATH=${PATH}:/usr/lbin
ORACLE_SID=PROD
export PATH ORACLE_SID
ORAENV_ASK=NO
. oraenv
ORAENV_ASK=

For the C shell, replace the following line in the .cshrc file:

source local_bin_directory/coraenv

with the following lines:

setenv PATH ${PATH}:/usr/lbin
setenv ORACLE_SID PROD
set ORAENV_ASK = NO
source /usr/lbin/coraenv
unset ORAENV_ASK

Multiple Instances

For multiple instances, define the sid at startup.

For the Bourne or Korn shell:

PATH=${PATH}:/usr/lbin
ORACLE_SID=PROD
export PATH ORACLE_SID
SIDLIST= `awk -F: '/^[^#]/ {printf "%s ", $1}' /etc/oratab'
echo "SIDS on this machine are $SIDLIST"
ORAENV_ASK=
oraenv

For the C shell:

setenv PATH ${PATH}:/usr/lbin
setenv ORACLE_SID PROD
set sidlist = `awk -F: '/^[^#]/ {printf "%s ", $1}' /etc/oratab'
echo "SIDS on this machine are $sidlist"
unset ORAENV_ASK
source /usr/lbin/coraenv


Contents Index Home Previous Next