snippetMinor
How can I be specific about which CDB I want to connect to wrapping a PDB?
Viewed 0 times
wantcanconnecthowcdbaboutwrappingspecificwhichpdb
Problem
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:
But can't I have two PDBs with the same name in different CDBs? If that happened,
EDIT: I found out that when I write
As far as I understand, I can map the service name to PDB name using
It seems to map services to CDBs I need to type
So I guess the instance
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.
sqlplus user/password@server:port/pdb1But 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 SERVERSo 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.
Solution
Quite easily.
The full syntax for Easy Connect is:
Understanding the Easy Connect Naming Method
You just need to specify the
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:
The full syntax for Easy Connect is:
Understanding the Easy Connect Naming Method
CONNECT username@[//]host[:port][/service_name][:server][/instance_name]You just need to specify the
service_name and the instance_name as well.$ lsnrctl services
...
Service "pdb1" has 2 instance(s).
Instance "RAIN", status READY, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:3 refused:0 state:ready
LOCAL SERVER
Instance "WIND", status READY, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:3 refused:0 state:ready
LOCAL SERVERYou 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:
sqlplus user/password@localhost:1521/pdb1The 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:
sqlplus user/password@localhost:1521/pdb1/rain
sqlplus user/password@localhost:1521/pdb1/windCode Snippets
CONNECT username@[//]host[:port][/service_name][:server][/instance_name]$ lsnrctl services
...
Service "pdb1" has 2 instance(s).
Instance "RAIN", status READY, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:3 refused:0 state:ready
LOCAL SERVER
Instance "WIND", status READY, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:3 refused:0 state:ready
LOCAL SERVERsqlplus user/password@localhost:1521/pdb1sqlplus user/password@localhost:1521/pdb1/rain
sqlplus user/password@localhost:1521/pdb1/windContext
StackExchange Database Administrators Q#197528, answer score: 2
Revisions (0)
No revisions yet.