<?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</title>
	<atom:link href="http://www.ludovicocaldara.net/dba/tag/oracle/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>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>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>
