The Oracle database-C multi-tenant option allows a single container database (CDB) to host multiple separate pluggable databases (PDB).
So how do we connect to the container database (CDB) and pluggable Database (PDB).
1. The V$services view can display the services available in the database.
Sql> Col pdb for A40
Sql> col name for A30;
SELECT name, PDB from V$services ORDER by name; Sql>
NAME PDB
------------------------------ ----------------------------------------
Sys$background Cdb$root
Sys$users Cdb$root
ANDYCDB Cdb$root
Andycdbxdb Cdb$root
PDB01 PDB01
--The Lsnrctl utility displays the available services.
[Email protected] ~]$ lsnrctl status
Listening Endpoints Summary ...
(Description= (address= (protocol=tcp) (HOST=12C01) (port=1521)))
Services Summary ...
Service "4ecf8621e3da38eee0531019640aa598" has 1 instance (s).
Instance "andycdb", status ready, have 1 handler (s) for the This service ...
Service "ANDYCDB" has 1 instance (s).
Instance "andycdb", status ready, have 1 handler (s) for the This service ...
Service "Andycdbxdb" has 1 instance (s).
Instance "andycdb", status ready, have 1 handler (s) for the This service ...
Service "PDB01" has 1 instance (s).
Instance "andycdb", status ready, have 1 handler (s) for the This service ...
The command completed successfully
2. Connect directly to a container database (CDB)
The root container that connects to the database is the same as a single DB instance that connects to a previous version. On the database server, you can use operating system authentication.
Method One:
[Email protected] ~]$ Sqlplus/as SYSDBA
Method Two:
or Tnsnames.ora file configuration
ANDYCDB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP) (HOST = 12c01) (PORT = 1521))
(Connect_data =
(SERVER = dedicated)
(service_name = andycdb)
)
)
C:\users\andy>sqlplus Sys/[email protected]:1521/andycdb as Sysdba
3. Connect directly to a pluggable database (PDB)
Tnsnames.ora File configuration:
PDB01 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP) (HOST = 10.100.25.16) (PORT = 1521))
(Connect_data =
(SERVER = dedicated)
(service_name = pdb01)
)
)
C:\users\andy>sqlplus Sys/[email Protected]:1521/pdb01 as Sysdba
Sql> Show Con_name
Con_name
------------------------------
PDB01
Description: A PDB with SYSDBA, Sysoper, sysbackup, or SYSDG privileges can connect to a closed PDB.
All other users of the PDB (users with Connect session permissions) can only connect to the PDB that is already open.
4. Switch between containers
sql> ALTER SESSION SET container=pdb01;
Session altered.
Sql> Show Con_name
Con_name
------------------------------
PDB01
Sql> alter session set Container=cdb$root;
Session altered.
Sql> Show Con_name
Con_name
------------------------------
Cdb$root
ORACLE12C How multi-tenancy connects to the CDB or PDB, CDB, and PDB container switches