{
  "date": "2018-02-12T20:32:28",
  "slug": "vmystat-delta-values",
  "link": "https://www.dbi-services.com/blog/vmystat-delta-values/",
  "title": {
    "rendered": "V$MYSTAT delta values"
  },
  "content": {
    "rendered": "<h2>By Franck Pachot</h2>\n<p>.<br />\nHere is a little script I use from time to time to look at V$MYSTAT values and displaying on one line a set of statistics with their delta value between two calls.<br />\n<!--more--><br />\nThe first script, _mystat_init.sql, initializes the variables. The second one displays the values, such as:</p>\n<pre><code>\nSQL&gt; @ _mystat_diff.sql\n&nbsp;\ndb block changes        redo size undo change vector size     redo entries\n---------------- ---------------- ----------------------- ----------------\n          57,371       15,445,852               6,111,608           37,709\n</code></pre>\n<p>Those two scripts are generated by defining the statistics:</p>\n<pre><code>\ndefine names=\"'redo size','redo entries','undo change vector size','db block changes'\"\n</code></pre>\n<p>abd running the following to spool the two scripts:</p>\n<pre><code>\nsqlplus -s / as sysdba &lt;&lt;&#039;END&#039;\nset pagesize 0 feedback off linesize 1000 trimspool on verify off echo off\nwith stats as (\n  select rownum n,stat_id,name from (select stat_id,name from v$statname where name in (&amp;names) order by stat_id)\n)\nselect &#039;define LAG&#039;||stat_id||&#039;=0&#039; from stats\nunion all\nselect &#039;column &quot;CUR&#039;||stat_id||&#039;&quot; new_value &#039;||&#039;LAG&#039;||stat_id||&#039; noprint&#039; from stats\nunion all\nselect &#039;column &quot;DIF&#039;||stat_id||&#039;&quot; heading &#039;&#039;&#039;||name||&#039;&#039;&#039; format 999G999G999G999&#039; from stats\n.\nspool _mystat_init.sql\n/\nspool off\nwith stats as (\n  select rownum n,stat_id,name from (select stat_id,name from v$statname where name in (&amp;names) order by stat_id)\n)\nselect &#039;set termout off verify off&#039; from dual\nunion all\nselect &#039;select &#039; from dual\nunion all\nselect &#039;   &#039;||decode(n,1,&#039; &#039;,&#039;,&#039;)||&#039;&quot;CUR&#039;||stat_id||&#039;&quot; - &#039;||&#039;&amp;&#039;||&#039;LAG&#039;||stat_id||&#039; &quot;DIF&#039;||stat_id||&#039;&quot;&#039; from stats\nunion all\nselect &#039;   &#039;||&#039;,nvl(&quot;CUR&#039;||stat_id||&#039;&quot;,0) &quot;CUR&#039;||stat_id||&#039;&quot;&#039; from stats\nunion all\n--select &#039;,&#039;&#039;&#039;||&#039;&amp;&#039;||&#039;1&#039;&#039; comments&#039; from dual\n--union all\nselect q&#039;[from (select stat_id,value from v$mystat join v$statname using(statistic#) where name in (&amp;names)) pivot (avg(value)for stat_id in (]&#039; from dual\nunion all\nselect &#039;   &#039;||decode(n,1,&#039; &#039;,&#039;,&#039;)||stat_id||&#039; as &quot;CUR&#039;||stat_id||&#039;&quot;&#039; from stats\nunion all\nselect &#039;))&#039; from dual\nunion all\nselect &#039;.&#039; from dual\nunion all\nselect &#039;set termout on&#039; from dual\nunion all\nselect &#039;/&#039; from dual\n.\nspool _mystat_diff.sql\n/\nspool off\nEND\n</code></pre>\n<p>Then, in sqlplus or SQLcl, you run:</p>\n<pre><code>\nSQL&gt; _mystat_init.sql\n</code></pre>\n<p>to initialize the values to 0 and:</p>\n<pre><code>\nSQL&gt; @ _mystat_diff.sql\n</code></pre>\n<p>each time you want to display the difference from last call.</p>\n",
    "protected": false
  }
}
