Creation of Pluggable Database (PDB)

Updated: Sep 8

In these instructions we will create a PLUGGABLE DATABASE (PDB) using PDB$SEED, for that you must have already created the CDB with a CDB$ROOT container there must be a PDB$SEED that is our base (template) for the creation of the new PDB .


If you have not created CDB, See Here...



The new PDB creation techniques will use the PDB seed files that copy the files associated with the PDB$SEED, to a new location.


Requirements

  • We will use SQLPlus, make sure that the current container is the root of the CDB or an application root;

  • Run the CREATE PLUGGABLE DATABASE command, specify a local administrator for the PDB;

  • The new PDB must open read / write mode;

  • Like everything we recommend doing a Backup.

Creating new PDB


SQLPLUS access with command;

sqlplus / as sysdba;

Let's see if the database is a non-CDB or a container in a CDB, ("Yes" Indicates that it is a container)

SELECT NAME, CDB, CON_ID FROM V$DATABASE;

NAME      CDB     CON_ID
--------- --- ----------
ORADES    YES          0

Check all existing PDBs:

show pdbs;

CON_ID CON_NAME                           OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO

Since everything is in agreement, with the command below we created a new PDB called HL_PDB01 (Homologation_pdb1) plus the user (HL_ADMIN) with DBA privileges.

CREATE PLUGGABLE DATABASE HL_PDB01 ADMIN USER HL_ADMIN IDENTIFIED BY my_password ROLES=(DBA);

Pluggable database created.    
    

Ready your new PDB HL_PDB01 was created successfully now you must put it in and open the read/write mode;

ALTER PLUGGABLE DATABASE HL_PDB01 OPEN;
Pluggable database altered.

show pdbs;

CON_ID CON_NAME                           OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 HL_PDB01                       READ WRITE NO

Don't forget to finish with BACKUP, See Here ...

Creation successful!


Drop PDB


You can delete a PDB when you no longer need it, for that you need to understand some requirements and some parameters of the command, before removing the PDB.


Requirements

  • The PDB must be in mounted mode, or it must be unplugged;

  • The current user must have SYSDBA or SYSOPER administrative privilege, and the privilege must be either commonly granted or locally granted in the PDB.

There are two clauses of the DROP PLUGGABLE DATABASE statement:

  • INCLUDING DATAFILES removes the data files from disk.

  • KEEP DATAFILES, the default, retains the data files;

Nota: If you want to keep user data files for some reason, the KEEP DATAFILES parameter

DROP PLUGGABLE DATABASE HL_PDB01 KEEP DATAFILES;

Deleting a PDB


We will put the PDB to be eliminated in the mount state using SQLPLUS /

sqlplus / as sysdba;

Note: If you try to Drop PDB with it OPEN in (READ WRITE) mode you will receive the following message.

ERROR at line 1:
ORA-65025: Pluggable database HL_PDB01 is not closed on all instances.

We will put the PDB to be deleted in the MOUNT state.

ALTER PLUGGABLE DATABASE HL_PDB01 CLOSE IMMEDIATE;
Pluggable database altered.

show pdbs;

CON_ID CON_NAME                           OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 HL_PDB01                       MOUNTED 

We will use the DROP PLUGGABLE DATABASE clauses with INCLUDING DATAFILES to remove the data files from the disk.

DROP PLUGGABLE DATABASE HL_PDB01 INCLUDING DATAFILES;

Pluggable database dropped.

show pdbs;

CON_ID CON_NAME                           OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO

Your PDB has been successfully removed completely !!!