Before plugging a PDB into another CDB, it must first be unplugged. Unplugging translates to disassociating a PDB from a CDB and generating an XML file that describes the PDB being unplugged.
This XML file can be used in the future to plug the PDB into another CDB. Before going down this path, however, consider the previous section that discussed refreshable clones.
This creates another PDB and can be refreshed and switched over. Still, there might be a need to move a PDB offline.
Here are the steps required to unplug a PDB:
1. Close the PDB (which changes its open mode to MOUNTED).
2. Unplug the pluggable database via the ALTER PLUGGABLE DATABASE … UNPLUG command.
First, connect to the root container as the SYS user, and then close the PDB:
$ sqlplus sysuser/Cr4zyPa$$word1 as sysdba
SQL> alter pluggable database mmpdb close immediate;
Next, unplug the PDB. Make sure you specify a directory that exists in your environment for the location of the XML file:
SQL> alter pluggable database mmpdb unplug into ‘/oradata/oracle/dba/ mmpdb.xml’;
The XML file contains metadata regarding the PDB, such as its data files. This XML is required if you want to plug the PDB into another CDB.
Note Once a PDB is unplugged, it must be dropped before it can be plugged back into the original CDB.
Plugging an Unplugged PDB into a CDB
Before a PDB can be plugged into a CDB, it must be compatible with a CDB in terms of data file endianness and compatible database options installed. The character set can be different, which is how you can get a different character set for PDBs in the same CDB. You can verify the compatibility via the DBMS_PDB package. You must provide as input to the package the directory and name of the XML file created when the PDB was unplugged. Here is an example:
SQL> set serveroutput on SQL> declare
hold_var boolean; begin hold_var := dbms_pdb.check_plug_compatibility(pdb_descr_file => ‘/oradata/ oracle/dba/mmpdb.xml’); if hold_var then dbms_output.put_line(‘YES’); else dbms_output.put_line(‘NO’);
If there are no compatibility issues, a YES is displayed by the prior code; a NO is displayed if the PDB is not compatible. You can query the contents of the PDB_PLUG_IN_ VIOLATIONS view for the details on why a PDB is not compatible with a CDB.
Plugging in a PDB is done with the CREATE PLUGGABLE DATABASE command. When you plug a PDB into a CDB, you must provide some key pieces of information, using
these two clauses:
• USING clause: This clause specifies the location of the XML file created when the PDB was unplugged.
• COPY FILE_NAME_CONVERT clause: This clause specifies the source of the PDB data files and the location where the PDB data files will be created within the destination CDB.
To plug in a PDB, connect to the CDB as a privileged user, and run the following:
SQL> create pluggable database mmpdb using ‘/oradata/oracle/dba/mmpdb.xml’ copy
file_name_convert = (‘/u01/app/oracle/oradata/cdb19/mmpdb’, ‘/u01/dbfile/mmdb23c/mmpdb’);
You can now open the PDB and begin using it.