Saturday 8 August 2020

Multitenant - Unplugged and Plugged database with same GUID copy method

Multitenant - Unplugged and Plugged database with same GUID copy method on same host database

UPLUGGABLE  : PDB3

PLUGGABLE  :PLM2

NOTE: If we do not specify NOCOPY then with same GUID we are unable to create PLUGGABLE DATABASE on same host CDB database. In remote CDB GUID is different we can use NOCOPY method.

Keywards:
  • ALTER PLUGGABLE DATABASE PDB3 UNPLUG INTO '/HOME/ORACLE/PDB3.XML';
  • Check compatibilty of unpluggable and pluggable on both host or remote database

 DECLARE
  2  compatible BOOLEAN := FALSE;
BEGIN
compatible := DBMS_PDB.CHECK_PLUG_COMPATIBILITY(PDB_DESCR_FILE => '/home/oracle/pdb3.xml');
if compatible then
DBMS_OUTPUT.PUT_LINE('It is compatible');
else
DBMS_OUTPUT.PUT_LINE('It is NOT compatible');
end if;
END;
/
  • CREATE PLUGGABLE DATABASE PLM2 USING '/HOME/ORACLE/PDB3.XML'  NOCOPY TEMPFILE REUSE;

Example:

SQL> sho pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 PLM1                           READ WRITE NO
         4 PDB2                           READ WRITE NO
         5 PDB3                           READ WRITE NO

SQL> set linesize 100
SQL> col name format a100
SQL> SELECT NAME  FROM V$DATAFILE WHERE CON_ID = (SELECT CON_ID FROM V$PDBS WHERE NAME='PDB3');

NAME
----------------------------------------------------------------------------------------------------
/u01/app/oracle/oradata/SMRCDB/SMRCDB/AC37117322776C58E0534938A8C02132/datafile/o1_mf_system_hlr3x0x
l_.dbf

/u01/app/oracle/oradata/SMRCDB/SMRCDB/AC37117322776C58E0534938A8C02132/datafile/o1_mf_sysaux_hlr3x0x
q_.dbf

/u01/app/oracle/oradata/SMRCDB/SMRCDB/AC37117322776C58E0534938A8C02132/datafile/o1_mf_undotbs1_hlr3x
0xq_.dbf


SQL> select GUID from v$pdbs where name='PDB3';

GUID
--------------------------------
AC37117322776C58E0534938A8C02132

SQL> ALTER PLUGGABLE DATABASE pdb3 close;

Pluggable database altered.

SQL> alter pluggable database pdb3 unplug into '/home/oracle/pdb3.xml';

Pluggable database altered.


SQL> host cat /home/oracle/pdb3.xml
<?xml version="1.0" encoding="UTF-8"?>
<PDB>
  <xmlversion>1</xmlversion>
  <pdbname>PDB3</pdbname>
  <cid>5</cid>
  <byteorder>1</byteorder>
  <vsn>203424000</vsn>
  <vsns>
    <vsnnum>12.2.0.1.0</vsnnum>
    <cdbcompt>12.2.0.0.0</cdbcompt>
    <pdbcompt>12.2.0.0.0</pdbcompt>
    <vsnlibnum>0.0.0.0.24</vsnlibnum>
    <vsnsql>24</vsnsql>
    <vsnbsv>8.0.0.0.0</vsnbsv>
  </vsns>
  <dbid>3048296195</dbid>
  <ncdb2pdb>0</ncdb2pdb>
  <cdbid>3280283628</cdbid>
  <guid>AC37117322776C58E0534938A8C02132</guid>
  <uscnbas>1769801</uscnbas>
  <uscnwrp>0</uscnwrp>
  <undoscn>225</undoscn>
  <rdba>4194824</rdba>
  <tablespace>
    <name>SYSTEM</name>
    <type>0</type>
    <tsn>0</tsn>
    <status>1</status>
    <issft>0</issft>
    <isnft>0</isnft>
    <encts>0</encts>
    <flags>0</flags>
    <bmunitsize>8</bmunitsize>
    <file>
      <path>/u01/app/oracle/oradata/SMRCDB/SMRCDB/AC37117322776C58E0534938A8C02132/datafile/o1_mf_system_hlr3x0xl_.dbf</path>
      <afn>18</afn>
      <rfn>1</rfn>
      <createscnbas>1645738</createscnbas>
      <createscnwrp>0</createscnwrp>
      <status>1</status>
      <fileblocks>33280</fileblocks>
      <blocksize>8192</blocksize>
      <vsn>203423744</vsn>
      <fdbid>3048296195</fdbid>
      <fcpsb>1769795</fcpsb>
      <fcpsw>0</fcpsw>
      <frlsb>1408558</frlsb>
      <frlsw>0</frlsw>
      <frlt>1047595884</frlt>
      <autoext>1</autoext>
      <maxsize>4194302</maxsize>
      <incsize>1280</incsize>
      <plugscn>0</plugscn>
      <plugafn>0</plugafn>
      <plugdbid>0</plugdbid>
    </file>
  </tablespace>
  <tablespace>
    <name>SYSAUX</name>
    <type>0</type>
    <tsn>1</tsn>
    <status>1</status>
    <issft>0</issft>
    <isnft>0</isnft>
    <encts>0</encts>
    <flags>0</flags>
    <bmunitsize>8</bmunitsize>
    <file>
      <path>/u01/app/oracle/oradata/SMRCDB/SMRCDB/AC37117322776C58E0534938A8C02132/datafile/o1_mf_sysaux_hlr3x0xq_.dbf</path>
      <afn>19</afn>
      <rfn>4</rfn>
      <createscnbas>1645741</createscnbas>
      <createscnwrp>0</createscnwrp>
      <status>1</status>
      <fileblocks>46080</fileblocks>
      <blocksize>8192</blocksize>
      <vsn>203423744</vsn>
      <fdbid>3048296195</fdbid>
      <fcpsb>1769795</fcpsb>
      <fcpsw>0</fcpsw>
      <frlsb>1408558</frlsb>
      <frlsw>0</frlsw>
      <frlt>1047595884</frlt>
      <autoext>1</autoext>
      <maxsize>4194302</maxsize>
      <incsize>1280</incsize>
      <plugscn>0</plugscn>
      <plugafn>0</plugafn>
      <plugdbid>0</plugdbid>
    </file>
  </tablespace>
  <tablespace>
    <name>UNDOTBS1</name>
    <type>2</type>
    <tsn>2</tsn>
    <status>1</status>
    <issft>0</issft>
    <isnft>0</isnft>
    <encts>0</encts>
    <flags>0</flags>
    <bmunitsize>8</bmunitsize>
    <file>
      <path>/u01/app/oracle/oradata/SMRCDB/SMRCDB/AC37117322776C58E0534938A8C02132/datafile/o1_mf_undotbs1_hlr3x0xq_.dbf</path>
      <afn>20</afn>
      <rfn>9</rfn>
      <createscnbas>1645743</createscnbas>
      <createscnwrp>0</createscnwrp>
      <status>1</status>
      <fileblocks>12800</fileblocks>
      <blocksize>8192</blocksize>
      <vsn>203423744</vsn>
      <fdbid>3048296195</fdbid>
      <fcpsb>1769795</fcpsb>
      <fcpsw>0</fcpsw>
      <frlsb>1408558</frlsb>
      <frlsw>0</frlsw>
      <frlt>1047595884</frlt>
      <autoext>1</autoext>
      <maxsize>4194302</maxsize>
      <incsize>640</incsize>
      <plugscn>0</plugscn>
      <plugafn>0</plugafn>
      <plugdbid>0</plugdbid>
    </file>
  </tablespace>
  <tablespace>
    <name>TEMP</name>
    <type>1</type>
    <tsn>3</tsn>
    <status>1</status>
    <issft>0</issft>
    <isnft>0</isnft>
    <encts>0</encts>
    <flags>0</flags>
    <bmunitsize>128</bmunitsize>
    <file>
      <path>/u01/app/oracle/oradata/SMRCDB/SMRCDB/AC37117322776C58E0534938A8C02132/datafile/o1_mf_temp_hlr3x0xr_.dbf</path>
      <afn>5</afn>
      <rfn>1</rfn>
      <createscnbas>1645739</createscnbas>
      <createscnwrp>0</createscnwrp>
      <status>1</status>
      <fileblocks>16512</fileblocks>
      <blocksize>8192</blocksize>
      <vsn>203423744</vsn>
      <autoext>1</autoext>
      <maxsize>4194302</maxsize>
      <incsize>80</incsize>
      <plugscn>0</plugscn>
      <plugafn>0</plugafn>
      <plugdbid>0</plugdbid>
    </file>
  </tablespace>
  <recover>0</recover>
  <optional>
    <ncdb2pdb>0</ncdb2pdb>
    <csid>873</csid>
    <ncsid>2000</ncsid>
    <options>
      <option>APS=12.2.0.1.0</option>
      <option>CATALOG=12.2.0.1.0</option>
      <option>CATJAVA=12.2.0.1.0</option>
      <option>CATPROC=12.2.0.1.0</option>
      <option>CONTEXT=12.2.0.1.0</option>
      <option>DV=12.2.0.1.0</option>
      <option>JAVAVM=12.2.0.1.0</option>
      <option>OLS=12.2.0.1.0</option>
      <option>ORDIM=12.2.0.1.0</option>
      <option>OWM=12.2.0.1.0</option>
      <option>SDO=12.2.0.1.0</option>
      <option>XDB=12.2.0.1.0</option>
      <option>XML=12.2.0.1.0</option>
      <option>XOQ=12.2.0.1.0</option>
    </options>
    <olsoid>0</olsoid>
    <dv>0</dv>
    <APEX>NULL</APEX>
    <parameters>
      <parameter>processes=800</parameter>
      <parameter>nls_language='AMERICAN'</parameter>
      <parameter>nls_territory='AMERICA'</parameter>
      <parameter>db_block_size=8192</parameter>
      <parameter>compatible='12.2.0'</parameter>
      <parameter>open_cursors=300</parameter>
      <parameter>pga_aggregate_target=597688320</parameter>
      <parameter>enable_pluggable_database=TRUE</parameter>
      <spfile>*.ddl_lock_timeout=12#HWM:12,</spfile>
    </parameters>
    <sqlpatches/>
    <tzvers>
      <tzver>primary version:26</tzver>
      <tzver>secondary version:0</tzver>
    </tzvers>
    <walletkey>0</walletkey>
    <services/>
    <opatches/>
    <hasclob>1</hasclob>
    <awr>
      <loadprofile>CPU used by this session=18.049089</loadprofile>
      <loadprofile>DB time=31.254604</loadprofile>
      <loadprofile>db block changes=512.911666</loadprofile>
      <loadprofile>execute count=621.649994</loadprofile>
      <loadprofile>logons cumulative=0.040400</loadprofile>
      <loadprofile>parse count (hard)=32.055749</loadprofile>
      <loadprofile>parse count (total)=303.904155</loadprofile>
      <loadprofile>physical reads=141.264852</loadprofile>
      <loadprofile>physical writes=38.204222</loadprofile>
      <loadprofile>redo size=89106.808472</loadprofile>
      <loadprofile>session logical reads=4789.740583</loadprofile>
      <loadprofile>user calls=2.785056</loadprofile>
      <loadprofile>user commits=1.110153</loadprofile>
      <loadprofile>user rollbacks=0.037911</loadprofile>
    </awr>
    <hardvsnchk>0</hardvsnchk>
    <localundo>1</localundo>
    <apps/>
    <dbedition>8</dbedition>
    <ver122010>1</ver122010>
  </optional>
</PDB>


SQL> SELECT PDB_NAME, STATUS FROM CDB_PDBS WHERE PDB_NAME IN ('PDB3');

PDB_NAME
----------------------------------------------------------------------------------------------------
STATUS
----------
PDB3
UNPLUGGED


SQL> DROP PLUGGABLE DATABASE PDB3 keep datafiles;

Pluggable database dropped.

SQL> SELECT PDB_NAME, STATUS FROM CDB_PDBS WHERE PDB_NAME IN ('PDB3');

no rows selected

SQL> set serveroutput on
SQL> DECLARE
  2  compatible BOOLEAN := FALSE;
BEGIN
compatible := DBMS_PDB.CHECK_PLUG_COMPATIBILITY(PDB_DESCR_FILE => '/home/oracle/pdb3.xml');
if compatible then
DBMS_OUTPUT.PUT_LINE('It is compatible');
else
DBMS_OUTPUT.PUT_LINE('It is NOT compatible');
end if;
END;
/   3    4    5    6    7    8    9   10   11
It is compatible

PL/SQL procedure successfully completed.



SQL> CREATE PLUGGABLE DATABASE PLM2 USING '/home/oracle/pdb3.xml'  NOCOPY TEMPFILE REUSE;

Pluggable database created.


NOTE: If we do not specify NOCOPY then with same GUID we are unable to create PLUGGABLE DATABASE on same host CDB database. In remote CDB GUID is different we can use NOCOPY method.

SQL> col pdb_name format a5
SQL> SELECT PDB_NAME, STATUS FROM CDB_PDBS WHERE PDB_NAME='PLM2';

PDB_N STATUS
----- ----------
PLM2  NEW

SQL> SELECT OPEN_MODE FROM V$PDBS WHERE NAME='PLM2';

OPEN_MODE
----------
MOUNTED

SQL> ALTER PLUGGABLE DATABASE  PLM2 open;

Pluggable database altered.


SQL> SELECT GUID FROM V$PDBS WHERE NAME='PLM2';

GUID
--------------------------------
AC37117322776C58E0534938A8C02132


SQL> select GUID from v$pdbs where name='PDB3';

GUID
--------------------------------
AC37117322776C58E0534938A8C02132

No comments:

Post a Comment