The Oracle Listener: A Complete Guide from Basics to Best Practices

English

“Having trouble with smooth database connections?”

Have you ever faced this problem? The key to solving it is the Oracle Listener. This article provides a comprehensive guide covering everything from the basics of the Listener to advanced configurations, troubleshooting, security settings, and performance optimization.

We’ll use diagrams and practical steps to make it understandable for beginners, while also providing valuable information for advanced users.

Overview of the Listener: Why is it Important?

The Listener is a network gateway that connects clients to the database.

Role of the Listener (Diagram)

  Client                   Listener               Database
+-----------+         +------------+        +----------------+
| SQL*Plus  | ----->  |  LISTENER  | -----> |  orcl instance |
+-----------+         +------------+        +----------------+

Without the Listener, clients cannot connect to the database. The Listener has the following roles:

  • Receiving connection requests from clients.
  • Mediating communication with the database.
  • Assigning the appropriate server process to the client.

Step 1: Basic Listener Configuration

1. The Listener Configuration File: listener.ora

listener.ora is the configuration file that defines the Listener’s behavior. This file is typically located at the following paths:

  • Linux/Unix: $ORACLE_HOME/network/admin/listener.ora
  • Windows: %ORACLE_HOME%\network\admin\listener.ora

Example: Basic configuration for a single instance

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    )
  )

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = orcl)
      (ORACLE_HOME = /u01/app/oracle/product/19c/dbhome_1)
    )
  )

2. Configuring the tnsnames.ora File

On the client side, tnsnames.ora is used to define database connections.

ORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    (CONNECT_DATA =
      (SERVICE_NAME = orcl)
    )
  )

Step 2: Managing the Listener

Main Management Commands (lsnrctl)

CommandDescriptionExample
lsnrctl startStarts the listener$ lsnrctl start
lsnrctl stopStops the listener$ lsnrctl stop
lsnrctl reloadReloads the configuration$ lsnrctl reload
lsnrctl statusChecks the current status of the listener$ lsnrctl status
lsnrctl servicesChecks the services it manages$ lsnrctl services

Step 3: Dynamic vs. Static Configuration

There are two types of Listener configuration: static and dynamic.

Static Configuration (Manual Registration)

This method involves writing all information directly in listener.ora. It is used in fixed environments.

Configuration Example (Multiple Instances)

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = orcl)
      (ORACLE_HOME = /u01/app/oracle/product/19c/dbhome_1)
    )
    (SID_DESC =
      (SID_NAME = testdb)
      (ORACLE_HOME = /u01/app/oracle/product/19c/dbhome_1)
    )
  )

Dynamic Configuration (Automatic Registration)

The database automatically registers with the Listener.

Steps

  1. Set LOCAL_LISTENER:SQLALTER SYSTEM SET LOCAL_LISTENER='(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))';
  2. Dynamic Registration:SQLALTER SYSTEM REGISTER;

Step 4: Enhancing Listener Security

1. Whitelist/Blacklist Configuration

Restricting access to specific IP addresses prevents unwanted connections.

Configuration Example (Whitelist) Add the following to sqlnet.ora:

TCP.VALIDNODE_CHECKING = YES
TCP.INVITED_NODES = (192.168.1.10, 192.168.1.11)

2. Configuring the TCPS Protocol (SSL/TLS)

Encrypting connections enhances security.

Step 5: Troubleshooting and Monitoring

1. Checking the Logs

The Listener log is saved at the following path:

  • Linux/Unix: $ORACLE_HOME/network/log/listener.log
  • Windows: %ORACLE_HOME%\network\log\listener.log

2. Checking for Port Conflicts

Check if port 1521 is being used by another process:

Bash

netstat -an | grep 1521

Step 6: Advanced Listener Configuration (Load Balancing and Failover)

By configuring multiple listeners, it is possible to distribute connections or automatically switch over in the event of a failure.

Failover Configuration Example tnsnames.ora:

SALESDB =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = node1)(PORT = 1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = node2)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = sales)
    )
  )

Best Practices

  • Regularly audit Listener security Enable whitelist settings and password protection.
  • Utilize monitoring tools Regularly check the Listener’s operational status with Enterprise Manager or custom scripts.
  • Document configuration management Manage the change history of configuration files.

Conclusion

This article covered everything from the basics to the advanced applications of the Listener. Beginners should start by learning the basic configuration and, once comfortable, try setting up dynamic configuration or failover. It is also crucial to enhance security settings to ensure the Listener’s safety.

[reference]
Oracle Database Database Net Services Reference, 19c

コメント

Copied title and URL