BIT352 ยท 2081 ยท 5 marks
What is listener? Explain about listener.ora and tnsnames.ora file in oracle database.
What is listener? Explain about listener.ora and tnsnames.ora file in oracle database. [5]
Quick answer
A listener is a server-side network process in Oracle Database that listens for incoming client connection requests on a specific network protocol (usually TCP/IP) and a specific port (default port: 1521).
Listener, listener.ora, and tnsnames.ora in Oracle Database
Listener
When a client wants to connect to an Oracle database, it sends a connection request to the listener. The listener receives the request, verifies it, and then hands off (redirects) the connection to the appropriate Oracle database instance.
Key points about Listener:
- It runs on the database server machine.
- It is managed using the lsnrctl (Listener Control) utility.
- Common commands:
lsnrctl start,lsnrctl stop,lsnrctl status - Without a running listener, remote clients cannot connect to the Oracle database.
listener.ora File
The listener.ora file is a server-side configuration file that defines the listener's properties and settings.
Location: $ORACLE_HOME/network/admin/listener.ora
It contains:
- The name of the listener (default:
LISTENER) - The protocol, host, and port on which the listener listens
- The Oracle database services/SIDs it serves
Example:
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS =
(PROTOCOL = TCP)
(HOST = myserver.example.com)
(PORT = 1521)
)
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = ORCL)
(ORACLE_HOME = /u01/app/oracle/product/19c/dbhome_1)
)
)
Key parameters:
| Parameter | Description |
|---|---|
PROTOCOL | Network protocol (TCP/IP) |
HOST | Server hostname or IP address |
PORT | Port number (default 1521) |
SID_NAME | Oracle System Identifier |
tnsnames.ora File
The tnsnames.ora file is a client-side configuration file that maps logical service names (aliases) to Oracle database connection descriptors (host, port, service name).
Location: $ORACLE_HOME/network/admin/tnsnames.ora
When a client application uses a connect string like sqlplus user/pass@ORCL, Oracle looks up ORCL in tnsnames.ora to find the actual connection details.
Example:
ORCL =
(DESCRIPTION =
(ADDRESS =
(PROTOCOL = TCP)
(HOST = myserver.example.com)
(PORT = 1521)
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl.example.com)
)
)
Key parameters:
| Parameter | Description |
|---|---|
ORCL | Net service name (alias used by client) |
HOST | IP address or hostname of the database server |
PORT | Port number of the listener |
SERVICE_NAME | The Oracle database service name |
SERVER | Connection type (DEDICATED or SHARED) |
Difference Between listener.ora and tnsnames.ora
| Feature | listener.ora | tnsnames.ora |
|---|---|---|
| Location | Server side | Client side |
| Purpose | Configures the listener process | Maps alias to connection details |
| Used by | Oracle Listener | Client applications |
| Managed by | DBA (server) | DBA / end user (client) |
In summary: The listener acts as a gatekeeper on the server; listener.ora tells the listener how to operate; and tnsnames.ora tells the client where and how to connect to the database.
Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.