{"id":146,"date":"2015-11-17T18:00:52","date_gmt":"2015-11-17T17:00:52","guid":{"rendered":"http:\/\/anjo.pt\/wp\/keyword-oracle\/?p=146"},"modified":"2015-11-17T20:27:22","modified_gmt":"2015-11-17T19:27:22","slug":"thin-pdb-clones-on-ext4-filesystem-with-oracle-12-1-0-2","status":"publish","type":"post","link":"https:\/\/anjo.pt\/keyword-oracle\/2015\/11\/17\/thin-pdb-clones-on-ext4-filesystem-with-oracle-12-1-0-2\/","title":{"rendered":"Thin PDB clones on ext4 filesystem with Oracle 12.1.0.2"},"content":{"rendered":"<p>Oracle 12.1.0.2 brings a great new functionality: you can create thin clones &#8211; that is, not copying the source files, just pointers &#8211; on ext4 filesystem, the current default on Red Hat Linux 6.<\/p>\n<p>Requirements for example below:<br \/>\n&#8211; Oracle 12.1.0.2<br \/>\n&#8211; Data files are on ext4 filesystem (or other supporting sparse files)<br \/>\n&#8211; Source PDB on read only mode<\/p>\n<p>It is very simple to set up:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nSQL&gt; alter system set clonedb=TRUE scope=spfile;\r\nSQL&gt; shutdown immediate\r\nSQL&gt; startup\r\n\r\nSQL&gt; show parameter clonedb\r\nNAME                                 TYPE        VALUE\r\n------------------------------------ ----------- ------------------------------\r\nclonedb                              boolean     TRUE\r\n<\/pre>\n<p>I will create a clone of the PDB2 database. <\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nSQL&gt; select name,con_id,open_mode,SNAPSHOT_PARENT_CON_ID from v$pdbs;\r\n\r\nNAME                               CON_ID OPEN_MODE  SNAPSHOT_PARENT_CON_ID\r\n------------------------------ ---------- ---------- ----------------------\r\nPDB$SEED                                2 READ ONLY                       0\r\nPDB1                                    3 MOUNTED                         0\r\nPDB2                                    4 READ ONLY                       0\r\n<\/pre>\n<p>For this I need first to create the target directory for the datafiles.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nSQL&gt; ! mkdir -p \/u01\/app\/oracle\/oradata\/NONRAC\/PDB2_CLONE1\r\n<\/pre>\n<p>Then I can do the clone using the &#8216;snapshot copy&#8217; clause. It took 9 seconds.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nSQL&gt; create pluggable database PDB2_C1 from PDB2 snapshot copy file_name_convert=('\/u01\/app\/oracle\/oradata\/NONRAC\/PDB2','\/u01\/app\/oracle\/oradata\/NONRAC\/PDB2_CLONE1');\r\nPluggable database created.\r\n\r\nElapsed: 00:00:09.35\r\n<\/pre>\n<p>Note that the new PDB remains in MOUNT state and without showing a connection to its parent. I find unfortunate the lack of that information. <\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nSQL&gt; select name,con_id,open_mode,SNAPSHOT_PARENT_CON_ID from v$pdbs;\r\n\r\nNAME                               CON_ID OPEN_MODE  SNAPSHOT_PARENT_CON_ID\r\n------------------------------ ---------- ---------- ----------------------\r\nPDB$SEED                                2 READ ONLY                       0\r\nPDB1                                    3 MOUNTED                         0\r\nPDB2                                    4 READ ONLY                       0\r\nPDB2_C1                                 5 MOUNTED                         0\r\n<\/pre>\n<p>After we open the clone in READ WRITE mode, then we can see the relationship with the parent. <\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nSQL&gt; alter pluggable database PDB2_C1 open read write;\r\nPluggable database altered.\r\nElapsed: 00:00:02.12\r\n\r\nSQL&gt; select name,con_id,open_mode,SNAPSHOT_PARENT_CON_ID from v$pdbs;\r\n\r\nNAME                               CON_ID OPEN_MODE  SNAPSHOT_PARENT_CON_ID\r\n------------------------------ ---------- ---------- ----------------------\r\nPDB$SEED                                2 READ ONLY                       0\r\nPDB1                                    3 MOUNTED                         0\r\nPDB2                                    4 READ ONLY                       0\r\nPDB2_C1                                 5 READ WRITE                      4\r\n<\/pre>\n<p>And below we verify that the clone uses 4MB instead of 800MB of the source database.  <\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nSQL&gt; ! du -m \/u01\/app\/oracle\/oradata\/NONRAC\/PDB2\/*\r\n6       \/u01\/app\/oracle\/oradata\/NONRAC\/PDB2\/PDB2_users01.dbf\r\n586     \/u01\/app\/oracle\/oradata\/NONRAC\/PDB2\/sysaux01.dbf\r\n261     \/u01\/app\/oracle\/oradata\/NONRAC\/PDB2\/system01.dbf\r\n1       \/u01\/app\/oracle\/oradata\/NONRAC\/PDB2\/temp01.dbf\r\n\r\nSQL&gt; ! du -m \/u01\/app\/oracle\/oradata\/NONRAC\/PDB2_CLONE1\/*\r\n1       \/u01\/app\/oracle\/oradata\/NONRAC\/PDB2_CLONE1\/PDB2_users01.dbf\r\n1       \/u01\/app\/oracle\/oradata\/NONRAC\/PDB2_CLONE1\/sysaux01.dbf\r\n1       \/u01\/app\/oracle\/oradata\/NONRAC\/PDB2_CLONE1\/system01.dbf\r\n1       \/u01\/app\/oracle\/oradata\/NONRAC\/PDB2_CLONE1\/temp01.dbf\r\n<\/pre>\n<p>We can also clone non-CDB databases with some more steps, as explained at:<br \/>\n<a href=\"https:\/\/dbamarco.wordpress.com\/2015\/03\/09\/small-change-big-difference\/\" target=\"_blank\">https:\/\/dbamarco.wordpress.com\/2015\/03\/09\/small-change-big-difference\/<\/a><\/p>\n<p>The clonedb.pl script (<a href=\"https:\/\/docs.oracle.com\/database\/121\/ADMIN\/create.htm#ADMIN14025\" target=\"_blank\">see documentation here<\/a>) can also be used, even though you might find easier to script yourself to your own environment.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Oracle 12.1.0.2 brings a great new functionality: you can create thin clones &#8211; that is, not copying the source files, just pointers &#8211; on ext4 filesystem, the current default on Red Hat Linux 6. Requirements for example below: &#8211; Oracle 12.1.0.2 &#8211; Data files are on ext4 filesystem (or other supporting sparse files) &#8211; Source [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36,6,7],"tags":[],"class_list":{"0":"post-146","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-cloning","7":"category-oracle","8":"category-oracle-12c","9":"czr-hentry"},"_links":{"self":[{"href":"https:\/\/anjo.pt\/keyword-oracle\/wp-json\/wp\/v2\/posts\/146","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/anjo.pt\/keyword-oracle\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/anjo.pt\/keyword-oracle\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/anjo.pt\/keyword-oracle\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/anjo.pt\/keyword-oracle\/wp-json\/wp\/v2\/comments?post=146"}],"version-history":[{"count":1,"href":"https:\/\/anjo.pt\/keyword-oracle\/wp-json\/wp\/v2\/posts\/146\/revisions"}],"predecessor-version":[{"id":147,"href":"https:\/\/anjo.pt\/keyword-oracle\/wp-json\/wp\/v2\/posts\/146\/revisions\/147"}],"wp:attachment":[{"href":"https:\/\/anjo.pt\/keyword-oracle\/wp-json\/wp\/v2\/media?parent=146"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/anjo.pt\/keyword-oracle\/wp-json\/wp\/v2\/categories?post=146"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/anjo.pt\/keyword-oracle\/wp-json\/wp\/v2\/tags?post=146"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}