Oracle 12c multitenant database normally uses the same oracle networking files as other Oracle RDBMS implementations. This article covers the configuration of the tnsnames.ora file for connection to a CDB database cdb1.
- Connect to your oracle database server as the oracle software owner.
[larry@linux2 ~]$ su – oracle
Password:
Last login: Mon Apr 24 10:45:22 EDT 2016 on pts/1
[oracle@linux2 ~]$
- You can use the following code to create the appropriate tnsnames.ora entries in the file $ORACLE_HOME/network/admin/tnsnames.ora or manually insert into the file knowing the machine IP, Port, SID, and service name.
echo -e “CDB1 =\n” \
” (DESCRIPTION =\n” \
” (ADDRESS_LIST =\n” \
” (ADDRESS = (PROTOCOL = TCP)(HOST = “`hostname -i`”)(PORT = 1521))\n” \
” )\n” \
” (CONNECT_DATA =\n” \
” (SERVER = DEDICATED)\n” \
” (SERVICE_NAME = “$ORACLE_SID”)\n” \
” (SID = “$ORACLE_SID”)\n” \
” )\n” \
” )\n” >> $ORACLE_HOME/network/admin/tnsnames.ora
Execution Example:
[oracle@linux2 admin]$ echo -e “CDB1 =\n” \
> ” (DESCRIPTION =\n” \
> ” (ADDRESS_LIST =\n” \
> ” (ADDRESS = (PROTOCOL = TCP)(HOST = “`hostname -i`”)(PORT = 1521))\n” \
> ” )\n” \
> ” (CONNECT_DATA =\n” \
> ” (SERVER = DEDICATED)\n” \
> ” (SERVICE_NAME = “$ORACLE_SID”)\n” \
> ” (SID = “$ORACLE_SID”)\n” \
> ” )\n” \
> ” )\n” >> $ORACLE_HOME/network/admin/tnsnames.ora
[oracle@linux2 admin]
- After execution or editing, you can view the contains of the tnsnames.ora file with the cat command as shown below:
oracle@linux2 admin]$ cat tnsnames.ora
CDB1 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.30.15.75)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = cdb1)
(SID = cdb1)
)
)
- As long as the listener process and database is up and running, you can test the connection through the tnsping utility by suppling the reference name in the tnsnames.ora file. In this example the reference name is CDB1, as shown below.
[oracle@linux2 ~]$ tnsping CDB1
TNS Ping Utility for Linux: Version 12.1.0.2.0 – Production on 24-APR-2016 11:49:44
Copyright (c) 1997, 2014, Oracle. All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 10.30.15.75)(PORT = 1521))) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = cdb1) (SID = cdb1)))
OK (0 msec)
[oracle@linux2 ~]$
- This completes setup of tnsnames.ora file for CDB connection in Oracle 12c.
Larry Catt
OCP