Updated: Sep 25, 2020
Application containers have been around since versions 12c, with a CDB root container, along with dependent application container PDBs, which allows PDBs to share database objects.
Currently in this example, the Database has a CDB$ROOT, where the PDB$SEED and an ORADES_PDB01 that belong to the CDB$ROOT according to the query below.
SELECT CON_ID, NAME, APPLICATION_ROOT AS ROOT, APPLICATION_PDB AS PDB FROM V$CONTAINERS; CON_ID NAME ROOT PDB ---------- --------------- --- --- 1 CDB$ROOT NO NO 2 PDB$SEED NO NO 3 ORADES_PDB01 NO NO
Creating a new application container
The creation of an application container is very similar to the creation of a PDB, but it is necessary to include the following clause AS APPLICATION CONTAINER.
We are going to call the new app container of "app_cont_hmp01" according to the command below:
Accessing with SQLPLUS
sqlplus / as sysdba
Creation application container
CREATE PLUGGABLE DATABASE app_cont_hmp01 AS APPLICATION CONTAINER ADMIN USER app_hmp01_admin IDENTIFIED BY My_Password; Pluggable database created.
Opening new application container
ALTER PLUGGABLE DATABASE app_cont_hmp01 OPEN; Pluggable database altered.
Now after creating a new CDB Root app_cont_hmp0, let's add a PDB associated with it.
To create a new application hmp_pdb01, you must be connected to an application root (app_cont_hmp01), not the CDB root (CDB$ROOT).
Let's connect to the application container app_cont_hmp1
ALTER SESSION SET CONTAINER=app_cont_hmp01; Session altered.
PDB creation in the new application container
Once connected at the root of the application, you can normally proceed with the creation of a new PDB that I will call hmp_pdb01
CREATE PLUGGABLE DATABASE hmp_pdb01 ADMIN USER hmp_pdb01_admin IDENTIFIED BY My_Password; Pluggable database created.
Let's connect to the new PDB already created.
ALTER PLUGGABLE DATABASE hmp_pdb01 OPEN; Pluggable database altered.
When creating one in the new PDB it is very important to synchronize them with all applications defined at the root of the application
ALTER SESSION SET CONTAINER=hmp_pdb01; Session altered. ALTER PLUGGABLE DATABASE APPLICATION ALL SYNC; Pluggable database altered.
End of synchronization between again in the application container session app_cont_hmp1, make sure it is in READ WRITE mode
ALTER SESSION SET CONTAINER=app_cont_hmp01; Session altered. show pdbs; CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 4 APP_CONT_HMP01 READ WRITE NO 5 HMP_PDB01 READ WRITE NO
Exit SQLPLUS and sign in again and run the following query:
sqlplus / as sysdba SET LINESIZE 100 SET PAGESIZE 100 COL NAME FORMAT a15 COL ROOT FORMAT a4 SELECT CON_ID, NAME, APPLICATION_ROOT AS ROOT,APPLICATION_PDB AS PDB FROM V$CONTAINERS; CON_ID NAME ROOT PDB ---------- --------------- ---- --- 1 CDB$ROOT NO NO 2 PDB$SEED NO NO 3 ORADES_PDB01 NO NO 4 APP_CONT_HMP01 YES NO 5 HMP_PDB01 NO YES
Now see that APP_CONT_HMP01 = YES, that is to say, it is an application container root CDB.
HMP_PDB01 = YES is exactly a PDB that we created in the container APP_CONT_HMP01.
Don't forget to finish with BACKUP, See Here ...
We finished the procedures.
Drop application container
Now we are going to discard an application container, so we need to understand some situations and requirements.
The CDB must be in mounted mode;
If you do not have associated PDBs, you can discard normally.
The current user must have SYSDBA or SYSOPER administrative privilege
After the application container is closed, it can be disposed of in the normal way, as long as it has no associated PDBs.
If there is no associated PDB you can remove it normally with the following command below:
ALTER PLUGGABLE DATABASE app_cont_hmp01 CLOSE IMMEDIATE; DROP PLUGGABLE DATABASE app_cont_hmp01 INCLUDING DATAFILES;
If you want to DROP a CDB that has an associated PDB you will receive ERROR ORA-65265: PDB cannot be dropped or unplugged. You cannot delete the Application PDBs belonging to the application container before attempting to remove and I need to disconnect the root of the application.
Choose one of the methods that suits your needs as described below:
Removing associated PDB
Remove the associated PDBs according to the method applied at this link: See the Drop PDB procedure here
Unplugging an associated PDB from a CDB
Unplugging a PDB disassociated the PDB from an CDB can be used in the following ways:
When you want to move the PDB to a different CDB;
Do you want to archive the PDB for later use;
When you no longer want the PDB to be available.
When disconnecting from the PDB, you can create an XML file that will contain metadata about the PDB or you can choose the extension (.pdb) which is more complete where it will be compressed into a single file with metadata, data files and the wallet file.
Connect to the root of the CDB or the root of the application and access the PDB, it must be closed before being disconnected the unplugged PDB is in mounted mode.
ALTER SESSION SET CONTAINER=app_cont_hmp01; Session altered. ALTER PLUGGABLE DATABASE hmp_pdb01 CLOSE IMMEDIATE; Session altered.
Unplugging PDB hmp_pdb01 Into an Archive File
ALTER PLUGGABLE DATABASE hmp_pdb01 UNPLUG INTO '/u01/app/orades/my_directory/data/hmp01.pdb'; Pluggable database altered.
We will use the DROP PLUGGABLE DATABASE clauses with INCLUDING DATAFILES to remove the data files from the disk.
DROP PLUGGABLE DATABASE hmp_pdb01 INCLUDING DATAFILES; Pluggable database dropped.
If there is no more associated PDB, normally do the Drop application container (CDB).
ALTER PLUGGABLE DATABASE app_cont_hmp01 CLOSE IMMEDIATE; Pluggable database altered. DROP PLUGGABLE DATABASE app_cont_hmp01 INCLUDING DATAFILES; Pluggable database dropped.
The container APP_CONT_HMP1 ceased to exist as per the query below:
SHOW CON_NAME CON_NAME ------------------------------ CDB$ROOT SQL>