I'm quite new to Oracle. I created a CDB like cdb1 and then a PDB within like pdb1. Now I can connect to my PDB using something like:
sqlplus user/password@server:port/pdb1
But can't I have two PDBs with the same name in different CDBs? If that happened, sqlplus
wouldn't know which PDB I wanted to connect to. Does the listener have some robust way to map the PDB passed in the connection to an actual PDB within a CDB on the machine where the listener is running?
EDIT: I found out that when I write pdb1
in the sqlplus
connection identifier, that is actually not the name of the PDB, but the name of the service, which just happens to be the same as the name of the PDB.
As far as I understand, I can map the service name to PDB name using select name, pdb from v$services;
.
It seems to map services to CDBs I need to type lsnrctl service
. And then I get output like:
Service "pdb1" has 1 instance(s).
Instance "cdb1", status READY, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:0 refused:0 state:ready
LOCAL SERVER
So I guess the instance cdb1
is referring to the CDB cdb1
? Or does it also just happen to have the same name?
Then again, surely the service stating that it has 1 instance, means it could have 2 instances and these could point to separate CDBs, which brings me back to my original question of how to differentiate different PDBs with the same name.
Best Answer
Quite easily.
The full syntax for Easy Connect is:
Understanding the Easy Connect Naming Method
You just need to specify the
service_name
and theinstance_name
as well.You will have more than 1 instance serving the same service. The below may connect to any of the instances, but the listener decides which instance it forwards to your request, not you:
The below commands always connect to just one of the instances. If that instance is down, the connection attempt fails, even though there is another instance providing the same service: