DB version: 11.2.0.4, 12.1
OS : Oracle Linux/RHEL 6.5
On a DB server with multiple instances running, my collegue wanted to add the environment variables ORACLE_SID and ORACLE_HOME of the most frequently accessed DB in .bash_profile file. But, I said this is a bad practice and advised to use oraenv script rather that hardcoding Oracle related environment variables in .bash_profile file.
On servers where more that one instances are running, I had trouble in the past due to setting ORACLE_HOME, ORACLE_SID for a particular DB in .bash_profile . This is because environment values set by .bash_profile somehow overrides environment variables.
To prove this to my colleagues, I tried to reproduce the error I encountered few years back. Below are two attempts I made. But, I couldn't reproduce the error. Have you guys encountered any issues due to setting ORACLE environment values in .bash_profile ? If so, please let me know.
Attempt1 to show that setting ORACLE_HOME, ORACLE_SID in .bash_profile is bad .
--- But it failed as everything seems to be working fine.
I am hardcoding ORACLE_HOME to mumboJumbo in .bash_profile file. But, later .oraenv file overrides it .
But, I remember 2 years back , I had an issue due to this.
root@10.194.135.176's password:
Last failed login: Tue Apr 5 23:32:44 MYT 2016 from 10.194.135.1 on ssh:notty
There were 2 failed login attempts since the last successful login.
Last login: Tue Apr 5 20:27:05 2016 from 10.194.135.1
[root@brcfwst176 ~]#
[root@brcfwst176 ~]#
[root@brcfwst176 ~]#
[root@brcfwst176 ~]# cat /home/oracle/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin
export PATH
export ORACLE_HOME=mumboJumbo
[root@brcfwst176 ~]#
[root@brcfwst176 ~]#
[root@brcfwst176 ~]# su - oracle
Last login: Tue Apr 5 20:28:19 MYT 2016 on pts/0
[oracle@brcfwst176 ~]$
[oracle@brcfwst176 ~]$
[oracle@brcfwst176 ~]$ echo $ORACLE_HOME
mumboJumbo
[oracle@brcfwst176 ~]$
[oracle@brcfwst176 ~]$
[oracle@brcfwst176 ~]$ cat /etc/oratab
#
BRCFMS:/u01/app/oracle/product/12.1.0/dbhome_1:N
[oracle@brcfwst176 ~]$
[oracle@brcfwst176 ~]$ . oraenv
ORACLE_SID = [oracle] ? BRCFMS
The Oracle base has been set to /u01/app/oracle
[oracle@brcfwst176 ~]$
[oracle@brcfwst176 ~]$
[oracle@brcfwst176 ~]$ echo $ORACLE_HOME
/u01/app/oracle/product/12.1.0/dbhome_1 ----------- > ORACLE_HOME set by .bash_profile is overridden by oraenv's sourcing
[oracle@brcfwst176 ~]$
[oracle@brcfwst176 ~]$ echo $ORACLE_SID
BRCFMS
[oracle@brcfwst176 ~]$
[oracle@brcfwst176 ~]$ sqlplus / as sysdba
SQL*Plus: Release 12.1.0.2.0 Production on Tue Apr 5 23:33:59 2016
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area 524288000 bytes
Fixed Size 2926320 bytes
Variable Size 432015632 bytes
Database Buffers 83886080 bytes
Redo Buffers 5459968 bytes
Database mounted.
Database opened.
SQL>
--- Attempt2
--- Rather than using oraenv script, I am setting the environment variables manually inside the su -c block as shown below
--- Adding the bad entry ORACLE_HOME=mumboJumbo
---- But, later when I switch user to oracle and set the ORACLE_SID and ORACLE_HOME variables, it seems to be working fine.
[root@cdrpvrac198 ~]# cat /home/oracle/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
export ORACLE_HOME=mumboJumbo
[root@cdrpvrac198 ~]#
As root, I am executing the following and it seems to working fine now. But, I had trouble because of this in the past.
[root@cdrpvrac198 ~]# su -l oracle -c 'export ORACLE_SID=ORCL1;export ORACLE_HOME=/u01/product/oracle/11.2.0;export PATH=$PATH:$ORACLE_HOME/bin;srvctl status database -d ORCL'
Instance ORCL1 is running on node cdrpvrac198
Instance ORCL2 is running on node cdrpvrac199