How to Fix ORA-12541: TNS No Listener in Oracle

Find where the listener really listens with lsnrctl status, start it when it is down, and check ports, Docker, and firewalls.

ORA-12541 means the client reached the host in the connect string, but nothing was listening on that port. Either the listener is not running, or it listens on a different host or port than the connect string uses. The database itself may be up; clients simply cannot reach it. Oracle AI Database 26ai names the host and port in the message, which tells you what was tried.

Reproduce the Error

A test user is created for the examples:

Example:

-- a test user for the examples
drop user if exists demo_app cascade;
create user demo_app identified by "Demo_Pass_26" default tablespace users;
grant create session to demo_app;

Connecting to port 1599, where no listener runs:

Example:

sqlplus -s -L demo_app/Demo_Pass_26@localhost:1599/FREEPDB1 <<'SQL'
select user from dual;
SQL

Output:

ERROR:
ORA-12541: Cannot connect. No listener at host 127.0.0.1 port 1599.

SP2-0751: Unable to connect to Oracle.  Exiting SQL*Plus

Fix: Find the Listener's Port and Use It

On the database server, lsnrctl status shows the addresses the listener listens on:

Example:

# where the listener really listens
lsnrctl status | grep "PORT="
sqlplus -s -L demo_app/Demo_Pass_26@localhost:1521/FREEPDB1 <<'SQL'
select user from dual;
SQL

Output:

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=0.0.0.0)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))

USER
----------
DEMO_APP

The listener uses port 1521, and the connection on that port works.

When the Listener Is Down

  • lsnrctl status then reports that it cannot connect; start the listener with lsnrctl start on the server.
  • After a restart, the database registers its services with the listener within about a minute, or at once with ALTER SYSTEM REGISTER.
  • With Docker, the container port must be published to the host, for example -p 1521:1521, or clients on the host find no listener.
  • A firewall that rejects the port can also produce this error; check that the port is open between client and server.

Related Guides

Conclusion

ORA-12541 means nothing listens at the host and port the client used. Check the listener's addresses with lsnrctl status, start it if it is down, and make sure the port is reachable from the client.

Vinish Kapoor
Vinish Kapoor

An Oracle ACE, author of four books on Oracle APEX, SQL and PL/SQL, and Oracle Forms, and a software developer building Oracle database applications since 2001.

guest

0 Comments
Oldest
Newest Most Voted