Plugging an Unplugged Pluggable Database
Unplugging the PDB
To unplug a PDB, you first close it and then generate an XML manifest file. The XML file contains information about the names and the full paths of the tablespaces, datafiles of the unplugged PDB. The information will be used by the plugging operation.
We are going to unplug the PDB to plug them with No copy methods.
[oracle@localhost pdb3]$ . oraenv ORACLE_SID = [cdb1] ? cdb1 The Oracle base remains unchanged with value /u01/app/oracle [oracle@localhost pdb3]$ sqlplus / as sysdba SQL> show con_name CON_NAME ------------------------------ CDB$ROOT SQL> alter pluggable database pdb2 close immediate; SQL> ! SQL> alter pluggable database pdb2 unplug into '/u01/app/oracle/oradata/cdb1/pdb2/pdb2.xml'; Pluggable database altered. SQL> drop pluggable database pdb2 keep datafiles; Pluggable database dropped. SQL> select pdb_name, status from cdb_pdbs where pdb_name in ('PDB2'); no rows selected SQL> Shutdown immediate; SQL> exit
Plugging the PDB into the Same or Another CDB
[oracle@localhost pdb3]$ ps -ef | grep pmon oracle 6950 2581 0 11:26 pts/1 00:00:00 grep pmon [oracle@localhost ~]$ . oraenv ORACLE_SID = [cdb1] ? cdb2 The Oracle base remains unchanged with value /u01/app/oracle [oracle@localhost ~]$ sqlplus / as sysdba SQL> startup; SQL> DECLARE compatible BOOLEAN := FALSE; BEGIN compatible := DBMS_PDB.CHECK_PLUG_COMPATIBILITY( pdb_descr_file => '/u01/app/oracle/oradata/cdb1/pdb2/pdb2.xml', pdb_name => 'pdb2'); if compatible then DBMS_OUTPUT.PUT_LINE('Is pluggable PDB2 compatible? SQL> YES'); else DBMS_OUTPUT.PUT_LINE('Is pluggable PDB2 compatible? NO'); end if; END; /
Note: The unplugging operation actually makes some changes in the PDB’s datafiles to record that the PDB was properly and successfully unplugged. Because it is still part of the CDB, you can do an ad hoc RMAN backup of it. This provides a convenient way to archive the unplugged PDB. Once you have backed it up, you then remove it from the CDB’s catalog. But, of course, you must preserve the datafiles for the subsequent plugging operation.
Method-1: Plug the unplugged PDB : NOCOPY Method
Use the datafiles of the unplugged PDB to plug the PDB into another CDB without any copy.
This operation lasts a few seconds. The original datafiles of the unplugged PDB now belong to the new plugged-in PDB in the new host CDB. A file with the same name as the tempfile specified in the XML file exists in the target location. Therefore, the TEMPFILE_REUSE clause is required.
SQL> create pluggable database pdb_plug_nocopy using '/u01/app/oracle/oradata/cdb1/pdb1/pdb1.xml' NOCOPY TEMPFILE REUSE; Pluggable database created. SQL>
Verify the status and open_mode of the plugged PDB. Proceed with the next section Opening the Plugged PDB to finalize the plugging operation.
SQL> set linesize 200 SQL> select pdb_name, status from cdb_pdbs where pdb_name='PDB_PLUG_NOCOPY'; SQL> select open_mode from v$pdbs where name='PDB_PLUG_NOCOPY'; SQL> select name from v$datafile where con_id=3; SQL> exit
Opening the plugged PDB
SQL> show con_name CON_NAME ------------------------------ CDB$ROOT SQL> alter pluggable database pdb_plug_nocopy open; Pluggable database altered
Connect to the plugged-in PDBs and verify the container name you are connected to:
SQL> connect sys/oracle@localhost:1521/pdb_plug_nocopy AS SYSDBA Connected. SQL> show con_name CON_NAME ------------------------------ PDB_PLUG_NOCOPY
Connect to the plugged-in PDBs and verify the container name you are connected to:
SQL> connect sys/oracle@localhost:1521/pdb_plug_nocopy AS SYSDBA Connected. SQL> show con_name CON_NAME ------------------------------ PDB_PLUG_NOCOPY
Unplug, and then drop the PDB_PLUG_NOCOPY database. This will be used to recreate the pdb1 database:
SQL> alter pluggable database pdb_plug_nocopy unplug into '/u01/app/oracle/oradata/pdb_plug_nocopy.xml'; Pluggable database altered. SQL> drop pluggable database pdb_plug_nocopy keep datafiles; Pluggable database dropped.
Plug the pdb1 database back into the cdb1 container database:
SQL> create pluggable database pdb1 using '/u01/app/oracle/oradata/pdb_plug_nocopy.xml' nocopy tempfile reuse; Pluggable database created. SQL> alter pluggable database pdb1 open; Pluggable database altered. SQL> exit [oracle@localhost ~]$ rm $ORACLE_BASE/oradata/pdb*.xml [oracle@localhost ~]$ rm -rf $ORACLE_BASE/oradata/cdb2/pdb_plug*