Skip to content

ORA-12505: Listener Does Not Currently Know of SID, Fixed

ORA-12505 almost always means a service name went where a SID goes, usually through a colon in a JDBC URL. Why a PDB has no SID to give you, the one-character fix, and the rare case where USE_SID_AS_SERVICE is fair.

ora-12505 oracle-jdbc jdbc-url service-name oracle-listener oracle-pdb oracle-database
Gopi Gorantala
Reading Progress

On This Page

Nine times out of ten, ORA-12505 is one character. A colon where a slash should be.

The listener is up, it answered, and it looked for an instance with the name you sent. It didn't find one, because the name you sent is a service (very often a pluggable database like FREEPDB1 or XEPDB1) and you sent it in the slot reserved for a SID. The fix is to send it as a service name. Everything below is about proving that's your case, and handling the tenth time when it isn't.

The exact message (two of them, depending on your driver)

On 19c-era clients and older JDBC drivers you get the line people have been pasting into search boxes for fifteen years:

ORA-12505, TNS:listener does not currently know of SID given in connect descriptor

Older Oracle JDBC drivers wrap it in their own sentence, so in a Java stack trace it usually looks like this (the exception class varies by driver version, SQLException or SQLRecoverableException):

java.sql.SQLException: Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor

The 23ai/26ai-generation wording finally tells you what it was looking for and where. This is the template from Oracle's error help page for ORA-12505, which lists it for 19c, 21c and 26ai, and the example from the 26ai Net Services Administrator's Guide:

ORA-12505: Cannot connect to database.
SID sales_sid is not registered with the listener at host 10.9.7.5 port 1522.
(CONNECTION_ID=1ABcDEabCd1aB+AbCdE1aB==)

Read the name after SID. If it's your PDB, you've found it already. And note when it happens: at connect time, every time, before a password is checked. If it only happens some of the time, see the last FAQ answer.

Colon or slash? Check that before anything else

Look at your connect string. That's the whole triage for most people:

# SID syntax: the name after the second colon is sent as SID=
spring.datasource.url=jdbc:oracle:thin:@db-host:1521:FREEPDB1

# Service syntax (EZConnect): the name after the slash is sent as SERVICE_NAME=
spring.datasource.url=jdbc:oracle:thin:@//db-host:1521/FREEPDB1

The thin driver turns the first form into a descriptor with (CONNECT_DATA=(SID=FREEPDB1)) and the second into (CONNECT_DATA=(SERVICE_NAME=FREEPDB1)). Same name, different question to the listener. If you use a tnsnames.ora alias instead of a URL, open the entry and look for SID= inside CONNECT_DATA. Same thing. In SQL Developer it's the radio button under the port field: "SID" or "Service name".

If the colon is there, skip to the fix. If you're already using a slash or SERVICE_NAME= and you still get ORA-12505, you have one of the rarer causes, and the next command tells you which. Run it on the database host:

lsnrctl services        # every service and every instance this listener knows, with READY/BLOCKED status

Each block starts with a Service "..." line and lists the Instance "..." lines under it. Instance names are what a SID has to match. Service names are what a service name has to match. Ten seconds of reading and you know which list your name belongs in, if any. (lsnrctl status and services, explained walks through the whole output.)

No shell on the host? A DBA can run SELECT instance_name FROM v$instance; for the SID and SELECT name, con_id FROM v$active_services ORDER BY con_id; for the services.

Make it fail on demand

This lab uses a throwaway Oracle Database Free container and a single-file Java program. Run it on your laptop, never against a shared database.

What you need: Docker, a JDK 17 or later, and an ojdbc11 jar from Maven Central (com.oracle.database.jdbc:ojdbc11, any 23.x release; pin the exact one you download). The image is gvenzl/oracle-free; in it the instance (the SID) is FREE and the default PDB is FREEPDB1. If you use Oracle's own image from container-registry.oracle.com instead, the names are the same but the password variable is ORACLE_PWD.

One honest note: the machine I wrote this on couldn't reach Docker Hub, Oracle's registry or Maven Central, so I couldn't run this lab for the article. The commands are what I'd type; the expected output is the message text from Oracle's documentation, not a capture from my terminal. If yours differs, tell me.

  1. Start the database and wait for it:
docker run -d --name lab-oracle -p 1521:1521 \
  -e ORACLE_PASSWORD=LabOnly_2026 \
  -e APP_USER=points -e APP_USER_PASSWORD=Points_2026 \
  gvenzl/oracle-free:23-slim-faststart

docker logs -f lab-oracle   # wait for "DATABASE IS READY TO USE!" then Ctrl+C

APP_USER makes the image create a local user called points inside FREEPDB1. That detail pays off in step 4.

  1. Save this as Lab.java. It's a cut-down version of the connection check a loyalty-points service would run at startup:
import java.sql.*;

public class Lab {
    public static void main(String[] args) throws Exception {
        String url = args[0];
        try (Connection c = DriverManager.getConnection(url, "points", "Points_2026");
             Statement s = c.createStatement();
             ResultSet rs = s.executeQuery(
                 "SELECT sys_context('USERENV','CON_NAME'), sys_context('USERENV','SERVICE_NAME') FROM dual")) {
            rs.next();
            System.out.println("connected: container=" + rs.getString(1) + " service=" + rs.getString(2));
        }
    }
}
  1. Pass the PDB name in the SID slot:
java -cp ojdbc11.jar Lab.java "jdbc:oracle:thin:@localhost:1521:FREEPDB1"   # colon: FREEPDB1 is sent as a SID

Expected: ORA-12505 naming FREEPDB1 as the SID that isn't registered, in the 26ai wording above with this driver generation. The listener checked its instance list, found only FREE, and refused.

  1. Now do what everybody does next, which is change the name to the one thing that is a SID:
java -cp ojdbc11.jar Lab.java "jdbc:oracle:thin:@localhost:1521:FREE"

ORA-12505 is gone. You get ORA-01017 instead. The listener happily handed you to instance FREE, which means you landed in the root container, CDB$ROOT, and the user points doesn't exist there. It lives in the PDB. This is the dead end I'd bet most readers have already walked into. It feels like progress, because the error changed. It isn't. ORA-01017 with the right password and CDB vs PDB cover where that road goes.

  1. Use the slash:
java -cp ojdbc11.jar Lab.java "jdbc:oracle:thin:@//localhost:1521/FREEPDB1"

Expected: connected: container=FREEPDB1 service=FREEPDB1 (the service may print in lower case, depending on how the image registered it).

Forcing levers: none. This one needs no shrunken limits; the wrong syntax is the whole reproduction.

Confirmation signal: the code is 12505 and the name in the message is the one you typed. If you see ORA-12514 instead, you sent a service name the listener doesn't know, which is a different article. If you see ORA-12541, nothing is listening on that port at all; see ORA-12541.

Where else it shows up: any client with a SID field: SQL Developer's SID radio button, a tnsnames.ora entry with SID=, python-oracledb's makedsn(..., sid=...), DBeaver or IntelliJ profiles set to "SID". SQLPlus EZConnect can't send a SID at all, so SQLPlus users only hit it through an alias.

Teardown:

docker rm -f lab-oracle     # the slim image keeps data inside the container; nothing else to clean

One paragraph, no theory

A SID names a running instance on one host. A service name names a database workload, and that's the only kind of name a pluggable database answers to. The listener keeps two lists, and the syntax you use decides which one it searches. Put a PDB name in the SID slot and the search comes back empty, so you get ORA-12505.

Why a PDB has no SID to give you

Here's the part every forum answer skips, and it's why the confusion exists at all.

Before 12c, one instance ran one database, and the instance name and the database's service name were usually the same string (ORCL and ORCL). People wrote @host:1521:ORCL for twenty years and it worked, because the listener could find ORCL in its instance list. The SID syntax and the service syntax were interchangeable by coincidence.

Multitenant broke the coincidence. One instance (one SID, FREE) now runs a container database with several pluggable databases inside it, and each PDB is reachable only through its own service. There's no instance per PDB, so there's nothing for a PDB to have a SID of. When the database starts, the listener registration process (LREG) tells the listener "instance FREE is here" and "services FREE, FREEPDB1 (and a few internal ones) are served by instance FREE." Your PDB name only ever lands in the service list.

So a connect descriptor with SID=FREEPDB1 asks the listener a question that, on 12c and later, can never be true for a PDB. Oracle's error page puts the cause as a SID that is "neither dynamically registered nor statically configured" in listener.ora. That's accurate and, for a PDB, permanent.

The surprise for me was where the wording comes from. The listener refuses with an error number and your client builds the text, which is why a 19c-era driver talking to 26ai still prints the old sentence. The new one adds the host, port and a CONNECTION_ID you can grep for in trace files.

There are two less common ways to get here with a SID that is real:

  • The instance hasn't registered yet. Right after the listener restarts, it knows nothing until LREG checks in. Oracle's own action text says to wait and retry. If it doesn't clear within a minute or so, ALTER SYSTEM REGISTER; (run as a DBA on the instance) forces registration now.
  • You used the database name, not the instance name. On RAC each node runs its own instance (ORCL1, ORCL2), and the database name ORCL isn't anyone's SID. I couldn't test RAC for this piece, so take the mechanism from lsnrctl services on the node rather than from me.

Fixing ORA-12505 in JDBC, SQL Developer and Python

The fix is the same idea everywhere: ask for a service. Why it works: the listener searches its service list, and that's where your PDB is.

JDBC and Spring Boot:

# before
spring.datasource.url=jdbc:oracle:thin:@db-host:1521:FREEPDB1
# after
spring.datasource.url=jdbc:oracle:thin:@//db-host:1521/FREEPDB1

tnsnames.ora:

# before
POINTS = (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=db-host)(PORT=1521))(CONNECT_DATA=(SID=FREEPDB1)))
# after
POINTS = (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=db-host)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=FREEPDB1)))

SQL Developer: edit the connection, switch the radio button from SID to Service name, keep the same text. Test, save.

python-oracledb:

import oracledb

# before: makedsn(..., sid=...) sends SID=
dsn = oracledb.makedsn("db-host", 1521, sid="FREEPDB1")
# after: an EZConnect string is always a service name
conn = oracledb.connect(user="points", password="Points_2026", dsn="db-host:1521/FREEPDB1")

What about the answers that tell you to edit the listener? There's a real parameter for that. Know what it does first.

Option What it does When it's right What it costs
Switch the client to service syntax Asks the right question Always, if you can change the client Nothing
USE_SID_AS_SERVICE_LISTENER=ON in listener.ora Listener treats every SID in every descriptor as a service name A client you can't change: a vendor jar with a baked-in SID URL Listener-wide; anyone who used a real instance SID that isn't also a service name now gets ORA-12514
Connect with the CDB's SID (FREE) Gets you past the listener into the root container Never, for application users ORA-01017, ORA-00942 or ORA-65096 later, depending on what you do next
Static SID_LIST_LISTENER entry Registers an instance by hand Data Guard, remote startup, external procedures Doesn't help a PDB at all

USE_SID_AS_SERVICE_listener_name is documented in the Net Services Reference as off by default, and exists so old clients with hard-coded descriptors can reach a PDB. The suffix is your listener's name, so for the default listener the line is USE_SID_AS_SERVICE_LISTENER=ON, followed by lsnrctl reload. It's a compatibility shim for software you don't own. If it's your code, change the URL. A listener setting that quietly rewrites every client's question is the kind of thing nobody remembers during the next migration.

Designing around it

One connect-string format, the service syntax, with the service name from per-environment config. Never from someone's memory of what the database used to be called.

# application.yml
spring:
  datasource:
    url: jdbc:oracle:thin:@//${ORACLE_HOST}:${ORACLE_PORT:1521}/${ORACLE_SERVICE}

In production, ask for an application service (say points_app, created with DBMS_SERVICE) instead of the default PDB service. Your DBAs can then move or drain it without you touching the URL. (The full picture of which identifier goes where is in SID vs service name vs PDB name.)

The test that would have caught this

A one-line CI check catches the SID syntax before it ships. It matches a thin URL with a port followed by a colon:

grep -rEn 'jdbc:oracle:thin:@[^/(][^/(]*:[0-9]+:' --include='*.properties' --include='*.yml' --include='*.yaml' --include='*.java' . \
  && { echo "SID-style Oracle URL found; use @//host:port/service"; exit 1; } || true

Pair it with an integration test that connects to a containerised Oracle at your production version using the app's own URL template.

On versions: the code and the cause haven't changed since the listener existed. What changed is the message. Clients and drivers from the 23ai generation onward print the "Cannot connect to database. SID ... is not registered" wording with a CONNECTION_ID; 19c-era clients print the old one. Log alerts that match the old text stop matching after a driver upgrade, so check them. What I verified for this one: both wordings against Oracle's error page (19c, 21c, 26ai) and the 26ai Net Services guide, plus the JDBC and python-oracledb syntax against their docs. No more than that.

Screenshot this bit

  • ORA-12505 means the listener searched its instance list and your name wasn't there. A PDB name will never be there.
  • In a thin JDBC URL, @host:port:NAME sends a SID and @//host:port/NAME sends a service. Use the slash.
  • Changing the name to the CDB's SID makes the error go away and puts you in the wrong container. Expect ORA-01017 next.
  • USE_SID_AS_SERVICE_LISTENER=ON is for clients you can't edit, and it affects everyone on that listener.

ORA-12505 questions people keep asking

How do I fix ORA-12505 in SQL Developer?

Edit the connection and switch the connection type option from "SID" to "Service name", keeping the same value (for example FREEPDB1 or XEPDB1). SQL Developer then sends SERVICE_NAME= instead of SID=, and the listener finds your PDB in its service list. If you then get ORA-12514, the service name itself is wrong; see ORA-12514.

What's the difference between SID and service name in a JDBC URL?

A SID identifies one running instance on one host; a service name identifies a database workload that one or more instances serve, and it's the only way to reach a pluggable database. In the thin driver, jdbc:oracle:thin:@host:1521:NAME sends a SID and jdbc:oracle:thin:@//host:1521/NAME sends a service name. On 12c and later, use the service form.

Is it safe to set USE_SID_AS_SERVICE_LISTENER=ON?

It works, and it's off by default for a reason. It makes the listener read every SID in every incoming descriptor as a service name, so clients that legitimately connected by a real instance SID that isn't also a service name start failing with ORA-12514. Use it only for third-party clients you can't reconfigure, and write down that you did.

Why does ORA-12505 go away after a few minutes?

Then your SID was right and the instance hadn't registered with the listener yet, which happens after a listener restart or while the database is still starting. Oracle's action text for the error is to wait and retry. If it keeps happening after restarts, a DBA can run ALTER SYSTEM REGISTER; to force registration, and in containers a healthcheck should gate your app until the database reports ready (the Docker startup version of this problem).

ora-12505oracle-jdbcjdbc-urlservice-nameoracle-listeneroracle-pdboracle-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