Skip to content

ORA-12541: TNS:no listener — Finding What Isn't Listening

ORA-12541 means nothing answered on the host and port you asked for. Listener down, wrong port, a listener bound to localhost, or localhost inside a container: how to tell which in a minute, and fix it.

ora-12541 oracle-listener connection-refused docker oracle-net oracle-database
Gopi Gorantala
Reading Progress

On This Page

spring.datasource.url=jdbc:oracle:thin:@//localhost:1521/FREEPDB1

That one line, sitting in the config of a payments gateway that had just been moved into a container, is the most common cause of ORA-12541 I know of. It worked on the laptop for months. Then it ran inside Docker next to an Oracle container, and every connection died before it ever reached a database. Nothing in Oracle was broken. The gateway was knocking on its own door.

What the client printed

On 19c-era clients and drivers, ORA-12541 is famously terse:

ORA-12541: TNS:no listener

That's it. No host, no port, no hint. It's one of the most viewed Oracle questions on Stack Overflow (this one sits at over 829,000 views as of today), and I think the missing detail is a big part of why.

The 23ai and 26ai message finally says where it looked. Oracle's error help page gives it as Cannot connect. No listener at host_port., and here's what it looks like for real, from a Spring Boot app with Hibernate 6.6 posted to the Docker forums in May 2025:

o.h.engine.jdbc.spi.SqlExceptionHelper   : ORA-12541: Cannot connect. No listener at host localhost port 1521. (CONNECTION_ID=7vNSSAivT6SrmiTWJdGREQ==)
https://docs.oracle.com/error-help/db/ora-12541/

Read that and the answer is already on the screen: localhost, from inside a container. The Net Services troubleshooting page for ORA-12541 adds two details worth knowing. The address shown is the last IP the client tried (or the redirect address, if a listener redirected you). And for IPC connections the message says No Listener at key EXTPROC instead of a host and port, which you'll see from external procedures, not from your app.

When does it show up? Always at connect time, and always fast. Milliseconds, not seconds. Keep that in mind, because it's the single best clue you have.

Is anything on that port at all?

ORA-12541 is raised on the client side, by Oracle Net, the networking layer inside SQL*Plus, the JDBC driver or python-oracledb. The client opened a TCP connection to the host and port in your connect string, and the operating system on the other end answered "nothing here" straight away. The listener, the process on the database host that accepts new connections and hands them to the database, never saw your request. So this isn't about service names, passwords or PDBs. It's about an address.

That gives you a two-minute triage, and none of it needs Oracle installed on your side:

# from the machine your app runs on (inside the app container, if it runs in one)
nc -vz db-host 1521

# on the database host: is a listener up, and on which addresses?
lsnrctl status                      # or: lsnrctl status LISTENER_NAME for a named listener
ss -ltnp | grep 1521                # Linux; who owns the port, and on which IP
# Windows and macOS equivalents for the database host
netstat -ano | findstr 1521
lsof -nP -iTCP:1521 -sTCP:LISTEN

nc saying "Connection refused" is ORA-12541 in miniature. "Connection timed out" is a different problem (a firewall eating packets), and that's ORA-12170. And if nc connects fine but your app still gets ORA-12541, your app isn't connecting to the address you just tested. That last case is more common than you'd think.

If you're not sure which of the three classic connection errors you're even looking at, ORA-12514 vs ORA-12541 vs ORA-12154 lays them side by side.

Getting a refusal on demand (no Oracle required)

I couldn't run an Oracle container in this session (the workspace had no Docker daemon), so I split the lab. The part that explains the mechanism doesn't need Oracle at all, because ORA-12541 is what an Oracle client says when TCP says "refused". That part I ran. The Oracle container part is below as commands, and I've marked it as not run.

What I ran it on: Ubuntu 24.04, OpenBSD netcat 1.226, OpenJDK 21.0.13.

Step 1: a port nobody's on.

nc -vz 127.0.0.1 1521
nc: connect to 127.0.0.1 port 1521 (tcp) failed: Connection refused

Step 2: a "listener" bound only to loopback. This stands in for a listener whose listener.ora says HOST=localhost.

nc -l 127.0.0.1 1521 &               # listens on 127.0.0.1 only
nc -vz -w 3 127.0.0.1 1521           # same machine, loopback
nc -vz -w 3 192.0.2.2 1521           # same machine, its other interface
Connection to 127.0.0.1 1521 port [tcp/*] succeeded!
nc: connect to 192.0.2.2 port 1521 (tcp) failed: Connection refused

Same box, same port, something is listening, and the second connection is still refused. That's exactly what a remote client sees when the listener is bound to loopback. On the database host, lsnrctl status looks perfectly healthy, which is what makes this one so annoying.

Step 3: what a JVM sees. Any Oracle JDBC thin connection starts with a plain socket, so this probe shows the raw failure the driver turns into an Oracle error:

import java.net.InetSocketAddress;
import java.net.Socket;

public class Probe {
    public static void main(String[] args) {
        String host = args[0];
        int port = Integer.parseInt(args[1]);
        long start = System.nanoTime();
        try (Socket s = new Socket()) {
            s.connect(new InetSocketAddress(host, port), 5_000); // 5 s connect timeout
            System.out.println("OPEN " + host + ":" + port);
        } catch (Exception e) {
            long ms = (System.nanoTime() - start) / 1_000_000;
            System.out.println(e.getClass().getName() + ": " + e.getMessage() + " after " + ms + " ms");
        }
    }
}
java Probe.java 127.0.0.1 1521
java Probe.java db-primary.invalid 1521
java.net.ConnectException: Connection refused (connect failed) after 15 ms
java.net.UnknownHostException: db-primary.invalid after 11 ms

Fifteen milliseconds. A refusal is an answer, and it comes back fast. The UnknownHostException is the near-miss worth knowing: a host name that doesn't resolve is ORA-12545 territory in Oracle clients, not ORA-12541.

Step 4: the Oracle version (not run here). With Docker available, this reproduces both container traps in about two minutes. Pin your own tag; I'd use a slim Free image.

# trap 1: forgot to publish the port
docker run -d --name lab-oracle -e ORACLE_PASSWORD=LabOnly_2026 gvenzl/oracle-free:23-slim-faststart
# from the host, once the logs say DATABASE IS READY TO USE!:
sqlplus -L system/LabOnly_2026@//localhost:1521/FREEPDB1
# trap 2: Compose, where the app says localhost
services:
  oracle:
    image: gvenzl/oracle-free:23-slim-faststart
    environment:
      ORACLE_PASSWORD: LabOnly_2026
  gateway:
    image: eclipse-temurin:21-jre
    environment:
      DB_URL: jdbc:oracle:thin:@//localhost:1521/FREEPDB1   # wrong: localhost is this container

Expected: an immediate ORA-12541 in both cases, in the 23ai wording if your client is new, naming localhost and 1521. Fix trap 1 with -p 1521:1521. Fix trap 2 by using the service name, //oracle:1521/FREEPDB1. Teardown is docker rm -f lab-oracle or docker compose down -v.

If you get ORA-12514 instead, congratulations, you got further: something answered on 1521 and it didn't know your service, which is also what happens if you connect in the first minute after the container starts.

Why it broke, the simple version

Your client sent a connection to a host and port. The operating system there had no process accepting connections on that address and said so. Either nothing's running, or it's running somewhere other than where you're knocking.

What a refused connection really means

Most "no listener" advice stops at lsnrctl start. That fixes the case where the listener isn't running, and does nothing for the other half, and the other half is where I lose time.

A TCP listener doesn't listen on "the machine". It listens on a specific IP address and port. When the Oracle listener starts, it reads its listener.ora (or falls back to its defaults: a listener called LISTENER on TCP port 1521) and binds the addresses in it. Each ADDRESS with a HOST becomes one bound socket. HOST=localhost means 127.0.0.1 only. A real host name means whatever that name resolves to on the database server, at the moment the listener starts.

That last bit is the surprise that got me. On Debian and Ubuntu, /etc/hosts often maps the machine's own host name to 127.0.1.1. So a listener.ora with HOST=dbhost01, which looks completely correct, can bind loopback only. lsnrctl status shows the listener up, the endpoint line shows the host name you expect, local SQL*Plus works, and every remote client gets ORA-12541. My first instinct was the firewall. It's always the firewall, except when it isn't. ss -ltnp showed 127.0.1.1:1521 and the mystery was over.

Containers bend the same rule from the other side. Inside a container, localhost is that container's own network namespace. An app container asking for localhost:1521 is asking itself, and it has no listener, so the refusal is instant. Docker Desktop on macOS and Windows adds a Linux VM in the middle, so even the host's localhost only reaches the database if the port is published.

And the firewall does matter, in one specific way. A firewall that rejects a connection sends something back, and the client can see a refusal much like this one. A firewall that drops packets sends nothing, and the client waits until its connect timeout runs out. Fast failure, listener problem or a rejecting rule. Slow failure, dropped packets and ORA-12170. The timing tells you which half of the network to blame before you've read a single config file.

Fixing ORA-12541 at the right address

Start from what the client tried, not from what you think it tried. On a 23ai/26ai client, it's in the message. On older clients, log the full connect string at startup (password masked) and turn on client tracing only if that isn't enough. Then match the case.

What you found What's wrong Fix
lsnrctl status fails on the DB host with TNS-12541 and "Connection refused" Listener isn't running lsnrctl start (or lsnrctl start LISTENER_NAME), then find out why it stopped
Listener up, ss shows 127.0.0.1:1521 or 127.0.1.1:1521 Bound to loopback Fix HOST in listener.ora or /etc/hosts, restart the listener
Listener up on a different port Client and listener disagree on port Change the connect string, not the listener, unless the port was the mistake
nc works from your laptop, fails from the app container App is using localhost or an old host Use the Compose or Kubernetes service name, or the real DNS name
nc fails on localhost from the host, works inside the DB container Port not published -p 1521:1521, or the ports: entry in Compose
Worked yesterday, refused after a migration DNS or tnsnames.ora still points at the old box Update the alias or the DNS record

A few of these need more than a line.

The listener isn't running. Starting it is fine, but find out why it wasn't. On Windows, the listener is its own service (the name ends in TNSListener) and if it's set to Manual it won't come back after a reboot. On Linux, check whether anything starts it at boot (Oracle Restart, a systemd unit, a dbstart script). If lsnrctl start itself fails with TNS-12542, another process holds the port, which is its own problem. Restarting the listener drops its dynamic service registrations for a short while, so expect a burst of ORA-12514 until the database re-registers. That's normal.

Bound to loopback. Here's the change I'd make in listener.ora. This touches every client of that listener, so do it in a maintenance window if the database is shared:

# before: reachable from this host only
LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))))

# after: bound to the server's routable name (check it resolves to the real IP, not 127.0.1.1)
LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = dbhost01.example.com)(PORT = 1521))))

Then lsnrctl stop and lsnrctl start, and confirm with ss -ltnp that the socket is on the routable address. lsnrctl reload re-reads most of the file, but I restart for address changes so there's no doubt. If you change the port, check the database's LOCAL_LISTENER parameter too, or you'll swap ORA-12541 for ORA-12514. (Reading the rest of the lsnrctl output is in lsnrctl status and services.)

The container localhost trap. The fix for the gateway at the top was one word:

# before
spring.datasource.url=jdbc:oracle:thin:@//localhost:1521/FREEPDB1
# after: the Compose service name of the database container
spring.datasource.url=jdbc:oracle:thin:@//oracle:1521/FREEPDB1

Don't reach for --network host or the host's IP address as a quick fix. The first gives up container isolation, the second breaks the next time the IP changes. The accepted answer in that Docker forum thread says to use a different IP. It works, and it's fragile.

Things that circulate and don't help: reinstalling the client, editing sqlnet.ora, and granting anything to anyone. ORA-12541 happens before the database knows you exist.

How to not end up here again

One connect string per environment, in one config value, with a real host name the app can resolve from where it runs. In containers, that's the service name. On VMs, a DNS name that you control, not an IP, so a database move is a DNS change.

For databases with a standby or more than one listener, let the connect descriptor try more than one address and retry briefly:

spring.datasource.url=jdbc:oracle:thin:@(DESCRIPTION=(CONNECT_TIMEOUT=5)(RETRY_COUNT=3)(RETRY_DELAY=2)(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=db-primary.example.com)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=db-standby.example.com)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=gateway_app.example.com)))

A refused address fails over to the next one in milliseconds. RETRY_COUNT and RETRY_DELAY cover the short window while a listener restarts. Check the defaults and limits for these in the Net Services Reference for your release before copying the numbers. And the service name should be the app's own, which is the SID vs service name story.

On the database side: the listener starts with the machine, every time, by whatever manages the instance. And HOST in listener.ora is a name you've checked resolves to a routable address on that server.

Which versions behave how

The message changed. 19c-era clients print TNS:no listener with nothing else; 23ai/26ai print Cannot connect. No listener at host ... port ..., often with a CONNECTION_ID and the help URL, as in the log above. Anything that greps logs for "TNS:no listener" will go quiet after a client or driver upgrade while the error carries on, so alert on ORA-12541, the code.

Older JDBC drivers often report a refused socket as the "Network Adapter could not establish the connection" I/O error instead of ORA-12541, with the ConnectException nested inside; that wrapper has its own article, IO Error: The Network Adapter could not establish the connection. The driver in the forum log above reports ORA-12541 directly. Which one you get depends on your driver release, so check yours rather than trusting either. python-oracledb in thin mode raises its own DPY- error and includes the underlying refusal.

For catching it early, I'd have three things. A deploy smoke test that opens a connection with the app's exact URL from where the app runs, before it takes traffic. A synthetic TCP check on 1521 from the app subnet, alerting if it fails for more than a minute. And a process check on the database host for the listener itself (tnslsnr on Linux, the TNSListener service on Windows), so you hear about a dead listener before the app does.

For the record, what I checked for this one: the 19c and 26ai wording against Oracle's error help and Net Services pages, the IPC variant, a real 23ai-style log from a public thread, and the TCP behaviour underneath on my own machine. I didn't get to run an Oracle container this time, and I've said so where it matters.

The short list

  • ORA-12541 is a TCP refusal in Oracle clothing. The listener never saw you.
  • Fast failure means refused (this error). Slow failure means dropped (ORA-12170).
  • lsnrctl status saying "up" doesn't mean reachable. Check which IP the socket is bound to with ss -ltnp.
  • Inside a container, localhost is the container. Use the service name.
  • On 23ai/26ai, read the host and port in the message before touching anything.

ORA-12541, asked the way people search it

How do I fix ORA-12541 TNS:no listener? Find out what host and port the client tried (23ai/26ai clients print them), then test that address with nc -vz host 1521 from where the app runs. If nothing answers, start the listener with lsnrctl start on the database host, or fix the host or port in your connect string. If the listener is up but remote clients are refused, it's probably bound to localhost.

Why do I get ORA-12541 when Oracle is running in Docker? Either the port isn't published (-p 1521:1521 missing), or your app runs in another container and connects to localhost, which means itself. Use the database container's service name in Compose, for example //oracle:1521/FREEPDB1.

How do I start the Oracle listener? On the database host, as the Oracle software owner, run lsnrctl start, or lsnrctl start LISTENER_NAME for a named listener. On Windows you can also start the listener's Windows service, whose name ends in TNSListener. Then run lsnrctl status and check the listening endpoints match what clients use.

What's the difference between ORA-12541 and ORA-12514? ORA-12541 means nothing answered on that host and port. ORA-12514 means the listener answered but doesn't know the service you asked for, so you got one step further. The full comparison, including ORA-12154, is in ORA-12514 vs ORA-12541 vs ORA-12154.

ora-12541oracle-listenerconnection-refuseddockeroracle-netoracle-database

Staff engineer architecting Kafka and Flink platforms for banking, where a dropped event is a reconciliation break, not a retry. Through javahandbook.com, I share production-tested guidance on building reliable event-driven systems.

Comments