Plugging An Unplugged Pluggable Database
Plugging An Unplugged Pluggable Database
Overview
Purpose
This tutorial covers the steps required to plug an unplugged pluggable database (PDB) from a container database (CDB) into another CDB.
Time to Complete
Approximately 20 minutes
Introduction
You can disassociate or unplug a PDB from a CDB and reassociate or plug the PDB into the same CDB or into another CDB. This capability is suitable for the following situations:
You have to upgrade a PDB to the latest Oracle version, but you do not want to apply it on all PDBs. Instead of upgrading a CDB from one release to another, you can unplug a PDB from one Oracle Database release, and the
plug it into a newly created CDB from a later release.
You want to test the performance of the CDB without a particular PDB. You unplug the PDB, test the performance without the PDB and, if necessary, replug the PDB into the CDB.
You want to maintain a collection of PDB “gold images” as unplugged PDBs.
Scenario
In this tutorial, you perform a PDB unplugging operation from a CDB. Next, you perform a plugging operation of the same PDB into another CDB by using SQL*Plus.
Plug the unplugged PDB by using the data files of the unplugged PDB. The unplugged PDB is disassociated from the source CDB.
The source data files are used with or without any copy.
The source data files are used after being moved to another location.
Plug the unplugged PDB as a clone to:
Allow developers and testers to rapidly and repeatedly provision a well-known starting state
Support self-paced learning
Provide a new way to deliver a brand-new application
Prerequisites
ORACLE_HOME: /u01/app/oracle/product/12.1.0
TNS Listener port: 1521
Container databases:
SID: cdb1
SID: cdb2
Pluggable databases (in cdb1):
pdb1
pdb2
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, as well as data files of the unplugged PDB. The information will be
used by the plugging operation.
In this section, you unplug two PDBs to plug them with different methods.
1. Use SQL*Plus to close the PDBs before they can be unplugged. Note: The pdb2 database may not have been opened, so you may receive an error that the PDB is already closed.
. oraenv
sqlplus / as sysdba
2. Unplug the closed PDB and then specify the path and name of the XML file.
exit
The unplugging operation makes changes in the PDB data files to record that the PDB was properly and successfully unplugged. Because the PDB is still part of the CDB, you can back it up in Oracle Recovery Manager (Oracle
RMAN). This backup provides a convenient way to archive the unplugged PDB. After backing it up, you then remove it from the CDB catalog. But, of course, you must preserve the data files for the subsequent plugging operation.
In this section, you plug the unplugged PDB into another CDB by using different methods.
Checking the Compatibility of the Unplugged PDB with the Host CDB
Before starting the plugging operation, make sure that the to-be-plugged-in PDB is compatible with the new host CDB. Execution of the PL/SQL block raises an error if it is not compatible.
. oraenv
sqlplus / as sysdba
set serveroutput on
DECLARE
compatible BOOLEAN := FALSE;
BEGIN
compatible := DBMS_PDB.CHECK_PLUG_COMPATIBILITY(
pdb_descr_file => '/u01/app/oracle/oradata/pdb1.xml');
if compatible then
DBMS_OUTPUT.PUT_LINE('Is pluggable PDB1 compatible? YES');
else DBMS_OUTPUT.PUT_LINE('Is pluggable PDB1 compatible? NO');
end if;
END;
/
DECLARE
compatible BOOLEAN := FALSE;
BEGIN
compatible := DBMS_PDB.CHECK_PLUG_COMPATIBILITY(
pdb_descr_file => '/u01/app/oracle/oradata/pdb2.xml');
if compatible then
DBMS_OUTPUT.PUT_LINE('Is pluggable PDB2 compatible? YES');
else DBMS_OUTPUT.PUT_LINE('Is pluggable PDB2 compatible? NO');
end if;
END;
/
This operation lasts a few seconds. The original data files 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 temp file specified in the XML file exists in
the target location. Therefore, the TEMPFILE_REUSE clause is required.
2. Verify the status and open mode of the plugged PDB. Proceed to the next section, "Opening the Plugged PDB," to finalize the plugging operation.
exit
mkdir /u01/app/oracle/oradata/cdb2/pdb_plug_copy
sqlplus / as sysdba
2. Use the data files of the unplugged PDB to plug the PDB into the CDB and copy the data files to a new location.
3. Verify the status and open mode of the plugged PDB. Proceed to the next section, "Opening the Plugged PDB," to finalize the plugging operation.
exit
mkdir /u01/app/oracle/oradata/cdb2/pdb_plug_move
sqlplus / as sysdba
2. Plug the PDB into the CDB and move the data files to a new location.
An error message is returned because of the non-uniqueness of the GUID. This is a good example of using the AS CLONE clause.
3. Verify the status and open mode of the plugged PDB. Proceed to the next section, "Opening the Plugged PDB," to finalize the plugging operation.
2. Connect to the plugged-in PDBs and verify the container name that you are connected to.
show con_name
show con_name
show con_name
exit
Perform the following steps to reset your environment prior to repeating the activities covered in this OBE or starting another OBE.
. oraenv
sqlplus / as sysdba
2. Unplug and then drop the PDB_PLUG_NOCOPY database so that you can use it to re-create the pdb1 database.
3. Unplug the PDB_PLUG_COPY database so that you can use it to re-create the pdb2 database.
6. Plug the pdb2 database back into the cdb1 container database.
7. Plug the pdb1 database back into the cdb1 container database.
exit
9. Remove the files that are no longer needed in the file system.
rm $ORACLE_BASE/oradata/pdb*.xml
rm -rf $ORACLE_BASE/cdb2/pdb_plug*
Summary
In this tutorial, you learned how to unplug a PDB and plug it into another CDB.
Resources
To learn more about pluggable databases, refer to additional OBEs in the Oracle Learning Library.
Credits