Oracle 12c - CDB - PDB - Performing Basic Tasks PDF
Oracle 12c - CDB - PDB - Performing Basic Tasks PDF
Overview
Purpose
This tutorial covers the steps to perform basic tasks on container databases (CDBs) and pluggable databases (PDBs).
Time to Complete
Approximately 45 minutes
Introduction
Note: For readability, formatting was applied to some columns shown in the output.
Prerequisites
ORACLE_HOME: /u01/app/oracle/product/12.1.0
TNS Listener port: 1521
Container databases:
SID: cdb1
SID: cdb2
Pluggable databases (in cdb1):
pdb1
pdb2
Creating a CDB creates a service whose name is the CDB name. As a side effect of creating a PDB in the CDB, a service
is created inside it with a property that identifies it as the initial current container. The service is also started as a side effect
of creating the PDB. The service has the same name as the PDB. Although its metadata is recorded inside the PDB, the
invariant is maintained so that a service name is unique within the entire CDB.
1. Use the Easy Connect syntax to connect to the root unless a net service name is configured in the tnsnames for
the root service.
. oraenv
show con_name
show con_id
connect / as sysdba
show con_name
show con_id
3. Display the list of available services for the root and the PDBs.
4. Use the Easy Connect syntax to connect to the PDB unless a net service name is configured in the tnsnames for
the PDB service.
connect sys/oracle@localhost:1521/pdb1 as sysdba
show con_name
show con_id
exit
In this section, you create a PDB from the seed PDB. Each CDB has a template PDB whose name is PDB$Seed.
Creating the OS Directory for the New Data Files and Temp Files of the PDB
Before starting the PDB creation, create a destination directory for the data files.
mkdir /u01/app/oracle/oradata/cdb1/pdb3
sqlplus / as sysdba
2. Verify the status, open mode, and service names of the PDBs in the CDB. If the status for a PDB shows
NEEDS SYNC, you can connect to the PDB and run the DBMS_PDB.SYNC_PDB procedure to change the
status to NORMAL.
In this section, you start the CDB and shut it down. You also open and close the PDBs.
show con_name
shutdown immediate
This operation first closes all PDBs, then dismounts the control files, and finally shuts down the instance.
3. Start the CDB. This operation requires the SYSDBA or SYSBACKUP privilege.
startup
This operation first starts the instance, then mounts the control files, and finally opens only the root
container.
4. Verify the open mode of the PDBs. This operation first starts the instance, then mounts the control files, and
finally opens only the root container.
Notice that PDB1 is opened automatically because of a database trigger that was previously created in this
environment. Later in this tutorial, you will learn how to create a trigger to open all PDBs after the CDB is
started.
4. Close a PDB.
When a CDB instance starts, you discover that its PDBs do not automatically open. In a development
environment, it is convenient to ensure that all PDBs open with the instance.
b. Shut down and start the CDB to verify that the trigger automatically opens all PDBs.
startup
Renaming a PDB
1. Open the PDB in restricted mode.
2. Rename the PDB. You must be connected to the PDB to rename it.
lt l bl d t b db3 l b l t db3 bi
alter pluggable database pdb3 rename global_name to pdb3_bis;
Note: You should receive an error message when you execute this statement because you are not
connected to the pluggable database that is being renamed.
connect sys/oracle@localhost:1521/pdb3 as sysdba
Each container in a CDB stores data in its own data files and handles temporary data in its own temp files.
connect / as sysdba
connect system/oracle@localhost:1521/pdb3_bis
Each container in a CDB holds common and local users. Any user, common or local, can only exercise the granted
privileges inside the specific container to which it is connected.
Common users are created from the root and are automatically replicated in each PDB except the seed PDB.
Common users can connect to any PDB. The name assigned to a common user must start with c##.
Local users are created in a PDB they need to access. Local users can only connect to the PDB where they are
created. They are not visible to the other PDBs of the same CDB.
connect / as sysdba
select username, common, con_id from cdb_users where username like 'C##%';
connect c##1/oracle@localhost:1521/pdb2
connect c##1/oracle@localhost:1521/pdb3_bis
The user is recognized in each PDB but cannot connect because the CREATE SESSION privilege was not yet
granted.
t t / l @l lh t 1521/ db3 bi
connect system/oracle@localhost:1521/pdb3_bis
connect hr/oracle@localhost:1521/pdb2
connect hr/oracle@localhost:1521/pdb3_bis
The user is recognized in the PDB where he was created (pdb3_bis) but not in another PDB (pdb2) because
he is local only to pdb3_bis.
Common roles are created from the root and are automatically replicated in each PDB except the seed PDB.
The name assigned to a common role must start with c##.
Common roles can be granted commonly: The grant operation is replicated in each PDB except the
seed PDB.
Common roles can be granted locally: The grant operation is performed in the container where the
operation takes place.
Local roles are created in a PDB they need to access. Local roles can be granted locally only in the PDB where
they are created. They are not visible to the other PDBs of the same CDB.
connect / as sysdba
2. Create a local role in a PDB. (When you are connected to a PDB, you cannot create a common role.)
connect system/oracle@localhost:1521/pdb3_bis
You should see an error message after executing this statement because you cannot create a common role
inside a PDB.
Managing Common and Local Privileges
You can grant common and local privileges to common and local users and roles. The privileges become common or
local based on how they are granted. They are common when they are granted with the CONTAINER=ALL clause.
Common privileges are automatically granted to the common grantee (user or role) in each PDB except the
seed PDB.
Local privileges are granted to a grantee (user or role) in a specific PDB.
connect / as sysdba
connect c##1/oracle@localhost:1521/pdb2
connect c##1/oracle@localhost:1521/pdb3_bis
connect system/oracle@localhost:1521/pdb3_bis
connect hr/oracle@localhost:1521/pdb2
[you should see an error message after executing this statement. why?]
connect hr/oracle@localhost:1521/pdb3_bis
Dropping PDBs
When you drop a PDB, you can specify to keep or delete the data files. Keeping the data files is required when you unplug
a PDB and want to plug it into another CDB (or the same CDB). The data files are reused when plugging in the PDB.
Perform the following steps to reset your environment prior to repeating the activities covered in this OBE or starting
another OBE.
3. Open pdb1 and replace the database trigger with a trigger that opens only pdb1 at CDB startup.
Summary
In this tutorial, you learned how to manage basic tasks on container and pluggable databases, including creating PDBs
from seed PDBs; managing tablespaces and security; and creating common and local users, roles, and privileges.
Resources
To learn more about pluggable databases, refer to additional OBEs in the Oracle Learning Library.
Credits