In multitenant environment, a PDB can unplug from a CDB and then plug it into another CDB.Once PDB is unplugged, it needs to be dropped from CDB as it become unusable in this CDB.Same PDB can be plugged back into the same CDB.
Unplugging PDB:
==================
Connect to PDB using sqlplus and list the location of all the datafiles of PDB which is going to unplugged.
sql>sqlplus "/ as sysdba"
sql>alter session set container=pdb1;
sql>select file_name from dba_data_files;
Close PDB:
==========
sql>alter pluggable database pdb1 close immediate;
Unplug PDB:
===========
sql> alter pluggable database pdb1 unplug into '/u01/pdb1_db.xml';
Complete path is needed to specify which would created during this process and will contain information about this PDB. Same xml would be used during plugging into CDB.
Copy Datafile:
===============
Copy the datafiles listed in the above step to the host of CDB where we want to plug.Also copy xml file.
Drop unplugged PDB:
===================
sql>drop pluggable database pdb1 keep datafiles;
**We can skip this step, if plugging PDB on a different host.
KEEP DATAFILES clause used with drop command so that datafile dont get dropped and can be re-used id plugging in the same CDB.
Plugging PDB:
================
This would be in destination.Compatibility of PDB should be checked against CDB where it will be plugged in.
Below codes can be used, O/p should be Yes to go ahead further:
SET SERVEROUTPUT ON
DECLARE
compatible CONSTANT VARCHAR2(3) :=
CASE DBMS_PDB.CHECK_PLUG_COMPATIBILITY(
pdb_descr_file => '/u01/pdb1_db.xml',
pdb_name => 'PDB1')
WHEN TRUE THEN 'YES'
ELSE 'NO'
END;
BEGIN
DBMS_OUTPUT.PUT_LINE(compatible);
END;
Plug in PDB in target CDB:
============================
Datafiles location on the destination host/CDB can be same or different. If location is same, we don’t need to do anything, otherwise we will need to use FILE_NAME_CONVERT option of CREATE PLUGGABLE DATABASE command to specify the new location of the datafiles.
sql> create pluggable database pdb1 using '/u01/pdb1_db.xml' copy file_name_convert=('/u01/app/pdb1','/u01/db/pdb1');
sql> alter pluggable database pdb1 open;
***COPY keyword is default to be used to copy files to the new destination. If destination is same as source, specify NOCOPY.
If you have copied datafiles on a different location on the destination, you will need to edit .xml file to specify the location where you have copied the datafiles so that during plugging in phase, datafiles can be searched at this location.
No comments:
Post a Comment