This tool gives full configuration and administration capabilities.
To invoke the command-line utility, type lsnrctl at the command line.
The most common functions that can be performed on the listener using this lsnrctl:
Starting the Listener You can type help at the LSNRCTL> prompt to display a list of lsnrctl commands. To start the default listener named LISTENER, type start at the prompt. To start a different listener, type start and then that listener name. For example, typing start listener1 starts the LISTENER1 listener.
Eg: D:\oracle\ora10g\BIN>lsnrctl start
Reloading the Listener If the listener is running and modifications are made to the listener.ora file manually, with Oracle Net Manager, or with Enterprise Manager, you must reload the listener to refresh the listener with the most current information. The reload command rereads the listener.ora file for the new definitions. It is not necessary to stop and start the listener to reload it.
Eg: D:\oracle\ora10g\BIN>lsnrctl reload
In the code example above, Oracle has reread the listener.ora file and applied any changes that we made to the file against the currently running listener process. We can see the address, protocol, and port designation of the default listener. Notice that this listener is listening on a nondefault port of 1522.
Showing the Status of the Listener You can display the status of the listener by using the status command.
The status command shows whether the listener is active, the locations of the logs and trace files, how long the listener has been running, and the services for the listener (a quick listing of vital information for the listener).
Eg: D:\oracle\ora10g\BIN>lsnrctl status
Listing the Services for the Listener The lsnrctl services command displays information about the services, such as whether the services have any dedicated prespawned server processes or dispatched processes associated with them and how many connections have been accepted and rejected per service. Use this method to check if a listener is listening for a particular service.
|change_password||Allows a user to change the password needed to stop the listener.|
|exit||Exits the lsnrctl utility.|
|quit||Performs the same function as exit.|
|reload||Rereads the listener.ora file without stopping the listener. Refreshes the listener if the file changes.|
|save_config||Copies the listener.ora file called listener.bak when changes are made to the listener.ora file from lsnrctl.|
|services||Lists a summary of services and details information on the number of connections established and the number of connections refused for each protocol service handler.|
|start listener||Starts the named listener.|
|status listener||Shows the status of the named listener.|
|stop listener||Stops the named listener.|
|trace||Turns on tracing for the listener.|
|version||Displays the version of the Oracle Net software and protocol adapters.|
The lsnrctl utility also has commands called set commands. To issue these commands, type set command name at the LSNRCTL> prompt. These commands are used to modify the listener.ora file.
For example, use this command to set up logging and tracing. (Most of these parameters can be set using Oracle Net Manager).
Use show command, which displays the current settings of the parameters set using the set command.
Type set or show to display a listing of all the commands.
|current_listener||Sets the listener to modify or shows the name of the current listener.|
|displaymode||Sets display for the lsnrctl utility to RAW, COMPACT, NORMAL, or VERBOSE.|
|inbound_connect_ timeout||Specifies the time in seconds for a client to complete a connection request to the listener after the network connection is established. An ORA-12525 error will be generated if the listener fails to receive the request in the allotted time.|
|log_status||Shows whether logging is on or off for the listener.|
|log_file||Shows the name of listener log file.|
|log_directory||Shows the log directory location.|
|rawmode||Shows more detail on STATUS and SERVICES when set to ON. Values: ON or OFF.|
|startup_waittime||Sets the length of time that a listener will wait to respond to a status command in the lsnrctl command-line utility.|
|save_config_on_stop||Saves changes to the listener.ora file when exiting lsnrctl.|
|trc_level||Sets the trace level to OFF, USER, ADMIN, SUPPORT. trc_file Sets the name of the listener trace file. trc_directory Sets the name of the listener trace directory.|
For example, to stop LISTENER1, type lsnrctl stop listener1.
If you are in the lsnrctl> facility, you will stop the current listener defined by the current_listener setting. To see what the current listener is set to, use the show command. The default value is LISTENER.
Stopping the listener does not affect clients connected to the database. But no new connections can use this listener until the listener is restarted.
Oracle 10g databases can automatically register their presence with an existing listener. The instance registers with the listener defined on the local machine. Dynamic service registration allows you to take advantage of other features, such as load balancing and automatic failover. The PMON process is responsible for registering this information with the listener.
When dynamic service registration is used, you will not see the service listed in the listener.ora file. To see the service listed, run the lsnrctl services command. Be aware that if the listener is started after the Oracle instance, there may be a time lag before the instance actually registers information with the listener.
For an instance to automatically register with a listener, the listener must be configured as a default listener, or you must specify the init.ora parameter LOCAL_LISTENER. The LOCAL_ LISTENER parameter defines the location of the listener with which you want the Oracle server to register. A default listener definition is shown here:
Listener Name = LISTENER
Port = 1521
Protocol = TCP/IP
And here is an example of the LOCAL_LISTENER parameter being used to register the Oracle server with a non-default listener:
local_listener="(ADDRESS_LIST = (Address = (Protocol = TCP) (Host=weishan) (Port=1522)))
In the previous example, the Oracle server registers with the listener listening on port 1522 using TCP/IP. This is a non- default port location, so you must use the LOCAL_LISTENER parameter in order for the registration to take place. You must configure two other init.ora parameters to allow an instance to register information with the listener. Two parameters are used to allow automatic registration: INSTANCE_ NAME and SERVICE_NAMES.
The INSTANCE_NAME parameter is set to the name of the Oracle instance that you want to register with the listener. The SERVICE_NAMES parameter is a combination of the instance name and the domain name. The domain name is set to the value of the DB_DOMAIN initialization parameter. For example, if your DB_DOMAIN is set to GR.COM and your Oracle instance is DBA, set the parameters as follows:
Instance_name = DBA Service_names = DBA.GR.COM
If you are not using domain names, set the INSTANCE_NAME and SERVICE_NAMES parameters to the same values.
If you have a more complex network environment with a large number of simultaneous connection requests or if you are using an advanced database design such as Oracle Real Application Clusters, you can configure multiple listeners to better manage connection loads. You also gain functionality when multiple listeners service your database connection requests. These features include Connect-Time Failover, Transparent Application Failover, Client Load Balancing, and Connection Load Balancing.
The Connect-Time Failover feature allows clients to connect to another listener if the initial connection to the first listener fails. Multiple listener locations are specified in the clients tnsnames.ora file. If a connection attempt to the first listener fails, a connection request to the next listener in the list is attempted. This feature increases the availability of the Oracle service should a listener location be unavailable. Here is an example of what a tnsnames.ora file looks like with connect-time failover enabled:
ORCL = (DESCRIPTION=
Notice the additional entry under the ADDRESS_LIST section. Two listeners are specified. If a connection is unsuccessful when attempting to connect to the DBPROD host on port 1521, a connection attempt is made to the DBFAIL host on port 1521. The time that the connection waits before attempting to failover is operating system dependent.
The Transparent Application Failover (TAF) feature is a runtime failover for high-availability environments, such as Oracle Real Application Clusters. TAF fails over and reestablishes application-to-service connections. It enables client applications to automatically reconnect to the database if the connection fails and, optionally, resume a SELECT statement that was in progress. The reconnection happens automatically from the OCI library.
The following code shows an example of the tnsnames.ora file setup for using Transparent Application Failover:
ORCL = (DESCRIPTION= (FAILOVER=ON)
In this example, notice additional entries in the tnsnames.ora file that enable the Transparent Application Failover. There are two hosts, DBPROD and DBFAIL. If DBPROD becomes unavailable, the connections will failover to the DBFAIL host and connect to the associated service. The database service of PROD must be the same on both the DBPROD and DBFAIL servers for this example to work properly.
Client Load Balancing is a feature that allows clients to randomly select from a list of listeners. Oracle Net moves
through the list of listeners and balances the load of connection requests across the available listeners. Here is an
example of the tnsnames.ora entry that allows for load balancing:
ORCL = (DESCRIPTION=
Notice the additional parameter of LOAD_BALANCE. This enables load balancing between the two listener locations specified.
Connection Load Balancing is a feature that enables better distribution of connection among a group of dispatchers in an Oracle Shared Server environment.