Sub topic 2
Service Names, SIDs, and the Listener
Assume you know basic SQL and can use a terminal. You also need access to an Oracle Database and permission to connect to it. This chapter explains how Oracle identifies a database service and how a client reaches it.
The listener's job
An Oracle listener is a network process that accepts connection requests. It normally listens on TCP port 1521, although an installation can use another port.
The listener does not store tables or execute SQL. After receiving a request, it finds a registered database service and passes the connection to the appropriate database instance. The client then communicates with the database server through that connection.
A database instance is the set of memory structures and background processes that manages database files. A database can have one instance or several instances in an Oracle Real Application Clusters environment.
Service name and SID
A service name is a logical name that clients use to request a database service. It can represent a database, a pluggable database, or a workload managed across several instances. For example, orclpdb1.example.com might be the service name for a pluggable database.
A SID, or system identifier, identifies a particular database instance. In a single-instance database, the SID may be ORCL. In a cluster, different instances can have different SIDs while offering the same service.
| Identifier | Identifies | Common use |
|---|---|---|
| Service name | A logical database service | Normal client connections |
| SID | One database instance | Administration and older connection configurations |
| Listener address | A network endpoint | Finding the listener on a host and port |
For normal application and user connections, prefer a service name. A service can move between instances or distribute users across instances. A SID points to one instance and is less flexible.
A local administrator may use the ORACLE_SID environment variable to select an instance on the database server. That variable does not replace the host, port, and service information needed by a remote client.
How the listener discovers services
When an instance starts, it usually registers its services dynamically with the listener. The listener can then route requests that name those services.
An administrator can inspect registered services on the database server with:
lsnrctl servicesThe output lists the listener endpoint and services known to it. If the requested service is absent, the listener cannot route the request.
A connect descriptor tells the client what to request. This Easy Connect identifier uses a service name:
//dbhost.example.com:1521/orclpdb1.example.comA descriptor can instead contain a SID, especially for older systems:
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = dbhost.example.com)(PORT = 1521))
(CONNECT_DATA = (SID = ORCL))
)Use the format required by your database administrator. Do not replace SERVICE_NAME with SID just because the database name looks familiar.
Common listener errors
ORA-12541: TNS:no listenerusually means no listener is reachable at the specified host and port. Check the hostname, port, network path, and listener status.ORA-12514: TNS:listener does not currently know of service requestedmeans the listener responded, but the requested service is not registered there. Check the service name and registration state.ORA-12154: TNS:could not resolve the connect identifier specifiedusually concerns a TNS alias that the client cannot resolve. Checktnsnames.oraand the client configuration.
Exercise
A connection reaches the listener successfully but returns ORA-12514. What should you check first?
Show answer
Check that the connect descriptor uses the correct SERVICE_NAME and that this service is registered with the listener. The host and port are probably reachable because the listener answered.