Configure Linux for multiple Oracle Database connections

You can have multiple database on a single server of any platform.    The key to this configuration is have the appropriate environmental parameter for the database you which to attach to.   This procedure demonstrates the setup of .bash_profile file to set the appropriate OS environmental parameters upon attachment as the Oracle software owner.  NOTE: This procedure was done on a Oracle Enterprise Linux server.

 

  1. Logon to your database server as the root user.

 

[larry@linux2 ~]$ su –

Password:

Last login: Wed Jan  7 08:49:18 EST 2016 on pts/1

[root@linux2 ~]#

 

  1. List the current databases running on your database server with command: ps –ef|grep smon

 

[root@linux2 ~]# ps -ef|grep smon

oracle    3793     1  0 08:47 ?        00:00:00 ora_smon_cdb1

oracle    6454     1  0 09:38 ?        00:00:00 ora_smon_orcl

root     15059 15008  0 13:44 pts/1    00:00:00 grep –color=auto smon

[root@linux2 ~]#

 

  1. From the ‘ps’ command, we can see there are two active database instance on this server: CDB1 and ORCL.   We need to adjust the .bash_profile file in the oracle software owner home directory to choose between these two instances at logon.
  2. Go to the home directory of your oracle software owner.

 

[root@linux2 ~]# cd /home/oracle

[root@linux2 oracle]#

 

  1. Now normal install of multiple databases on a single server will all use the same Oracle binaries, thus the only thing which will be different between the environmental variables will be the ORACLE_SID value. If something else is different, you can adjust the shell script below to allow for more variable definition.   In this example attach the following to end of the .bash_profile file with vi.

 

## Beginning of request for information

database=””

while [ -z “$db” ]

do

   echo “Enter database to use:”

   echo “1 – ORCL       “

   echo “2 – CDB1       “

   echo “Option > “

read db

   if [[ “$db” != “1” &&

         “$db” != “2” ]]

   then

      echo “$db” is not valid >&2

      db=””

   fi

done

## Ending of request for information </strong>

 

 

 

##Beginning of local variable definitions

if [[ $db = “1” ]]

then

   export ORACLE_SID=orcl

elif [[ $db = “2” ]]

then

   export ORACLE_SID=cdb1

else

   echo “Invalid options “

fi

## Ending of local variable definitions

 

  1. Now logon as the oracle software owner and you will be prompted to give 1 for orcl instance or 2 for cdb1. Any other options will produce nothing.

 

Choosing option 1 example:

 

[root@linux2 oracle]# su – oracle

Last login: Wed Jan  7 14:02:23 EST 2016 on pts/1

Enter database to use:

1 – ORCL

2 – CDB1

1

[oracle@linux2 ~]$ echo $ORACLE_SID

orcl

[oracle@linux2 ~]$

 

 

 

 

 

Choosing option 2 example:

 

[root@linux2 oracle]# su – oracle

Last login: Wed Jan  7 14:04:51 EST 2016 on pts/1

Enter database to use:

1 – ORCL

2 – CDB1

2

[oracle@linux2 ~]$ echo $ORACLE_SID

cdb1

[oracle@linux2 ~]$

 

 

Choosing option other than 1 or 2 example:

 

[root@linux2 oracle]# su – oracle

Last login: Wed Jan  7 14:12:24 EST 2016 on pts/1

Enter database to use:

1 – ORCL

2 – CDB1

Option >

3

3 is not valid

Enter database to use:

1 – ORCL

2 – CDB1

Option >

4

4 is not valid

Enter database to use:

1 – ORCL

2 – CDB1

Option >

 

 

 

  1. This completes setup of Linux for multiple Oracle Databases.

 

 

Larry Catt

OCP