Skip to content

Oracle tnsnames.ora configuration

The tnsnames.ora file is a configuration file used by Oracle clients to establish connections to a database.^[600-developer-database-oracle-oracle-plsql.md] It typically resides in the Oracle Instant Client directory on the local machine.^[600-developer-database-oracle-oracle-plsql.md]

Syntax and Parameters

The configuration file defines network aliases using specific parameters for protocol, address, and connection data.

Connection Types

The file syntax varies depending on whether the target database is identified by a SERVICE_NAME or a SID^[600-developer-database-oracle-oracle-plsql.md#L38-61].

  • SERVICE_NAME: Used to connect to a specific service registered with the listener^[600-developer-database-oracle-oracle-plsql.md#L38-45].
    DB1 =
      (DESCRIPTION =
        (ADDRESS_LIST =
          (ADDRESS = (PROTOCOL = TCP)(HOST = 10.xxx.xx.xx)(PORT = 1521))
        )
        (CONNECT_DATA =
          (SERVICE_NAME = sdb1)
        )
      )
    
  • SID: Used to connect to a specific System Identifier^[600-developer-database-oracle-oracle-plsql.md#L48-61].
    DB2 =
      (DESCRIPTION =
        (ADDRESS_LIST =
          (ADDRESS = (PROTOCOL = TCP)(HOST = 10.xxx.xx.xxx)(PORT = 1521))
        )
        (CONNECT_DATA =
          (SID = sdb2)
        )
      )
    

Key Elements

  • (DESCRIPTION): The outer wrapper containing the connection details.
  • (ADDRESS_LIST): Contains one or more (ADDRESS) blocks.
  • (ADDRESS): Specifies the network protocol (PROTOCOL), target server hostname (HOST), and port number (PORT).
  • (CONNECT_DATA): Specifies the database identity, using either SERVICE_NAME or SID.

Sources

^[600-developer-database-oracle-oracle-plsql.md]