Tuesday, October 1, 2013

12c connect to multiple PDBs with the same name in different CDBs



When you create a Pluggable Database (PDB) , the database automatically creates and starts a service inside the Container Database ( CDB) . Let us assume you have a PDB_1 database in CDB1. I created a another container called DUP and created a pdb called PDB_1.
In my case, i just used RMAN to duplicate the CDB1 to DUP.

Now, if i try to connect to the service using the easy connect or tnsnames.ora to PDB_1, which CDB--> PDB will i be connected to ?

easy_connect syntax is
sqlplus scott/tiger@//localhost:1521/pdb_1 

What chances are that i could be connected to CDB1-->PDB_1 database or DUP-->PDB_1 database ..
To prove my point, let us look at the listener status.

[oracle@unknown080027afa328 dup]$ lsnrctl stat

LSNRCTL for Linux: Version 12.1.0.1.0 - Production on 01-OCT-2013 17:03:22

Copyright (c) 1991, 2013, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 12.1.0.1.0 - Production
Start Date                01-OCT-2013 15:58:19
Uptime                    0 days 1 hr. 5 min. 3 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/12.1.0/dbhome_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/unknown080027afa328/listener/alert/log.xml
Services Summary...

Service "cdb1" has 2 instance(s).
  Instance "cdb1", status UNKNOWN, has 1 handler(s) for this service...
  Instance "cdb1", status READY, has 1 handler(s) for this service...
Service "cdb1XDB" has 1 instance(s).
  Instance "cdb1", status READY, has 1 handler(s) for this service...
Service "dup" has 2 instance(s).
  Instance "dup", status UNKNOWN, has 1 handler(s) for this service...
  Instance "dup", status READY, has 2 handler(s) for this service...
Service "pdb_1" has 2 instance(s).
  Instance "cdb1", status READY, has 1 handler(s) for this service...
  Instance "dup", status READY, has 1 handler(s) for this service...
...

 The service has the same name as the PDB_1. But observe that it has two instances...
Solution:
This is where i remember that in easy connect and tnsnames.ora we always had a option to connect to an instance_name. I was using that functionality in RAC services or db links to connect to one node, even if the services can span multiple nodes for load balancing.. 
Now using the existing functionality, i can now  pick which PDB to connect..

example below.

sqlplus scott/tiger@//localhost:1521/pdb_1/dup  and

sqlplus scott/tiger@//localhost:1521/pdb_1/cdb1

or if you use tnsnames.ora it would be

PDB_1_dup =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = pdb_1) (instance_name = dup)
    )
  )

No comments:

Post a Comment

Feedback welcome