How to Unplug and Plug a PDB in Same Host

  • by
First of all, check the status of the target PDB to unplug.
SQL> show pdbs;

    CON_ID CON_NAME  OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
...
4 FINANCE_PDB  READ WRITE NO

It's in READ WRITE mode. So we need to close it before unplugging it.

1. Close the PDB.
SQL> alter pluggable database finance_pdb close immediate;

Pluggable database altered.

SQL> show pdbs;

    CON_ID CON_NAME  OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
...
4 FINANCE_PDB  MOUNTED

Actually, there're two steps in unplugging. The first step is to unplug and save the status of the PDB into a XML file for later use. The second step is to drop the PDB.

2. Unplug the PDB.
SQL> alter pluggable database finance_pdb unplug into '/u01/app/oracle/oradata/orcl/Finance_Pdb/Finance_Pdb.xml';

Pluggable database altered.

The XML will document all the information about the PDB. For example:
[oracle@test1 ~]$ cat /u01/app/oracle/oradata/orcl/Finance_Pdb/Finance_Pdb.xml
<?xml version="1.0" encoding="UTF-8"?>
<PDB>
  <xmlversion>1</xmlversion>
  <pdbname>FINANCE_PDB</pdbname>
  <cid>4</cid>
  <byteorder>1</byteorder>
  <vsn>202375680</vsn>
  <vsns>
    <vsnnum>12.1.0.2.0</vsnnum>
    <cdbcompt>12.1.0.2.0</cdbcompt>
    <pdbcompt>12.1.0.2.0</pdbcompt>
    <vsnlibnum>0.0.0.0.22</vsnlibnum>
    <vsnsql>22</vsnsql>
    <vsnbsv>8.0.0.0.0</vsnbsv>
  </vsns>
  <dbid>4203379900</dbid>
  <ncdb2pdb>0</ncdb2pdb>
  <cdbid>1404255397</cdbid>
  <guid>22BC10FDAB190D76E0530100007F06C0</guid>
  <uscnbas>3084603</uscnbas>
  <uscnwrp>0</uscnwrp>
  <rdba>4194824</rdba>
  <tablespace>
    <name>SYSTEM</name>
    <type>0</type>
    <tsn>0</tsn>
    <status>1</status>
    <issft>0</issft>
    <file>
      <path>/u01/app/oracle/oradata/orcl/Finance_Pdb/system01.dbf</path>
      <afn>28</afn>
      <rfn>1</rfn>
      <createscnbas>3083338</createscnbas>
      <createscnwrp>0</createscnwrp>
      <status>1</status>
      <fileblocks>34560</fileblocks>
      <blocksize>8192</blocksize>
      <vsn>202375680</vsn>
      <fdbid>4203379900</fdbid>
      <fcpsw>0</fcpsw>
      <fcpsb>3084599</fcpsb>
      <frlsw>0</frlsw>
      <frlsb>2972684</frlsb>
      <frlt>893727268</frlt>
    </file>
  </tablespace>
  <tablespace>
    <name>SYSAUX</name>
    <type>0</type>
    <tsn>1</tsn>
    <status>1</status>
    <issft>0</issft>
    <file>
      <path>/u01/app/oracle/oradata/orcl/Finance_Pdb/sysaux01.dbf</path>
      <afn>29</afn>
      <rfn>4</rfn>
      <createscnbas>3083341</createscnbas>
      <createscnwrp>0</createscnwrp>
      <status>1</status>
      <fileblocks>72960</fileblocks>
      <blocksize>8192</blocksize>
      <vsn>202375680</vsn>
      <fdbid>4203379900</fdbid>
      <fcpsw>0</fcpsw>
      <fcpsb>3084599</fcpsb>
      <frlsw>0</frlsw>
      <frlsb>2972684</frlsb>
      <frlt>893727268</frlt>
    </file>
  </tablespace>
  <tablespace>
    <name>TEMP</name>
    <type>1</type>
    <tsn>2</tsn>
    <status>1</status>
    <issft>0</issft>
    <bmunitsize>128</bmunitsize>
    <file>
      <path>/u01/app/oracle/oradata/orcl/Finance_Pdb/pdbseed_temp012015-04-08_09-11-58-AM.dbf</path>
      <afn>4</afn>
      <rfn>1</rfn>
      <createscnbas>3083339</createscnbas>
      <createscnwrp>0</createscnwrp>
      <status>0</status>
      <fileblocks>2560</fileblocks>
      <blocksize>8192</blocksize>
      <vsn>202375680</vsn>
      <autoext>1</autoext>
      <maxsize>4194302</maxsize>
      <incsize>80</incsize>
    </file>
  </tablespace>
  <tablespace>
    <name>USERS</name>
    <type>0</type>
    <tsn>3</tsn>
    <status>1</status>
    <issft>0</issft>
    <file>
      <path>/u01/app/oracle/oradata/orcl/Finance_Pdb/users01.dbf</path>
      <afn>30</afn>
      <rfn>10</rfn>
      <createscnbas>3083344</createscnbas>
      <createscnwrp>0</createscnwrp>
      <status>1</status>
      <fileblocks>3200</fileblocks>
      <blocksize>8192</blocksize>
      <vsn>202375680</vsn>
      <fdbid>4203379900</fdbid>
      <fcpsw>0</fcpsw>
      <fcpsb>3084599</fcpsb>
      <frlsw>0</frlsw>
      <frlsb>2972684</frlsb>
      <frlt>893727268</frlt>
    </file>
  </tablespace>
  <optional>
    <ncdb2pdb>0</ncdb2pdb>
    <csid>873</csid>
    <ncsid>2000</ncsid>
    <options>
      <option>APS=12.1.0.2.0</option>
      <option>CATALOG=12.1.0.2.0</option>
      <option>CATJAVA=12.1.0.2.0</option>
      <option>CATPROC=12.1.0.2.0</option>
      <option>CONTEXT=12.1.0.2.0</option>
      <option>DV=12.1.0.2.0</option>
      <option>JAVAVM=12.1.0.2.0</option>
      <option>OLS=12.1.0.2.0</option>
      <option>ORDIM=12.1.0.2.0</option>
      <option>OWM=12.1.0.2.0</option>
      <option>SDO=12.1.0.2.0</option>
      <option>XDB=12.1.0.2.0</option>
      <option>XML=12.1.0.2.0</option>
      <option>XOQ=12.1.0.2.0</option>
    </options>
    <olsoid>0</olsoid>
    <dv>0</dv>
    <APEX>5.0.0.00.31:1</APEX>
    <parameters>
      <parameter>processes=300</parameter>
      <parameter>memory_target=838860800</parameter>
      <parameter>db_block_size=8192</parameter>
      <parameter>compatible='12.1.0.2.0'</parameter>
      <parameter>open_cursors=300</parameter>
      <parameter>enable_pluggable_database=TRUE</parameter>
    </parameters>
    <sqlpatches>
      <sqlpatch>PSU bundle patch 3 (Database Patch Set Update : 12.1.0.2.3 (20299023)): APPLY SUCCESS</sqlpatch>
      <sqlpatch>SQL patch ID/UID 20415564/18617752 (Database PSU 12.1.0.2.3, Oracle JavaVM Component (Apr2015)): APPLY SUCCESS</sqlpatch>
    </sqlpatches>
    <tzvers>
      <tzver>primary version:18</tzver>
      <tzver>secondary version:0</tzver>
    </tzvers>
    <walletkey>0</walletkey>
    <opatches>
      <opatch>19769480</opatch>
      <opatch>20299023</opatch>
      <opatch>20415564</opatch>
    </opatches>
    <hasclob>1</hasclob>
    <awr>
      <loadprofile>CPU Usage Per Sec=0.000000</loadprofile>
      <loadprofile>DB Block Changes Per Sec=0.000000</loadprofile>
      <loadprofile>Database Time Per Sec=0.000000</loadprofile>
      <loadprofile>Executions Per Sec=0.000000</loadprofile>
      <loadprofile>Hard Parse Count Per Sec=0.000000</loadprofile>
      <loadprofile>Logical Reads Per Sec=0.000000</loadprofile>
      <loadprofile>Logons Per Sec=0.000000</loadprofile>
      <loadprofile>Physical Reads Per Sec=0.000000</loadprofile>
      <loadprofile>Physical Writes Per Sec=0.000000</loadprofile>
      <loadprofile>Redo Generated Per Sec=0.000000</loadprofile>
      <loadprofile>Total Parse Count Per Sec=0.000000</loadprofile>
      <loadprofile>User Calls Per Sec=0.000000</loadprofile>
      <loadprofile>User Rollbacks Per Sec=0.000000</loadprofile>
      <loadprofile>User Transaction Per Sec=0.000000</loadprofile>
    </awr>
    <hardvsnchk>0</hardvsnchk>
  </optional>
</PDB>

3. Drop the PDB.
SQL> drop pluggable database finance_pdb keep datafiles;

Pluggable database dropped.

SQL> show pdbs;

    CON_ID CON_NAME  OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
...

Please note that if you use INCLUDE instead of KEEP, there's no way to plug the PDB. Now, let's plug the PDB back to the root container. You can plug the PDB to the original CDB or a new CDB in the same host.

4. Create the PDB.
By using the destination of  XML file with NOCOPY and REUSE after logging into the CDB.
SQL> create pluggable database finance_pdb using '/u01/app/oracle/oradata/orcl/Finance_Pdb/Finance_Pdb.xml' nocopy tempfile reuse;

Pluggable database created.

SQL> show pdbs;

    CON_ID CON_NAME  OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
...
4 FINANCE_PDB  MOUNTED

Since the PDB is in MOUNT state. So, we need to open the PDB.

5. Open the PDB.
SQL> alter pluggable database finance_pdb open;

Pluggable database altered.

SQL> show pdbs;

    CON_ID CON_NAME  OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
...
4 FINANCE_PDB  READ WRITE NO

We're done.

If you just want to remove the PDB from the CDB entirely. You can only do step 1 and 3.

Leave a Reply

Your email address will not be published. Required fields are marked *