Moneycontrol Brokerage Recos

Thursday, September 5, 2019

PDB Cloning in same CDB


In this article, I would explain how to clone an existing Pluggable Database into a new PDB or you can say - create a new PDB from an existing PDB in the same container database.


In this demo, we would be cloning PDB3 as a new Pluggable Database named PDB4.

1 - Let's see the existing list of PDBs currently we have using "show pdbs" command.


SQL> show pdbs

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


2 - Review the GUID for the individual PDBs

SQL> select con_id, guid, name, open_mode from v$pdbs;

    CON_ID GUID                             NAME                           OPEN_MODE
---------- -------------------------------- ------------------------------ ----------
         2 8FA8EFE7EE287653E0537C17800A501C PDB$SEED                       READ ONLY
         3 90C13D2FC47D70F9E0537C17800ACC04 PDB1                           READ WRITE
         4 91AC92BB3457B533E0537C17800AF412 PDB2                           READ WRITE
         5 91C3038EF67B5702E0537C17800A84C6 PDB3                           READ WRITE


3 - Here I am going to create a new tablespace into the PDB3 so that when we clone this as PDB4 so difference be visible.

SQL> alter session set container = pdb3;

Session altered.

SQL> show con_name

CON_NAME
------------------------------
PDB3
SQL>


SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
+DATAC1/CDB1/DATAFILE/undotbs1.11084.1015822335
+DATAC1/CDB1/91C3038EF67B5702E0537C17800A84C6/DATAFILE/system.9073.1018133353
+DATAC1/CDB1/91C3038EF67B5702E0537C17800A84C6/DATAFILE/sysaux.3022.1018133353
+DATAC1/CDB1/91C3038EF67B5702E0537C17800A84C6/DATAFILE/users.3693.1018133353

SQL>


SQL> create tablespace tbs1 datafile '+DATAC1' size 100m;

Tablespace created.



SQL> select name from v$datafile;


NAME
--------------------------------------------------------------------------------
+DATAC1/CDB1/DATAFILE/undotbs1.11084.1015822335
+DATAC1/CDB1/91C3038EF67B5702E0537C17800A84C6/DATAFILE/system.9073.1018133353
+DATAC1/CDB1/91C3038EF67B5702E0537C17800A84C6/DATAFILE/sysaux.3022.1018133353
+DATAC1/CDB1/91C3038EF67B5702E0537C17800A84C6/DATAFILE/users.3693.1018133353
+DATAC1/CDB1/91C3038EF67B5702E0537C17800A84C6/DATAFILE/tbs1.3023.1018133807

SQL>



4 - Here now we create PDB4 from the existing PDB3 using the below simple command. This is how simple it is to clone a PDB into Oracle Multi-tenant Architecture.

SQL> create pluggable database pdb4 from pdb3;

Pluggable database created.



5 - You can list all the PDBs in the CDB using the "show pdbs" command and you can see that new PDB4 is created now. By default, new PDB be in MOUNT state when gets created.

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 PDB1                           READ WRITE NO
         4 PDB2                           READ WRITE NO
         5 PDB3                           READ WRITE NO
         6 PDB4                           MOUNTED


6 - Open the Pluggable Database using below command.

SQL> alter pluggable database pdb4 open;

Pluggable database altered.


7 - Validate the PDB open status now.

SQL> show pdbs

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


8 - Validate new PDB details.

SQL> alter session set container = pdb4;

Session altered.

SQL> show con_name

CON_NAME
------------------------------
PDB4
SQL>


Each PDB has its own GUID named directory under the parent Container Database directory where individual PDBs store its local tablespace/datafiles in there.

SQL> select con_id, guid, name, open_mode from v$pdbs;

    CON_ID GUID                             NAME                           OPEN_MODE
---------- -------------------------------- ------------------------------ ----------
         2 8FA8EFE7EE287653E0537C17800A501C PDB$SEED                       READ ONLY
         3 90C13D2FC47D70F9E0537C17800ACC04 PDB1                           READ WRITE
         4 91AC92BB3457B533E0537C17800AF412 PDB2                           READ WRITE
         5 91C3038EF67B5702E0537C17800A84C6 PDB3                           READ WRITE
         6 91C324409E5776D8E0537C17800A746B PDB4                           READ WRITE


Cloned PDB4 has all tablespaces as it was in PDB3 under its own GUID directory path.

SQL> select name from v$datafile;

NAME
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+DATAC1/CDB1/DATAFILE/undotbs1.11084.1015822335
+DATAC1/CDB1/91C324409E5776D8E0537C17800A746B/DATAFILE/system.3134.1018133901
+DATAC1/CDB1/91C324409E5776D8E0537C17800A746B/DATAFILE/sysaux.663.1018133901
+DATAC1/CDB1/91C324409E5776D8E0537C17800A746B/DATAFILE/users.7266.1018133901
+DATAC1/CDB1/91C324409E5776D8E0537C17800A746B/DATAFILE/tbs1.7233.1018133901




Hope it helps, subscribe to this blog to stay updated on latest Oracle Technologies and new articles.

Twitter : @rajsoft8899
Linkedin : https://www.linkedin.com/in/raj-kumar-kushwaha-5a289219/


No comments:

Post a Comment