A CDB connection is a network connection to an Oracle multitenant container database (CDB), which allows for the consolidation of many different databases into a single database environment.
A CDB acts as a master database that contains one or more independent pluggable databases (PDBs). A CDB connection is used by database administrators to manage the overall multitenant environment and to perform operations that affect all the PDBs within it. In contrast, a PDB connection is for client applications and users who only need to interact with a specific, isolated pluggable database.
Understanding the multitenant architecture
To understand a CDB connection, you must first grasp Oracle's multitenant architecture. Introduced in Oracle Database 12c and the only supported architecture since Oracle 21c, this model addresses the challenges of managing numerous separate databases.
- Container Database (CDB): The CDB is the master database that provides the physical foundation for the entire multitenant environment. It comprises a root container (
CDB$ROOT) and a seed PDB (PDB$SEED).- Root Container (
CDB$ROOT): Stores Oracle-supplied metadata and the common users that can manage all of the PDBs. - Seed PDB (
PDB$SEED): A template for creating new PDBs. It cannot be modified.
- Root Container (
- Pluggable Database (PDB): A PDB is a user-created collection of schemas, objects, and data that appears to a user or application as a fully functional, separate database. Each PDB is logically isolated, even though it shares the CDB's background processes, memory, and physical files.
Purpose of a CDB connection
A CDB connection is distinct from a PDB connection and serves a different purpose within the multitenant architecture.
| Feature | CDB Connection | PDB Connection |
|---|---|---|
| User | Primarily used by a CDB administrator with common user privileges (e.g., SYS, SYSTEM). |
Used by local users (tied to a single PDB) and application users. |
| Scope | Manages the entire multitenant environment, including all PDBs and the root container. | Restricted to actions within a single PDB. |
| Tasks | Aggregation-level tasks such as: * Performing a full database backup * Applying patches and upgrades * Allocating resources among PDBs * Creating, cloning, and unplugging PDBs | Application-specific tasks such as: * Creating and managing schemas and objects * Executing application code (SQL, PL/SQL) * Querying and modifying data |
How to connect to a CDB
To establish a connection to a CDB, you must use a database service name associated with the CDB itself, not a specific PDB. This is often done using command-line tools like SQL*Plus or graphical interfaces like Oracle SQL Developer.
Connection methods
- Easy Connect Syntax: This is the simplest way to connect using a connection string that specifies the host, port, and service name. The CDB's service name is typically the same as the CDB's name.
sqlplus sys/oracle@localhost:1521/cdb1 as sysdba - TNSNames.ora File: You can define a net service name in your
tnsnames.orafile, which is useful for simplifying connections and storing connection details centrally.``` CDB1 = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = cdb1) ) )You would then connect using: `sqlplus sys/oracle@CDB1 as sysdba`.
Connecting to a PDB from a CDB connection
A common scenario for a CDB administrator is to connect to the CDB root and then perform administrative tasks within a specific PDB. This is achieved using the ALTER SESSION command.
- Connect to the CDB root: Use the methods described above to connect as a common user to the CDB.
sqlplus / as sysdba``SQL> show con_name;``CON_NAME``CDB$ROOT - Switch the container: Use the
ALTER SESSIONcommand to set the current container to a specific PDB.SQL> ALTER SESSION SET CONTAINER = PDB1;``Session altered.``SQL> show con_name;``CON_NAME``PDB1
This process demonstrates the clear separation of concerns: the physical database (CDB$ROOT) is managed from one connection, while the logical, application-specific database (PDB1) is managed from another within the same session.
Key takeaways
- A CDB connection is an administrative connection to the root container of an Oracle multitenant database, allowing for system-wide operations.
- A PDB connection is a user-facing connection to a specific pluggable database, used for application data and code.
- The multitenant architecture allows a single physical database instance to host multiple, logically isolated databases (PDBs), which provides numerous benefits for consolidation, resource management, and portability.
- Connecting to a CDB requires a common user with privileges to manage the entire container environment.
- Administrators can switch between containers within a single session using the
ALTER SESSION SET CONTAINERcommand.