By default, after installing Oracle Database Server, the Listener service will wait for and accept connections on TCP port 1521. However, it is possible to reconfigure the listener to use a different port. The procedure comprises two steps:
- reconfiguring the listener.
- reconfiguring the database instance(s) to register to the listener on the new, non-default port.
There are two ways to achieve this:
- Through the configuration tools
- by manually adjusting the appropriate configuration files.
The preferred way is to use the configuration tools.
Using Configuration Tools
Before changing the listener configuration you should stop it run the following command:
$ lsnrctl stop
Launch Oracle Net Manager (execute “netmgr” at the command line) and follow these steps:
$ netmgr
- Select Local / Listeners / LISTENER in the left pane.
- Select Listening Locations in the right pane upper selection button.
- Browse through the AddressX tabs and choose the one with Protocol TCP/IP.
- Change the value in the Port: field to your desired port number.
- In the left pane select Local / Service Naming.
- Create a new Net Service Name:
- Click the green plus (“+”) icon on the leftmost toolbar; dialog will appear.
- Type a name for the new Service Name (e.g. MYLISTENER); press Next.
- Select TCP/IP (Internet Protocol); press Next.
- Type your hostname in Hostname: field and the same port number you chose in the previous steps in the Port Number: field; press Next
- Type the name of an existent database (e.g. ORCL); press Next
- Optionally you may Test the new connection.
- Press Finish.
- Select from menus File / Save Network Configuration and close the Net Manager
Restart the listener by running the following commands at the command prompt:
$ lsnrctl start
However, after you changed the default listener port number, the database instances will not be able to register themselves with this new listener as the database will contact the listener(s) on the default port 1521. To fix this problem you need to add/change the “local_listener” initialization parameter for each database.
Use Oracle Enterprise Manager to change the “local_listener” initialization parameter to have the value “MYLISTENER” for the database(s) you work with or create in the future. Make sure you make this change permanent by storing it in the SPFile, in which case you need to restart the database instance to take effect.
Using Configuration Files
Before changing the listener configuration you should stop it by running the following command:
$ lsnrctl stop
The Oracle Listener is configured through the LISTENER.ORA file, which, by default is located in ORACLE_HOME under the NETWORK/ADMIN subdirectory. Edit this file with you preferred text editor and change the (PORT=1521) from under the default LISTENER profile to your desired value. If you do not have this file then you may use the following sample:
LISTENER = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0)) (ADDRESS = (PROTOCOL = TCP)(HOST = myhostname)(PORT = myport)) )
Please replace “myhostname” with your system hostname and “myport” with your desired port number. After changing the LISTENER.ORA file you need to restart the listener. To do that run the following commands at the command prompt:
However, if you are changing the default listener port number, the database instances will not be able to register themselves with this new listener as the database will contact the listener(s) on the default port 1521.
To fix this problem you need to add/change the “local_listener” initialization parameter for each database. This can be achieved in two steps:
- creating a alias name for the new listener.
- adjusting the LOCAL_LISTENER initialization parameter.
In the TNSNAMES.ORA file (in the same location as LISTENER.ORA) add the following entry:
MYLISTENER = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = myserver )(PORT = myport)) )
Please replace the “myhostname” and “myport” with the values used for listener configuration in LISTENER.ORA. Now adjust the LOCAL_LISTENER parameter — use the following SQL statement as SYSDBA:
SQL> ALTER SYSTEM SET LOCAL_LISTENER='MYLISTENER' SCOPE=BOTH;
Please take into consideration the effect of the SCOPE argument (as shown above it will also save the change in the spfile); also you may want to restrict the change to a certain instance with the help of the SID='[db_sid]’ argument if you employ a common spfile for many instances.