Saturday, April 25, 2015

Customizing the Oracle User's Environment


Linux for the Oracle DBA -Customizing the Oracle User's Environment


There are many ways to customize the Oracle user on the system.  I strongly recommend making the changes covered in this section.  Other less common customizations will be examined in Chapter 8, 'Customizing the User Environment'??.
To effectively administer the Oracle installation we that was just made, it is useful to have several environment variables set whenever a command line session is started.  The Oracle provided script oraenv is the best way to set these variables automatically. The oraenv scriptis installed in /usr/local/bin and takes values from the oratab file located in /etc.  The oratab filetypically contains an entry for each database, but in the current configuration, there is no database set up.  To use the oraenv script, set up a dummy entry in the oratab file.
The oratab file can be edited by the oracle user using vi or another text editor.  Each line in the oratab file has three elements separated by colons.  The first element is the SID, the second indicates the Oracle Home directory for that SID, and the third indicates if the database should be started and stopped by the dbstart/dbshut commands.
Edit the oratab file and add the following line:
db_11g:/u01/app/oracle/product/11.1.0/db_1:N
Though a database does not exist by the name db_11g, this entry allows us to setting up the environment for this home without having to set several variables manually.  Make sure the final element is set to N so Oracle does not attempt to start a database that is not there.
With an entry now in the oratab file, use the oraenv command to set up theour environment.  To do that, run .oraenv which causes the oraenv script to be run as part of the current shell rather than as a subprogram.
$ . oraenv

ORACLE_SID = [oracle] ? db_11g
The Oracle base for ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1 is /u01/app/oracle
 

$ echo $ORACLE_SID

db_11g

$ echo $ORACLE_HOME

/u01/app/oracle/product/11.1.0/db_1

$ echo $PATH
 

/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/oracle/bin:/u01/app/
oracle/product/11.1.0/db_1/bin

Among other things, the oraenv script sets the ORACLE_SID and ORACLE_HOME variables.  The PATH variable is also updated to include the location of the Oracle binaries. Though they could be set manually, the oraenv script is the best way to set these variables.  Since these variables should be set anytime, log in as oracle and can then add the oraenv command to the user's profile.
A user's profile, often referred to as the dot-profile, is a hidden file in their home directory that is executed when a user logs in. Since Linux uses the bash shell by default, the profile file is called .bash_profile.  Using the -a option, it can be seen in an ls listing. 
$ pwd

/home/oracle

$ ls -a

.              .bash_logout   database_11g  .gconfd          .mozilla
..             .bash_profile  .emacs        .gnome2          .viminfo
.bash_history  .bashrc        .gconf        .gnome2_private  .Xauthority

The profile can be edited with vi or another text editor.  To run oraenv when the user
logs in, add the following lines to the .bash_profile file.
ORACLE_SID=db_11g
ORAENV_ASK=NO
. oraenv
This causes the Oracle variables to be set based on the oratab entry for db_11g without any prompting.  If the variable ORAENV_ASK is changed to YES or is not set at all, there is a prompted to enter a SID when logging in.
Conclusion
There are a lot of steps to getting a system ready for Oracle.  System requirements, installed software and many settings must all be correct or Oracle will not function properly.  As these steps are reviewed, it is a good idea to take notes on what things were set to when they were found and what changes were made to prepare for Oracle.  This will make preparing future systems much easier.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.