{"id":73100,"date":"2016-09-20T14:00:03","date_gmt":"2016-09-20T14:00:03","guid":{"rendered":"https:\/\/www.red-gate.com\/simple-talk\/uncategorized\/oracle-12-1-0-2c-hot-cloning-of-pluggable-databases\/"},"modified":"2021-07-14T13:07:02","modified_gmt":"2021-07-14T13:07:02","slug":"oracle-12-1-0-2c-hot-cloning-of-pluggable-databases","status":"publish","type":"post","link":"https:\/\/www.red-gate.com\/simple-talk\/databases\/oracle-databases\/oracle-12-1-0-2c-hot-cloning-of-pluggable-databases\/","title":{"rendered":"Oracle Database 12.1.0.2c: Hot Cloning Of Pluggable Databases"},"content":{"rendered":"<p>Cloning\u00a0of a Pluggable Database\u00a0(PDB) in Oracle Multitenant\u00a0is a great feature and is very useful. Oracle Database 12c Release 1 has introduced various enhancements to the cloning of Pluggable Databases to overcome the limitations imposed by the initial release of Oracle Database 12c (12.1.0.1). In Oracle 12.1.0.2c:<\/p>\n<ul>\n<li>PDBs can be hot cloned, i.e. you don&#8217;t need to put the source PDB in read-only for cloning so that it can be cloned to a CDB online. In Oracle 12.1.0.1c, a pluggable database can be cloned only if it is read-only.<\/li>\n<li>PDBs can be remote cloned, i.e. the source PDB may be located in a remote container. This feature was listed in Oracle Database 12c Release 1 (12.1.0.1), but didn&#8217;t work.<\/li>\n<li>There is no need to create the directories where the database files of clone PDB will be placed. If the directory is not already present, it will be automatically created as part of the cloning operation.<\/li>\n<\/ul>\n<p>In this article, I will demonstrate hot cloning of a PDB locally as well as remotely. For the purpose of this demonstration, I have two virtual machines, each with a container database.<\/p>\n<h2>Current scenario:<\/h2>\n<p>Host: <strong>host01<\/strong><br \/> Container Database 12.1.0.2c: <strong>cdb1<\/strong> with pluggable database <strong>pdb1<\/strong><\/p>\n<p>Host: <strong>host02<\/strong><br \/> Container Database 12.1.0.2c: <strong>destcdb<\/strong> with pluggable database <strong>pdb1<\/strong><\/p>\n<h3>Demonstration 1: Hot cloning of PDB locally<\/h3>\n<p>We will clone the pluggable database <strong>pdb1<\/strong> to <strong>pdb1clone<\/strong> in the same CDB, i.e. <strong>cdb1<\/strong> on host <strong>host01<\/strong><\/p>\n<p>Source host: <strong>host01<\/strong><br \/> Source PDB: <strong>pdb1 <\/strong>in container database <strong>cdb1<\/strong><\/p>\n<p>Destination host: <strong>host01<\/strong><br \/> Destination PDB: <strong>pdb1clone <\/strong>in container database <strong>cdb1<\/strong><\/p>\n<p>Currently, there is only one PDB called <strong>pdb1<\/strong> currently open in <code>READ WRITE<\/code> mode in the container database <strong>cdb1.<\/strong><\/p>\n<p><strong>CDB1&gt;select name, cdb from v$database;<\/strong><\/p>\n<pre>CDB1&gt;select name, cdb from v$database;\r\nNAME      CDB\r\n--------- ---\r\n<span style=\"color: red; font-weight: bold;\">CDB1      YES<\/span>\r\n\r\nCDB1&gt;select con_id, name, open_mode from v$pdbs;\r\n    CON_ID NAME                           OPEN_MODE\r\n---------- ------------------------------ ----------\r\n         2 PDB$SEED                       READ ONLY\r\n         3 <span style=\"color: red; font-weight: bold;\">PDB1                           READ WRITE<\/span>\r\n\r\nCDB1&gt;select name from v$datafile where con_id = 3;\r\nNAME\r\n--------------------------------------------------------------------------------\r\n\/u01\/app\/oracle\/oradata\/cdb1\/pdb1\/system01.dbf\r\n\/u01\/app\/oracle\/oradata\/cdb1\/pdb1\/sysaux01.dbf\r\n\/u01\/app\/oracle\/oradata\/cdb1\/pdb1\/SAMPLE_SCHEMA_users01.dbf\r\n\/u01\/app\/oracle\/oradata\/cdb1\/pdb1\/example01.dbf<\/pre>\n<p>Verify that directory corresponding to data files of target PDB, i.e. <strong>pdb1clone<\/strong> is not present:<\/p>\n<pre>[oracle@host01 cdb1]$ ls -l \/u01\/app\/oracle\/oradata\/cdb1\/ \r\ntotal 1782620\r\n-rw-r----- 1 oracle asmadmin  17973248 Jul 26 15:03 control01.ctl\r\ndrwxr-x--- 2 oracle oinstall      4096 Jun 29 12:06 pdb1\r\ndrwxr-x--- 2 oracle oinstall      4096 Jun 29 11:59 pdbseed\r\n-rw-r----- 1 oracle asmadmin  52429312 Jul 25 15:18 redo01.log\r\n-rw-r----- 1 oracle asmadmin  52429312 Jul 25 15:18 redo02.log\r\n-rw-r----- 1 oracle asmadmin  52429312 Jul 26 15:03 redo03.log\r\n-rw-r----- 1 oracle asmadmin 650125312 Jul 26 15:02 sysaux01.dbf\r\n-rw-r----- 1 oracle asmadmin 817897472 Jul 26 15:02 system01.dbf\r\n-rw-r----- 1 oracle asmadmin  62922752 Jul 26 15:02 temp01.dbf\r\n-rw-r----- 1 oracle asmadmin 173023232 Jul 26 15:01 undotbs01.dbf\r\n-rw-r----- 1 oracle asmadmin   5251072 Jul 25 15:18 users01.dbf\r\n\r\n[oracle@host01 cdb1]$ ls -l \/u01\/app\/oracle\/oradata\/cdb1\/ | grep pdb1\r\ndrwxr-x--- 2 oracle oinstall      4096 Jun 29 12:06 pdb1<\/pre>\n<p>Using the <code>CREATE PLUGGABLE DATABASE ... FROM<\/code> command we will clone the existing PDB (<strong>pdb1<\/strong>) to create a new PDB (<strong>pdb1clone<\/strong>) in the same container database (<strong>cdb1<\/strong>). This statement copies the files associated with the source PDB to a new location and associates the files with the target PDB.<\/p>\n<pre>CDB1&gt;create pluggable database pdb1clone from pdb1 \r\n     file_name_convert = ('pdb1','pdb1clone');\r\nPluggable database created.<\/pre>\n<p>We can see that the new PDB called <strong>pdb1clone<\/strong> is in <code>MOUNTED<\/code> state when created and is opened successfully thereafter.<\/p>\n<p><strong>CDB1&gt;sho pdbs<\/strong><\/p>\n<pre>CDB1&gt;sho pdbs\r\n    CON_ID CON_NAME                       OPEN MODE  RESTRICTED\r\n---------- ------------------------------ ---------- ----------\r\n         2 PDB$SEED                       READ ONLY  NO\r\n         3 PDB1                           READ WRITE NO\r\n         4 <span style=\"color: red; font-weight: bold;\">PDB1CLONE                      MOUNTED<\/span>\r\n\r\nCDB1&gt;alter pluggable database pdb1clone open;\r\nPluggable database altered.\r\n\r\nCDB1&gt;sho pdbs\r\n    CON_ID CON_NAME                       OPEN MODE  RESTRICTED\r\n---------- ------------------------------ ---------- ----------\r\n         2 PDB$SEED                       READ ONLY  NO\r\n         3 PDB1                           READ WRITE NO\r\n         4 <span style=\"color: red; font-weight: bold;\">PDB1CLONE                      READ WRITE<\/span> NO\r\nCDB1&gt;alter session set container=pdb1clone;\r\nSession altered.\r\n\r\nCDB1&gt;sho con_name\r\nCON_NAME\r\n------------------------------\r\nPDB1CLONE\r\n\r\nCDB1&gt;select count(*) from hr.employees;\r\n  COUNT(*)\r\n----------\r\n       107\r\n<\/pre>\n<p>Note that the directory for the data files of the clone PDB <strong>pdb1clone <\/strong>has been created automatically in the location specified using <code>FILE_NAME_CONVERT<\/code><strong>.<\/strong><\/p>\n<p><strong>[oracle@host01 cdb1]$ ls -l \/u01\/app\/oracle\/oradata\/cdb1\/pdb1clone<\/strong><\/p>\n<pre>[oracle@host01 cdb1]$ ls -l \/u01\/app\/oracle\/oradata\/cdb1\/<span style=\"color: red; font-weight: bold;\">pdb1clone<\/span>\r\ntotal 2089832\r\n-rw-r----- 1 oracle asmadmin 1304174592 Jul 25 15:53 example01.dbf\r\n-rw-r----- 1 oracle asmadmin   20979712 Jul 25 15:52 pdb1clone_temp012016-06-29_12-06-27-PM.dbf\r\n-rw-r----- 1 oracle asmadmin    5251072 Jul 25 15:53 SAMPLE_SCHEMA_users01.dbf\r\n-rw-r----- 1 oracle asmadmin  555753472 Jul 25 15:53 sysaux01.dbf\r\n-rw-r----- 1 oracle asmadmin  272637952 Jul 25 15:53 system01.dbf<\/pre>\n<p>Hence, we have been able to hot clone a PDB locally without:<\/p>\n<ul>\n<li>Placing the source PDB in <code>READ ONLY<\/code> mode<\/li>\n<li>Creating the directory for the destination PDB<\/li>\n<\/ul>\n<h3>Demonstration 2: Hot cloning of PDB remotely<\/h3>\n<p>We will clone the pluggable database <strong>pdb1<\/strong> in CDB <strong>cdb1<\/strong> on host <strong>host01<\/strong> to <strong>pdb1new<\/strong> in another CDB, i.e. <strong>destcdb<\/strong> on host <strong>host02:<\/strong><\/p>\n<p>Source host: <strong>host01<\/strong><br \/> Source PDB: <strong>pdb1 <\/strong>in container database <strong>cdb1<\/strong><\/p>\n<p>Destination host: <strong>host02<\/strong><br \/> Destination PDB: <strong>pdb1new <\/strong>in container database <strong>destcdb<\/strong><\/p>\n<p>Currently, there is only one PDB called <strong>pdb1<\/strong> open in <code>READ WRITE<\/code> mode in destination container database <strong>destcdb:<\/strong><\/p>\n<pre>DESTCDB&gt;sho pdbs\r\n\r\n    CON_ID CON_NAME                       OPEN MODE  RESTRICTED\r\n---------- ------------------------------ ---------- ----------\r\n         2 PDB$SEED                       READ ONLY  NO\r\n         3 <span style=\"color: red; font-weight: bold;\">PDB1                           READ WRITE<\/span> NO<\/pre>\n<p>On the target container database <strong>destcdb<\/strong>, we need to create the database link to connect to source container database <strong>cdb1<\/strong> which will be used in the <code>CREATE PLUGGABLE DATABASE<\/code>.<\/p>\n<pre>DESTCDB&gt;create database link cdb1_link \r\n        connect to system identified by oracle using 'host01:1521\/cdb1';\r\nDatabase link created.<\/pre>\n<p>Verify that the source pluggable database (<strong>pdb1@cdb1<\/strong>) that we want to clone is in <code>READ WRITE<\/code> mode.<\/p>\n<pre>CDB1&gt; select con_id, name, open_mode from v$pdbs where name = 'PDB1';\r\n\r\n    CON_ID NAME                           OPEN_MODE\r\n---------- ------------------------------ ----------\r\n         3 <span style=\"color: red; font-weight: bold;\">PDB1                           READ WRITE<\/span><\/pre>\n<p>Let&#8217;s execute the <code>CREATE PLUGGABLE DATABASE<\/code> statement using the database link (<strong>cdb1_link)<\/strong> as previously defined.<\/p>\n<pre>DESTCDB&gt; create pluggable database pdb1new from pdb1@cdb1_link;\r\n create pluggable database pdb1new from pdb1@cdb1_link\r\n                                                     *\r\nERROR at line 1:\r\n<span style=\"color: red; font-weight: bold;\">ORA-65016: FILE_NAME_CONVERT must be specified<\/span><\/pre>\n<p>Let&#8217;s find out location of datafiles for <strong>pdb1@cdb1<\/strong> on <strong>host01:<\/strong><\/p>\n<pre>CDB1&gt;alter session set container = pdb1;\r\nSession altered.\r\nCDB1&gt;select name from v$datafile;\r\nNAME\r\n--------------------------------------------------------------------------------\r\n\/u01\/app\/oracle\/oradata\/cdb1\/undotbs01.dbf\r\n\/u01\/app\/oracle\/oradata\/cdb1\/pdb1\/system01.dbf\r\n\/u01\/app\/oracle\/oradata\/cdb1\/pdb1\/sysaux01.dbf\r\n\/u01\/app\/oracle\/oradata\/cdb1\/pdb1\/SAMPLE_SCHEMA_users01.dbf\r\n\/u01\/app\/oracle\/oradata\/cdb1\/pdb1\/example01.dbf<\/pre>\n<p>Verify that directory corresponding to data files of target PDB, i.e. <strong>pdb1new<\/strong>, is not present on the target host <strong>host02:<\/strong><\/p>\n<pre>[oracle@host02 destcdb]$ ls -l \/u01\/app\/oracle\/oradata\/destcdb\r\ntotal 1761816\r\n-rw-r----- 1 oracle asmadmin  17973248 Jul 25 15:35 control01.ctl\r\ndrwxr-x--- 2 oracle oinstall      4096 Jul 24 16:04 PDB1\r\ndrwxr-x--- 2 oracle oinstall      4096 Jul 24 15:57 pdbseed\r\n-rw-r----- 1 oracle asmadmin  52429312 Jul 24 16:09 redo01.log\r\n-rw-r----- 1 oracle asmadmin  52429312 Jul 25 15:35 redo02.log\r\n-rw-r----- 1 oracle asmadmin  52429312 Jul 24 16:08 redo03.log\r\n-rw-r----- 1 oracle asmadmin 629153792 Jul 25 15:34 sysaux01.dbf\r\n-rw-r----- 1 oracle asmadmin 817897472 Jul 25 15:35 system01.dbf\r\n-rw-r----- 1 oracle asmadmin  62922752 Jul 25 15:26 temp01.dbf\r\n-rw-r----- 1 oracle asmadmin 173023232 Jul 25 15:35 undotbs01.dbf\r\n-rw-r----- 1 oracle asmadmin   5251072 Jul 25 15:19 users01.dbf<\/pre>\n<p>Let&#8217;s specify <code>FILE_NAME_CONVERT<\/code> and re-execute the <code>CREATE PLUGGABLE DATABASE<\/code> statement using the database link (<code><strong>cdb1_link)<\/strong><\/code> we previously defined:<\/p>\n<pre>DESTCDB&gt;create pluggable database pdb1new from pdb1@cdb1_link \r\n        file_name_convert = ('\/u01\/app\/oracle\/oradata\/cdb1\/pdb1','\/u01\/app\/oracle\/oradata\/destcdb\/pdb1new');\r\nPluggable database created.\r\n<\/pre>\n<p>By default the new pluggable database is created in MOUNTED state and can be opened.<\/p>\n<pre>DESTCDB&gt;sho pdbs\r\n    CON_ID CON_NAME                       OPEN MODE  RESTRICTED\r\n---------- ------------------------------ ---------- ----------\r\n         2 PDB$SEED                       READ ONLY  NO\r\n         3 PDB1                           READ WRITE NO\r\n         4 PDB1NEW                        MOUNTED\r\n\r\nDESTCDB&gt;alter pluggable database pdb1new open;\r\nPluggable database altered.\r\n\r\nDESTCDB&gt;sho pdbs\r\n    CON_ID CON_NAME                       OPEN MODE  RESTRICTED\r\n---------- ------------------------------ ---------- ----------\r\n         2 PDB$SEED                       READ ONLY  NO\r\n         3 PDB1                           READ WRITE NO\r\n         4 PDB1NEW                        READ WRITE NO\r\nDESTCDB&gt;alter session set container=pdb1new;\r\nSession altered.\r\nDESTCDB&gt;select count(*) from hr.employees;\r\n  COUNT(*)\r\n----------\r\n       107<\/pre>\n<p>Verify that the directory for data files of <strong>pbdnew<\/strong> has been created automatically on <strong>host02<\/strong> in the location specified using <code>FILE_NAME_CONVERT<\/code>:<\/p>\n<pre>[oracle@host02 pdb1new]$ ls -l \/u01\/app\/oracle\/oradata\/destcdb\/pdb1new\r\ntotal 2089832\r\n-rw-r----- 1 oracle asmadmin 1304174592 Jul 25 15:41 example01.dbf\r\n-rw-r----- 1 oracle asmadmin   20979712 Jul 25 15:39 pdb1_temp012016-06-29_12-06-27-PM.dbf\r\n-rw-r----- 1 oracle asmadmin    5251072 Jul 25 15:41 SAMPLE_SCHEMA_users01.dbf\r\n-rw-r----- 1 oracle asmadmin  555753472 Jul 25 15:41 sysaux01.dbf\r\n-rw-r----- 1 oracle asmadmin  272637952 Jul 25 15:41 system01.dbf<\/pre>\n<p>Hence, we have been able to hot clone a PDB remotely without:<\/p>\n<ul>\n<li>Placing the source PDB in <code>READ ONLY<\/code> mode<\/li>\n<li>Creating the directory for the destination PDB<\/li>\n<\/ul>\n<h2>Summary:<\/h2>\n<p>In Oracle 12.1.0.2c, various enhancements been made to cloning of PDB:<\/p>\n<ul>\n<li>PDBs can be hot cloned, i.e. you don&#8217;t need to put the source PDB in read-only for cloning so that it can be cloned to a CDB online.<\/li>\n<li>PDBs can be hot cloned remotely as well, i.e. the source PDB can be located in a remote container.<\/li>\n<li>There is no need to create the directories where the database files of clone PDB will be placed. If the directory is not already present, it will be automatically created as part of the cloning operation.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Cloning\u00a0of a Pluggable Database\u00a0(PDB) in Oracle Multitenant\u00a0is a great feature and is very useful. Oracle Database 12c Release 1 has introduced various enhancements to the cloning of Pluggable Databases to overcome the limitations imposed by the initial release of Oracle Database 12c (12.1.0.1). In Oracle 12.1.0.2c: PDBs can be hot cloned, i.e. you don&#8217;t need to put the source PDB&hellip;<\/p>\n","protected":false},"author":316217,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[143533],"tags":[48347,48377,48476],"coauthors":[],"class_list":["post-73100","post","type-post","status-publish","format-standard","hentry","category-oracle-databases","tag-12c","tag-cloning","tag-pluggable-databases"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/73100","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/users\/316217"}],"replies":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/comments?post=73100"}],"version-history":[{"count":1,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/73100\/revisions"}],"predecessor-version":[{"id":91599,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/73100\/revisions\/91599"}],"wp:attachment":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media?parent=73100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/categories?post=73100"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/tags?post=73100"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/coauthors?post=73100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}