Sunday, May 3, 2015

Connecting to Pluggable DB in Oracle 12c



Server name: dev121.localdomain
IP Address: 1.0.3.52
CDB: cdb1
PDB: pdb1

Sources:
http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/12c/r1/pdb/pdb_basics/pdb_basics.html
http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/12c/r1/12c_sqldev/pdb/12cPDB01.html
http://oracle-base.com/articles/12c/multitenant-connecting-to-cdb-and-pdb-12cr1.php

- to connect to pluggable database in Oracle 12c you have to two option:

- Pluggable Database (PDB) Automatic Startup with container database
  
$ sqlplus / as sysdba
create or replace trigger open_pdbs
  after startup on database
begin
   execute immediate 'alter pluggable database all open';
end open_pdbs;
/
Option A: using easy connect in SQL Plus:
  

SQL> connect sys/oracle@localhost:1521/pdb1 as sysdba
SQL> col pdb_name format a45
SQL> select pdb_name, status from cdb_pdbs;
PDB_NAME                                     |STATUS
---------------------------------------------|---------
PDB1                                         |NORMAL
PDB$SEED                                     |NORMAL


Option B: connect to pluggable database as a service SQL Plus or SQL Developer which requires an entry in the "$ORACLE_HOME/network/admin/tnsnames.ora" file, such as the one shown below.
  

$ vim $ORACLE_HOME/network/admin/tnsnames.ora
LISTENER_CDB1 =
  (ADDRESS = (PROTOCOL = TCP)(HOST = dev121.localdomain)(PORT = 1521))


CDB1 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = dev121.localdomain)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = cdb1)
    )
  )


PDB1 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = dev121.localdomain)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = pdb1)
    )
  )
$ lsnrctl reload
$ sqlplus system/oracle@pdb1

- using SQL developer to connect a pluggable database as a service
  
$ sqlplus system/oracle@pdb1
SQL> ALTER USER system IDENTIFIED BY oracle account unlock;
SQL> ALTER USER hr IDENTIFIED BY oracle account unlock;
SQL> ALTER USER scott IDENTIFIED BY oracle account unlock;
SQL> ALTER USER oe IDENTIFIED BY oracle account unlock;


- Managing Pluggable Databases (PDBs) using Oracle SQL Developer:

No comments:

Post a Comment