{
  "date": "2015-09-06T17:11:37",
  "slug": "set-stateapply-off-and-datafile-consistency",
  "link": "https://www.dbi-services.com/blog/set-stateapply-off-and-datafile-consistency/",
  "title": {
    "rendered": "set state=apply-off and datafile consistency"
  },
  "content": {
    "rendered": "<h2>By Franck Pachot</h2>\n<p>.<br />\nIn a standby database (or in any database you recover) do you think the recovery uses buffer cache? And when you stop the apply in a standby database, do you think the datafiles are in a consistent state? We know the answer, but want to prove it. This is the kind of question you may have, as I did last Friday morning in the train with <a href=\"https://twitter.com/ludodba\" target=\"_blank\" rel=\"noopener noreferrer\">Ludovico Caldara</a> when going to the <a href=\"https://twitter.com/ParisOracle\" target=\"_blank\" rel=\"noopener noreferrer\">Paris Oracle Meetup</a>.<br />\n<!--more--><br />\nHere is the buffer cache status summary in a Data Guard standby database instance:</p>\n<pre><code>\nSQL&gt; select status,count(*) from v$bh group by status;\n&nbsp;\nSTATUS       COUNT(*)\n---------- ----------\nfree             1473\nmemory              2\nmrec             4846\n</code></pre>\n<p>The MREC status is the status of the blocks where redo from recovery is applied. It&#8217;s a current version of the block for recovery purpose only.</p>\n<p>Let&#8217;s see what happens when we stop the apply:</p>\n<pre><code>\nDGMGRL&gt; edit database demo12 set state=apply-off;\nSucceeded.\n</code></pre>\n<p>The alert.log shows that the data files are in a consistent state, which is similar to a checkpoint:</p>\n<pre><code>\nRecovery interrupted!\nRecovered data files to a consistent state at change 5683001\n</code></pre>\n<p>And here is the buffer cache:</p>\n<pre><code>\nSQL&gt; select status,count(*) from v$bh group by status;\n&nbsp;\nSTATUS       COUNT(*)\n---------- ----------\nfree             6344\n</code></pre>\n<p>All my MREC blocks have become free, as with any checkpoint.</p>\n<p>It&#8217;s exactly what we expected, but sometimes I just want to prove it to myself because there can be bugs, implementation oddities, or simply something that I overlooked. Now I&#8217;m conviced: the physical standby data files are consistent after an apply-off.</p>\n",
    "protected": false
  }
}
