Skip to content

Oracle tnsnames.ora configuration format

The tnsnames.ora file is a configuration file used by Oracle databases to define network connectivity parameters. It maps database connection aliases to detailed connection descriptors, which specify the host, port, and specific database service or SID to use^[600-developer__database__oracle__oracle-plsql.md].

Configuration Syntax

A standard entry in the tnsnames.ora file consists of a network alias name followed by an equals sign and a connection descriptor wrapped in parentheses. The descriptor typically contains two main sections: ADDRESS_LIST and CONNECT_DATA^[600-developer__database__oracle__oracle-plsql.md].

Common Parameters

  • ADDRESS / ADDRESS_LIST: Defines the protocol, host, and port.
    • PROTOCOL: Usually TCP^[600-developer__database__oracle__oracle-plsql.md].
    • HOST: The IP address or hostname of the database server (e.g., 10.xxx.xx.xx)^[600-developer__database__oracle__oracle-plsql.md].
    • PORT: The listening port, typically 1521^[600-developer__database__oracle__oracle-plsql.md].
  • CONNECT_DATA: Identifies the specific database instance.
    • SERVICE_NAME: The global database name.
    • SID: The System Identifier (a unique name for the instance).

Examples

Using SERVICE_NAME

When connecting via a specific service name (e.g., sdb1), the configuration follows this format^[600-developer__database__oracle__oracle-plsql.md]:

DB1 =
  (DESCRIPTION =
    (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.xxx.xx.xx)(PORT = 1521))
  )
  (CONNECT_DATA =
    (SERVICE_NAME = sdb1)
  )
)

Using SID

When connecting via a specific SID (e.g., sdb2), the configuration follows this format^[600-developer__database__oracle__oracle-plsql.md]:

DB2 =
  (DESCRIPTION =
    (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.xxx.xx.xxx)(PORT = 1521))
  )
  (CONNECT_DATA =
    (SID = sdb2)
  )
)
  • Oracle PL/SQL
  • [[Database connection strings]]
  • [[Docker Oracle setup]]

Sources

^[600-developer__database__oracle__oracle-plsql.md]