<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>DBA survival BLOG &#187; Oracle Database</title>
	<atom:link href="http://www.ludovicocaldara.net/dba/category/oracledb/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ludovicocaldara.net/dba</link>
	<description>Keep DBA job simple. Thanks.</description>
	<lastBuildDate>Thu, 27 Aug 2009 13:58:01 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Oracle capacity planning with RRDTOOL</title>
		<link>http://www.ludovicocaldara.net/dba/oracle-capacity-planning-with-rrdtool/</link>
		<comments>http://www.ludovicocaldara.net/dba/oracle-capacity-planning-with-rrdtool/#comments</comments>
		<pubDate>Mon, 25 May 2009 16:18:50 +0000</pubDate>
		<dc:creator>Ludovico</dc:creator>
				<category><![CDATA[Oracle Database]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[awr]]></category>
		<category><![CDATA[Capacity Planning]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[rrdtool]]></category>
		<category><![CDATA[workload]]></category>

		<guid isPermaLink="false">http://www.ludovicocaldara.net/dba/?p=68</guid>
		<description><![CDATA[RRDize everything, chapter 2
Oracle Database Server has the most powerful system catalog that allows to query almost any aspect inside an oracle instance.
You can query many v$ fixed views at regular intervals and populate many RRD files through rrdtool: space usage, wait events. system statistics and so on&#8230;
Since release 10.1 Oracle has introduced Automatic Workload [...]]]></description>
			<content:encoded><![CDATA[<p><strong>RRDize everything, chapter 2</strong></p>
<p>Oracle Database Server has the most powerful system catalog that allows to query almost any aspect inside an oracle instance.<br />
You can query many <em>v$</em> fixed views at regular intervals and populate many RRD files through <a href="http://oss.oetiker.ch/rrdtool/">rrdtool</a>: space usage, wait events. system statistics and so on&#8230;</p>
<p>Since release 10.1 Oracle has introduced <a href="www.oracle.com/technology/pub/articles/10gdba/week6_10gdba.html">Automatic Workload Repository</a>, a finer version of old good Statspack.<br />
No matter if you are using AWR or statspack, you can rely on their views to collect data for your RRDs.</p>
<p>If you are administering a new instance and you haven&#8217;t collected its statistics so far, you can query (as example) the DBA_HIST_BG_EVENT_SUMMARY view to gather all AWR data about wait events. Historical views could be useful also to collect historical data once a week rather than query the fixed views every few minutes doing the hard work twice (you and AWR).</p>
<p>The whole process of gathering performance data and update rrd files can be resumed into the following steps:</p>
<p>- connect to the database<br />
- query the AWR&#8217;s views<br />
- build and execute an rrdtool update command<br />
- check if rrd file exists or create it<br />
- update the rrd file</p>
<p>The less rrdtool update commands you will execute, the better the whole process will perform.<br />
Do it in a language you are comfortable with and that supports easily connection descriptors.</p>
<p>Since I&#8217;m very comfortable with php, I did it this way.</p>
<p>This is a very basilar script that works greatly for me with good performances:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/php -f
</span><span style="color: #339933;">&lt;</span> ?php                                         
&nbsp;
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WD'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'/opt/oracle/awr'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$cs</span>         <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'argv'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$user</span>       <span style="color: #339933;">=</span> <span style="color: #0000ff;">'mymonitoruser'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pass</span>       <span style="color: #339933;">=</span> <span style="color: #0000ff;">'mystrongpassword'</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #666666; font-style: italic;">/* open a new connection */</span>
<span style="color: #000088;">$ds</span> <span style="color: #339933;">=</span> oci_connect<span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span><span style="color: #339933;">,</span> <span style="color: #000088;">$pass</span><span style="color: #339933;">,</span> <span style="color: #000088;">$cs</span><span style="color: #009900;">&#41;</span>
        or <span style="color: #990000;">die</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Cannot connect to Oracle Database &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$cs</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* setting client nls environment */</span>
<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;alter session set nls_timestamp_format='MM/DD/YY HH24:MI'&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$stmt</span> <span style="color: #339933;">=</span> oci_parse<span style="color: #009900;">&#40;</span><span style="color: #000088;">$ds</span><span style="color: #339933;">,</span> <span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
oci_execute<span style="color: #009900;">&#40;</span><span style="color: #000088;">$stmt</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
oci_free_statement<span style="color: #009900;">&#40;</span><span style="color: #000088;">$stmt</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>                                         
&nbsp;
<span style="color: #666666; font-style: italic;">/* create directory that will contain rrds (if not exists) */</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span>WD<span style="color: #339933;">.</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$cs</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                <span style="color: #990000;">mkdir</span><span style="color: #009900;">&#40;</span>WD<span style="color: #339933;">.</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$cs</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span>WD<span style="color: #339933;">.</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$cs</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/wait'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                <span style="color: #990000;">mkdir</span><span style="color: #009900;">&#40;</span>WD<span style="color: #339933;">.</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$cs</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/wait'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>                   
&nbsp;
<span style="color: #666666; font-style: italic;">/* function to create new RRDs */</span>
<span style="color: #000000; font-weight: bold;">function</span> createRRD<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$interval</span><span style="color: #339933;">,</span> <span style="color: #000088;">$cs</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$hb</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$interval</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//heartbeat</span>
        <span style="color: #000088;">$cmd</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;rrdtool create &quot;</span><span style="color: #339933;">.</span>WD<span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$cs</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/wait/<span style="color: #006699; font-weight: bold;">${name}</span>.rrd -s &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$interval</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; <span style="color: #000099; font-weight: bold;">\
</span>                -b <span style="color: #000099; font-weight: bold;">\&quot;</span>now -3month<span style="color: #000099; font-weight: bold;">\&quot;</span> DS:waits:DERIVE:<span style="color: #006699; font-weight: bold;">$hb</span>:0:U <span style="color: #000099; font-weight: bold;">\
</span>                DS:mswaited:DERIVE:<span style="color: #006699; font-weight: bold;">$hb</span>:0:U <span style="color: #000099; font-weight: bold;">\
</span>                RRA:AVERAGE:0.5:1:1440 RRA:AVERAGE:0.5:30:336 <span style="color: #000099; font-weight: bold;">\
</span>                RRA:AVERAGE:0.5:120:372 RRA:AVERAGE:0.5:720:730 <span style="color: #000099; font-weight: bold;">\
</span>                RRA:MIN:0.5:1:1440 RRA:MIN:0.5:30:336 <span style="color: #000099; font-weight: bold;">\
</span>                RRA:MIN:0.5:120:372 RRA:MIN:0.5:720:730 <span style="color: #000099; font-weight: bold;">\
</span>                RRA:MAX:0.5:1:1440 RRA:MAX:0.5:30:336 <span style="color: #000099; font-weight: bold;">\
</span>                RRA:MAX:0.5:120:372 RRA:MAX:0.5:720:730 <span style="color: #000099; font-weight: bold;">\
</span>                RRA:LAST:0.5:1:1440&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">//print $cmd.&quot;\n&quot;;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #990000;">passthru</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cmd</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>                                                                              
&nbsp;
<span style="color: #666666; font-style: italic;">/* take the snapshot frequency from dba_hist_wr_control
 to create the RDD with correct heartbeat value */</span>
<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'select extract(hour from snap_interval)*3600 +
extract(minute from snap_interval)*60 as SEED from DBA_HIST_WR_CONTROL'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$stmt</span> <span style="color: #339933;">=</span> oci_parse<span style="color: #009900;">&#40;</span><span style="color: #000088;">$ds</span><span style="color: #339933;">,</span> <span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
oci_execute<span style="color: #009900;">&#40;</span><span style="color: #000088;">$stmt</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> oci_fetch_assoc<span style="color: #009900;">&#40;</span><span style="color: #000088;">$stmt</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$interval</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SEED'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
oci_free_statement<span style="color: #009900;">&#40;</span><span style="color: #000088;">$stmt</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>                                              
&nbsp;
<span style="color: #666666; font-style: italic;">/* statement definition that will collect
 all snapshots for a certain wait event with more than
 a certain amonut of time waited.
 Gathering ALL EVENTS could be time consuming and useless.
 I fetch rows ordered by event_name rather
 then by date because I can update many values
 into the same rrd with very few rrdupdate commands
*/</span>
<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'select s.END_INTERVAL_TIME END_INTERVAL_TIME,
    g.EVENT_NAME, g.WAIT_CLASS, g.TOTAL_WAITS,
    round(g.TIME_WAITED_MICRO/1000) MS
  from DBA_HIST_SNAPSHOT s,
   dba_hist_bg_event_summary g,
   v$instance i
 where s.SNAP_ID=g.SNAP_ID and g.wait_class!=\'Idle\'
  and g.TIME_WAITED_MICRO&amp;gt;100000
  and s.instance_number=i.instance_number
  and s.instance_number=g.instance_number
 order by 2,1'</span><span style="color: #339933;">;</span>                                      
&nbsp;
<span style="color: #666666; font-style: italic;">/* default prefetch size (148) matches default snapshot retention (24hx7dd) */</span>
<span style="color: #000088;">$stmt</span> <span style="color: #339933;">=</span> oci_parse<span style="color: #009900;">&#40;</span><span style="color: #000088;">$ds</span><span style="color: #339933;">,</span> <span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
oci_set_prefetch<span style="color: #009900;">&#40;</span><span style="color: #000088;">$stmt</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">148</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
oci_execute<span style="color: #009900;">&#40;</span><span style="color: #000088;">$stmt</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$oldevent</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> oci_fetch_assoc<span style="color: #009900;">&#40;</span><span style="color: #000088;">$stmt</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$oldevent</span> <span style="color: #339933;">!=</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'EVENT_NAME'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #666666; font-style: italic;">//NEW EVENT DETECTED: WILL START A NEW UPDATE CMD</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">!=</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> <span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cmd</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #666666; font-style: italic;">/* not the first occurrence,
                         I bet there's something in my buffer */</span>
                        <span style="color: #990000;">passthru</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cmd</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #000088;">$cleanName</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;([^[:alnum:]_-])&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;_&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'EVENT_NAME'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #666666; font-style: italic;">// if there is no rrd for this event, I create a new one</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span>WD<span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$cs</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/wait/<span style="color: #006699; font-weight: bold;">${cleanName}</span>.rrd&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        createRRD<span style="color: #009900;">&#40;</span><span style="color: #000088;">$cleanName</span><span style="color: #339933;">,</span> <span style="color: #000088;">$interval</span><span style="color: #339933;">,</span> <span style="color: #000088;">$cs</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #666666; font-style: italic;">/*
                * I initialize a new update command. This string act as a buffer: I append many
                * values to be updated so I'll update many values in a single command line:
                * less forks of rrdtool and less file opens: the whole update process has an
                * enormous improvement.
                */</span>
                <span style="color: #000088;">$precmd</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;rrdtool update &quot;</span><span style="color: #339933;">.</span>WD<span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$cs</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/wait/<span style="color: #006699; font-weight: bold;">${cleanName}</span>.rrd &quot;</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$lastcmd</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;rrdtool info &quot;</span><span style="color: #339933;">.</span>WD<span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$cs</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/wait/<span style="color: #006699; font-weight: bold;">${cleanName}</span>.rrd&quot;</span><span style="color: #339933;">.</span>
                        <span style="color: #0000ff;">&quot;| grep last_update | awk '{print <span style="color: #000099; font-weight: bold;">\$</span>NF}'&quot;</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$last</span><span style="color: #339933;">=</span><span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span>`<span style="color: #000088;">$lastcmd</span>`<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #990000;">printf</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #009933; font-weight: bold;">%s</span> - <span style="color: #009933; font-weight: bold;">%s</span> - last: <span style="color: #009933; font-weight: bold;">%d</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'EVENT_NAME'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$cleanName</span><span style="color: #339933;">,</span> <span style="color: #000088;">$last</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$cmd</span><span style="color: #339933;">=</span><span style="color: #000088;">$precmd</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$oldevent</span><span style="color: #339933;">=</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'EVENT_NAME'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000088;">$time</span><span style="color: #339933;">=</span><span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'END_INTERVAL_TIME'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">//print &quot;time: &quot;.$time.&quot;  last: &quot;.$last.&quot;\n&quot;;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$time</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #000088;">$last</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$cmd</span><span style="color: #339933;">.=</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$time</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;:&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'TOTAL_WAITS'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;:&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'MS'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$i</span><span style="color: #339933;">++;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;=</span> <span style="color: #cc66cc;">40</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #666666; font-style: italic;">// when I reach 40 values per commandline I force</span>
                <span style="color: #666666; font-style: italic;">// the update: next loop will reinitialize a new commandline.</span>
                <span style="color: #990000;">passthru</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cmd</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$cmd</span><span style="color: #339933;">=</span><span style="color: #000088;">$precmd</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">!=</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">/* one more update pending in my buffer */</span>
        <span style="color: #990000;">passthru</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cmd</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
oci_free_statement<span style="color: #009900;">&#40;</span><span style="color: #000088;">$stmt</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
oci_close<span style="color: #009900;">&#40;</span><span style="color: #000088;">$ds</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Depending on how many different wait events you have, you&#8217;ll have a certain number of rrd files:</p>
<pre># ls -l
total 3864
-rw-r--r-- 1 ludovico ludovico 165304 May 25 15:00 Streams_AQ__enqueue_blocked_on_low_memory.rrd
-rw-r--r-- 1 ludovico ludovico 165304 May 20 08:18 buffer_busy_waits.rrd
-rw-r--r-- 1 ludovico ludovico 165304 May 25 15:00 control_file_parallel_write.rrd
-rw-r--r-- 1 ludovico ludovico 165304 May 25 15:00 control_file_sequential_read.rrd
-rw-r--r-- 1 ludovico ludovico 165304 Apr 30 10:12 cursor__pin_S_wait_on_X.rrd
-rw-r--r-- 1 ludovico ludovico 165304 May 25 15:00 db_file_scattered_read.rrd
-rw-r--r-- 1 ludovico ludovico 165304 May 25 15:00 db_file_sequential_read.rrd
-rw-r--r-- 1 ludovico ludovico 165304 May 25 15:00 events_in_waitclass_Other.rrd
-rw-r--r-- 1 ludovico ludovico 165304 May 25 15:00 latch__cache_buffers_chains.rrd
-rw-r--r-- 1 ludovico ludovico 165304 May 25 15:00 latch__library_cache.rrd
-rw-r--r-- 1 ludovico ludovico 165304 May 11 13:22 latch__library_cache_lock.rrd
-rw-r--r-- 1 ludovico ludovico 165304 May 20 08:18 latch__redo_writing.rrd
-rw-r--r-- 1 ludovico ludovico 165304 May 25 15:00 latch__row_cache_objects.rrd
-rw-r--r-- 1 ludovico ludovico 165304 May 25 15:00 latch__shared_pool.rrd
-rw-r--r-- 1 ludovico ludovico 165304 May 25 15:00 library_cache_load_lock.rrd
-rw-r--r-- 1 ludovico ludovico 165304 Apr 15 13:17 library_cache_lock.rrd
-rw-r--r-- 1 ludovico ludovico 165304 May 25 15:00 log_buffer_space.rrd
-rw-r--r-- 1 ludovico ludovico 165304 May 25 15:00 log_file_parallel_write.rrd
-rw-r--r-- 1 ludovico ludovico 165304 May 25 15:00 log_file_sequential_read.rrd
-rw-r--r-- 1 ludovico ludovico 165304 May 25 15:00 log_file_single_write.rrd
-rw-r--r-- 1 ludovico ludovico 165304 May 25 15:00 log_file_switch_completion.rrd
-rw-r--r-- 1 ludovico ludovico 165304 May 11 13:22 log_file_sync.rrd
-rw-r--r-- 1 ludovico ludovico 165304 May 25 15:00 os_thread_startup.rrd</pre>
<p>As you can see, they are not so big&#8230;</p>
<p>Once you have your data in rrd files, it&#8217;s quite simple to script even complex plots with several datasources. Everything depends on the results you want.<br />
This script stack all my wait events for a certain instance: it takes the directory containing all the rrds as first argument and the number of hours we want to be plotted as second argument:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">cs</span>=$<span style="color: #000000;">1</span>
<span style="color: #007800;">hours</span>=<span style="color: #800000;">${2:-148}</span>
&nbsp;
<span style="color: #007800;">eventlist</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #007800;">$cs</span><span style="color: #000000; font-weight: bold;">/</span>wait<span style="color: #000000; font-weight: bold;">/*</span>rrd<span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
colors<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>=<span style="color: #ff0000;">&quot;#000000&quot;</span>
colors<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>=<span style="color: #ff0000;">&quot;#000055&quot;</span>
colors<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>=<span style="color: #ff0000;">&quot;#0000aa&quot;</span>
colors<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>=<span style="color: #ff0000;">&quot;#0000ff&quot;</span>
colors<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">5</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>=<span style="color: #ff0000;">&quot;#550055&quot;</span>
colors<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">6</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>=<span style="color: #ff0000;">&quot;#aa00aa&quot;</span>
colors<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">7</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>=<span style="color: #ff0000;">&quot;#ff00ff&quot;</span>
colors<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">8</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>=<span style="color: #ff0000;">&quot;#550000&quot;</span>
colors<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">9</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>=<span style="color: #ff0000;">&quot;#aa0000&quot;</span>
colors<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">10</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>=<span style="color: #ff0000;">&quot;#ff0000&quot;</span>
colors<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">11</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>=<span style="color: #ff0000;">&quot;#555500&quot;</span>
colors<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">12</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>=<span style="color: #ff0000;">&quot;#aaaa00&quot;</span>
colors<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">13</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>=<span style="color: #ff0000;">&quot;#ffff00&quot;</span>
colors<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">14</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>=<span style="color: #ff0000;">&quot;#005500&quot;</span>
colors<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">15</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>=<span style="color: #ff0000;">&quot;#00aa00&quot;</span>
colors<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">16</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>=<span style="color: #ff0000;">&quot;#00ff00&quot;</span>
colors<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">17</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>=<span style="color: #ff0000;">&quot;#005555&quot;</span>
colors<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">18</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>=<span style="color: #ff0000;">&quot;#00aaaa&quot;</span>
colors<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">19</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>=<span style="color: #ff0000;">&quot;#00ffff&quot;</span>
colors<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">20</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>=<span style="color: #ff0000;">&quot;#555555&quot;</span>
colors<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">21</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>=<span style="color: #ff0000;">&quot;#aaaaaa&quot;</span>
&nbsp;
<span style="color: #007800;">i</span>=<span style="color: #000000;">0</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> event <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$eventlist</span> ; <span style="color: #000000; font-weight: bold;">do</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$i</span> <span style="color: #660033;">-eq</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> ; <span style="color: #000000; font-weight: bold;">then</span>
                <span style="color: #007800;">end</span>=<span style="color: #000000; font-weight: bold;">`</span>rrdtool info <span style="color: #007800;">$event</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> last_update <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $NF}'</span><span style="color: #000000; font-weight: bold;">`</span>
                <span style="color: #007800;">end</span>=<span style="color: #000000; font-weight: bold;">`</span>rrdtool info <span style="color: #007800;">$cs</span><span style="color: #000000; font-weight: bold;">/</span>wait<span style="color: #000000; font-weight: bold;">/</span>control_file_parallel_write.rrd <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> last_update <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $NF}'</span><span style="color: #000000; font-weight: bold;">`</span>
                <span style="color: #007800;">cmd</span>=<span style="color: #ff0000;">&quot;rrdtool graph - -s end-<span style="color: #007800;">${hours}</span>hours -e <span style="color: #007800;">$end</span>  -v <span style="color: #000099; font-weight: bold;">\&quot;</span>milliseconds waited<span style="color: #000099; font-weight: bold;">\&quot;</span> -l 0 -w 640 -h 240 -t <span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #007800;">$cs</span> WAIT PROFILE<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span>
                <span style="color: #007800;">i</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$i</span>+<span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #000000; font-weight: bold;">fi</span>
        <span style="color: #007800;">color</span>=<span style="color: #800000;">${colors[$i]}</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$color</span>
        <span style="color: #007800;">evname</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">basename</span> <span style="color: #007800;">$event</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-e</span> s<span style="color: #000000; font-weight: bold;">/</span>\.rrd\$<span style="color: #000000; font-weight: bold;">//`</span>
        <span style="color: #007800;">cmd</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$cmd</span>  DEF:<span style="color: #007800;">$evname</span>=<span style="color: #007800;">$event</span>:mswaited:AVERAGE&quot;</span>
        <span style="color: #007800;">cmd</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$cmd</span>  AREA:<span style="color: #007800;">${evname}</span><span style="color: #007800;">${color}</span>:&quot;</span><span style="color: #007800;">$evname</span><span style="color: #ff0000;">&quot;:STACK&quot;</span>
        <span style="color: #007800;">i</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$i</span>+<span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$i</span> <span style="color: #660033;">-eq</span> <span style="color: #000000;">20</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> ; <span style="color: #000000; font-weight: bold;">then</span>
                <span style="color: #007800;">i</span>=<span style="color: #000000;">1</span>
        <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">done</span>
        <span style="color: #007800;">cmd</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$cmd</span>  |display /dev/input&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$cmd</span>
        <span style="color: #7a0874; font-weight: bold;">eval</span> <span style="color: #007800;">$cmd</span>
<span style="color: #7a0874; font-weight: bold;">exit</span></pre></div></div>

<p>The resulting command is very long:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rrdtool graph - <span style="color: #660033;">-s</span> end-148hours <span style="color: #660033;">-e</span> <span style="color: #000000;">1243252800</span> \
 <span style="color: #660033;">-v</span> <span style="color: #ff0000;">&quot;milliseconds waited&quot;</span> <span style="color: #660033;">-l</span> <span style="color: #000000;">0</span> <span style="color: #660033;">-w</span> <span style="color: #000000;">640</span> <span style="color: #660033;">-h</span> <span style="color: #000000;">240</span> <span style="color: #660033;">-t</span> <span style="color: #ff0000;">&quot;mydb WAIT PROFILE&quot;</span>\
 DEF:<span style="color: #007800;">Streams_AQ__enqueue_blocked_on_low_memory</span>=mydb<span style="color: #000000; font-weight: bold;">/</span>wait<span style="color: #000000; font-weight: bold;">/</span>Streams_AQ__enqueue_blocked_on_low_memory.rrd:mswaited:AVERAGE \
 AREA:Streams_AQ__enqueue_blocked_on_low_memory<span style="color: #666666; font-style: italic;">#000000:Streams_AQ__enqueue_blocked_on_low_memory:STACK\</span>
 DEF:<span style="color: #007800;">buffer_busy_waits</span>=mydb<span style="color: #000000; font-weight: bold;">/</span>wait<span style="color: #000000; font-weight: bold;">/</span>buffer_busy_waits.rrd:mswaited:AVERAGE \
 AREA:buffer_busy_waits<span style="color: #666666; font-style: italic;">#000055:buffer_busy_waits:STACK\</span>
 DEF:<span style="color: #007800;">control_file_parallel_write</span>=mydb<span style="color: #000000; font-weight: bold;">/</span>wait<span style="color: #000000; font-weight: bold;">/</span>control_file_parallel_write.rrd:mswaited:AVERAGE \
 AREA:control_file_parallel_write<span style="color: #666666; font-style: italic;">#0000aa:control_file_parallel_write:STACK\</span>
 DEF:<span style="color: #007800;">control_file_sequential_read</span>=mydb<span style="color: #000000; font-weight: bold;">/</span>wait<span style="color: #000000; font-weight: bold;">/</span>control_file_sequential_read.rrd:mswaited:AVERAGE \
 AREA:control_file_sequential_read<span style="color: #666666; font-style: italic;">#0000ff:control_file_sequential_read:STACK\</span>
 DEF:<span style="color: #007800;">cursor__pin_S_wait_on_X</span>=mydb<span style="color: #000000; font-weight: bold;">/</span>wait<span style="color: #000000; font-weight: bold;">/</span>cursor__pin_S_wait_on_X.rrd:mswaited:AVERAGE \
 AREA:cursor__pin_S_wait_on_X<span style="color: #666666; font-style: italic;">#550055:cursor__pin_S_wait_on_X:STACK\</span>
 DEF:<span style="color: #007800;">db_file_scattered_read</span>=mydb<span style="color: #000000; font-weight: bold;">/</span>wait<span style="color: #000000; font-weight: bold;">/</span>db_file_scattered_read.rrd:mswaited:AVERAGE \
 AREA:db_file_scattered_read<span style="color: #666666; font-style: italic;">#aa00aa:db_file_scattered_read:STACK\</span>
 DEF:<span style="color: #007800;">db_file_sequential_read</span>=mydb<span style="color: #000000; font-weight: bold;">/</span>wait<span style="color: #000000; font-weight: bold;">/</span>db_file_sequential_read.rrd:mswaited:AVERAGE \
 AREA:db_file_sequential_read<span style="color: #666666; font-style: italic;">#ff00ff:db_file_sequential_read:STACK\</span>
 DEF:<span style="color: #007800;">events_in_waitclass_Other</span>=mydb<span style="color: #000000; font-weight: bold;">/</span>wait<span style="color: #000000; font-weight: bold;">/</span>events_in_waitclass_Other.rrd:mswaited:AVERAGE \
 AREA:events_in_waitclass_Other<span style="color: #666666; font-style: italic;">#550000:events_in_waitclass_Other:STACK\</span>
 DEF:<span style="color: #007800;">latch__cache_buffers_chains</span>=mydb<span style="color: #000000; font-weight: bold;">/</span>wait<span style="color: #000000; font-weight: bold;">/</span>latch__cache_buffers_chains.rrd:mswaited:AVERAGE \
 AREA:latch__cache_buffers_chains<span style="color: #666666; font-style: italic;">#aa0000:latch__cache_buffers_chains:STACK\</span>
 DEF:<span style="color: #007800;">latch__library_cache</span>=mydb<span style="color: #000000; font-weight: bold;">/</span>wait<span style="color: #000000; font-weight: bold;">/</span>latch__library_cache.rrd:mswaited:AVERAGE \
 AREA:latch__library_cache<span style="color: #666666; font-style: italic;">#ff0000:latch__library_cache:STACK\</span>
 DEF:<span style="color: #007800;">latch__library_cache_lock</span>=mydb<span style="color: #000000; font-weight: bold;">/</span>wait<span style="color: #000000; font-weight: bold;">/</span>latch__library_cache_lock.rrd:mswaited:AVERAGE \
 AREA:latch__library_cache_lock<span style="color: #666666; font-style: italic;">#555500:latch__library_cache_lock:STACK\</span>
 DEF:<span style="color: #007800;">latch__redo_writing</span>=mydb<span style="color: #000000; font-weight: bold;">/</span>wait<span style="color: #000000; font-weight: bold;">/</span>latch__redo_writing.rrd:mswaited:AVERAGE \
 AREA:latch__redo_writing<span style="color: #666666; font-style: italic;">#aaaa00:latch__redo_writing:STACK\</span>
 DEF:<span style="color: #007800;">latch__row_cache_objects</span>=mydb<span style="color: #000000; font-weight: bold;">/</span>wait<span style="color: #000000; font-weight: bold;">/</span>latch__row_cache_objects.rrd:mswaited:AVERAGE \
 AREA:latch__row_cache_objects<span style="color: #666666; font-style: italic;">#ffff00:latch__row_cache_objects:STACK\</span>
 DEF:<span style="color: #007800;">latch__shared_pool</span>=mydb<span style="color: #000000; font-weight: bold;">/</span>wait<span style="color: #000000; font-weight: bold;">/</span>latch__shared_pool.rrd:mswaited:AVERAGE \
 AREA:latch__shared_pool<span style="color: #666666; font-style: italic;">#005500:latch__shared_pool:STACK\</span>
 DEF:<span style="color: #007800;">library_cache_load_lock</span>=mydb<span style="color: #000000; font-weight: bold;">/</span>wait<span style="color: #000000; font-weight: bold;">/</span>library_cache_load_lock.rrd:mswaited:AVERAGE \
 AREA:library_cache_load_lock<span style="color: #666666; font-style: italic;">#00aa00:library_cache_load_lock:STACK\</span>
 DEF:<span style="color: #007800;">library_cache_lock</span>=mydb<span style="color: #000000; font-weight: bold;">/</span>wait<span style="color: #000000; font-weight: bold;">/</span>library_cache_lock.rrd:mswaited:AVERAGE \
 AREA:library_cache_lock<span style="color: #666666; font-style: italic;">#00ff00:library_cache_lock:STACK\</span>
 DEF:<span style="color: #007800;">log_buffer_space</span>=mydb<span style="color: #000000; font-weight: bold;">/</span>wait<span style="color: #000000; font-weight: bold;">/</span>log_buffer_space.rrd:mswaited:AVERAGE \
 AREA:log_buffer_space<span style="color: #666666; font-style: italic;">#005555:log_buffer_space:STACK\</span>
 DEF:<span style="color: #007800;">log_file_parallel_write</span>=mydb<span style="color: #000000; font-weight: bold;">/</span>wait<span style="color: #000000; font-weight: bold;">/</span>log_file_parallel_write.rrd:mswaited:AVERAGE \
 AREA:log_file_parallel_write<span style="color: #666666; font-style: italic;">#00aaaa:log_file_parallel_write:STACK\</span>
 DEF:<span style="color: #007800;">log_file_sequential_read</span>=mydb<span style="color: #000000; font-weight: bold;">/</span>wait<span style="color: #000000; font-weight: bold;">/</span>log_file_sequential_read.rrd:mswaited:AVERAGE \
 AREA:log_file_sequential_read<span style="color: #666666; font-style: italic;">#00ffff:log_file_sequential_read:STACK\</span>
 DEF:<span style="color: #007800;">log_file_single_write</span>=mydb<span style="color: #000000; font-weight: bold;">/</span>wait<span style="color: #000000; font-weight: bold;">/</span>log_file_single_write.rrd:mswaited:AVERAGE \
 AREA:log_file_single_write<span style="color: #666666; font-style: italic;">#000000:log_file_single_write:STACK\</span>
 DEF:<span style="color: #007800;">log_file_switch_completion</span>=mydb<span style="color: #000000; font-weight: bold;">/</span>wait<span style="color: #000000; font-weight: bold;">/</span>log_file_switch_completion.rrd:mswaited:AVERAGE \
 AREA:log_file_switch_completion<span style="color: #666666; font-style: italic;">#000055:log_file_switch_completion:STACK\</span>
 DEF:<span style="color: #007800;">log_file_sync</span>=mydb<span style="color: #000000; font-weight: bold;">/</span>wait<span style="color: #000000; font-weight: bold;">/</span>log_file_sync.rrd:mswaited:AVERAGE \
 AREA:log_file_sync<span style="color: #666666; font-style: italic;">#0000aa:log_file_sync:STACK\</span>
 DEF:<span style="color: #007800;">os_thread_startup</span>=mydb<span style="color: #000000; font-weight: bold;">/</span>wait<span style="color: #000000; font-weight: bold;">/</span>os_thread_startup.rrd:mswaited:AVERAGE \
 AREA:os_thread_startup<span style="color: #666666; font-style: italic;">#0000ff:os_thread_startup:STACK |display /dev/input</span></pre></div></div>

<p>This is the resulting graph:<br />
<a href="http://www.ludovicocaldara.net/images/mydb_events.png"><img alt="Graph plotted with rrdtool displaying Oracle instance Wait Events" src="http://www.ludovicocaldara.net/images/mydb_events.png" title="Oracle Instance Wait Events" width="737" height="398" /></a></p>
<p><strong>OHHHHHHHHHHHH COOOOL!!!</strong><br />
 <img src='http://www.ludovicocaldara.net/dba/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Any comment is appreciated! thanks</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ludovicocaldara.net/dba/oracle-capacity-planning-with-rrdtool/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>More about Dataguard and how to check it</title>
		<link>http://www.ludovicocaldara.net/dba/more-about-dataguard-and-how-to-check-it/</link>
		<comments>http://www.ludovicocaldara.net/dba/more-about-dataguard-and-how-to-check-it/#comments</comments>
		<pubDate>Fri, 06 Feb 2009 11:27:51 +0000</pubDate>
		<dc:creator>Ludovico</dc:creator>
				<category><![CDATA[Oracle Database]]></category>
		<category><![CDATA[MRP0]]></category>
		<category><![CDATA[Oracle Dataguard]]></category>
		<category><![CDATA[real-time apply]]></category>
		<category><![CDATA[Standby]]></category>

		<guid isPermaLink="false">http://www.ludovicocaldara.net/dba/?p=54</guid>
		<description><![CDATA[After my post Quick Oracle Dataguard check script I have some considerations to add:
to check the gap of applied log stream by MRP0 process it&#8217;s sufficient to replace this query in the perl script I posted:

 SELECT SEQUENCE#, BLOCK# from v\$managed_standby
        WHERE process='RFS' AND client_process='LGWR'

with this new one:

 [...]]]></description>
			<content:encoded><![CDATA[<p>After my post <a href="http://www.ludovicocaldara.net/dba/quick-oracle-dataguard-check-script/">Quick Oracle Dataguard check script</a> I have some considerations to add:<br />
to check the gap of applied log stream by <strong>MRP0</strong> process it&#8217;s sufficient to replace this query in the perl script I posted:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"> <span style="color: #993333; font-weight: bold;">SELECT</span> SEQUENCE<span style="color: #808080; font-style: italic;">#, BLOCK# from v\$managed_standby</span>
        <span style="color: #993333; font-weight: bold;">WHERE</span> process<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'RFS'</span> <span style="color: #993333; font-weight: bold;">AND</span> client_process<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'LGWR'</span></pre></div></div>

<p>with this new one:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"> <span style="color: #993333; font-weight: bold;">SELECT</span> SEQUENCE<span style="color: #808080; font-style: italic;">#, BLOCK# from v\$managed_standby</span>
        <span style="color: #993333; font-weight: bold;">WHERE</span> process<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'MRP0'</span></pre></div></div>

<p>To check this you have to meet the following condition: You should have real-time apply enabled (and possibly NODELAY clause specified in your recover statement). Check it with this query:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> RECOVERY_MODE <span style="color: #993333; font-weight: bold;">FROM</span> V$ARCHIVE_DEST_STATUS;</pre></div></div>

<p>It should be &#8220;MANAGED REAL TIME APPLY&#8221;.<br />
If not using realtime apply your MRP0 process will wait until you have a new archive, so even if you have redo transport mode set to LGWR you&#8217;ll wait for standby log completion. Your gap of applied redo stream will be at least one sequence#.</p>
<p>With transport mode set to LGWR and real-time apply the output of the perl script is similar to this one:</p>
<pre>
# ./checkDataGuard.sh
PROD   :       1230      20631
STANDBY:       1230      20613
18         blocks gap
</pre>
<p>The whole gap between your primary and standby database should be LOW.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ludovicocaldara.net/dba/more-about-dataguard-and-how-to-check-it/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quick Oracle Dataguard check script</title>
		<link>http://www.ludovicocaldara.net/dba/quick-oracle-dataguard-check-script/</link>
		<comments>http://www.ludovicocaldara.net/dba/quick-oracle-dataguard-check-script/#comments</comments>
		<pubDate>Mon, 05 Jan 2009 15:49:10 +0000</pubDate>
		<dc:creator>Ludovico</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Oracle Database]]></category>
		<category><![CDATA[Oracle Dataguard]]></category>

		<guid isPermaLink="false">http://www.ludovicocaldara.net/dba/?p=38</guid>
		<description><![CDATA[Oracle Dataguard has his own command-line dgmgrl to check the whole dataguard configuration status.
At least you should check that the show configuration command returns SUCCESS.
This is an hypothetic script:

#!/bin/bash
export ORACLE_HOME=/u1/app/oracle/product/10.2.0
export ORACLE_SID=orcldg
result=`echo &#34;show configuration;&#34; &#124; \
  $ORACLE_HOME/bin/dgmgrl sys/strongpasswd &#124; \
  grep -A 1 &#34;Current status for&#34; &#124; grep -v &#34;Current status for&#34;`
if &#91; &#34;$result&#34; [...]]]></description>
			<content:encoded><![CDATA[<p>Oracle Dataguard has his own command-line <i>dgmgrl</i> to check the whole dataguard configuration status.<br />
At least you should check that the <i>show configuration</i> command returns <b>SUCCESS</b>.</p>
<p>This is an hypothetic script:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">ORACLE_HOME</span>=<span style="color: #000000; font-weight: bold;">/</span>u1<span style="color: #000000; font-weight: bold;">/</span>app<span style="color: #000000; font-weight: bold;">/</span>oracle<span style="color: #000000; font-weight: bold;">/</span>product<span style="color: #000000; font-weight: bold;">/</span>10.2.0
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">ORACLE_SID</span>=orcldg
<span style="color: #007800;">result</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;show configuration;&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> \
  <span style="color: #007800;">$ORACLE_HOME</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>dgmgrl sys<span style="color: #000000; font-weight: bold;">/</span>strongpasswd <span style="color: #000000; font-weight: bold;">|</span> \
  <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-A</span> <span style="color: #000000;">1</span> <span style="color: #ff0000;">&quot;Current status for&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> <span style="color: #ff0000;">&quot;Current status for&quot;</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$result</span>&quot;</span> = <span style="color: #ff0000;">&quot;SUCCESS&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> ; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span>
<span style="color: #000000; font-weight: bold;">else</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>

<p>Another script should check for the gap between production online log and the log stream received by the standby database. This can be accomplished with v$managed_standby view.<br />
The Total Block Gap between production and standby can be calculated this way:<br />
Sum all blocks from v$archived_logs where seq# between  Current Standby Seq# and Current Production Seq#.  Then add current block# of the production LGWR process and subtract current block# from RFS standby process. This gives you total blocks even if there is a log sequence gap between sites.<br />
This is NOT the gap of online log APPLIED to the standby database. THIS IS THE GAP OF ONLINE LOG TRANSMITTED TO THE STANDBY RFS PROCESS and can be used to monitor your dataguard transmission from production to disaster recovery environment.</p>
<p>This is an excerpt of such script (please take care that it does not check against RFS failures, so it can fails when RFS is not alive):</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/u1/app/oracle/product/10.2.0/perl/bin/perl -w</span>
<span style="color: #000000; font-weight: bold;">use</span> DBI<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> DBD<span style="color: #339933;">::</span><span style="color: #006600;">Oracle</span> <span style="color: #000066;">qw</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">:</span>ora_session_modes<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;"># DB connection #</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$prod</span>  <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;orclprod&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$stby</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;orcldr&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$prodh</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">unless</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$prodh</span> <span style="color: #339933;">=</span> DBI<span style="color: #339933;">-&gt;</span><span style="color: #006600;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'dbi:Oracle:'</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$prod</span><span style="color: #339933;">,</span>
  <span style="color: #ff0000;">'sys'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'strongpassword'</span><span style="color: #339933;">,</span>
  <span style="color: #009900;">&#123;</span>PrintError<span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> AutoCommit <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
  ora_session_mode <span style="color: #339933;">=&gt;</span> ORA_SYSDBA<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>  <span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;Error connecting to DB: $DBI::errstr<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #0000ff;">$prodh</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>RaiseError<span style="color: #009900;">&#125;</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$stbyh</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">unless</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$stbyh</span> <span style="color: #339933;">=</span> DBI<span style="color: #339933;">-&gt;</span><span style="color: #006600;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'dbi:Oracle:'</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$stby</span><span style="color: #339933;">,</span>
  <span style="color: #ff0000;">'sys'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'strongpassword'</span><span style="color: #339933;">,</span>
  <span style="color: #009900;">&#123;</span>PrintError<span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> AutoCommit <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
  ora_session_mode <span style="color: #339933;">=&gt;</span> ORA_SYSDBA<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>  <span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;Error connecting to DB: $DBI::errstr<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #0000ff;">$prodh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">disconnect</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #0000ff;">$stbyh</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>RaiseError<span style="color: #009900;">&#125;</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$sth</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">### query prod</span>
<span style="color: #0000ff;">$sth</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$prodh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">prepare</span><span style="color: #009900;">&#40;</span> <span style="color: #339933;">&lt;</span> <span style="color: #339933;">&lt;</span>EOSQL <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">select</span> SEQUENCE<span style="color: #666666; font-style: italic;">#, BLOCK# from v\$managed_standby</span>
        where process<span style="color: #339933;">=</span><span style="color: #ff0000;">'LGWR'</span>
EOSQL
<span style="color: #0000ff;">$sth</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$psequence</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$pblock</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$sth</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">fetchrow_array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$sth</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">finish</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">### query stdby</span>
<span style="color: #0000ff;">$sth</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$stbyh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">prepare</span><span style="color: #009900;">&#40;</span> <span style="color: #339933;">&lt;</span> <span style="color: #339933;">&lt;</span>EOSQL <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">select</span> SEQUENCE<span style="color: #666666; font-style: italic;">#, BLOCK# from v\$managed_standby</span>
        where process<span style="color: #339933;">=</span><span style="color: #ff0000;">'RFS'</span> <span style="color: #b1b100;">and</span> client_process<span style="color: #339933;">=</span><span style="color: #ff0000;">'LGWR'</span>
EOSQL
<span style="color: #0000ff;">$sth</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$ssequence</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$sblock</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$sth</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">fetchrow_array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$sth</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">finish</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">printf</span> <span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;PROD   : %10d %10d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$psequence</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$pblock</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">printf</span> <span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;STANDBY: %10d %10d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$ssequence</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$sblock</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$sth</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$stbyh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">prepare</span><span style="color: #009900;">&#40;</span> <span style="color: #339933;">&lt;</span> <span style="color: #339933;">&lt;</span>EOSQL <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">select</span> nvl<span style="color: #009900;">&#40;</span>sum<span style="color: #009900;">&#40;</span>blocks<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
        <span style="color: #339933;">+</span> <span style="color: #0000ff;">$pblock</span> <span style="color: #339933;">-</span> <span style="color: #0000ff;">$sblock</span> as BLOCK_GAP
    from v<span style="color: #0000ff;">\$archived_log</span>
        where sequence<span style="color: #666666; font-style: italic;"># between $ssequence and $psequence</span>
EOSQL
<span style="color: #0000ff;">$sth</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$blockgap</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$sth</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">fetchrow_array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$sth</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">finish</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">printf</span> <span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;%-10d blocks gap<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$blockgap</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$stbyh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">disconnect</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$prodh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">disconnect</span><span style="color: #339933;">;</span></pre></div></div>

<p>Any comment is appreciated!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ludovicocaldara.net/dba/quick-oracle-dataguard-check-script/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Tips: Bash Prompt and Oracle</title>
		<link>http://www.ludovicocaldara.net/dba/tips-bash-prompt-and-oracle/</link>
		<comments>http://www.ludovicocaldara.net/dba/tips-bash-prompt-and-oracle/#comments</comments>
		<pubDate>Mon, 29 Dec 2008 23:19:18 +0000</pubDate>
		<dc:creator>Ludovico</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Oracle Database]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[prompt]]></category>

		<guid isPermaLink="false">http://www.ludovicocaldara.net/dba/?p=36</guid>
		<description><![CDATA[
export PS1=\u@\h:\w\$

I disagree with default bash prompt. Do you? It&#8217;s quote common to work with long paths:

ludovico@host:/u01/app/oracle/product/10.2.0/network/admin$ \
/nooo/this/command/line/is/really/long/and/offcourse -I \
-will -wrap -my -command -line

and, when working on multi-database environments I need to check my environment:

env &#124; grep -i oracle
#or
echo $ORACLE_SID
echo $ORACLE_HOME

I currently use this prompt, instead:

export PS1=$'\\n# [ $LOGNAME@\h:$PWD [\\t] [`ohvers` SID:${ORACLE_SID:-&#34;no sid&#34;}] ]\\n# '
&#160;
# [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PS1</span>=\u<span style="color: #000000; font-weight: bold;">@</span>\h:\<span style="color: #c20cb9; font-weight: bold;">w</span>\$</pre></div></div>

<p>I disagree with default bash prompt. Do you? It&#8217;s quote common to work with long paths:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ludovico<span style="color: #000000; font-weight: bold;">@</span>host:<span style="color: #000000; font-weight: bold;">/</span>u01<span style="color: #000000; font-weight: bold;">/</span>app<span style="color: #000000; font-weight: bold;">/</span>oracle<span style="color: #000000; font-weight: bold;">/</span>product<span style="color: #000000; font-weight: bold;">/</span>10.2.0<span style="color: #000000; font-weight: bold;">/</span>network<span style="color: #000000; font-weight: bold;">/</span>admin$ \
<span style="color: #000000; font-weight: bold;">/</span>nooo<span style="color: #000000; font-weight: bold;">/</span>this<span style="color: #000000; font-weight: bold;">/</span>command<span style="color: #000000; font-weight: bold;">/</span>line<span style="color: #000000; font-weight: bold;">/</span>is<span style="color: #000000; font-weight: bold;">/</span>really<span style="color: #000000; font-weight: bold;">/</span>long<span style="color: #000000; font-weight: bold;">/</span>and<span style="color: #000000; font-weight: bold;">/</span>offcourse <span style="color: #660033;">-I</span> \
<span style="color: #660033;">-will</span> <span style="color: #660033;">-wrap</span> <span style="color: #660033;">-my</span> <span style="color: #660033;">-command</span> <span style="color: #660033;">-line</span></pre></div></div>

<p>and, when working on multi-database environments I need to check my environment:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">env</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-i</span> oracle
<span style="color: #666666; font-style: italic;">#or</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$ORACLE_SID</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$ORACLE_HOME</span></pre></div></div>

<p>I currently use this prompt, instead:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PS1</span>=$<span style="color: #ff0000;">'\\n# [ $LOGNAME@\h:$PWD [\\t] [`ohvers` SID:${ORACLE_SID:-&quot;no sid&quot;}] ]\\n# '</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># [ ludovico@caldara_2k:/u01/app/oracle/product/10.2.0/db_1/network/admin [23:15:58] [10.2.0 SID:orcl] ]</span>
<span style="color: #666666; font-style: italic;">#</span></pre></div></div>

<p>What is `<em>ohvers</em>`?? I defined this function to get the version of oracle from my ORACLE_HOME variable:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ohvers <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">&#123;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #007800;">$ORACLE_HOME</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">'s/.*\/\([[:digit:].]\+\)\/.*/\1/p'</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>Pros:</p>
<ul>
<li>I have a blank line that separate my prompt from previous output</li>
<li>I get the system clock (useful when saving my konsole history. Did I say konsole?)</li>
<li>I can see my Oracle Environment before launching dangerous commands</li>
<li>I have an empty line to start my endless commands</li>
<li>I have a lot of sharps &#8220;#&#8221; : they are fine against wrong copy&amp;paste operations&#8230;</li>
</ul>
<p>Suggestions?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ludovicocaldara.net/dba/tips-bash-prompt-and-oracle/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Oracle RAC Standard Edition to achieve low cost and high performance</title>
		<link>http://www.ludovicocaldara.net/dba/oracle-rac-standard-edition-to-achieve-low-cost-and-high-performance/</link>
		<comments>http://www.ludovicocaldara.net/dba/oracle-rac-standard-edition-to-achieve-low-cost-and-high-performance/#comments</comments>
		<pubDate>Thu, 27 Nov 2008 23:43:04 +0000</pubDate>
		<dc:creator>Ludovico</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Oracle Database]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[cluster]]></category>
		<category><![CDATA[RAC]]></category>
		<category><![CDATA[Standard Edition]]></category>

		<guid isPermaLink="false">http://www.ludovicocaldara.net/dba/?p=29</guid>
		<description><![CDATA[I finished today to create a new production environment based on 2 Linux serverX86_64 and running Oracle RAC 10gR2. (I know, there is 11g right now, but I&#8217;m a conservative!)
Wheeew, I just spent a couple of hours applying all the recommended patches!
We choosed 2 nodes with a maximum of 2 multi-core processors each one so [...]]]></description>
			<content:encoded><![CDATA[<p>I finished today to create a new production environment based on 2 Linux serverX86_64 and running Oracle RAC 10gR2. (I know, there is 11g right now, but I&#8217;m a conservative!)<br />
Wheeew, I just spent a couple of hours applying all the recommended patches!<br />
We choosed 2 nodes with a maximum of 2 multi-core processors each one so we can license Standard Edition instead of Enterprise Edition. 64bits addressing allow us to allocate many gigabytes of SGA. I&#8217;m starting with 5Gb but I think we&#8217;ll need more. And a set of 6&#215;300Gb 15krpms disks (it can be expanded with more disks and more shelves).<br />
This configuration keeps low the total cost of ownership but achieves best performance.<br />
Due to disks layout, costs and needed usable storage, we had to configure one huge RAID5 on the SAN with multi-path. I decided anyway to create 2 ASM disk groups (ASM is mandatory for Standard Edition RAC), one for the DB, the second one for the recovery area. With spare disks we should have enough availability and even if it&#8217;s a RAID5 I saw good write performances (&gt;150M/s).</p>
<p>Welcome new RAC, I hope we&#8217;ll feel good together!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ludovicocaldara.net/dba/oracle-rac-standard-edition-to-achieve-low-cost-and-high-performance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>It&#8217;s time to trouble&#8230;</title>
		<link>http://www.ludovicocaldara.net/dba/its-time-to-trouble/</link>
		<comments>http://www.ludovicocaldara.net/dba/its-time-to-trouble/#comments</comments>
		<pubDate>Fri, 21 Nov 2008 10:42:58 +0000</pubDate>
		<dc:creator>Ludovico</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Oracle Database]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://www.ludovicocaldara.net/dba/?p=24</guid>
		<description><![CDATA[Sometimes it&#8217;s hard to find enough time to write something or even to only THINK about writing something&#8230;
The following are the projects I have to complete before the deadline of December 17th (at least if I still want to go on vacation&#8230;)

A totally new Oracle 10gR2 RAC SE on Linux (OCFS2, ASM) including jboss frontends, [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes <strong>it&#8217;s hard to find enough time to</strong> write something or even to only <strong>THINK about writing something</strong>&#8230;</p>
<p>The following are the projects I have to complete before the deadline of December 17th (at least if I still want to go on vacation&#8230;)</p>
<ul>
<li>A totally new <strong>Oracle 10gR2 RAC SE</strong> on Linux (<strong>OCFS2</strong>, <strong>ASM</strong>) including <strong>jboss</strong> frontends, backups, monitoring, documentation. (Servers are ready today).</li>
</ul>
<ul>
<li>A <strong>Disaster recovery</strong> architecture based on <strong>Dataguard</strong> with scripts based on rsync to do filesystem replication, with failover and failback, including backups, monitoring, documentation. (The server in DR site is reachable via network today).</li>
</ul>
<ul>
<li>A <strong>17 server</strong> infrastructure (among others a <strong>RAC 10gR2</strong> on linux) <strong>transfer</strong> from Milan datacenter to here. It&#8217;s planned for december 11th but I have to crosscheck backup and contingency requirements.</li>
</ul>
<ul>
<li>A <strong>14 serve</strong>r infrastructure (based on Windows and <strong>SqlServer</strong>) transfer from Milan datacenter to here. To be planned in december.</li>
</ul>
<ul>
<li>A totally new cold failover cluster based on linux with <strong>Oracle DBMS and E-business suite</strong> (Servers will be provided soon, I hope!).</li>
</ul>
<ul>
<li>A new standalone <strong>Windows Server 64bit</strong> to outstand the 32bit allocation bottleneck for a <strong>500Gb</strong> oracle database (Server will be provided not before december 10th).</li>
</ul>
<ul>
<li>Normally manage the day-by-day work, including replying to e-mails and answering the phone.</li>
</ul>
<p><strong>AARGH!!</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ludovicocaldara.net/dba/its-time-to-trouble/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>System triggers, stats$user_log and side effects</title>
		<link>http://www.ludovicocaldara.net/dba/system-triggers-statsuser_log-and-side-effects/</link>
		<comments>http://www.ludovicocaldara.net/dba/system-triggers-statsuser_log-and-side-effects/#comments</comments>
		<pubDate>Thu, 09 Oct 2008 15:44:21 +0000</pubDate>
		<dc:creator>Ludovico</dc:creator>
				<category><![CDATA[Oracle Database]]></category>
		<category><![CDATA[Performance]]></category>

		<guid isPermaLink="false">http://www.ludovicocaldara.net/dba/?p=22</guid>
		<description><![CDATA[Sometimes people get advice from internet: both Metalink or well-known consulting sites.
If people need a fix or a feature, they use to trust advices.
Last week I heard a collegue about a 10g RAC database with performance problems and, since I never lay on my chair, I probed both AWR and ADDM . I suddenly recognized [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes people get advice from internet: both Metalink or well-known consulting sites.<br />
If people need a fix or a feature, they use to trust advices.</p>
<p>Last week I heard a collegue about a 10g RAC database with performance problems and, since I never lay on my chair, I probed both AWR and ADDM . I suddenly recognized heavy enqueues and physical reads<br />
over a segment named STATS$USER_LOG. &#8220;Strange&#8221;, I said, &#8220;I cannot remember this name in neither perfstat or catalog segments&#8221;.<br />
Then I searched the Internet and the Metalink and found the same thing in BOTH metalink.oracle.com and www.dba-oracle.com: a trick to trace logon and logoffs into a table using system triggers.</p>
<p>Look at this code:</p>
<p><code>create or replace trigger<br />
logon_audit_trigger<br />
AFTER LOGON ON DATABASE<br />
BEGIN<br />
insert into stats$user_log values(<br />
user,<br />
sys_context('USERENV','SESSIONID'),<br />
sys_context('USERENV','HOST'),<br />
sysdate,<br />
to_char(sysdate, 'hh24:mi:ss'),<br />
[...]<br />
);<br />
COMMIT;<br />
END;<br />
/</code></p>
<p>Cool, every single access is kept into stats$user_log.</p>
<p>Let&#8217;s see the logoff trigger:</p>
<p><code>create or replace trigger<br />
logoff_audit_trigger<br />
BEFORE LOGOFF ON DATABASE<br />
BEGIN<br />
-- ***************************************************<br />
-- Update the last action accessed<br />
-- ***************************************************<br />
update stats$user_log [...]<br />
--***************************************************<br />
-- Update the last program accessed<br />
-- ***************************************************<br />
update stats$user_log [...]<br />
-- ***************************************************<br />
[ ... many, many updates ...]<br />
-- ***************************************************<br />
update stats$user_log [...]<br />
-- ***************************************************<br />
-- Compute the elapsed minutes<br />
-- ***************************************************<br />
update stats$user_log set elapsed_minutes =<br />
round((logoff_day - logon_day)*1440)<br />
where<br />
sys_context('USERENV','SESSIONID') = session_id;<br />
COMMIT;<br />
END;<br />
/<br />
</code><br />
That&#8217;s all. It inserts a row when someone logons. It updates MANY rows when someone logoffs.<br />
There is no match between the record inserted and the records updated (but the session_id).<br />
Neither indexes or constraints.</p>
<p>What&#8217;s the matter?</p>
<p>What happens if we have many logons?</p>
<p><code>SQL&gt; select num_rows from dba_tables where table_name='STATS$USER_LOG';</code></p>
<p>NUM_ROWS<br />
&#8212;&#8212;&#8212;-<br />
3053931</p>
<p>What happens if the execution plan does a full scan?</p>
<p>SQL&gt; explain plan for update stats$user_log [...]</p>
<p>Explained.</p>
<p><code>SQL&gt; @?/rdbms/admin/utlxpls<br />
---------------------------------------------<br />
| Id  | Operation          | Name           |<br />
---------------------------------------------<br />
|   0 | UPDATE STATEMENT   |                |<br />
|   1 |  UPDATE            | STATS$USER_LOG |<br />
|   2 |   TABLE ACCESS FULL| STATS$USER_LOG |<br />
---------------------------------------------</code></p>
<p>How many reads should it take?</p>
<p><code>SQL&gt; select bytes/1024/1024 Mb from dba_Segments where segment_name='STATS$USER_LOG';</code></p>
<p>MB<br />
&#8212;&#8212;&#8212;-<br />
237</p>
<p>The database performace will decrease constantly and very slowly&#8230;..<br />
Remember: never trust a solution if it involves a change on the system.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ludovicocaldara.net/dba/system-triggers-statsuser_log-and-side-effects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sometimes they come back</title>
		<link>http://www.ludovicocaldara.net/dba/sometimes-they-come-back/</link>
		<comments>http://www.ludovicocaldara.net/dba/sometimes-they-come-back/#comments</comments>
		<pubDate>Tue, 07 Oct 2008 09:08:31 +0000</pubDate>
		<dc:creator>Ludovico</dc:creator>
				<category><![CDATA[Oracle Database]]></category>
		<category><![CDATA[nt]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[use_shared_socket]]></category>

		<guid isPermaLink="false">http://www.ludovicocaldara.net/dba/?p=20</guid>
		<description><![CDATA[A collegue called me yesterday.
Collegue: &#8220;Hi, I cannot acces a customer database, it&#8217;s urgent. Can you help me?&#8221;
Me: &#8220;Did you ever connect to the database?&#8221;
Collegue: &#8220;Off course, but last monday netadmins reconfigured a router: that&#8217;s when the problem started.&#8221;
Me: &#8220;Reconfigured what?
Collegue: &#8220;A router: the router lost the config.&#8221;
I tried the connection to the database: network [...]]]></description>
			<content:encoded><![CDATA[<p>A collegue called me yesterday.<br />
Collegue: &#8220;Hi, I cannot acces a customer database, it&#8217;s urgent. Can you help me?&#8221;<br />
Me: &#8220;Did you ever connect to the database?&#8221;<br />
Collegue: &#8220;Off course, but last monday netadmins reconfigured a router: that&#8217;s when the problem started.&#8221;<br />
Me: &#8220;Reconfigured what?<br />
Collegue: &#8220;A router: the router lost the config.&#8221;</p>
<p>I tried the connection to the database: network timeout received.</p>
<p>Me: &#8220;Can the customer connect from his network?&#8221;<br />
Collegue: &#8220;Yes, it doesn&#8217;t work only from our network.&#8221;<br />
Me: &#8220;Is there a NAT?&#8221;<br />
Collegue: &#8220;Yes, the real address is different.&#8221;<br />
Me: &#8220;Is the db server running Windows&#8221;?<br />
Collegue: &#8220;I forgot! It&#8217;s a Windows NT.&#8221;<br />
Me: &#8220;Mmh, I should ask netadmins. Perhaps you can workaround putting &#8220;USE_SHARED_SOCKET&#8221; in the registry&#8230; Is the release at least 9i?&#8221;<br />
Collegue: &#8220;It&#8217;s a 7.3&#8243;<br />
Me: &#8220;@#&#8221;&#038;%!?&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ludovicocaldara.net/dba/sometimes-they-come-back/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Plot Oracle historical statistics within SQL*Plus</title>
		<link>http://www.ludovicocaldara.net/dba/plot-oracle-historical-statistics-within-sqlplus/</link>
		<comments>http://www.ludovicocaldara.net/dba/plot-oracle-historical-statistics-within-sqlplus/#comments</comments>
		<pubDate>Wed, 24 Sep 2008 13:43:42 +0000</pubDate>
		<dc:creator>Ludovico</dc:creator>
				<category><![CDATA[Oracle Database]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[awr]]></category>
		<category><![CDATA[dba_hist_sysstat]]></category>
		<category><![CDATA[graph]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[repository]]></category>
		<category><![CDATA[SQL*Plus]]></category>
		<category><![CDATA[workload]]></category>

		<guid isPermaLink="false">http://www.ludovicocaldara.net/dba/?p=10</guid>
		<description><![CDATA[More than often I&#8217;m asked to investigate &#8220;what happened yesterday when performance problems appeared&#8221;.
Sometimes I have the Enterprise Manager DB Console licensed, sometimes not. Sometimes I have direct SQL*Net access to the database that I may use to produce custom reports with my LAMP self-developed application. But it may happen that only an ssh access [...]]]></description>
			<content:encoded><![CDATA[<p>More than often I&#8217;m asked to investigate &#8220;what happened yesterday when performance problems appeared&#8221;.</p>
<p>Sometimes I have the Enterprise Manager DB Console licensed, sometimes not. Sometimes I have direct SQL*Net access to the database that I may use to produce custom reports with my LAMP self-developed application. But it may happen that only an ssh access is granted to the db server.</p>
<p>That&#8217;s why I started to develop some little scripts to plot the trends of database timed statistics.</p>
<p>Let&#8217;s see this one:<br />
<code><br />
SQL&gt; @sysstat.sql<br />
Enter a sysstat to search for: <strong>physical reads</strong></code><br />
<code><br />
STAT_ID     STAT_NAME<br />
----------- ------------------------------------------</code><br />
<strong>2263124246</strong><code> physical reads<br />
4171507801 physical reads cache<br />
297908839  physical reads cache prefetch<br />
2589616721 physical reads direct<br />
2564935310 physical reads direct (lob)<br />
2663793346 physical reads direct temporary tablespace<br />
473165409  physical reads for flashback new<br />
3102888545 physical reads prefetch warmup<br />
531193461  physical reads retry corrupt</code></p>
<p>9 rows selected.</p>
<p>Enter the desired stat_id: <strong>2263124246</strong><br />
<code>Enter the start date (YYYYMMDD) [defaults today] :</code><strong> 20080922</strong><br />
<code>Enter the end date date (YYYYMMDD) [defaults today] :</code><strong> 20080922</strong><br />
<code><br />
STAT_NAME        START    END<br />
---------------- -------- --------<br />
physical reads   20080922 20080922</code></p>
<p><code>BEGIN_INTERVAL_TIME           VALORE PLOTTED_VALUE<br />
------------------------- ---------- -------------------------<br />
22-SEP-08 12.00.12.122 AM          0<br />
22-SEP-08 01.00.28.253 AM     120092<br />
22-SEP-08 02.00.05.039 AM      35780<br />
22-SEP-08 03.00.55.595 AM       4792<br />
22-SEP-08 04.00.43.725 AM       4905<br />
22-SEP-08 05.00.31.855 AM       7300<br />
22-SEP-08 06.00.17.017 AM     234596<br />
22-SEP-08 07.00.08.132 AM      24651<br />
22-SEP-08 08.00.50.936 AM     481884<br />
22-SEP-08 09.00.33.488 AM     130201<br />
22-SEP-08 10.00.03.805 AM    1300306 **<br />
22-SEP-08 11.00.07.764 AM     491857<br />
22-SEP-08 12.00.31.548 PM     304702<br />
22-SEP-08 01.01.04.880 PM    1023664 *<br />
22-SEP-08 02.00.17.822 PM    8588180 ************<br />
22-SEP-08 03.00.36.969 PM    2201615 ***<br />
22-SEP-08 04.01.01.397 PM   17237098 *************************<br />
22-SEP-08 05.00.39.262 PM    1606300 **<br />
22-SEP-08 06.00.03.829 PM     451568<br />
22-SEP-08 07.00.31.461 PM     137684<br />
22-SEP-08 08.00.05.966 PM     203803<br />
22-SEP-08 09.00.24.829 PM     536394<br />
22-SEP-08 10.00.12.945 PM   10209783 **************<br />
22-SEP-08 11.00.35.123 PM    6151663 *********</code></p>
<p>24 rows selected.</p>
<p>Oh! At 4.00 PM we had a lot of physical reads. Nice.</p>
<p>This is the code:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">-- display given statistics from DBA_HIST_SYSSTAT</span>
col BEGIN_INTERVAL_TIME <span style="color: #993333; font-weight: bold;">FOR</span> a25
<span style="color: #993333; font-weight: bold;">SET</span> pages <span style="color: #cc66cc;">100</span> <span style="color: #993333; font-weight: bold;">LINES</span> <span style="color: #cc66cc;">130</span>
<span style="color: #993333; font-weight: bold;">SET</span> verify off term <span style="color: #993333; font-weight: bold;">ON</span>
&nbsp;
accept sysstat prompt <span style="color: #ff0000;">'Enter a sysstat to search for: '</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> STAT_ID<span style="color: #66cc66;">,</span> STAT_NAME
  <span style="color: #993333; font-weight: bold;">FROM</span> DBA_HIST_STAT_NAME
   <span style="color: #993333; font-weight: bold;">WHERE</span> lower<span style="color: #66cc66;">&#40;</span>STAT_NAME<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">LIKE</span> lower<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'%&amp;amp;sysstat%'</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> stat_name;
&nbsp;
accept stat_id prompt <span style="color: #ff0000;">'Enter the desired stat_id: '</span>
accept startdate prompt <span style="color: #ff0000;">'Start date (YYYYMMDD) [today] : '</span>
accept enddate prompt <span style="color: #ff0000;">'End date date (YYYYMMDD) [today] : '</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">SELECT</span> STAT_NAME<span style="color: #66cc66;">,</span>
  nvl<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'&amp;amp;startdate'</span><span style="color: #66cc66;">,</span>to_char<span style="color: #66cc66;">&#40;</span>sysdate<span style="color: #66cc66;">,</span><span style="color: #ff0000;">'YYYYMMDD'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;START&quot;</span><span style="color: #66cc66;">,</span>
  nvl<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'&amp;amp;enddate'</span><span style="color: #66cc66;">,</span>to_char<span style="color: #66cc66;">&#40;</span>sysdate<span style="color: #66cc66;">,</span><span style="color: #ff0000;">'YYYYMMDD'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;END&quot;</span>
 <span style="color: #993333; font-weight: bold;">FROM</span> DBA_HIST_STAT_NAME
<span style="color: #993333; font-weight: bold;">WHERE</span> STAT_ID <span style="color: #66cc66;">=</span> &amp;amp;stat_id;
&nbsp;
<span style="color: #993333; font-weight: bold;">SELECT</span> BEGIN_INTERVAL_TIME<span style="color: #66cc66;">,</span> VALORE<span style="color: #66cc66;">,</span>
  substr<span style="color: #66cc66;">&#40;</span> rpad<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'*'</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">40</span><span style="color: #66cc66;">*</span>round<span style="color: #66cc66;">&#40;</span> VALUE<span style="color: #66cc66;">/</span>max<span style="color: #66cc66;">&#40;</span>VALORE<span style="color: #66cc66;">&#41;</span>over<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'*'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">40</span><span style="color: #66cc66;">&#41;</span> PLOTTED_VALORE
  <span style="color: #993333; font-weight: bold;">FROM</span> <span style="color: #66cc66;">&#40;</span>
  <span style="color: #993333; font-weight: bold;">SELECT</span> s<span style="color: #66cc66;">.</span>BEGIN_INTERVAL_TIME BEGIN_INTERVAL_TIME<span style="color: #66cc66;">,</span>
    nvl<span style="color: #66cc66;">&#40;</span>decode<span style="color: #66cc66;">&#40;</span>greatest<span style="color: #66cc66;">&#40;</span>VALUE<span style="color: #66cc66;">,</span> nvl<span style="color: #66cc66;">&#40;</span>lag<span style="color: #66cc66;">&#40;</span>VALUE<span style="color: #66cc66;">&#41;</span> over
      <span style="color: #66cc66;">&#40;</span>partition <span style="color: #993333; font-weight: bold;">BY</span> s<span style="color: #66cc66;">.</span>dbid<span style="color: #66cc66;">,</span> s<span style="color: #66cc66;">.</span>instance_number<span style="color: #66cc66;">,</span> g<span style="color: #66cc66;">.</span>stat_name <span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> s<span style="color: #66cc66;">.</span>snap_id<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
    VALUE<span style="color: #66cc66;">,</span>
    VALUE <span style="color: #66cc66;">-</span> lag<span style="color: #66cc66;">&#40;</span>VALUE<span style="color: #66cc66;">&#41;</span> over
      <span style="color: #66cc66;">&#40;</span>partition <span style="color: #993333; font-weight: bold;">BY</span> s<span style="color: #66cc66;">.</span>dbid<span style="color: #66cc66;">,</span> s<span style="color: #66cc66;">.</span>instance_number<span style="color: #66cc66;">,</span> g<span style="color: #66cc66;">.</span>stat_name <span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> s<span style="color: #66cc66;">.</span>snap_id<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>VALUE<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> VALORE
  <span style="color: #993333; font-weight: bold;">FROM</span> DBA_HIST_SNAPSHOT s<span style="color: #66cc66;">,</span>
          DBA_HIST_SYSSTAT g<span style="color: #66cc66;">,</span>
          v$instance i
  <span style="color: #993333; font-weight: bold;">WHERE</span> s<span style="color: #66cc66;">.</span>SNAP_ID<span style="color: #66cc66;">=</span>g<span style="color: #66cc66;">.</span>SNAP_ID
  <span style="color: #993333; font-weight: bold;">AND</span> g<span style="color: #66cc66;">.</span>STAT_ID<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'&amp;amp;stat_id'</span>
  <span style="color: #993333; font-weight: bold;">AND</span> s<span style="color: #66cc66;">.</span>BEGIN_INTERVAL_TIME &amp;gt;<span style="color: #66cc66;">=</span>
    trunc<span style="color: #66cc66;">&#40;</span>to_timestamp<span style="color: #66cc66;">&#40;</span>nvl<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'&amp;amp;startdate'</span><span style="color: #66cc66;">,</span>to_char<span style="color: #66cc66;">&#40;</span>sysdate<span style="color: #66cc66;">,</span><span style="color: #ff0000;">'YYYYMMDD'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'YYYYMMDD'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #993333; font-weight: bold;">AND</span> s<span style="color: #66cc66;">.</span>BEGIN_INTERVAL_TIME &amp;lt; <span style="color: #66cc66;">=</span>
   trunc<span style="color: #66cc66;">&#40;</span>to_timestamp<span style="color: #66cc66;">&#40;</span>nvl<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'&amp;amp;enddate'</span><span style="color: #66cc66;">,</span>to_char<span style="color: #66cc66;">&#40;</span>sysdate<span style="color: #66cc66;">,</span><span style="color: #ff0000;">'YYYYMMDD'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'YYYYMMDD'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">+</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #993333; font-weight: bold;">AND</span> s<span style="color: #66cc66;">.</span>instance_number<span style="color: #66cc66;">=</span>i<span style="color: #66cc66;">.</span>instance_number
  <span style="color: #993333; font-weight: bold;">AND</span> s<span style="color: #66cc66;">.</span>instance_number<span style="color: #66cc66;">=</span>g<span style="color: #66cc66;">.</span>instance_number
  <span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #cc66cc;">1</span>
<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>Ciao<br />
&#8211;<br />
Ludovico</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ludovicocaldara.net/dba/plot-oracle-historical-statistics-within-sqlplus/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
