{
  "date": "2018-07-09T17:21:18",
  "slug": "data-guard-always-set-db_create_file_dest-on-the-standby",
  "link": "https://www.dbi-services.com/blog/data-guard-always-set-db_create_file_dest-on-the-standby/",
  "title": {
    "rendered": "Data Guard: always set db_create_file_dest on the standby"
  },
  "content": {
    "rendered": "<h2>By Franck Pachot</h2>\n<p>.<br />\nThe file name convert parameters are not dynamic and require a restart of the instance. An enhancement request was filled in 2011. I mentioned recently on Twitter that it can be annoying with Active Data Guard when a file on the primary server is created on a path that has no file name conversion. However, Ian Baugaard mentioned that  there is a workaround for this specific case because db_create_file_dest is dynamic:<br />\n<!--more--></p>\n<blockquote class=\"twitter-tweet\" data-width=\"500\" data-dnt=\"true\">\n<p lang=\"en\" dir=\"ltr\">I recall seeing a MOS note indicating the order of precedence when it comes to db_file_name_convert and db_create_file_dest. The latter wins and makes config much easier especially when using OMF and ASM</p>\n<p>&mdash; Ian Baugaard (@IanBaugaard) <a href=\"https://twitter.com/IanBaugaard/status/1014887885273812993?ref_src=twsrc%5Etfw\">July 5, 2018</a></p></blockquote>\n<p><script async src=\"https://platform.twitter.com/widgets.js\" charset=\"utf-8\"></script></p>\n<p>I&#8217;ve quickly created a 18c Data Guard configuration on the Oracle Cloud DBaaS to test it and here it is.</p>\n<p>In the primary database and the standby database, here are the datafiles:</p>\n<pre><code>\nRMAN&gt; report schema;\n&nbsp;\nReport of database schema for database with db_unique_name ORCL_01\n&nbsp;\nList of Permanent Datafiles\n===========================\nFile Size(MB) Tablespace           RB segs Datafile Name\n---- -------- -------------------- ------- ------------------------\n1    830      SYSTEM               YES     /u02/app/oracle/oradata/ORCL/system01.dbf\n3    510      SYSAUX               NO      /u02/app/oracle/oradata/ORCL/sysaux01.dbf\n4    60       UNDOTBS1             YES     /u02/app/oracle/oradata/ORCL/undotbs01.dbf\n5    340      PDB$SEED:SYSTEM      NO      /u02/app/oracle/oradata/ORCL/pdbseed/system01.dbf\n6    620      PDB$SEED:SYSAUX      NO      /u02/app/oracle/oradata/ORCL/pdbseed/sysaux01.dbf\n7    5        USERS                NO      /u02/app/oracle/oradata/ORCL/users01.dbf\n8    200      PDB$SEED:UNDOTBS1    NO      /u02/app/oracle/oradata/ORCL/pdbseed/undotbs01.dbf\n12   340      PDB1:SYSTEM          YES     /u02/app/oracle/oradata/ORCL/PDB1/system01.dbf\n13   620      PDB1:SYSAUX          NO      /u02/app/oracle/oradata/ORCL/PDB1/sysaux01.dbf\n14   200      PDB1:UNDOTBS1        YES     /u02/app/oracle/oradata/ORCL/PDB1/undotbs01.dbf\n15   50       PDB1:USERS           NO      /u02/app/oracle/oradata/ORCL/PDB1/PDB1_users01.dbf\n&nbsp;\nList of Temporary Files\n=======================\nFile Size(MB) Tablespace           Maxsize(MB) Tempfile Name\n---- -------- -------------------- ----------- --------------------\n1    33       TEMP                 32767       /u04/app/oracle/oradata/temp/temp01.dbf\n2    62       PDB$SEED:TEMP        32767       /u04/app/oracle/oradata/temp/pdbseed_temp012018-02-08_13-49-27-256-PM.dbf\n4    62       PDB1:TEMP            32767       /u04/app/oracle/oradata/temp/temp012018-02-08_13-49-27-256-PM.dbf\n</code></pre>\n<p>The properties of the standby database define no DbFileNameConvert because the directory structure is supposed to be the same:</p>\n<pre><code>\nDGMGRL&gt; show configuration\n&nbsp;\nConfiguration - fsc\n&nbsp;\n  Protection Mode: MaxPerformance\n  Members:\n  ORCL_01 - Primary database\n    ORCL_02 - Physical standby database\n&nbsp;\nFast-Start Failover: DISABLED\n&nbsp;\nConfiguration Status:\nSUCCESS   (status updated 45 seconds ago)\n&nbsp;\n&nbsp;\nDGMGRL&gt; show database verbose 'ORCL_02';\n&nbsp;\nDatabase - ORCL_02\n&nbsp;\n  Role:               PHYSICAL STANDBY\n  Intended State:     APPLY-ON\n  Transport Lag:      0 seconds (computed 0 seconds ago)\n  Apply Lag:          0 seconds (computed 0 seconds ago)\n  Average Apply Rate: 15.00 KByte/s\n  Active Apply Rate:  532.00 KByte/s\n  Maximum Apply Rate: 535.00 KByte/s\n  Real Time Query:    ON\n  Instance(s):\n    ORCL\n&nbsp;\n  Properties:\n    DGConnectIdentifier             = 'ORCL_02'\n...\n    DbFileNameConvert               = ''\n    LogFileNameConvert              = 'dummy, dummy'\n...\n&nbsp;\n  Log file locations:\n    Alert log               : /u01/app/oracle/diag/rdbms/orcl_02/ORCL/trace/alert_ORCL.log\n    Data Guard Broker log   : /u01/app/oracle/diag/rdbms/orcl_02/ORCL/trace/drcORCL.log\n&nbsp;\nDatabase Status:\nSUCCESS\n</code></pre>\n<p>You can see that Oracle defines a dummy log file name convert. This a good idea to avoid some RMAN duplicate issues.</p>\n<p>On the standby server, I have no db_create_file_dest defined:</p>\n<pre><code>\nSQL&gt; show parameter create%dest\n&nbsp;\nNAME                                 TYPE        VALUE\n------------------------------------ ----------- ------------------------------\ndb_create_file_dest                  string\ndb_create_online_log_dest_1          string      .\ndb_create_online_log_dest_2          string\ndb_create_online_log_dest_3          string\ndb_create_online_log_dest_4          string\ndb_create_online_log_dest_5          string\n</code></pre>\n<p>Note that the Oracle Cloud DBaaS defines it. I&#8217;ve reset it for the purpose of this demo.</p>\n<h3>New filesystem on Primary server only</h3>\n<p>I create a new filesystem on the primary server:</p>\n<pre><code>\n[root@DG-dg01 opc]# mkdir /DATA ; chown oracle:dba /DATA\n</code></pre>\n<p>I create a datafile on this new filesystem:</p>\n<pre><code>\nSQL&gt; alter session set container=PDB1;\nSession altered.\n&nbsp;\nSQL&gt; create tablespace FRANCK datafile '/DATA/franck.dbf' size 100M;\nTablespace created.\n</code></pre>\n<p>The apply is stuck:</p>\n<pre><code>\nDGMGRL&gt; show database 'ORCL_02';\n&nbsp;\nDatabase - ORCL_02\n&nbsp;\n  Role:               PHYSICAL STANDBY\n  Intended State:     APPLY-ON\n  Transport Lag:      0 seconds (computed 2 seconds ago)\n  Apply Lag:          11 seconds (computed 2 seconds ago)\n  Average Apply Rate: 16.00 KByte/s\n  Real Time Query:    OFF\n  Instance(s):\n    ORCL\n&nbsp;\n  Database Error(s):\n    ORA-16766: Redo Apply is stopped\n&nbsp;\nDatabase Status:\nERROR\n</code></pre>\n<p>The standby alert.log shows the error about the impossibility to create the datafile:</p>\n<pre><code>\n2018-07-06T08:04:59.077730+00:00\nErrors in file /u01/app/oracle/diag/rdbms/orcl_02/ORCL/trace/ORCL_pr00_29393.trc:\nORA-01274: cannot add data file that was originally created as '/DATA/franck.dbf'\n2018-07-06T08:04:59.111881+00:00\nBackground Media Recovery process shutdown (ORCL)\n</code></pre>\n<h3>db_file_name_convert</h3>\n<p>The first idea is to set a db_file_name_convert, however, this requires an instance restart, which means downtime when you have sessions on the Active Data Guard standby:</p>\n<pre><code>\nDGMGRL&gt; edit database 'ORCL_02' set property DbFileNameConvert='/DATA,/u02/app/oracle/oradata/ORCL';\nWarning: ORA-16675: database instance restart required for property value modification to take effect\n&nbsp;\nProperty \"dbfilenameconvert\" updated\n&nbsp;\nDGMGRL&gt; show database 'ORCL_02';\n&nbsp;\nDatabase - ORCL_02\n&nbsp;\n  Role:               PHYSICAL STANDBY\n  Intended State:     APPLY-ON\n  Transport Lag:      0 seconds (computed 2 seconds ago)\n  Apply Lag:          3 minutes 32 seconds (computed 2 seconds ago)\n  Average Apply Rate: 16.00 KByte/s\n  Real Time Query:    OFF\n  Instance(s):\n    ORCL\n      Warning: ORA-16675: database instance restart required for property value modification to\n take effect\n      Warning: ORA-16714: the value of property DbFileNameConvert is inconsistent with the member setting\n&nbsp;\n  Database Error(s):\n    ORA-16766: Redo Apply is stopped\n&nbsp;\n  Database Warning(s):\n    ORA-16853: apply lag has exceeded specified threshold\n&nbsp;\nDatabase Status:\nERROR\n</code></pre>\n<h3>db_create_file_dest</h3>\n<p>The solution is set db_create_file_dest which, on the standby, has higher priority than the convert:</p>\n<pre><code>\nSQL&gt; alter system set db_create_file_dest='/u02/app/oracle/oradata';\nSystem altered.\n</code></pre>\n<p>I restart the apply:</p>\n<pre><code>\nDGMGRL&gt; edit database 'ORCL_02' set state=apply-on;\nSucceeded.\n</code></pre>\n<p>No need to restart and future datafile creations will be created there. However, it is too late for this datafile as it has already been created as UNNAMED in the controlfile:</p>\n<pre><code>\nORA-01186: file 18 failed verification tests\nORA-01157: cannot identify/lock data file 18 - see DBWR trace file\nORA-01111: name for data file 18 is unknown - rename to correct file\nORA-01110: data file 18: '/u01/app/oracle/product/18.0.0/dbhome_1/dbs/UNNAMED00018'\n</code></pre>\n<h3>Manual CREATE DATAFILE</h3>\n<p>Then I must manually create it, but I cannot do that while I am in standby_file_management=auto:</p>\n<pre><code>\nSQL&gt; alter session set container=PDB1;\nSession altered.\n&nbsp;\nSQL&gt; alter database create datafile '/u01/app/oracle/product/18.0.0/dbhome_1/dbs/UNNAMED00018' as '/u02/app/oracle/oradata/ORCL/franck.dbf';\nalter database create datafile '/u01/app/oracle/product/18.0.0/dbhome_1/dbs/UNNAMED00018' as '/u02/app/oracle/oradata/ORCL/franck.dbf'\n*\nERROR at line 1:\nORA-01275: Operation CREATE DATAFILE is not allowed if standby file management\nis automatic.\n</code></pre>\n<p>This can be changed dynamically:</p>\n<pre><code>\nDGMGRL&gt; edit database 'ORCL_02' set property StandbyFileManagement=manual;\nProperty \"standbyfilemanagement\" updated\n</code></pre>\n<p>And then the creation is possible:</p>\n<pre><code>\nSQL&gt; alter session set container=PDB1;\nSession altered.\n&nbsp;\nSQL&gt; alter database create datafile '/u01/app/oracle/product/18.0.0/dbhome_1/dbs/UNNAMED00018' as new;\nDatabase altered.\n</code></pre>\n<p>You can see that because I have defined db_create_file_dest, I don&#8217;t need to name the datafile and create it as OMF with the &#8216;new&#8217; keyword.</p>\n<p>Now I can start the apply and it will resolve the gap:</p>\n<pre><code>\nDGMGRL&gt; edit database 'ORCL_02' set state=apply-on;\nSucceeded.\n&nbsp;\nDGMGRL&gt; show database 'ORCL_02';\n&nbsp;\nDatabase - ORCL_02\n&nbsp;\n  Role:               PHYSICAL STANDBY\n  Intended State:     APPLY-ON\n  Transport Lag:      0 seconds (computed 3 seconds ago)\n  Apply Lag:          0 seconds (computed 3 seconds ago)\n  Average Apply Rate: 22.00 KByte/s\n  Real Time Query:    ON\n  Instance(s):\n    ORCL\n      Warning: ORA-16675: database instance restart required for property value modification to take effect\n      Warning: ORA-16714: the value of property DbFileNameConvert is inconsistent with the member setting\n&nbsp;\nDatabase Status:\nWARNING\n</code></pre>\n<p>Do not forget to put back standby_file_management&#8221;to auto:</p>\n<pre><code>\nDGMGRL&gt; edit database 'ORCL_02' set property StandbyFileManagement=auto;\nProperty \"standbyfilemanagement\" updated\n</code></pre>\n<p>So, now that db_create_file_dest is set, new datafiles will be created automatically as OMF (Oracle Managed Files), without caring about file name conversion:</p>\n<pre><code>\nSQL&gt; alter session set container=PDB1;\nSession altered.\n&nbsp;\nSQL&gt; alter tablespace FRANCK add datafile '/DATA/franck2.dbf' size 100M;\nTablespace altered.\n</code></pre>\n<p>This is confirmed from the standby alert.log:</p>\n<pre><code>\n(4):Datafile 19 added to flashback set\n(4):Successfully added datafile 19 to media recovery\n(4):Datafile #19: '/u02/app/oracle/oradata/ORCL_02/7050211FE75F26FAE05392781D0AADAA/datafile/o1_mf_franck_fmybw332_.dbf'\n</code></pre>\n<h3>Conclusion</h3>\n<p>Always define db_create_file_dest in the standby database so that datafiles will be created. Better to have them at the wrong place rather than stopping the apply. And anyway, if you don&#8217;t like the OMF names, and you are at least in 12c Enterprise Edition, you can change their name later with online move:</p>\n<pre><code>\nSQL&gt; alter session set container=PDB1;\nSession altered.\n&nbsp;\nSQL&gt; alter database move datafile '/u02/app/oracle/oradata/ORCL_02/7050211FE75F26FAE05392781D0AADAA/datafile/o1_mf_franck_fmybw332_.dbf' to '/u02/app/oracle/oradata/ORCL/franck2.dbf';\nDatabase altered.\n</code></pre>\n",
    "protected": false
  }
}
