Back to: Oracle DBA Tutorials
Default Listener Examples in Oracle
In this article, I am going to discuss Default Listener Examples in Oracle. Please read our previous article where we discussed Default Listener in Oracle.
Default Listener Examples in Oracle
Until now we have learned the default listener. Let us go ahead and do an important exercise regarding the listener. We are going to prove that the listener is not necessary to connect to the database. In case we need to use the default port and TCP/IP protocol. Let us go ahead and go to the below path where the listener and tnsnames files are present.
Let us open the terminal from this path and check the status of the listener using “lsnrctl status”.
From the status of the listener, we can see the listener parameter file is present in the path called “/u01/app/oracle/product/19.0.0/dbhome_1/network/admin/listener.ora”. We are on the exact path. Let us go ahead and change the name of the listener.ora. We are changing the name of the listener from listener.ora to abclistener.ora
So, we have changed the name of the listener.ora file to abclistener.ora. Now, let’s go ahead and stop the listener.
Now, the listener is stopped. Let us try to start the listener again and see how it works.
We can see the listener is started but we do not find the Listener parameter file in the output. This is because we have changed the name of the listener. We can see the listener supports no services. Let us wait for 60 seconds and try to check the status listener to check the services.
We can see the services are registered to the listener and running fine. Let us go ahead and check the connectivity of the database using the SQL developer. Open SQL developer and try to connect using the database. Open the SQL developer and we are connecting with username as sys and password for sys user and the hostname as oracletest.com and port number as 1521 and SID as jayadb. Let us try to test the connection of the database.
The test connection is a success. So, we can understand that we can connect to the database even if the listener file is not present. Even if the listener file is not present, we can connect using the default port and the default protocol. Even the listener.ora file is not present the services are registered to the listener.
How the listener registered the services without the listener file?
This is called Dynamic registration. This is because we are using the local listener. Let us go ahead and see the local listener in the database. Connect to the database using “sqlplus / as sysdba” and use the command “show parameter local”.
The command “show parameter local” displays all the parameters with the word local in it. The parameter local_listener is having the value LISTENER_JAYADB. The default name is LISTENER_instance_name. This information is stored in the file called tnsnames.ora. This file is very important for local_listener. Let us go ahead and open the tnsnames.ora file and check for the local_listener.
The part that we have highlighted in the above image is local_listener. This local_listener is responsible for registering the services to the listener. Let us go ahead and change the local_listener value in the database. Let us use the command below.
Command: alter system set local_listener =’ ‘;
We are not providing any value to the local_listener. As we are leaving the value as an empty name. Let us see what happens to the local listener. Let’s check the parameter again ”show parameter local”.
So, the value of local_listener has changed. Now, exit from the database and check the listener status by restarting the listener.
Now, that the listener is stopped, Let us go ahead and start the listener again and check the services.
We can see the listener is started but the listener does not support any services. If we wait for 60 seconds the LREG will register all the services to the listener. This happens because we are using the default port number and the default protocol. If you take the name local_listener and search for the name local_listener on the internet. Make sure to search for the 19c version.
You will find many results after searching about local_listener parameter 19c. Select the oracle website.
You can see there is a website from oracle.com. You can visit that website to know more about local_listener. You can go through this website. LOCAL_LISTENER (oracle.com)
We can see more information about listeners. We can see the default port number is 1521 and the default protocol is TCP protocol. So, even though we have made multiple changes to the listener file and the local_listener at the database level, we can see the listener is running because of the default port number and default protocol. Let us check the listener status again.
We can see all the services are restored and registered to the listener. So, we can clear that if we are using the default protocol and the default port number then there is no need for a listener and local listener. So, we understood the necessity of the port number and the protocol and the local listener. Let us go ahead and change the value of local_listener back to its original value.
Let us go ahead and change the value of local_listener to the original value. Take the local_listener name from the tnsnames.ora file.
Command: alter system set local_listener=LISTENER_JAYADB;
From the output, we can see the local_listener value is back to the original. After making any changes to the listener parameter make sure to restart the listener again.
In the next article, I am going to discuss the Non-Default Port in Oracle with Examples. Here, in this article, I try to explain Default Listener Examples in Oracle and I hope you enjoy this Default Listener Examples in Oracle article.