5 Creating a PDB Using a Non-CDB
You can create a PDB using a non-CDB in different ways.
- Adopting a Non-CDB as a PDB
You can adopt (move) a non-CDB into a PDB by using theDBMS_PDB.DESCRIBEprocedure.
Adopting a Non-CDB as a PDB
You can adopt (move) a non-CDB into a PDB by using the DBMS_PDB.DESCRIBE procedure.
To adopt a non-CDB as a PDB using the DBMS_PDB package:
-
Create the CDB if it does not exist.
-
Ensure that the non-CDB is in a transactionally-consistent state.
-
Place the non-CDB in read-only mode.
-
Connect to the non-CDB, and run the
DBMS_PDB.DESCRIBEprocedure to construct an XML file that describes the non-CDB.The current user must have
SYSDBAadministrative privilege. The user must exercise the privilege usingAS SYSDBAat connect time.For example, to generate an XML file named
ncdb.xmlin the/disk1/oracledirectory, run the following procedure:BEGIN DBMS_PDB.DESCRIBE( pdb_descr_file => '/disk1/oracle/ncdb.xml'); END; /After the procedure completes successfully, you can use the XML file and the non-CDB database files to plug the non-CDB into a CDB.
-
Run the
DBMS_PDB.CHECK_PLUG_COMPATIBILITYfunction to determine whether the non-CDB is compatible with the CDB.When you run the function, set the following parameters:
-
pdb_descr_file- Set this parameter to the full path to the XML file. -
pdb_name- Specify the name of the new PDB. If this parameter is omitted, then the PDB name in the XML file is used.
For example, to determine whether a non-CDB described by the
/disk1/oracle/ncdb.xmlfile is compatible with the current CDB, run the following PL/SQL block:SET SERVEROUTPUT ON DECLARE compatible CONSTANT VARCHAR2(3) := CASE DBMS_PDB.CHECK_PLUG_COMPATIBILITY( pdb_descr_file => '/disk1/oracle/ncdb.xml', pdb_name => 'NCDB') WHEN TRUE THEN 'YES' ELSE 'NO' END; BEGIN DBMS_OUTPUT.PUT_LINE(compatible); END; /If the output is
YES, then the non-CDB is compatible, and you can continue with the next step. If the output isNO, then the non-CDB is not compatible, and you can check thePDB_PLUG_IN_VIOLATIONSview to see why it is not compatible. All violations must be corrected before you continue. For example, any version or patch mismatches should be resolved by running an upgrade or the datapatch utility. After correcting the violations, runDBMS_PDB.CHECK_PLUG_COMPATIBILITYagain to ensure that the non-CDB is compatible with the CDB. -
-
Shut down the non-CDB.
-
Plug in the non-CDB.
For example, the following SQL statement plugs in a non-CDB, copies its files to a new location, and includes only the
tbs3user tablespace from the non-CDB:CREATE PLUGGABLE DATABASE ncdb USING '/disk1/oracle/ncdb.xml' COPY FILE_NAME_CONVERT = ('/disk1/oracle/dbs/', '/disk2/oracle/ncdb/') USER_TABLESPACES=('tbs3');If there are no violations, then do not open the new PDB. You will open it in the following step.
The
USER_TABLESPACESclause enables you to separate data that was used for multiple tenants in a non-CDB into different PDBs. You can use multipleCREATE PLUGGABLE DATABASEstatements with this clause to create other PDBs that include the data from other tablespaces that existed in the non-CDB. -
Run the
ORACLE_HOME/rdbms/admin/noncdb_to_pdb.sqlscript. This script must be run before the PDB can be opened for the first time.If the PDB was not a non-CDB, then running the
noncdb_to_pdb.sqlscript is not required. To run thenoncdb_to_pdb.sqlscript, complete the following steps:-
Access the PDB.
The current user must have
SYSDBAadministrative privilege, and the privilege must be either commonly granted or locally granted in the PDB. The user must exercise the privilege usingAS SYSDBAat connect time. -
Run the
noncdb_to_pdb.sqlscript:@$ORACLE_HOME/rdbms/admin/noncdb_to_pdb.sql
The script opens the PDB, performs changes, and closes the PDB when the changes are complete.
-
-
Open the new PDB in read/write mode.
You must open the new PDB in read/write mode for Oracle Database to complete the integration of the new PDB into the CDB. An error is returned if you attempt to open the PDB in read-only mode. After the PDB is opened in read/write mode, its status is
NORMAL. -
Back up the PDB.
A PDB cannot be recovered unless it is backed up.
Note:
If an error is returned during PDB creation, then the PDB being created might be in an UNUSABLE state. You can check a PDB's state by querying the CDB_PDBS or DBA_PDBS view, and you can learn more about PDB creation errors by checking the alert log. An unusable PDB can only be dropped, and it must be dropped before a PDB with the same name as the unusable PDB can be created.
Parent topic: Creating a PDB Using a Non-CDB