DBAtlas · Database operations atlas

Unplug a PDB and plug it into another (or the same) CDB

OracleMultitenant

Command

-- SOURCE CDB: close and unplug to an XML manifest
ALTER PLUGGABLE DATABASE <pdb> CLOSE IMMEDIATE;
ALTER PLUGGABLE DATABASE <pdb> UNPLUG INTO '/u01/stage/<pdb>.xml';
-- (Single-file archive: UNPLUG INTO '/u01/stage/<pdb>.pdb' - includes datafiles, 12.2+)
DROP PLUGGABLE DATABASE <pdb> KEEP DATAFILES;

-- TARGET CDB: check compatibility first
SET SERVEROUTPUT ON
DECLARE
  l_ok BOOLEAN;
BEGIN
  l_ok := DBMS_PDB.CHECK_PLUG_COMPATIBILITY(
            pdb_descr_file => '/u01/stage/<pdb>.xml',
            pdb_name       => '<pdb>');
  DBMS_OUTPUT.PUT_LINE(CASE WHEN l_ok THEN 'COMPATIBLE' ELSE 'NOT COMPATIBLE - see PDB_PLUG_IN_VIOLATIONS' END);
END;
/
SELECT name, cause, type, status, message
FROM   pdb_plug_in_violations
WHERE  name = UPPER('<pdb>') AND status <> 'RESOLVED';

-- NOCOPY if the files stay in place, COPY FILE_NAME_CONVERT if they move:
CREATE PLUGGABLE DATABASE <pdb> USING '/u01/stage/<pdb>.xml' NOCOPY TEMPFILE REUSE;
-- From a .pdb archive: CREATE PLUGGABLE DATABASE <pdb> USING '/u01/stage/<pdb>.pdb'
--                    FILE_NAME_CONVERT = ('/u01/stage/', '/u02/oradata/<cdb>/<pdb>/');
ALTER PLUGGABLE DATABASE <pdb> OPEN;

What it does

Detaches the PDB from the CDB and writes its metadata to an XML manifest (or a single .pdb archive together with the datafiles); after a compatibility check it plugs it back into the target CDB with the same files.

When to use it

To move a PDB to a newer-release CDB on the same server (unplug/plug upgrade), for CDB consolidation, or for moves where cloning over the network is not possible.

Caution

After unplugging, the PDB is unavailable in the source CDB (downtime). Files plugged in with NOCOPY now belong to the target CDB; take a file-level copy or an RMAN backup first so you can fall back on failure. Until ERROR-type violations are resolved the PDB opens RESTRICTED. When plugging back into the same CDB, omitting AS CLONE can cause a GUID conflict.

Open in DBAtlas →

Related