Category Archives: tnsnames

ORACLE 12c – Configure server and client network for database

Oracle Net Services are the elements that provides connection for distributed services. This article covers the methods of: Oracle Net; Local Naming Method; Easy Connect Naming Method; Directory Naming Method; and External Naming Methods

 

 

Oracle Net Method:

Oracle Net acts as the data courier, it establishes and maintains the connection between client and server.   In Oracle Net configuration a client is setup to connect to a listener process on the server via an alias name in the configuration file.   The Listener process on the server performs connection to database and client.  Oracle Net Services can handle non Oracle data source connections such as SQL Server, DB2 and external code libraries through EXTPROC.  Database server receives initial connection through the Listener and then hands off connection from client to a server process, once handoff has occurred the client communicates directly with database server.   Listener failure will not stop currently connected sessions, only new ones.  Client must configure a descriptor to give the database location, service name and port.  In order to connect, the tnsnames.ora file descriptor must have a matching entry in listener.ora of the listener process on server.

 

There are several other types of network connections besides Oracle Net:

  1. Java Application Connections
  2. Web Client connections by Application Web Server.
  3. OCI

 

 

Client TNSNAMES.ORA file:

 

ORCL =

  (DESCRIPTION =

    (ADDRESS_LIST =

      (ADDRESS = (PROTOCOL = TCP)

(HOST = mylinux.localdomain.com)

(PORT = 1521))

    )

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = ORCL)

      (SID = ORCL)

    )

  )

 

Address Section:

Protocol – defines protocal being used by listener device, TCP is for TCP/IP

Host – can use name or IP, identifies IP of Listener

Port – Defines port listener is listening on, default is 1521

Connect data Section:

SID – Name of SID for database you wish to connect to.

SERVICE_NAME – Name given in the SERVICE_NAMES initialization parameter is the global database name.

INSTANCE_NAME – Id the database instance, it is optional and default is the SID.

DEDICATED SERVER – listener will start a dedicated server process for each incoming connection.  Each client will have its own server process which will terminate upon exit of the session.

 

Steps for listener connection:

  1. Listener receives client request.
  2. Listener starts dedicated server process and passes connection request to process.
  3. Client now connected directly to server process.
  4. Server process checks client’s credentials for authentication.
  5. If credentials are good, session is created for client.

 

 

Local Naming Method:

Local naming method uses TNSNAMES.ORA file to provide client with connection address, file is normally located in $ORACLE_HOME/network/admin

 

Easy Connect Naming Method:

Bypasses lookup in TNSNAMES.ORA file and uses simple string to connect to database server.  You can use Easy Connect if the following conditions are met:

  1. Oracle Net Services software installed
  2. TCP/IP supported on server and client.
  3. No add-ons like external procedure calls or heterogeneous services exist.
  4. EZCONNECT is listed in NAMES.DIRECTORY_PATH of SQLNET.ORA file.

 

CONNECT username/password@host/ORCL

 

Directory Naming Method:

Uses LDAP compliant technology such as Oracle Internet Directory, connection are mapped to connection descriptors in directory server.   LDAP server provides central management of network connection services.  Directory service is created during database creation and use EM Cloud or Oracle Net Manager to configure client for directory method.

 

External Naming Methods:

Third part method such as Network Information Services (NIS), allows client to resolve service to network service name and prevents local configuration of database connections.

 

 

Larry Catt

OCP

Configure tnsnames.ora file for PDB

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 PDB database cdb1.

 

  1. 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 ~]$

 

  1. 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.

 

NOTE:  You have to edit the parameter SERVICE_NAME and Alias, in below example they are pdb1 and PDB1 respectively.   PDBs do not have SID listings because they are Services which are contained within a CDB and only CDBs have SIDs in multitenant architecture.

 

echo -e “PDB1 =\n” \

”  (DESCRIPTION =\n” \

”    (ADDRESS_LIST =\n” \

”      (ADDRESS = (PROTOCOL = TCP)(HOST = “`hostname -i`”)(PORT = 1521))\n” \

”    )\n” \

”    (CONNECT_DATA =\n” \

”      (SERVER = DEDICATED)\n”  \

”      (SERVICE_NAME = pdb1)\n” \

”      (SID = “$ORACLE_SID”)\n” \

”    )\n” \

”  )\n” >> $ORACLE_HOME/network/admin/tnsnames.ora

 

Execution Example:

 

[oracle@linux2 admin]$ echo -e “PDB1 =\n” \

> ”  (DESCRIPTION =\n” \

> ”    (ADDRESS_LIST =\n” \

> ”      (ADDRESS = (PROTOCOL = TCP)(HOST = “`hostname -i`”)(PORT = 1521))\n” \

> ”    )\n” \

> ”    (CONNECT_DATA =\n” \

> ”      (SERVER = DEDICATED)\n”  \

> ”      (SERVICE_NAME = pdb1)\n” \

> ”      (SID = “$ORACLE_SID”)\n” \

> ”    )\n” \

> ”  )\n” >> $ORACLE_HOME/network/admin/tnsnames.ora

[oracle@linux2 admin]

 

 

  1. 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)

     )

   )

 

PDB1 =

   (DESCRIPTION =

     (ADDRESS_LIST =

       (ADDRESS = (PROTOCOL = TCP)(HOST = 10.30.15.75)(PORT = 1521))

     )

     (CONNECT_DATA =

       (SERVER = DEDICATED)

       (SERVICE_NAME = pdb1)

       (SID = cdb1)

     )

   )

 

[oracle@linux2 admin]$

  1. As long as the listener processes is started, the container database is up and running, and the respective PDB is up; you can test the connection through the tnsping utility by suppling the reference alias name in the tnsnames.ora file. In this example the reference name is PDB1, as shown below.

 

[oracle@linux2 admin]$ tnsping PDB1

 

TNS Ping Utility for Linux: Version 12.1.0.2.0 – Production on 24-APR-2016 11:56:34

 

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 = pdb1) (SID = cdb1)))

OK (0 msec)

[oracle@linux2 admin]$

 

  1. This completes setup of tnsnames.ora file for PDB connection in Oracle 12c.

 

Larry Catt

OCP

 

Oracle 12c – Troubleshoot network issues

Troubleshooting of Oracle networking issues can be a bit more complicated than a general database issue because it involves the client configuration, network, and server configuration.   On the client side we have determine the method used for connection and that all the parameter used to resolve the server side connection are correct.   Ensuring the network connection from the client machine to the server is also critical and will normally include network administrative support.   Finally, on the server side, the listener process must be properly configured to accept client connection requests and pass them to the appropriate server process.    The entire process of determining the solution to an Oracle networking issue can be very convoluted.   It helps to eliminate first what is not the problem.   This article outlines steps to address networking issues in a systematic process.    It addresses the three areas of network issues separately and if all work should make for a fluid network connection between oracle client and oracle database server.    It is assumed that the network connection has worked in the past and all appropriate files have been configured.

 

Server side network troubleshooting:

  1. Logon to your oracle database server as the oracle software owner.

 

[larry@linux2 ~]$ su – oracle

Password:

Last login: Thu Jan  5 07:25:33 EST 2015 on pts/1

Enter database to use:

1 – ORCL

2 – CDB1

Option >

1

[oracle@linux2 ~]$

 

  1. Verify that the listener process is running with the command lsnrctl status.

 

[oracle@linux2 ~]$ lsnrctl status

LSNRCTL for Linux: Version 12.1.0.2.0 – Production on 05-JAN-2015 10:46:48

Copyright (c) 1991, 2014, Oracle.  All rights reserved.

 

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.102)(PORT=1521)))

TNS-12541: TNS:no listener

 TNS-12560: TNS:protocol adapter error

  TNS-00511: No listener

   Linux Error: 111: Connection refused

[oracle@linux2 ~]$

 

  1. The listener process is not running start the process with lsnrctl start.

 

[oracle@linux2 ~]$ lsnrctl start

LSNRCTL for Linux: Version 12.1.0.2.0 – Production on 05-JAN-2015 10:47:01

Copyright (c) 1991, 2014, Oracle.  All rights reserved.

Starting /opt/app/oracle/product/12.1.0.2/db_1/bin/tnslsnr: please wait…

 

TNSLSNR for Linux: Version 12.1.0.2.0 – Production

System parameter file is /opt/app/oracle/product/12.1.0.2/db_1/network/admin/listener.ora

Log messages written to /opt/app/oracle/diag/tnslsnr/linux2/listener/alert/log.xml

Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.0.102)(PORT=1521)))

 

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.102)(PORT=1521)))

STATUS of the LISTENER

————————

Alias                     LISTENER

Version                   TNSLSNR for Linux: Version 12.1.0.2.0 – Production

Start Date                05-JAN-2015 10:47:01

Uptime                    0 days 0 hr. 0 min. 0 sec

Trace Level               off

Security                  ON: Local OS Authentication

SNMP                      OFF

Listener Parameter File   /opt/app/oracle/product/12.1.0.2/db_1/network/admin/listener.ora

Listener Log File         /opt/app/oracle/diag/tnslsnr/linux2/listener/alert/log.xml

Listening Endpoints Summary…

  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.0.102)(PORT=1521)))

Services Summary…

Service “cdb1” has 1 instance(s).

  Instance “cdb1”, status UNKNOWN, has 1 handler(s) for this service…

The command completed successfully

[oracle@linux2 ~]$

 

  1. Once listener has been started attempt to use the listener with tnsping utility.

 

[oracle@linux2 ~]$ tnsping orcl

TNS Ping Utility for Linux: Version 12.1.0.2.0 – Production on 05-JAN-2015 10:48:42

Copyright (c) 1997, 2014, Oracle.  All rights reserved.

Used parameter files:

 

 

Used TNSNAMES adapter to resolve the alias

Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.102)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl)))

OK (10 msec)

[oracle@linux2 ~]$

 

  1. This shows that the listener is accepting connection, but there may be issues in the database such as dispatcher or server processes that are beyond this instruction set.

 

 

Network troubleshooting between client and server:

 

  1. From the client machine open a command prompt, ensure that you can successfully ping the client machine.

 

C:\Users\MYWINDOWS>ping 192.168.0.102

 

Pinging 192.168.0.102 with 32 bytes of data:

Reply from 192.168.0.102: bytes=32 time<1ms TTL=64

Reply from 192.168.0.102: bytes=32 time<1ms TTL=64

Reply from 192.168.0.102: bytes=32 time<1ms TTL=64

 

Ping statistics for 192.168.0.102:

    Packets: Sent = 3, Received = 3, Lost = 0 (0% loss),

Approximate round trip times in milli-seconds:

    Minimum = 0ms, Maximum = 0ms, Average = 0ms

Control-C

^C

C:\Users\MYWINDOWS>

 

  1. Success full connection to server machine. If this connection fails, contact your network administrator.

 

 

Client side:

 

Client side network troubleshooting:

  1. Logon to your oracle client machine with normal user account.
  2. Open a command prompt and attempt a tnsping to your alias machine

 

C:\Users\MYWINDOWS> tnsping orcl

 

TNS Ping Utility for Linux: Version 12.1.0.2.0 – Production on 05-JAN-2015 10:48:42

 

Copyright (c) 1997, 2014, Oracle.  All rights reserved.

 

Used parameter files:

 

Used TNSNAMES adapter to resolve the alias

Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.102)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl)))

OK (10 msec)

C:\Users\MYWINDOWS>

 

  1. If this fails verify that the values for POTOCAL, HOST, PORT, SERVICE_NAME are correct for the server and database service you are seeking to connect to.

 

 

 

NOTE:   You can trace oracle net communications at the server level and client level this gives very detail logs of the communications occurring and very helpful in troubleshooting network connectivity issues.

 

 

 

Larry Catt

OCP