{"id":3999,"date":"2014-09-10T17:22:16","date_gmt":"2014-09-10T15:22:16","guid":{"rendered":"https:\/\/www.dbi-services.com\/blog\/oracle-how-to-move-omf-datafiles-in-11g-and-12c\/"},"modified":"2014-09-10T17:22:16","modified_gmt":"2014-09-10T15:22:16","slug":"oracle-how-to-move-omf-datafiles-in-11g-and-12c","status":"publish","type":"post","link":"https:\/\/www.dbi-services.com\/blog\/oracle-how-to-move-omf-datafiles-in-11g-and-12c\/","title":{"rendered":"Oracle: How to move OMF datafiles in 11g and 12c"},"content":{"rendered":"<h2>By Franck Pachot<\/h2>\n<p>.<br \/>\nWith OMF datafiles, you don&#8217;t manage the datafile names. But how do you set the destination when you want to move them to another mount point? Let&#8217;s see how easy (and online) it works in 12c. And how to do it with minimal downtime in 11g.<\/p>\n<h3>Testcase<\/h3>\n<p>Let&#8217;s create a tablespace with two datafiles. It&#8217;s OMF and goes into \/u01:<\/p>\n<pre><code>SQL&gt; alter system set db_create_file_dest='\/u01\/app\/oracle\/oradata' scope=memory;\nSystem altered.\n\nSQL&gt; show parameter db_create_file_dest\nNAME                                 TYPE        VALUE\n------------------------------------ ----------- ------------------------------\ndb_create_file_dest                  string      \/u01\/app\/oracle\/oradata\n\nSQL&gt; create tablespace DEMO_OMF datafile size 5M;\nTablespace created.\n\nSQL&gt; alter tablespace DEMO_OMF add datafile size 5M;\nTablespace altered.\n<\/code><\/pre>\n<p>And I want to move those files in \/u02.<\/p>\n<h3>12c online move<\/h3>\n<p>Here is how I generate my MOVE commands for all datafiles in \/u01:<\/p>\n<pre><code>set echo off linesize 1000 trimspool on pagesize 0 feedback off\nspool _move_omf.rcv\nprompt set echo on;;\nprompt report schema;;\nprompt alter session set db_create_file_dest='\/u02\/app\/oracle\/oradata';;\nselect 'alter database move datafile '||file_id||';' from dba_data_files where file_name like '\/u01\/%' \n\/\nprompt report schema;;\nspool off\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>which generates the following:<\/p>\n<p>&nbsp;<\/p>\n<pre><code>set echo on;\nreport schema;\nalter session set db_create_file_dest='\/u02\/app\/oracle\/oradata';\nalter database move datafile 7;\nalter database move datafile 2;\nreport schema;\n<\/code><\/pre>\n<p>This works straightforward and online. That is the right solution if you are in 12c Enterprise Edition. The OMF destination is set at session level here. The move is done online, without any lock. The only overhead is that writes occured twice during the move operation. And in 12c we can run any SQL statement from RMAN, which is great.<\/p>\n<h3>11g backup as copy<\/h3>\n<p>How do you manage that in 11g? I like to do it with RMAN COPY. If you&#8217;re in ARCHIVELOG then you can copy the datafiles one by one: backup it as copy, offline it, recover it, switch to it, online it. This is the fastest way. You can avoid the recovery step by putting the tablespace offline but:<\/p>\n<ul>\n<li>you will have to wait that the earliest transaction finishes.<\/li>\n<li>your downtime includes the whole copy. When activity is low the recovery is probably faster.<\/li>\n<\/ul>\n<p>Here is how I generate my RMAN commands for all datafiles in \/u01:<\/p>\n<pre><code>set echo off linesize 1000 trimspool on pagesize 0 feedback off\nspool _move_omf.rcv\nprompt set echo on;;\nprompt report schema;;\nwith files as (\n select file_id , file_name , bytes from dba_data_files where file_name like '\/u01\/%' and online_status ='ONLINE' \n)\nselect stmt from (\nselect 00,bytes,file_id,'# '||to_char(bytes\/1024\/1024,'999999999')||'M '||file_name||';' stmt from files\nunion all\nselect 10,bytes,file_id,'backup as copy datafile '||file_id||' to destination''\/u02\/app\/oracle\/oradata'';' stmt from files\nunion all\nselect 20,bytes,file_id,'sql \"alter database datafile '||file_id||' offline\";' from files\nunion all\nselect 30,bytes,file_id,'switch datafile '||file_id||' to copy;' from files\nunion all\nselect 40,bytes,file_id,'recover datafile '||file_id||' ;' from files\nunion all\nselect 50,bytes,file_id,'sql \"alter database datafile '||file_id||' online\";' from files\nunion all\nselect 60,bytes,file_id,'delete copy of datafile '||file_id||';' from files\nunion all\nselect 90,bytes,file_id,'report schema;' from files\nunion all\nselect 91,bytes,file_id,'' from files\norder by 2,3,1\n)\n\/\n<\/code><\/pre>\n<p>which generates the following:<\/p>\n<pre><code>set echo on;\nreport schema;\n#          5M \/u01\/app\/oracle\/oradata\/DEMO\/datafile\/o1_mf_demo_omf_b0vg07m8_.dbf;\nbackup as copy datafile 2 to destination'\/u02\/app\/oracle\/oradata';\nsql \"alter database datafile 2 offline\";\nswitch datafile 2 to copy;\nrecover datafile 2 ;\nsql \"alter database datafile 2 online\";\ndelete copy of datafile 2;\nreport schema;\n<\/code><\/pre>\n<p>(I have reproduced the commands for one datafile only here.)<\/p>\n<p>And I can run it in RMAN. Run it as cmdfile or in a run block so that it stops if an error is encountered. Of course, it&#8217;s better to run them one by one and check that the datafiles are online at the end. Note that it does not concern SYSTEM tablespace for which the database must be closed.<\/p>\n<p>Online datafile move is my favorite Oracle 12c feature. And it&#8217;s the first new feature that you will practice if you come at our <a href=\"https:\/\/www.dbi-services.com\/trainings\/type\/oracle-en\/\">12c new features workshop. And in any versions RMAN is my preferred way to manipulate database files.<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>By Franck Pachot . With OMF datafiles, you don&#8217;t manage the datafile names. But how do you set the destination when you want to move them to another mount point? Let&#8217;s see how easy (and online) it works in 12c. And how to do it with minimal downtime in 11g. Testcase Let&#8217;s create a tablespace [&hellip;]<\/p>\n","protected":false},"author":27,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[198,59],"tags":[96],"type_dbi":[],"class_list":["post-3999","post","type-post","status-publish","format-standard","hentry","category-database-management","category-oracle","tag-oracle"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.2 (Yoast SEO v27.2) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Oracle: How to move OMF datafiles in 11g and 12c - dbi Blog<\/title>\n<meta name=\"description\" content=\"Move datafiles in 11g (with rman) and 12c (online move)\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.dbi-services.com\/blog\/oracle-how-to-move-omf-datafiles-in-11g-and-12c\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Oracle: How to move OMF datafiles in 11g and 12c\" \/>\n<meta property=\"og:description\" content=\"Move datafiles in 11g (with rman) and 12c (online move)\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dbi-services.com\/blog\/oracle-how-to-move-omf-datafiles-in-11g-and-12c\/\" \/>\n<meta property=\"og:site_name\" content=\"dbi Blog\" \/>\n<meta property=\"article:published_time\" content=\"2014-09-10T15:22:16+00:00\" \/>\n<meta name=\"author\" content=\"Oracle Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Oracle Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/oracle-how-to-move-omf-datafiles-in-11g-and-12c\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/oracle-how-to-move-omf-datafiles-in-11g-and-12c\/\"},\"author\":{\"name\":\"Oracle Team\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee\"},\"headline\":\"Oracle: How to move OMF datafiles in 11g and 12c\",\"datePublished\":\"2014-09-10T15:22:16+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/oracle-how-to-move-omf-datafiles-in-11g-and-12c\/\"},\"wordCount\":386,\"commentCount\":0,\"keywords\":[\"Oracle\"],\"articleSection\":[\"Database management\",\"Oracle\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/oracle-how-to-move-omf-datafiles-in-11g-and-12c\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/oracle-how-to-move-omf-datafiles-in-11g-and-12c\/\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/oracle-how-to-move-omf-datafiles-in-11g-and-12c\/\",\"name\":\"Oracle: How to move OMF datafiles in 11g and 12c - dbi Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\"},\"datePublished\":\"2014-09-10T15:22:16+00:00\",\"author\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee\"},\"description\":\"Move datafiles in 11g (with rman) and 12c (online move)\",\"breadcrumb\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/oracle-how-to-move-omf-datafiles-in-11g-and-12c\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/oracle-how-to-move-omf-datafiles-in-11g-and-12c\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/oracle-how-to-move-omf-datafiles-in-11g-and-12c\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\/\/www.dbi-services.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Oracle: How to move OMF datafiles in 11g and 12c\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/\",\"name\":\"dbi Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee\",\"name\":\"Oracle Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g\",\"caption\":\"Oracle Team\"},\"url\":\"https:\/\/www.dbi-services.com\/blog\/author\/oracle-team\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Oracle: How to move OMF datafiles in 11g and 12c - dbi Blog","description":"Move datafiles in 11g (with rman) and 12c (online move)","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.dbi-services.com\/blog\/oracle-how-to-move-omf-datafiles-in-11g-and-12c\/","og_locale":"en_US","og_type":"article","og_title":"Oracle: How to move OMF datafiles in 11g and 12c","og_description":"Move datafiles in 11g (with rman) and 12c (online move)","og_url":"https:\/\/www.dbi-services.com\/blog\/oracle-how-to-move-omf-datafiles-in-11g-and-12c\/","og_site_name":"dbi Blog","article_published_time":"2014-09-10T15:22:16+00:00","author":"Oracle Team","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Oracle Team","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.dbi-services.com\/blog\/oracle-how-to-move-omf-datafiles-in-11g-and-12c\/#article","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/oracle-how-to-move-omf-datafiles-in-11g-and-12c\/"},"author":{"name":"Oracle Team","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee"},"headline":"Oracle: How to move OMF datafiles in 11g and 12c","datePublished":"2014-09-10T15:22:16+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/oracle-how-to-move-omf-datafiles-in-11g-and-12c\/"},"wordCount":386,"commentCount":0,"keywords":["Oracle"],"articleSection":["Database management","Oracle"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dbi-services.com\/blog\/oracle-how-to-move-omf-datafiles-in-11g-and-12c\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dbi-services.com\/blog\/oracle-how-to-move-omf-datafiles-in-11g-and-12c\/","url":"https:\/\/www.dbi-services.com\/blog\/oracle-how-to-move-omf-datafiles-in-11g-and-12c\/","name":"Oracle: How to move OMF datafiles in 11g and 12c - dbi Blog","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/#website"},"datePublished":"2014-09-10T15:22:16+00:00","author":{"@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee"},"description":"Move datafiles in 11g (with rman) and 12c (online move)","breadcrumb":{"@id":"https:\/\/www.dbi-services.com\/blog\/oracle-how-to-move-omf-datafiles-in-11g-and-12c\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dbi-services.com\/blog\/oracle-how-to-move-omf-datafiles-in-11g-and-12c\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.dbi-services.com\/blog\/oracle-how-to-move-omf-datafiles-in-11g-and-12c\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/www.dbi-services.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Oracle: How to move OMF datafiles in 11g and 12c"}]},{"@type":"WebSite","@id":"https:\/\/www.dbi-services.com\/blog\/#website","url":"https:\/\/www.dbi-services.com\/blog\/","name":"dbi Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee","name":"Oracle Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g","caption":"Oracle Team"},"url":"https:\/\/www.dbi-services.com\/blog\/author\/oracle-team\/"}]}},"_links":{"self":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/3999","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/users\/27"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/comments?post=3999"}],"version-history":[{"count":0,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/3999\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media?parent=3999"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/categories?post=3999"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/tags?post=3999"},{"taxonomy":"type","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/type_dbi?post=3999"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}