Professional Documents
Culture Documents
Oracle Multitenant 12c
Oracle Multitenant 12c
Oracle Multitenant
Oracle Multitenant is a new option for Oracle Database 12c Enterprise Edition that helps customers reduce IT costs
by simplifying consolidation, provisioning, upgrades, and more. It is supported by a new architecture that allows a
container database to hold many pluggable databases. And it fully complements other options, including Oracle Real
Application Clusters and Oracle Active Data Guard. An existing database can be simply adopted, with no change, as a
pluggable database; and no changes are needed in the other tiers of the application.
Oracle Database 12c supports a new architecture that lets you have many “sub databases” inside a single “super
database”. From now on, we shall use the official terminology. The “super database” is the multitenant container
database — abbreviated as CDB; and the “sub database” is the pluggable database — abbreviated as PDB. In other
words, the new architecture lets you have many PDBs inside a single CDB. (In 12.1, the maximum number is 252.) We
shall refer to the new architecture as the multitenant architecture.
We clearly now need a term for the old kind of database, the only kind of database that was supported through
Oracle Database 11g. We shall call this a non-CDB. Oracle Database 12c Release 1 supports both the new multitenant
architecture and the old non-CDB architecture. In other words, you can certainly upgrade a pre-12.1 database, which
necessarily is a non-CDB, to a 12.1 non-CDB and continue to operate it as such. But, if you choose, you can adopt the
12.1 non-CDB into a CDB as a PDB
One root container, named CDB$ROOT. The root contains the master set of data dictionary views, which have
metadata regarding the root as well as every child pluggable database within the CDB.
One static seed container, named PDB$SEED. This container exists solely as a template for providing data files
and metadata used to create new pluggable databases within the CDB.
Zero, or one or more, pluggable databases (with a maximum of 252). Each pluggable database is self-
contained and functions like an isolated non-CDB database. Additionally, each pluggable database contains its
own data files and application objects (users, tables, indexes and so on). When connected to a pluggable
database, there is no visibility to the root container or any other pluggable databases present within the CDB.
Each of these components is called a container. Therefore, the root is a container, the seed is a container, and each
PDB is a container. Each container has a unique container ID and name within a CDB
Cost reduction
By consolidating hardware and sharing database memory and files, you reduce costs for hardware, storage,
availability, and labor.
Easier and more rapid movement of data and code
By design, you can plug a PDB into a CDB, unplug the PDB from the CDB, and then plug this PDB into a
different CDB. Therefore, you can easily move an application's database back end from one server to another.
Easier management and monitoring of the physical database
The CDB administrator can attend to one physical database (one set of files and one set of database
instances) rather than split attention among dozens or hundreds of non-CDBs. Backup strategies and disaster
recovery are simplified.
Separation of data and code
Although consolidated into a single physical CDB, PDBs mimic the behavior of traditional non-CDBs. For
example, if a user error causes data loss, then a PDB administrator can use point-in-time recovery to retrieve
the lost data without affecting other PDBs.
Ease of performance tuning
It is easier to collect performance metrics for a CDB than for multiple non-CDBs. It is easier to size one SGA
than several SGAs.
Support for Oracle Database Resource Manager
In a CDB, one concern is contention for system resources among the PDBs running on the same server.
Another concern is limiting resource usage for more consistent, predictable performance. To address such
resource contention, usage, and monitoring issues, you can use Oracle Database Resource Manager.
Fewer patches and upgrades
It is easier to apply a patch to one CDB than to multiple non-CDBs and to upgrade one CDB than to upgrade
several non-CDBs.
The following list highlights some key points to understand about the new architecture:
• A connection to the CDB database is synonymous with connecting to the CDB$ROOT root container. The main
purpose of the root container is to house metadata for any associated PDBs.
• You can access the root container via the SYS user, just as you would a non-CDB database. In other words, when
logged in to the database server, you can use OS authentication to connect directly to the root container without
specifying a username and password (sqlplus / as sysdba). You do not need a listener running to connect to the root
container.
• The seed pluggable database container (PDB$SEED) only exists as a template for creating new pluggable databases.
You can connect to the seed, but it is read-only, meaning you can’t issue transactions against it.
• Besides the two default containers (root and seed), for this particular CDB, additional pluggable databases have
been manually created, named PDB_1 and PDB_n.
• Pluggable databases exist within individual namespaces. Pluggable databases must be unique within the CDB, but
objects within a pluggable database follow the namespace rules of a non-CDB database. For example, tablespace
names and user names have to be unique within the individual pluggable databases, but not within the CDB.
• Each pluggable database has its own SYSTEM and SYSAUX tablespaces and, optionally, a TEMP tablespace. If a
pluggable database does not have its own TEMP file, it can consume resources in the root container TEMP file.
• The SYSTEM tablespace of each pluggable database contains information regarding the pluggable database
metadata, such as its users and objects; these metadata are accessible via the DBA/ALL/USER-level views from the
pluggable database and are visible via CDB-level views from the root container.
• You can set the time zones for the CDB and all associated PDBs or you can set the time zone individually per PDB.
• Figure shows a non-RAC configuration, so there is only one memory allocation and one set of background
processes. In other words, there is one instance. All pluggable databases within the CDB use the same instance and
background processes. If this were a RAC configuration, then any connections to the RAC instance would share that
instance and background processes.
• The CDB instance is started and stopped while connected as SYS to the root container. You can’t start/stop the CDB
instance while connected to a pluggable database.
• There is one initialization parameter file that is read by the instance when starting. A privileged user connected to
the root container can modify all initialization parameters. In contrast, a privileged user connected to a pluggable
database can only modify parameters applicable to the currently connected pluggable database. When connected to
a pluggable database and modifying initialization parameters, these modifications only apply to the currently
connected pluggable database and persist for the pluggable database across database restarts. The
ISPDB_MODIFIABLE column in V$PARAMETER shows which parameters are modifiable while connected as a
privileged user to a pluggable database.
• Application users can only access the pluggable databases via a network connection. Therefore, a listener must be
running and listening for service names corresponding to associated pluggable databases. If a listener is not running,
then there is no way for an application user to connect to a pluggable database.
• The individual pluggable databases aren’t stopped or started database instance. When you start/stop a pluggable
database, you are not allocating memory or starting/stopping background processes. Rather, pluggable databases are
either made available or not (open or closed).
• There is one set of control files for the CDB. The control files are managed while connected to the root container as
a privileged user.
• There is one UNDO tablespace for the CDB. All pluggable databases within the CDB use the same UNDO tablespace
(if RAC, then one active undo tablespace per instance).
• There is one thread of redo (per instance) that is managed while connected to the root container as a user with
appropriate privileges. Only privileged connections to root can enable archiving or switching online logs. Connections
to users with SYSDBA privileges to pluggable databases cannot alter online redo or archiving settings.
• There is one alert log and set of trace files for a CDB. Any applicable database messages for associated pluggable
databases are written to the common CDB alert log.
• Each container is assigned a unique container ID. The root container is assigned a container ID of 1; the seed
database is assigned a container ID of 2. Each subsequently created pluggable database is assigned a unique
sequential container ID.
• There is one FRA for the CDB. Separate directories are not created for pluggable databases within the FRA. RMAN
backup files, control files, and online redo logs are placed in a directory associated with the CDB and are not
segregated by pluggable database.
• The Flashback Database feature is turned on and off via a privileged connection to the root container. You cannot
enable flashback at the pluggable database level.
• AWR, ADDM, and ASH reports are issued across all PDBs in the CDB. Resource consumption is identified per
pluggable database.
• When resolving SQL performance issues, queries are associated with a particular pluggable database via the
CON_ID column in views such as V$SQL and V$SQLAREA.
• While connected to the root container with SYSDBA or SYSBACKUP privileges, you have the option of backing up all
the data files within the CDB (root, seed, and all pluggable databases) via one backup command. You also have the
choice of performing B&R tasks at a pluggable database level of granularity.
• While connected directly to a pluggable database with SYSDBA or SYSBACKUP privileges, you can only back up and
recover data files associated with the currently connected pluggable database; you cannot view or operate on the
root container data files or other pluggable database data files.
• An incomplete recovery of the entire CDB must be performed with a connection to the root container with SYSDBA
or SYSBACKUP privileges. All data files within the CDB (root container and associated pluggable databases) are
unavailable during an incomplete recovery of the entire CDB.
• A direct connection to a pluggable database with SYSDBA or SYSBACKUP privileges can perform an incomplete
recovery only on the currently connected pluggable database without affecting any other pluggable databases within
the CDB.
• Because there is a shared UNDO tablespace, any point-in-time incomplete recoveries of a pluggable database will
also have to temporarily restore the root container’s UNDO tablespace to an auxiliary database location so that it can
participate in the point-in-time recovery of the pluggable database.
Term Meaning
Container database (CDB), A database capable of housing one or more pluggable databases
multitenant database
Pluggable database, (PDB) A set of data files and metadata that can be seamlessly transferred from
one CDB to another
Root container A master set of data files and metadata containing information regarding all containers within
a CDB. The root container is named CDB$ROOT.
Container A collection of data files and metadata. Can be root, seed, or a pluggable database.
Seed pluggable database A template of data files and metadata used to create new pluggable databases. The seed
pluggable database is named PDB$SEED.
Plugging Associating the metadata and data files of a pluggable database with a CDB
Unplugging Disassociating the metadata and data files of a pluggable database from a CDB
Cloning Creating a pluggable database from a copy of another database (seed, PDB, or non-CDB)
CON_ID A unique identifier for each container within a CDB. The CDB-level views contain a CON_ID
column that identifies the container with which the information being viewed is associated
CDB data dictionary views Views that contain metadata regarding all pluggable databases within a CDB. These views
only display meaningful information when queried via a privileged connection from the root
container. The pluggable databases must be open for use.
non-CDB database An Oracle database created without the pluggable database feature enabled (the only type of
database that was available prior to 12c)
Prior to Oracle Database 12c, the metadata that describes the Oracle system and the metadata that describes the
user schema were stored collectively in a set of tables (Obj$, Tab$, Col$, and so on) that are referred to as the data
dictionary. The data dictionary tables were stored in dedicated tablespaces, namely SYSTEM and SYSAUX.
Initially, when you create the database, the data dictionary tables have only Oracle system-related metadata. Later
on, when a user creates data, the data dictionary tables contain user and system metadata. The user tablespace
contains only user data.
In Oracle Database 12c the data dictionary tables are horizontally partitioned: one subset containing the Oracle
system metadata is stored in the Root database and another subset containing user metadata is stored in the PDB.
Now, transporting an application database from one database to another means Oracle processes just copy the files
containing user data and user metadata. The user metadata is stored in the SYSTEM and SYSAUX tablespaces of the
PDB, and the system metadata is stored in the SYSTEM and SYSAUX tablespaces of the CDB.
The data dictionary in the PDB contains pointers to the data dictionary in the root. Internally, Oracle-supplied objects
such as data dictionary table definitions and PL/SQL packages are represented only in the root. This architecture
achieves two main goals within the CDB:
Reduction of duplication
For example, instead of storing the source code for the DBMS_ADVISOR PL/SQL package in every PDB, the
CDB stores it only in CDB$ROOT, which saves disk space.
Ease of database upgrade
If the definition of a data dictionary table existed in every PDB, and if the definition were to change in a new
release, then each PDB would need to be upgraded separately to capture the change. Storing the table
definition only once in the root eliminates this problem.
Metadata and Object Links
The CDB uses an internal mechanism to achieve the preceding goals. Specifically, Oracle Database uses the following
automatically managed pointers:
Metadata links
Oracle Database stores metadata about dictionary objects only in the root. For example, the column
definitions for the OBJ$ dictionary table, which underlies the DBA_OBJECTS data dictionary view, exist only in
the root. The OBJ$ table in each PDB uses an internal mechanism called a metadata link to point to the
definition of OBJ$ stored in the root.
The data corresponding to a metadata link resides in its PDB, not in the root. For example, if you create table
mytable in hrpdb and add rows to it, then the rows are stored in the PDB files. The data dictionary views in
the PDB and in the root contain different rows. For example, a new row describing mytable exists in the OBJ$
table in hrpdb, but not in the OBJ$ table in the root. Thus, a query of DBA_OBJECTS in the root and
DBA_OBJECTS in hrdpb shows different result sets.
Object links
In some cases, Oracle Database stores the data (not metadata) for an object only once in the root. For
example, AWR data resides in the root. Each PDB uses an internal mechanism called an object link to point to
the AWR data in the root, thereby making views such as DBA_HIST_ACTIVE_SESS_HISTORY and
DBA_HIST_BASELINE accessible in each separate container.
Oracle Database automatically creates and manages object and metadata links. Users cannot add, modify, or remove
these links.
When the current container is the root, a common user can query CDB_ views to see metadata for the root and for
PDBs for which this user is privileged. When the current container is a PDB, however, a user can view data dictionary
information for the current PDB only. To an application connected to a PDB, the data dictionary appears as it would
for a non-CDB.
Creating a CDB
To use the pluggable database feature, you have to specifically create a pluggable enabled CDB. There are a several
different techniques for creating a CDB:
Manually issuing the SQL CREATE DATABASE command
Using DBCA
Generating the required scripts with the DBCA, and then manually running the scripts to create a CDB
Using RMAN to duplicate an existing CDB
Focus to create a database with the CREATE DATABASE command and the DBCA.
Using the DBCA
You can use the DBCA utility to create a CDB through either a graphical interface or the command-line mode. When
using the graphical interface, you’ll be prompted as to whether or not you want to create a CDB.
First, ensure that your ORACLE_SID, ORACLE_HOME, and PATH variables are set for your CDB environment
$ export ORACLE_SID=CDB1
$ export ORACLE_HOME=/u01/app/oracle/product/12.1.0.1/db_1
$ export PATH=$ORACLE_HOME/bin:$PATH
Next, create a parameter initialization file in the ORACLE_HOME/dbs directory. Make certain you set the
ENABLE_PLUGGABLE_DATABASE parameter to TRUE. Here, create a file named initCDB.ora and placed within it the
following parameter:
db_name='CDB'
enable_pluggable_database=true
audit_trail='db'
control_files='/u01/dbfile/CDB/control01.ctl','/u01/dbfile/CDB/control02.ctl'
db_block_size=8192
db_domain=''
memory_target=629145600
memory_max_target=629145600
open_cursors=300
processes=300
remote_login_passwordfile='EXCLUSIVE'
undo_tablespace='UNDOTBS1'
Next, ensure you have created any directories referenced in the parameter file and the CREATE DATABASE
statement:
$ mkdir -p /u01/dbfile/CDB/pdbseed
$ mkdir -p /u01/dbfile/CDB
$ mkdir -p /u01/oraredo/CDB
Now, start up your database in nomount mode, and execute create database command.
$ sqlplus / as sysdba
SQL> startup nomount;
SQL> CREATE DATABASE CDB
MAXLOGFILES 16
MAXLOGMEMBERS 4
MAXDATAFILES 1024
MAXINSTANCES 1
MAXLOGHISTORY 680
CHARACTER SET US7ASCII
NATIONAL CHARACTER SET AL16UTF16
DATAFILE '/u01/dbfile/CDB/system01.dbf' SIZE 500M
EXTENT MANAGEMENT LOCAL
UNDO TABLESPACE undotbs1 DATAFILE '/u01/dbfile/CDB/undotbs01.dbf' SIZE 800M
SYSAUX DATAFILE '/u01/dbfile/CDB/sysaux01.dbf' SIZE 500M
DEFAULT TEMPORARY TABLESPACE TEMP TEMPFILE '/u01/dbfile/CDB/temp01.dbf' SIZE 500M
DEFAULT TABLESPACE USERS DATAFILE '/u01/dbfile/CDB/users01.dbf' SIZE 50M
LOGFILE GROUP 1 ('/u01/oraredo/CDB/redo01a.rdo') SIZE 50M,
GROUP 2 ('/u01/oraredo/CDB/redo02a.rdo') SIZE 50M
USER sys IDENTIFIED BY foo
USER system IDENTIFIED BY foo
USER_DATA TABLESPACE userstbs DATAFILE '/u01/dbfile/CDB/userstbsp01.dbf' SIZE 500M
ENABLE PLUGGABLE DATABASE
SEED FILE_NAME_CONVERT = ('/u01/dbfile/CDB','/u01/dbfile/CDB/pdbseed');
Close/open the seed PDB and run postcreation scripts.
- Set the session with a new parameter:
SQL> alter session set "_oracle_script"=true;
- Close and open the seed PDB:
SQL> alter pluggable database pdb$seed close;
SQL> alter pluggable database pdb$seed open;
- Execute catalog.sql and other postcreation scripts.
SQL>?/rdbms/admin/catalog.sql
SQL>?/rdbms/admin/catblock.sql
SQL>?/rdbms/admin/catproc.sql
SQL>?/rdbms/admin/catoctk.sql
SQL>?/rdbms/admin/owminst.plb
SQL>?/sqlplus/admin/pupbld.sql
Note: To get the full list of scripts executed and the sequence of execution to follow, run DBCA to create CDB and in
the last step, generate the scripts only. The scripts are created in the $ORACLE_BASE/admin/<cdb_name>/scripts
directory. The shell script <cdb_name>.sh is the first script to read.
$ sqlplus / as sysdba
SQL> startup;
Starting the CDB database does not open any associated pluggable databases. You can open all pluggable databases
with this command:
SQL> alter pluggable database all open;
Just as with a non-CDB database, the prior line shuts down the CDB instance and disconnects any users connected to
the database. If any pluggable databases are open, they are closed, and users are disconnected.
FILE_NAME_CONVERT Specifies the location of the seed database data files and the location where they should be
copied
Note: If you’re using OMF DB_CREATE_FILE_DEST or New parameter PDB_FILE_NAME_CONVERT, you don’t need to
specify the FILE_NAME_CONVERT clause when creating a pluggable database, because Oracle automatically
determines the names and locations of the pluggable database data files.
Then use the cdb_pdbs view to verify that the new PDB and its tablespaces exist:
SQL> SELECT * FROM cdb_pdbs;
SQL> SELECT * FROM cdb_tablespaces;
SQL> SELECT * FROM cdb_data_files;
This technique copies the files associated with the source PDB to a new location and
associates the copied files with the new PDB. You can clone a PDB that resides in the
same CDB (Local) or in a different CDB (Remote). If in a different CDB, then you must
use a database link to specify the remote CDB that contains the PDB to be cloned.
Local
In this example an existing pluggable database (pdb1) is used to create a new
pluggable database (pdb3).
First, connect to the root container, and place the existing source pluggable database
in read-only mode:
$ sqlplus / as sysdba
SQL> alter pluggable database pdb1 close;
SQL> alter pluggable database pdb1 open read only;
Now, run the following SQL to create the new pluggable database:
SQL> CREATE PLUGGABLE DATABASE pdb3 FROM pdb1
FILE_NAME_CONVERT = ('/u01/app/oracle/oradata/CDB/pdb1','/u01/dbfile/CDB/pdb3')
STORAGE (MAXSIZE 6G MAX_SHARED_TEMP_SIZE 100M);
Note: If the underlying file system of a PDB supports storage snapshots, then you may specify the SNAPSHOT COPY
clause to clone a PDB using storage snapshots. In this case, Oracle Database does not make a complete copy of
source data files, but creates a storage-level snapshot of the underlying file system, and uses it to create PDB clones.
Snapshot copies make cloning almost instantaneous. Built on copy-on-write capability of underlying file system and
Supported on ZFSSA, ACFS, NetApp
Remote
You can also create a pluggable database as a clone of a remote pluggable database. First, you need to create a
database link from the CDB to the pluggable database that will serve as the source for the clone. Both the local user
and the user specified in the database link must have the CREATE PLUGGABLE DATABASE privilege.
This example shows a local connection as SYS to the root container. This is the database in which the new pluggable
database will be created:
$ sqlplus / as sysdba
In this database, create a database link to the pluggable database in the remote CDB. The remote CDB contains a
pluggable database named pdb1, with a user that has been created with the CREATE PLUGGABLE DATABASE privilege
granted to it. This is the user that will be used in the database link:
SQL> CREATE DATABASE LINK pdb1dblink CONNECT TO pdb1adm IDENTIFIED BY foo USING
'cdr2hostname:1521/pdb1';
Next, connect to the remote database that contains the pluggable database that will be cloned:
$ sqlplus sys/foo@cdr2hostname:1521/pdb1 as sysdba
Close the pluggable database, and open it in read-only mode:
SQL> alter pluggable database pdb1 close;
SQL> alter pluggable database pdb1 open read only;
Now, connect to the destination CDB as SYS, and create the new pluggable database by cloning the remote pluggable
database, as shown:
$ sqlplus / as sysdba
SQL> CREATE PLUGGABLE DATABASE pdb3 FROM pdb1@pdb1dblink
FILE_NAME_CONVERT = ('/u01/app/oracle/oradata/CDB/pdb1','/u01/dbfile/CDB2/pdb3');
To plug in a pluggable database, connect to the CDB as a privileged user, and run the following:
SQL> CREATE PLUGGABLE DATABASE pdb1 USING '/orahome/oracle/dba/pdb1.xml'
COPY FILE_NAME_CONVERT = ('/u01/app/oracle/oradata/CDB1/pdb1, '/u01/dbfile/CDB2/pdb1');
You can now open the pluggable database and begin using it.
Note: If you run the prior queries while connected directly to a pluggable database, no information will be displayed
in CDB_PDBS. Also, the V$PDBS will only display information for the currently connected pluggable database.
A common user is a database user that has the same identity in the root and in every existing and future PDB. Every
common user can connect to and perform operations within the root, and within any PDB in which it has privileges.
Every common user is either Oracle-supplied or user-created. Examples of Oracle-supplied common users are SYS and
SYSTEM.
The name of every user-created common user must begin with the characters c## or C##, every common user is
uniquely named across all containers. The schemas for a common user can differ in each container
$ sqlplus / as sysdba
A local user is a database user that is not common and can operate only within a single PDB, cannot log in to another
PDB or to the root. The name of a local user must not begin with the characters c## or C## and must only be unique
within its PDB. A local user cannot be created in the root
The syntax is the same as in a traditional or non-CDB. This is in keeping with the application transparency goal for
PDBs. The syntax for commands in a PDB are identical to commands in a non-CDB.
SQL> CONNECT system@pdb1
SQL> CREATE USER abc_local IDENTIFIED BY local123;
Note: The DROP USER and ALTER USER commands are identical, as the commands in a non- CDB.
A privilege becomes common or local based on the way it is granted. A privilege granted across all containers is a
common privilege. A privilege granted in a specific PDB is local.
Common and local users can exercise common and local privileges that have been granted in the context of the PDB
to which they are connected. A common user can be granted both common and local privileges. That means the
privileges granted to a common user can be different in every PDB.
A common privilege is granted to a grantee in all containers.
SQL> GRANT create session TO c##abc CONTAINER=ALL;
SQL> GRANT drop user TO c##user CONTAINER=ALL;
SQL> REVOKE drop user FROM c##_user CONTAINER=ALL;
A local privilege is granted to a grantee in one container.
SQL> GRANT advisor TO u1;
SQL> GRANT alter user TO local_user CONTAINER=CURRENT;
SQL> REVOKE alter user FROM local_user;
Every Oracle-supplied role is common. In Oracle-supplied scripts, every privilege or role granted to Oracle-supplied
users and roles is granted commonly, with one exception: system privileges are granted locally to the common role
PUBLIC. User-created roles are either local or common
A common role is a database role that exists in the root and in every existing and future PDB. Common roles are
useful for cross-container operations. Every common role is either user-created or Oracle-supplied. All Oracle-
supplied roles are common, such as DBA and PUBLIC. User-created common roles must have names starting with C##
or c##.
A local role exists only in a single PDB, just as a role in a non-CDB exists only in the non-CDB. A local role can only
contain roles and privileges that apply within the container in which the role exists. PDBs in the same CDB may
contain local roles with the same name.
A user can create common roles if the user has the CREATE ROLE privilege, and SET CONTAINER for all PDBs. A
common user can create a local role if the user has the CREATE ROLE and SET CONTAINER privileges for that PDB. The
CONTAINER clause determines whether the role is common or local. A common role must begin with C## characters.
Any role can be granted to any role or user. It does not matter whether the user or role is defined to be local or
common.
A common role is created in all containers.
SQL> CREATE ROLE c##r1 CONTAINER=ALL;
Note: GRANT and REVOKE are mostly unchanged. The syntax has been extended with the CONTAINER clause so that
common and local roles can be granted or revoked commonly or locally.
Using the SRVCTL utility in a Grid Infrastructure environment with Oracle Restart:
$ srvctl add service -db mycdb -service hrpdb -pdb hrpdb
$ srvctl start service -db mycdb -service hrpdb
Caution If you have multiple CDB databases on one server, ensure that the pluggable database service names are
unique across all CDB databases on the server. It’s not advisable to register two pluggable database databases with
the exact same name with one common listener. This will lead to confusion as to which pluggable database you are
actually connecting to.
$ sqlplus username/password@net_service
SQL> CONNECT sys@CDB1 AS SYSDBA
SQL> CONNECT sys@PDBtest AS SYSDBA
SQL> CONNECT local_user1@hostname1:1521/PDBHR
SQL> CONNECT common_user2@PDBdev
Switching Connection
Two possible ways to switch connection between containers within a CDB:
Reconnect
SQL> CONNECT / AS SYSDBA
SQL> CONNECT local_user1@PDBdev
Notes:
- Using CONNECT allows connection under common or local user.
- Using ALTER SESSION SET CONTAINER allows connection under common user only who is granted new
system privilege SET CONTAINER.
AFTER LOGON triggers do not fire.
Transactions that are not committed nor rolled back in the original container are still in a pending
state while switching to another container and when switching back to the original container.
Note: When you start/stop a pluggable database, you aren’t starting/stopping an instance. Rather, you are making
the pluggable database either available or unavailable, open or closed. You can change the open mode of a pluggable
database from either a connection to the root container as SYS or a direct connection to the pluggable database as
SYS.
To change the open mode of a pluggable database from the root container, do as follows:
$ sqlplus / as sysdba
SQL> alter pluggable database pdb1 open;
You can also start a pluggable database in a particular state, such as read-only or restricted mode:
SQL> startup pluggable database pdb1 open read only;
SQL> alter pluggable database pdb1 open restricted;
To close a pluggable database, you can specify the name of the pluggable database:
SQL> alter pluggable database pdb1 close immediate;
You can also open or close all pluggable databases while connected to the root container as SYS:
SQL> alter pluggable database all open;
SQL> alter pluggable database all close immediate;
From Pluggable
To open/start a pluggable database, connect to the pluggable database as SYS:
$ sqlplus sys/foo@salespdb as sysdba
SQL> startup;
Or
SQL> alter pluggable database open;
You can use an ALTER SYSTEM statement to change the way a PDB operates. When the current container is a PDB,
you can run the following ALTER SYSTEM statements:
ALTER SYSTEM FLUSH SHARED_POOL / BUFFER_CACHE
ALTER SYSTEM ENABLE / DISABLE RESTRICTED SESSION
ALTER SYSTEM SET USE_STORED_OUTLINES
ALTER SYSTEM SUSPEND / RESUME
ALTER SYSTEM CHECK DATAFILES
ALTER SYSTEM REGISTER
ALTER SYSTEM KILL SESSION
ALTER SYSTEM DISCONNECT SESSION
ALTER SYSTEM SET initialization_parameter
All other ALTER SYSTEM statements affect the entire CDB and must be run by a common user in the root.
Some ALTER SYSTEM statements can be run from within a PDB but still affect the whole CDB such as ALTER SYSTEM
CHECKPOINT except those in read only or offline. Other ALTER SYSTEM statements affect the entire CDB and must be
run by a common user in the root such as ALTER SYSTEM SWITCH LOGFILE, unless you set the CDB_COMPATIBLE
parameter to FALSE, which enables you to get a behavior similar to a non-CDB when issuing SQL commands inside a
PDB.
There is a single SPFILE per CDB to store parameters. Values of parameters are associated with the root and apply to
the root and serve as default values for all other containers.
The ALTER SYSTEM SET initialization_parameter statement can modify only some initialization parameters for PDBs.
All initialization parameters can be set for the root. For any initialization parameter that is not set explicitly for a PDB,
the PDB inherits the root's parameter value. PDB parameters are stored in the root container.
You can modify an initialization parameter for a PDB when the ISPDB_MODIFIABLE column is TRUE for the parameter
in the V$SYSTEM_PARAMETER view. The following query lists all of the initialization parameters that are modifiable
for a PDB:
SQL> SELECT NAME FROM V$SYSTEM_PARAMETER WHERE ISPDB_MODIFIABLE='TRUE' ORDER BY NAME;
When the current container is a PDB, run the ALTER SYSTEM SET initialization_parameter statement to modify the
PDB. The statement does not affect the root or other PDBs.
SCOPE Setting Behavior
MEMORY The initialization parameter setting is changed in memory and takes effect immediately in the PDB. The new
setting affects only the PDB. The setting reverts to the value set in the root in the any of the following cases:
An ALTER SYSTEM SET statement sets the value of the parameter in the root with SCOPE equal to
BOTH or MEMORY, and the PDB is closed and re-opened. The parameter value in the PDB is not
changed if SCOPE is equal to SPFILE, and the PDB is closed and re-opened.
The CDB is shut down and re-opened.
SPFILE The initialization parameter setting is changed for the PDB in the SPFILE. The new setting takes effect in any of
the following cases:
The PDB is closed and re-opened.
The CDB is shut down and re-opened.
BOTH The initialization parameter setting is changed in memory, and it is changed for the PDB in the SPFILE. The new
setting takes effect immediately in the PDB and persists after the PDB is closed and re-opened or the CDB is
shut down and re-opened. The new setting affects only the PDB.
When a PDB is unplugged from a CDB, the values of the initialization parameters that were specified for the PDB with
SCOPE=BOTH or SCOPE=SPFILE are added to the PDB's XML metadata file. These values are restored for the PDB
when it is plugged in to a CDB.
Note: A text initialization parameter file (PFILE) cannot contain PDB-specific parameter values.
Tablespaces in PDBs
In a non-CDB, all the tablespaces belong to one database. In the CDB, one set of tablespaces belong to the root
container, and each PDB has its own set of tablespaces.
The UNDO tablespace is common to all PDBs, that is, there is only one active UNDO tablespace per CDB.
Create a permanent tablespace in the root container:
SQL> CONNECT system@cdb1
SQL> CREATE TABLESPACE tbs_CDB DATAFILE '/u1/app/oradata/cdb/cdb_users01.dbf' SIZE 100M;
Create a permanent tablespace in a PDB:
SQL> CONNECT system@PDB1
SQL> CREATE TABLESPACE tbs_PDB1 DATAFILE '/u1/app/oradata/cdb/pdb1/users01.dbf' SIZE 100M;
Temporary Tablespace
A CDB can have only one default temporary tablespace. As with a non-CDB there
can be other temporary tablespaces to which users can be assigned. The default
temporary tablespace is a shared resource for all PDBs, that is, any user in any PDB
will use the CDB default temporary tablespace unless that user is assigned to a
specific temporary tablespace.
A default temporary tablespace can be set for each PDB. A PDB may have multiple
temporary tablespaces, but only one default per PDB. When you create a user you
can specify a temporary tablespace to be used by that user. If a temporary
tablespace is not specified, the default tablespace for the PDB is used. If a default tablespace has not been specified
for the PDB, the temporary tablespace for the CDB is used.
SQL> CONNECT pdb1_admin@pdbhr
SQL> ALTER PLUGGABLE DATABASE DEFAULT TEMPORARY TABLESPACE local_temp;
The default temporary tablespace in the CDB is shared by all the PDBs. The amount of space a single PDB can use in
the shared temporary tablespace can be set in the PDB by:
SQL> ALTER PLUGGABLE DATABASE STORAGE (MAX_SHARED_TEMP_SIZE 500M);
Drop the pluggable database and its data files. (INCLUDING DATAFILES)
$ sqlplus / as sysdba
SQL> alter pluggable database pdb1 close immediate;
SQL> drop pluggable database pdb1 including datafiles;
Drop the pluggable database, and leave its data files in place. (KEEP DATAFILES) default - The PDB's temp file
is removed even when KEEP DATAFILES is specified
$ sqlplus / as sysdba
SQL> alter pluggable database pdb1 close immediate;
SQL> drop pluggable database pdb1;
When you drop a PDB, the control file of the CDB is modified to eliminate all references to the dropped PDB. Archived
redo log files and backups associated with the PDB are not removed, but you can use Oracle Recovery Manager
(RMAN) to remove them.
$ export ORACLE_SID=cdb1
$ rman TARGET /
$ rman TARGET jim@pdb1
Recovery
In a CDB, the granularity of media recovery is very flexible and can be done for the entire CDB, for a PDB, for a
tablespace, for a data file, or even for a block.
Instance Failure
Crash and instance recovery is supported for a CDB as a whole, because there is one single instance for the root and
all its PDBs. When the instance crashes, the only possible instance recovery is a CDB instance recovery.
The instance recovery is performed while opening the root. There is no way to perform a PDB instance recovery.
$ rman TARGET /
RMAN> STARTUP NOMOUNT;
RMAN> RESTORE CONTROLFILE FROM AUTOBACKUP;
RMAN> ALTER DATABASE MOUNT;
RMAN> RECOVER DATABASE;
RMAN> ALTER DATABASE OPEN RESETLOGS;
RMAN> ALTER PLUGGABLE DATABASE ALL OPEN;
Flashback CDB
You can configure Flashback Database for the CDB as you would do for any non-CDB, Restrictions
• You cannot flash back the root alone without flashing back the entire CDB.
• Flashback Database operations on a CDB may not be permitted if point-in-time recovery has been performed on
any of its PDBs. When point-in-time recovery is performed on a PDB, you cannot directly rewind the CDB to a point
that is earlier than the point at which DBPITR for the PDB was performed.
RMAN> SHUTDOWN IMMEDIATE
RMAN> STARTUP MOUNT
Thank You
Ahmed Fathi
Resources
Oracle® Database Administrator's Guide 12c Release 1 (12.1) - E17636-21 - Oracle 12c Documentation
Oracle Database 12c: Managing Multitenant Architecture - D79128GC10 - Oracle Education
Pro Oracle Database 12c Administration, 2nd Edition – Darl Kuhm
Oracle Multitenant White Paper - Bryn Llewellyn