Back to: Oracle DBA Tutorials
Default Listener in Oracle
In this article, I am going to discuss Default Listener in Oracle with Examples. Please read our previous article where we discussed Establishing a Connection and Session in Oracle with Examples. Previously we understood how to establish a session and how to establish a connection, how to establish a session. Now, we will discuss default listeners.
Default Listener in Oracle:
During an Oracle database installation, Oracle Universal Installer launches Oracle Net Configuration Assistant and creates a local listener named LISTENER. So, this is the default listener.
LISTENER is automatically populated with available database services through a feature called dynamic service registration. We have a process called LREG which registers all the services to the listener. The Dynamic service registration is started in Oracle 9i version. Before 9i there is static service registration. The Default listener listens to the following TCP/IP protocol address.
ADDRESS=(PROTOCOL=tcp)(HOST=host_name)(PORT=1521)
Without any configuration, you can access your database instance immediately through LISTENER. So, this indicates is not necessary after oracle 9i. The listener is necessary to connect to the different ports or use advanced features. Even if we don’t have any listener the default listener will keep working using the TCP protocol and the port number will be 1521. If the listener’s name is LISTENER and it cannot be resolved, a protocol address of TCP/IP and a port number of 1521 is assumed. Now, let us do some exercise.
Examples to Understand Default Listener in Oracle:
Open the virtual machine and log in as an oracle user. Open a terminal. Let us go ahead and find the listener’s location. The listener is stored in the ORACLE_HOME directory. Let us go to the ORACLE_HOME directory.
Command: cd $ORACLE_HOME
We can see the ORACLE_HOME path is /u01/app/oracle/product/19.0.0/dbhome_1. This is the oracle home path. We have a directory named NETWORK. In this NETWORK directory, there is another directory named admin. We have listener and tnsnames.ora files present in that directory.
From the output, we can see path /u01/app/oracle/product/19.0.0./dbhome_1/network/admin/. This path contains listener.ora and tnsnames.ora files. Let us go ahead and open the listener.ora file.
Command: cat listener.ora
We can see the default listener named LISTENER and this listener is listen to all the connections which have a protocol as TCP and port number 1521. We have another protocol IPC protocol. We can check the same in the file manager as well. Go to the below path you can find the listener.ora and the tnsnames.ora files.
We can see the tnsnames.ora and listener.ora files. Let us go ahead and connect to the database.
Note: Sometimes after starting the database, the listener might be down. There is no relation between the database and the listener. Let us try to start the listener now.
Command: lsnrctl start
Now, that the listener is up and running. We can see more additional information about the listener. When we run the command “lsnrctl start” the listener will be started. If the listener is already running then we will find an error.
From the status of the listener, we can see information like the listener name as LISTENER and the version of the listener is TNSLSNR is 19.0.0.0.0 and the start date is 24-Nov-2022 and we can see the uptime that is mentioned as 19 seconds which means it has started now. If we go ahead and check the status of the listener again using the command “lsnrctl status” then we will find the below information.
From the above image, we can see there are many services. All these services are related to the oracle database. Sometimes, Oracle has a background process named LREG which takes 60 seconds to register all these services to the listener. So, the listener had listener registered with all these services.
We can get additional information about the protocol that is used to connect to the listener i.e. we are using TCP protocol and the hostname is oracletest.com and the port number is 1521. We can also get additional information like the Listener parameter file, where the listener file is stored is ’/u01/app/oracle/product/19.0./dbhome_1/network/admin/listener.ora’. Until now, we have learned about the listener’s status and how to start and stop the listener. Let us learn about listener utility.
Listener Utility in Oracle:
The listener utility is a tool where we can execute the listener commands and know information about listener commands. Use the command “lsnrctl” and press enter.
So, we are connected to the listener utility. We can know more information here using the command “help”.
From the help command, we can see there are multiple other commands present in the listener utility. There are commands like start, stop, status, services, show, reload, quit, and exit. Let’s go ahead and check with the command “show”.
From the image, we can see show command has other options as well. After entering the show command we use any of these commands to check the information. Let us try with “show current_listener”.
So, the current listener is LISTENER which is the same as present in the listener status. This is the same as discussed before as well. Oracle Net Configuration Assistant and creates a local listener named LISTENER. So, this is the default listener. We can even stop the listener with one command “stop”.
This indicates that the database will not accept any further connections as the listener is down. Let us start the listener using the command “start”.
The listener is started but not all the services are registered. Let’s go ahead and register all the services. In order to register all the services, we have to exit from the listener utility and then connect to the database. We cannot connect to the database when we are in the listener utility.
We have also executed the command “alter system register” where the LREG background process registered all the services to the listener. Let us go ahead and check the status of the listener now using the command “lsnrctl status”.
We can see all the services. We have used the command “alter system register” to register all the services to the listener.
In the next article, I am going to discuss Default Listener Examples in Oracle. Here, in this article, I try to explain Default Listener in Oracle and I hope you enjoy this Default Listener in Oracle article.