We can unplug the pluggable database from existing CDB and Plug it in a different CDB or in the same CDB, depending upon the required. While plugging you can keep the pdb name same as before or can give a different name.
DEMO:
Here we will unplug PDBCD2 pdb and then plug it into the same CDB with different name PDBCD3
Connect to the pluggable database PDBCD2 and close it.
SQL> show pdbs; CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 2 PDB$SEED READ ONLY NO 3 PDBCDB READ WRITE NO 4 PDBCDB2 READ WRITE NO SQL> SQL> alter session set container=PDBCDB2; Session altered. SQL> select file_name from dba_data_files; FILE_NAME -------------------------------------------------------------------------------- /data/app/oracle/oradata/CDB/pdbcdb2/system01.dbf /data/app/oracle/oradata/CDB/pdbcdb2/sysaux01.dbf /data/app/oracle/oradata/CDB/pdbcdb2/undotbs01.dbf /data/app/oracle/oradata/CDB/pdbcdb2/users01.dbf /data/app/oracle/oradata/CDB/pdbcdb2/users02.dbf /data/app/oracle/oradata/CDB/pdbcdb2/tbs_perm_pdb.dat /data/app/oracle/oradata/CDB/pdbcdb2/bigtbs01.dbf SQL> shutdown immediate; Pluggable Database closed.
Connect to container and unplug pdb to a xml file.
[oracle@localhost orcl_plug]$ sqlplus sys/oracle@prim as sysdba SQL*Plus: Release 19.0.0.0.0 - Production on Sun Jun 20 19:44:31 2021 Version 19.3.0.0.0 Copyright (c) 1982, 2019, Oracle. All rights reserved. Connected to: Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production Version 19.3.0.0.0 SQL> alter pluggable database PDBCD2 unplug into '/data/orcl_plug.xml'; Pluggable database altered. SQL> select pdb_name, status from dba_pdbs; PDB_NAME STATUS ------------------------------ ---------- PDBCDB NORMAL PDB$SEED NORMAL PDBCDB2 UNPLUGGED
Now drop the pluggable database
SQL> drop pluggable database PDBCDB2; Pluggable database dropped.
PLUGGING:
Here plug the pdb PDBCDB2 to the Same Container Database
Connect to root container in target database and create pluggable:
[oracle@localhost orcl_plug]$ sqlplus sys/oracle@prim as sysdba SQL*Plus: Release 19.0.0.0.0 - Production on Sun Jun 20 19:44:31 2021 Version 19.3.0.0.0 Copyright (c) 1982, 2019, Oracle. All rights reserved. Connected to: Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production Version 19.3.0.0.0 SQL> create pluggable database PDBCDB3 using '/data/orcl_plug.xml' FILE_NAME_CONVERT=('/data/app/oracle/oradata/CDB/PDBCDB2','/data/app/oracle/oradata/CDB/pdbcdb3'); Pluggable database created.
Open the PDB:
SQL> alter pluggable database PDBCDB3 open; Pluggable database altered. SQL> select name, open_mode, total_size from v$pdbs; NAME OPEN_MODE TOTAL_SIZE ------------------------------ ---------- ---------- PDB$SEED READ ONLY 771751936 PDBCDB READ WRITE 978321408 PDBCDB3 READ WRITE 978321408
Above steps will be same till unplug the pluggable database
Drop the PDB pdb_db2 by preserving the datafiles
SQL> drop pluggable database pdb_db2 keep datafiles; Pluggable database dropped. SQL> select name, open_mode from v$pdbs; NAME OPEN_MODE --------------- ---------- PDB$SEED READ ONLY PDB1 READ WRITE PDB2 READ WRITE PDB3 READ WRITE PDB_DB2_NEW READ WRITE
Run DBMS_PDB.CHECK_PLUG_COMPATIBILITY Function to check compatibility
SET SERVEROUTPUT ON DECLARE compatible CONSTANT VARCHAR2(3) := CASE DBMS_PDB.CHECK_PLUG_COMPATIBILITY( pdb_descr_file => '/u01/pdb_clone/pdb_db2.xml', pdb_name => 'pdb_db2') WHEN TRUE THEN 'YES' ELSE 'NO' END; BEGIN DBMS_OUTPUT.PUT_LINE(compatible); END; / PL/SQL procedure successfully completed. YES
Create pluggable database with nocopy option
SQL> create pluggable database pdb_db2 using '/u01/pdb_clone/pdb_db2.xml' NOCOPY TEMPFILE REUSE; Pluggable database created.