How to connect to Pluggable Databases in Oracle 19

In this tutorial, I used the Default Service for connecting to the PDB. Made in the tnsnames.ora file that defines database addresses that allow us to establish a connection with the database. The status of the PDB needs to be changed from mounted to read-write mode.

The concepts

  • The Container Database (CDB).
  • Pluggable Database (PDB).

Example connect to Pluggable Databases in Oracle 19

  • Where cpdb is the global database.
  • pdb1 and pdb2 are the two pluggable databases created.

Made in the tnsnames.ora file as below:

$ sudo su - oracle
$ cat $ORACLE_HOME/network/admin/tnsnames.ora

#The content tnsnames.ora as below:

CPDB01 =
  (DESCRIPTION =
    (ENABLE = BROKEN)
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.x.x)(PORT = 1655))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = DEVOPSROLES)
      (SERVER = DEDICATED)
    )
  )

PDB01 =
  (DESCRIPTION =
    (ENABLE = BROKEN)
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.x.x)(PORT = 1655))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = PDB01_DEVOPSROLES)
      (SERVER = DEDICATED)
    )
  )

PDB02 =
  (DESCRIPTION =
    (ENABLE = BROKEN)
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.x.x)(PORT = 1655))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = PDB02_DEVOPSROLES)
      (SERVER = DEDICATED)
    )
  )

Changing the status of the pluggable database

When the pdbs are created, by default, the open_mode is ‘Mounted’ only. Query status opens mode pdbs as command below:

$ sudo su - oracle
$ export ORACLE_SID=CPDB01
$ sqlplus "/as sysdba"
SQL> select name, open_mode from v$pdbs;

If pdbs open mode is “Mounted” only. You run the command that opens all the pluggable databases in a read-write mode.

SQL> Alter pluggable database all open;

After this connection can be established with the database using sqlplus command as below:

$ sqlplus "sys/oracle@PDB01"

Conclusion

Thought the article, “How to connect to Pluggable Databases in Oracle 19″ as above. I hope will this your helpful. Thank you for reading the DevopsRoles page!

About HuuPV

My name is Huu. I love technology and especially Devops Skill such as Docker, vagrant, git so forth. I likes open-sources. so I created DevopsRoles.com site to share the knowledge that I have learned. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

Leave a Reply

Your email address will not be published.

Comment moderation is enabled. Your comment may take some time to appear.

This site uses Akismet to reduce spam. Learn how your comment data is processed.