Net Service Names and the tnsnames.ora File

The Oracle RAC database installation process creates a tnsnames.ora file on each node. This file acts as a repository of net service names.

Each net service name is associated with a connect identifier. A connect identifier is an identifier that maps a user-defined name to a connect descriptor. A connect descriptor contains the following information:

  • The network route to the service, including the location of the listener through a protocol address

  • The SERVICE_NAME parameter, with the value set to the name of a database service

    Note:

    The SERVICE_NAME parameter that you use in the tnsnames.ora file is singular, because you can specify only one service name. The SERVICE_NAME parameter is not the same as the service_names database initialization parameter. The service_names database parameter defaults to the global database name, a name comprising the db_name and db_domain parameters in the initialization parameter file. When you add service names using SRVCTL or Oracle Enterprise Manager Cloud Control, it lists additional cluster-managed services for the database.

The tnsnames.ora file is located in both the Grid_home/network/admin and ORACLE_HOME/network/admin directories. By default, the tnsnames.ora file is read from the Grid home when Oracle Grid Infrastructure is installed. However, you can create the file in other directories. Oracle Net checks for the tnsnames.ora file in the following order:
  1. The directory specified by the TNS_ADMIN environment variable.
  2. If the TNS_ADMIN environment variable is not set or the file is not found in the TNS_ADMIN directory, then Oracle Net checks the Grid_home/network/admin and ORACLE_HOME/network/admin directories. For a read-only Oracle home, Oracle Net checks the ORACLE_BASE_HOME/network/admin directory.
  3. For a read-only Oracle home, if the file is not available in the ORACLE_BASE_HOME/network/admin directory, then Oracle Net checks for the file in the ORACLE_HOME/network/admin directory.

The order for checking tnsnames.ora is the same for both the Oracle home and Oracle Grid Infrastructure home (Grid home) installations.

With Oracle Clusterware 11g Release 2 and later, the listener association no longer requires tnsnames.ora file entries. The listener associations are configured as follows:

  • DBCA no longer sets the LOCAL_LISTENER parameter. The Oracle Clusterware agent that starts the database sets the LOCAL_LISTENER parameter dynamically, and it sets it to the actual value, not an alias. So listener_alias entries are no longer needed in the tnsnames.ora file.

  • The REMOTE_LISTENER parameter is configured by DBCA to reference the SCAN and SCAN port, without any need for a tnsnames.ora entry. Oracle Clusterware uses the Easy Connect naming method with scanname:scanport, so no listener associations for the REMOTE_LISTENER parameter are needed in the tnsnames.ora file.

For example, after you create the database, to add a second listener, listening on port 2012, use a command similar to the following command to have the database register with both listeners on startup:

SQL> alter system set local_listener='(DESCRIPTION=
(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.61)(PORT=1521))
(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.61)(PORT=2012))))' 
scope=BOTH SID='OCRL1';

See Also: