Skip to main content
Oracle12c

Oracle 12c – Clone Pluggable Database

By September 28, 2015September 12th, 2016No Comments

How to Clone a Pluggable Database?

In my last post, I had explained the steps to Unplug and Plug in the Pluggable Database in a CDB. Now in this post, we will see about the Cloning mechanism for the Pluggable Databases in a Multitenant Architecture.

Currently, we have the below databases.,

Container Database – GGCDB1

Pluggable Database – PDB1 and PDB2

In this article we will see How to clone the Pluggable Database PDB1.

Below is the list of databases in the environment. There are two Pluggable Databases and both are in READ WRITE mode.

 

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

To Clone the Pluggable Database, either the Pluggable Database should be in opened in Restricted Mode or Read Only Mode. Please follow the below steps to do it.,

 

  • Close the Pluggable Database PDB1. Issue the below command to close the PDB1.,
SQL> alter pluggable database pdb1 close;

Pluggable database altered.

 

SQL> show pdbs

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

 

  • Open the Pluggable Database PDB1 with Read Only mode.
SQL> alter pluggable database pdb1 open read only;

Pluggable database altered.
SQL> show pdbs

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

 

  • Now, we need to create a new directory for the new Clone Pluggable Database PDB1_clone to store its datafiles.
    Just see which mount point has free space or according to your wish you can create a directory for the new PDB_clone using the OS command,
[oracle@Oracle12c GGCDB1]$ pwd
/vol1/oradata/GGCDB1

[oracle@Oracle12c GGCDB1]$ mkdir PDB1_clone

[oracle@Oracle12c GGCDB1]$ ls -ldrt PDB1_clone

 

  • Configure the OMF to the newly created directory for the new clone Pluggable Database PDB1_clone.
alter system set db_create_file_dest='/vol1/oradata/GGCDB1/PDB1_clone';
SQL> alter system set db_create_file_dest='/vol1/oradata/GGCDB1/PDB1_clone';
System altered.

SQL> show parameter db_create_file_dest

NAME                   TYPE         VALUE
---------------------  -----------  ----------------------------------------------
db_create_file_dest    string       /vol1/oradata/GGCDB1/PDB1_clone

 

So, we have completed the Preliminary steps to Clone a Pluggable Database.

  • Now issue the below command to clone the Pluggable Database PDB1 to PDB1_clone.
 create pluggable database pdb1_clone from pdb1;
SQL> create pluggable database pdb1_clone from pdb1;

Pluggable database created.

 

You could see the below in the alertlog file.,

create pluggable database pdb1_clone from pdb1
 Mon Sep 28 12:12:11 2015
 ****************************************************************
 Pluggable Database PDB1_CLONE with pdb id - 5 is created as UNUSABLE.
 If any errors are encountered before the pdb is marked as NEW,
 then the pdb must be dropped
 ****************************************************************
 Deleting old file#18 from file$
 Deleting old file#19 from file$
 Deleting old file#20 from file$
 Adding new file#27 to file$(old file#18)
 Adding new file#28 to file$(old file#19)
 Adding new file#29 to file$(old file#20)
 Successfully created internal service pdb1_clone at open
 ALTER SYSTEM: Flushing buffer cache inst=0 container=5 local
 ****************************************************************
 Post plug operations are now complete.
 Pluggable database PDB1_CLONE with pdb id - 5 is now marked as NEW.
 ****************************************************************
 Completed: create pluggable database pdb1_clone from pdb1

 

  •  The Pluggable Database PDB1 has been cloned to PDB1_clone. Check the status of the Pluggable databases.,
SQL> show pdbs

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

 

  • Bring back the Pluggable Database PDB1 to READ WRITE mode.
SQL> alter pluggable database pdb1 close immediate;

Pluggable database altered.

 

SQL> show pdbs

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

 

SQL> alter pluggable database pdb1 open;

Pluggable database altered.

 

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       PDB1_CLONE MOUNTED

 

  • Bring the Cloned Pluggable Database PDB1_clone to OPEN READ WRITE mode.,
SQL> alter pluggable database pdb1_clone open;

Pluggable database altered.

 

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       PDB1_CLONE READ WRITE     NO

 

So, The Pluggable Database PDB1 has been cloned to PDB1_clone successfully and now all the pluggable databases are available in READ WRITE mode.

Leave a Reply