Create and manage pluggable databases 

Go back to OCM 12c Preparation Project

The multitenant option introduced in Oracle Database 12c allows a single container database (CDB) to host multiple separate pluggable databases (PDB). This article covers the various major operations possible with PDBs.

  1. Create a pluggable database
  2. Unplug a pluggable database
  3. Plugin a pluggable database
  4. Clone a pluggable database
  5. Delete a pluggable database
  6. Configure a pluggable database

With GUI there are 4 tools to perform these tasks

1.) Oracle Universal Installer (OUI)
2.) Database Configuration Assistant (DBCA)
3.) SQL Developer
4.) Cloud Control

Without GUI / CLI Method we can use below 2 tools to perform the same tasks

5.) Manual (SQL*Plus)
6.) DBCA Command Line

  1. Oracle Universal Installer (OUI)

OUI1

OUI allows you to create a CDB during the software installation. The “Typical Install Configuration” screen has a checkbox to indicate the database is a container database. You can optionally create a PDB in this screen also.

OUI2

The advanced configuration option provides the same ability on the “Database Identifiers” screen.

DB Identifier

In both cases the creation of a PDB is optional, so you can create an empty container database and create the pluggable database later.

2. Database Configuration Assistant (DBCA)

DBCA gives similar options to the OUI. The “Creation Mode” page allows you to enter the default installation configuration details directly.

creation mode

If you chose the “Advanced Mode” option, you can create a CDB and multiple PBDs in one go.

Advanced Mode

The DBCA includes a new option on the opening “Database Operation” screen that allows you to manage the pluggable databases of an existing container database. Select the “Manage Pluggable Databases” option and click the “Next” button.

Manage PDBs

You can see from the resulting screen what operations are possible with pluggable databases.

PDB Options

The following sections describe some of these options.

Create a Pluggable Database (PDA) using the DBCA

Manage Pluggable Database –> Create a Pluggable Database –> select the container database to house the new pluggable database

Create PDB Using DBCA

PDBs Status Before

Select the “Create a new Pluggable Database” option and click the “Next” button. If you were plugging in a previously unplugged database, you would select the PDB Archive or PDB File Set options to match the format of the files containing the unplugged PDB.

Create PDB Using DBCA_New PDB

Enter the pluggable database name, database location and admin credentials, then click the “Next” button.

Create PDB Using DBCA_New PDB_NAME

Check the summary information, click the “Finish” button.

PDB_CREATION_Summary

Wait while the pluggable database is created. Once complete, click the “OK” button on the message dialog and the “Close” button on the main screen.

PDB_CREATION_Summary_INProgress

The new pluggable database has been created as a clone of the seed database.

PDB_CREATION_Summary_Completed

PDBs Status After

Unplug a Pluggable Database (PDB) using the DBCA

Manage Pluggable Databases –> Unplug a Pluggable Database –> select the container database that houses the pluggable database to be unplugged

unplug_PDB

Select the PDB to unplug, decide whether to use a pluggable database archive or a file set and enter the appropriate location details. Click the “Next” button.

unplug_PDB_Into_PDB_Archive

Check the summary information, click the “Finish” button.

unplug_PDB_Into_PDB_Archive_Summary

Wait while the pluggable database is unplugged. Once complete, click the “OK” button on the message dialog and the “Close” button on the main screen.

unplug_PDB_Into_PDB_Archive_Summary_InPrg

The pluggable database has now been unplugged.

unplug_PDB_Into_PDB_Archive_Summary_Completed

Plugin a Pluggable Database (PDB) using the DBCA

Manage Pluggable Databases–>Create a Pluggable Database–>select the container database to house the new pluggable database.

Plug_PDB_1

Select the “Create Pluggable Database From PDB Archive” or “Create Pluggable Database using PDB File Set” option and enter the location of the required files. You can browse for the files using the “Browse” button.

Plug_PDB_2

Enter the pluggable database name, database location and admin credentials, then click the “Next” button.

Plug_PDB_3

Check the summary information, click the “Finish” button.

Plug_PDB_4

Wait while the pluggable database is created. Once complete, click the “OK” button on the message dialog and the “Close” button on the main screen.

Plug_PDB_5

The pluggable database has been plugged into the container database.

SQL> show pdbs

CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 MYPDB READ WRITE NO
4 PDB2 READ WRITE NO
5 PDB3 READ WRITE NO

Delete a Pluggable Database (PDB) using the DBCA

Manage Pluggable Databases–>Delete a Pluggable Database–>select the container database that houses the pluggable database

Delete PDB

  • Check the summary information, click the “Finish” button.
  • Wait while the pluggable database is deleted. Once complete, click the “OK” button on the message dialog and the “Close” button on the main screen.
  • The pluggable database has been deleted from the container database.
SQL> show pdbs

CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 MYPDB READ WRITE NO
5 PDB3 READ WRITE NO

Configure a Pluggable Database (PDB) using the DBCA

Manage Pluggable Databases–>Configure a Pluggable Database–>select the container database that houses the pluggable database to be configured

Configure_PDB_1.PNG

Select the PDB to configure and click the “Next” button.

SQL> show pdbs

CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
5 PDB3 READ WRITE NO
SQL>
SQL> select dbms_xdb_config.gethttpsport () from dual;

DBMS_XDB_CONFIG.GETHTTPSPORT()
------------------------------
0

Select any additional options you would like to configure, then click the “Next” button.

Configure_PDB_2.PNG

  • Check the summary information, click the “Finish” button.
  • Wait while the pluggable database is configured. Once complete, click the “OK” button on the message dialog and the “Close” button on the main screen.

Configure_PDB_3The pluggable database has been configured.

SQL> select dbms_xdb_config.gethttpsport () from dual;

DBMS_XDB_CONFIG.GETHTTPSPORT()
------------------------------
5501

SQL> show pdbs

CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
5 PDB3 READ WRITE NO

3. SQL Developer

SQL_DEV_Connection.PNG

Open Menu -> View -> DBA

SQL_DEV_PDB

SQL> show pdbs

CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 MYPDB READ WRITE NO
5 PDB3 READ WRITE NO

Create Pluggable Database

SQL_DEV_CREATE_PDB

SQL> show pdbs

CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 MYPDB READ WRITE NO
4 SD_PDB MOUNTED
5 PDB3 READ WRITE NO

Clone Pluggable Database

SQL_DEV_CLONE_PDB

SQL> show pdbs

CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 MYPDB READ WRITE NO
4 SD_PDB READ WRITE NO
5 PDB3 READ WRITE NO
6 NEW_PDB READ WRITE NO

4. Cloud Control

Oracle Cloud Control 12cR3 onward supports pluggable database functionality.

Container database, the “Oracle Database > Control > Open/Close Pluggable Database

29-cloud-control-1

The “Oracle Database > Provision > Provision Pluggable Database

30-cloud-control-2

5. Manual (SQL*Plus)

  • You must be connected to a CDB and the current container must be the root.
  • You must have the CREATE PLUGGABLE DATABASE system privilege.

Create a Pluggable Database (PDB) Manually

To create a new pluggable database from the seed database, all we have to do is tell Oracle where the file should be placed.

There are three methods to tell oracle where the file should be placed.

1. Oracle Managed Files (OMF) 

SQL> show parameter db_create_file_dest
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_create_file_dest string

SQL> create pluggable database pdb1 admin user pdb_adm identified by Oracle_4U;
create pluggable database pdb1 admin user pdb_adm identified by Oracle_4U
*
ERROR at line 1:
ORA-65016: FILE_NAME_CONVERT must be specified

SQL> alter system set db_create_file_dest='/u01/app/oracle/oradata';
System altered.

SQL> create pluggable database pdb1 admin user pdb_adm identified by Oracle_4U;
Pluggable database created.

SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 MYPDB READ WRITE NO
4 SD_PDB READ WRITE NO
5 PDB3 READ WRITE NO
6 NEW_PDB READ WRITE NO
7 PDB1 MOUNTED
SQL> alter pluggable database pdb1 open;

Pluggable database altered.

SQL> show pdbs

CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 MYPDB READ WRITE NO
4 SD_PDB READ WRITE NO
5 PDB3 READ WRITE NO
6 NEW_PDB READ WRITE NO
7 PDB1 READ WRITE NO

2. OMF location for the new PDB using CREATE_FILE_DEST clause onwards 12.1.0.2

SQL> alter system set db_create_file_dest='';
System altered.

SQL> show parameter db_create_file_dest
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_create_file_dest                  string

SQL> CREATE PLUGGABLE DATABASE PDB2 ADMIN USER PDB2_ADM IDENTIFIED BY Oracle_4U
2 CREATE_FILE_DEST='/u01/app/oracle/oradata';
Pluggable database created.

SQL> ALTER PLUGGABLE DATABASE PDB2 OPEN;
Pluggable database altered.

SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 MYPDB READ WRITE NO
4 SD_PDB READ WRITE NO
5 PDB3 READ WRITE NO
6 NEW_PDB READ WRITE NO
7 PDB1 READ WRITE NO
8 PDB2 READ WRITE NO

3. FILE_NAME_CONVERT clause

SQL> CREATE PLUGGABLE DATABASE PDB4 ADMIN USER PDB4_ADM IDENTIFIED BY Oracle_4U
2 FILE_NAME_CONVERT=('/u01/app/oracle/oradata/cdb/pdbseed/','/u01/app/oracle/oradata/cdb/pdb4/');
Pluggable database created.

OR

SQL> ALTER SESSION SET PDB_FILE_NAME_CONVERT='/u01/app/oracle/oradata/cdb/pdbseed/','/u01/app/oracle/oradata/cdb/pdb5/';
Session altered.

SQL> CREATE PLUGGABLE DATABASE PDB5 ADMIN USER PDB5_ADM IDENTIFIED BY Oracle_4U;
Pluggable database created.

Commands to verify the details of PDBs

COLUMN pdb_name FORMAT A20
SELECT pdb_name, status
FROM dba_pdbs
ORDER BY pdb_name;

COLUMN name FORMAT A20
SELECT name, open_mode
FROM v$pdbs
ORDER BY name;

SHOW PDBS;

The PDBs are created with the status of 'NEW'. They must be opened in READ WRITE mode at least once for the integration of the PDB into the CDB to be complete.

 

Unplug a Pluggable Database (PDB) Manually

  • Before attempting to unplug a PDB, you must make sure it is closed.
  • To unplug the database use the ALTER PLUGGABLE DATABASE command with the UNPLUG INTO clause to specify the location of the XML metadata file.

We will Unplug the pluggable database (pdb1) from Container database (cdb)

SQL> ALTER PLUGGABLE DATABASE PDB1 CLOSE IMMEDIATE;
Pluggable database altered.

SQL> ALTER PLUGGABLE DATABASE PDB1 UNPLUG INTO '/u01/app/oracle/oradata/cdb/pdb1/pdb1.xml';
Pluggable database altered.

SQL> SELECT name, open_mode FROM v$pdbs ORDER BY name;
NAME OPEN_MODE
------------------------------ ----------
NEW_PDB READ WRITE
PDB$SEED READ ONLY
PDB1 MOUNTED
PDB2 READ WRITE

SQL> DROP PLUGGABLE DATABASE PDB1 KEEP DATAFILES;
Pluggable database dropped.

SQL> SELECT name, open_mode FROM v$pdbs ORDER BY name; 
NAME OPEN_MODE
------------------------------ ----------
NEW_PDB READ WRITE
PDB$SEED READ ONLY
PDB2 READ WRITE

 

Plugin a Pluggable Database (PDB) Manually

  • Plugging in a PDB into the CDB is similar to creating a new PDB.
  • First check the PBD is compatible with the CDB by calling the DBMS_PDB.CHECK_PLUG_COMPATIBILITY function,
  • passing in the XML metadata file and the name of the PDB

We will plug the PDB1 from Container Database(cdb) into Container Database (cdb2) with name CDB_PDB1. (Plug something from a different charset and convert it.)

SET SERVEROUTPUT ON
DECLARE
l_result BOOLEAN;
BEGIN
l_result := DBMS_PDB.check_plug_compatibility(
pdb_descr_file => '/u01/app/oracle/oradata/cdb/pdb1/pdb1.xml',
pdb_name => 'cdb_pdb1');
IF l_result THEN
DBMS_OUTPUT.PUT_LINE('compatible');
ELSE
DBMS_OUTPUT.PUT_LINE('incompatible');
END IF;
END;
/SQL> 2 3 4 5 6 7 8 9 10 11 12 13 14
incompatible
PL/SQL procedure successfully completed.

If the PDB is not compatible, violations are listed in the 
PDB_PLUG_IN_VIOLATIONS view. If the PDB is compatible, 
create a new PDB using it as the source. If we were creating 
it with a new name we might do something like this.

SQL> select NAME,MESSAGE from PDB_PLUG_IN_VIOLATIONS;
NAME MESSAGE
--------------------------------------------------------------------------------
PDB$SEED Character set mismatch: PDB character set WE8MSWIN1252. CDB character set AL32UTF8.

SQL> select property_name,property_value from database_properties where property_name='NLS_CHARACTERSET';
PROPERTY_NAME PROPERTY_VALUE
--------------------------------------------------------------------------------
NLS_CHARACTERSET WE8MSWIN1252

SQL> show parameter db_name
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_name string cdb2
SQL> exit

-bash-4.1$ . oraenv
ORACLE_SID = [cdb2] ? cdb
The Oracle base remains unchanged with value /u01/app/oracle
-bash-4.1$ sqlplus / as sysdba
SQL> show parameter db_name
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_name string cdb

SQL> select property_name,property_value from database_properties where property_name='NLS_CHARACTERSET';
PROPERTY_NAME PROPERTY_VALUE
--------------------------------------------------------------------------------
NLS_CHARACTERSET AL32UTF8

SQL> show parameter db_name
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_name string cdb2
SQL>
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>
SQL> startup restrict
ORACLE instance started.
Total System Global Area 939524096 bytes
Fixed Size 2931088 bytes
Variable Size 348128880 bytes
Database Buffers 583008256 bytes
Redo Buffers 5455872 bytes
Database mounted.
Database opened.
SQL>
SQL> select property_name,property_value from database_properties where property_name='NLS_CHARACTERSET';
PROPERTY_NAME PROPERTY_VALUE
--------------------------------------------------------------------------------
NLS_CHARACTERSET WE8MSWIN1252

SQL> Alter database character set internal_use AL32UTF8;
Database altered.

SQL> Alter database character set AL32UTF8;
Database altered.

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup;
ORACLE instance started.
Total System Global Area 939524096 bytes
Fixed Size 2931088 bytes
Variable Size 348128880 bytes
Database Buffers 583008256 bytes
Redo Buffers 5455872 bytes
Database mounted.
Database opened.
SQL> SELECT value$ FROM sys.props$ WHERE name = 'NLS_CHARACTERSET';

VALUE$
--------------------------------------------------------------------------------
AL32UTF8

SQL> select property_name,property_value from database_properties where property_name='NLS_CHARACTERSET';

PROPERTY_NAME PROPERTY_VALUE
--------------------------------------------------------------------------------
NLS_CHARACTERSET AL32UTF8

SQL> SET SERVEROUTPUT ON
DECLARE
l_result BOOLEAN;
BEGIN
l_result := DBMS_PDB.check_plug_compatibility(
pdb_descr_file => '/u01/app/oracle/oradata/cdb/pdb1/pdb1.xml',
pdb_name => 'cdb_pdb1');
IF l_result THEN
DBMS_OUTPUT.PUT_LINE('compatible');
ELSE
DBMS_OUTPUT.PUT_LINE('incompatible');
END IF;
END;
/SQL> 2 3 4 5 6 7 8 9 10 11 12 13 14
compatible
PL/SQL procedure successfully completed.
SQL>

SQL> CREATE PLUGGABLE DATABASE CDB_PDB1 USING '/u01/app/oracle/oradata/cdb/pdb1/pdb1.xml' NOCOPY
TEMPFILE REUSE; 2
Pluggable database created.

SQL> ALTER PLUGGABLE DATABASE CDB_PDB1 OPEN READ WRITE;
Pluggable database altered.

SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 CDB_PDB1 READ WRITE NO

 

Clone a Pluggable Database (PDB) Manually

In Cloning we have to use the any source pluggable database instead of seed PDB, which we have to identify using the FROM clause.

SQL> ALTER PLUGGABLE DATABASE PDB2 CLOSE;
Pluggable database altered.

SQL> ALTER PLUGGABLE DATABASE PDB2 OPEN READ ONLY;
Pluggable database altered.

SQL> CREATE PLUGGABLE DATABASE PDB3 FROM PDB2
2 create_file_dest='/u01/app/oracle/oradata/cdb/';
Pluggable database created.

SQL> alter pluggable database pdb3 open;
Pluggable database altered.

SQL> alter pluggable database pdb2 close;
Pluggable database altered.

SQL> alter pluggable database pdb2 open read write;
Pluggable database altered.

SQL> show pdbs
    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 PDB3                           READ WRITE NO
         6 NEW_PDB                        READ WRITE NO
         8 PDB2                           READ WRITE NO

Clone a Remote PDB or Non-CDB

Coming soon

Clone a Pluggable Database (PDB) Manually (Metadata Only : NO DATA)

Coming soon

Delete a Pluggable Database (PDB) Manually

Coming soon

6. DBCA Command Line

Create the container database without PDBs

-bash-4.1$ dbca -silent -createdatabase -createascontainerdatabase true -sid cdb2 -gdbname cdb2 -syspassword oracle_4U -systempassword oracle_4U -templatename /u01/app/oracle/product/12.1.0.2/db_1/assistants/dbca/templates/General_Purpose.dbc -datafiledestination /u01/app/oracle/oradata/ -emconfiguration DBEXPRESS -memorypercentage 20 -storagetype fs -databasetype oltp
Copying database files
1% complete
3% complete
11% complete
18% complete
26% complete
37% complete
Creating and starting Oracle instance
40% complete
45% complete
46% complete
47% complete
52% complete
57% complete
58% complete
59% complete
62% complete
Completing Database Creation
66% complete
70% complete
74% complete
85% complete
89% complete
100% complete
Look at the log file "/u01/app/oracle/cfgtoollogs/dbca/cdb2/cdb20.log" for further details.
-bash-4.1$
-bash-4.1$ . oraenv
ORACLE_SID = [cdb] ? cdb2
The Oracle base remains unchanged with value /u01/app/oracle

-bash-4.1$ sqlplus / as sysdba
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO

SQL> show parameter db_name
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_name string cdb2

One thought on “Create and manage pluggable databases 

  1. Pingback: OCM 12c Preparation | ORACLE -LEARN

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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