<?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>DBAToolZ &#187; microseconds</title>
	<atom:link href="http://www.dbatoolz.com/t/tag/microseconds/feed" rel="self" type="application/rss+xml" />
	<link>http://www.dbatoolz.com</link>
	<description>Lightweight Oracle DBA Tools</description>
	<lastBuildDate>Tue, 16 Feb 2010 01:17:35 +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>Making sense of ASH TIME_WAITED Units</title>
		<link>http://www.dbatoolz.com/t/ash-time_waited-units.html</link>
		<comments>http://www.dbatoolz.com/t/ash-time_waited-units.html#comments</comments>
		<pubDate>Fri, 31 Jul 2009 23:25:46 +0000</pubDate>
		<dc:creator>MVE</dc:creator>
				<category><![CDATA[Tuning]]></category>
		<category><![CDATA[ASH]]></category>
		<category><![CDATA[DBA_HIST_SQLSTAT]]></category>
		<category><![CDATA[microseconds]]></category>
		<category><![CDATA[SQL_ID]]></category>
		<category><![CDATA[TIME_WAITED]]></category>
		<category><![CDATA[v$active_session_history]]></category>
		<category><![CDATA[WAIT_TIME]]></category>

		<guid isPermaLink="false">http://www.dbatoolz.com/?p=374</guid>
		<description><![CDATA[It&#8217;s widely believed that v$active_session_history.TIME_WAITED is presented in microseconds.  It sure seems like it, but something is amiss as my small test shows. Using two sessions I created a test table in one, inserted a row and then from another session tried to select the same row for update:

&#124; session A &#62; SQL&#62; create [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s widely believed that v$active_session_history.TIME_WAITED is presented in <a href="http://www.google.com/search?q=define%3Amicroseconds">microseconds</a>.  It sure seems like it, but something is amiss as my small test shows. Using two sessions I created a test table in one, inserted a row and then from another session tried to select the same row for update:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">| session A &gt; SQL&gt; create table ash_time_waited_test (t number);
| session A &gt; 
| session A &gt; Table created.
| session A &gt; 
| session A &gt; SQL&gt; insert into ash_time_waited_test values(1);
| session A &gt; 
| session A &gt; 1 row created.
| session A &gt; 
| session A &gt; SQL&gt; commit;
| session A &gt; 
| session A &gt; Commit complete.
| session A &gt; 
| session A &gt; SQL&gt; update ash_time_waited_test set t=2 where t=1;
| session A &gt; 
| session A &gt; 1 row updated.
&nbsp;
| session B &gt; SQL&gt; !date
| session B &gt; Thu Jul 30 18:20:15 PDT 2009
| session B &gt; 
| session B &gt; SQL&gt; select * from ash_time_waited_test for update;
&nbsp;
| session A &gt; 
| session A &gt; SQL&gt; commit;
| session A &gt; 
| session A &gt; Commit complete.
| session A &gt; 
| session A &gt; SQL&gt;
| session A &gt; 
&nbsp;
| session B &gt; 
| session B &gt;          T
| session B &gt; ----------
| session B &gt;          2
| session B &gt; 
| session B &gt; SQL&gt; !date
| session B &gt; Thu Jul 30 18:20:38 PDT 2009
| session B &gt;</pre></div></div>

<p>What I found next was rather strange &#8212; the sum(TIME_WAITED) from ASH (<a href="http://download.oracle.com/docs/cd/B19306_01/server.102/b14237/dynviews_1007.htm">v$active_session_history</a>) did not add up to the total time <strong>session A</strong> kept the lock on the test table:</p>
<p>First we get the SQL_ID for session B (the waiter) so we can tie into ASH.SQL_ID later:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">SQL&gt; select sql_id from v$sql where sql_text = 'select * from ash_time_waited_test for update';
&nbsp;
SQL_ID
-------------
fpm89fyrsf6gv</pre></div></div>

<p>Now having the SQL_ID in hand we can dig into ASH to see what waits our session experienced:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">SQL&gt; col SAMPLE_TIME format a25
SQL&gt; col event format a30
SQL&gt; select sample_time,EVENT,WAIT_TIME,TIME_WAITED from v$active_session_history
  2  where sql_id = 'fpm89fyrsf6gv'
  3  order by sample_time;
&nbsp;
SAMPLE_TIME               EVENT                           WAIT_TIME TIME_WAITED
------------------------- ------------------------------ ---------- -----------
30-JUL-09 06.20.25.751 PM enq: TX - row lock contention           0      489233
30-JUL-09 06.20.26.761 PM enq: TX - row lock contention           0      489244
30-JUL-09 06.20.27.761 PM enq: TX - row lock contention           0      489242
30-JUL-09 06.20.28.761 PM enq: TX - row lock contention           0      489238
30-JUL-09 06.20.29.761 PM enq: TX - row lock contention           0      489244
30-JUL-09 06.20.30.761 PM enq: TX - row lock contention           0      489242
30-JUL-09 06.20.31.761 PM enq: TX - row lock contention           0      489244
30-JUL-09 06.20.32.761 PM enq: TX - row lock contention           0      489253
30-JUL-09 06.20.33.761 PM enq: TX - row lock contention           0      489233
30-JUL-09 06.20.34.761 PM enq: TX - row lock contention           0      489245
30-JUL-09 06.20.35.761 PM enq: TX - row lock contention           0      489245
&nbsp;
11 rows selected.
&nbsp;
SQL&gt;</pre></div></div>

<p>Based on the output above we know that the first sample that trapped this wait occurred at &#8220;06.20.25.751 PM&#8221; and the last one at &#8220;06.20.35.761 PM&#8221;.  The difference (delta) between these two timestamps is just over 10 seconds:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">SQL&gt; select e.SAMPLE_TIME - s.SAMPLE_TIME
  2  from v$active_session_history s,
  3       v$active_session_history e
  4  where s.sample_id = (select min(sample_id) from v$active_session_history where sql_id = 'fpm89fyrsf6gv')
  5    and e.sample_id = (select max(sample_id) from v$active_session_history where sql_id = 'fpm89fyrsf6gv')
  6  ;
&nbsp;
E.SAMPLE_TIME-S.SAMPLE_TIME
---------------------------------------------------------------------------
+000000000 00:00:10.010
&nbsp;
SQL&gt;</pre></div></div>

<p>So far so good.  Now lets see what we get by summing up the TIME_WAITED:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">SQL&gt; select sum(TIME_WAITED) from v$active_session_history
  2  where sql_id = 'fpm89fyrsf6gv'
  3  ;
&nbsp;
SUM(TIME_WAITED)
----------------
         5381663</pre></div></div>

<p>Interesting?  If the ASH.TIME_WAITED is measured in microseconds then the total wait time = 5381663/1000000 = 5.381663 seconds and as we know it&#8217;s not correct.  In fact, we can prove this using another metric, the <a href="http://download.oracle.com/docs/cd/B19306_01/server.102/b14237/statviews_3183.htm#I1023447">ELAPSED_TIME_* from DBA_HIST_SQLSTAT</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">SQL&gt; select ELAPSED_TIME_TOTAL, ELAPSED_TIME_DELTA,
  2  APWAIT_TOTAL, APWAIT_DELTA,
  3  CCWAIT_TOTAL, CCWAIT_DELTA
  4  from DBA_HIST_SQLSTAT
  5  where sql_id = 'fpm89fyrsf6gv'
  6  ;
&nbsp;
ELAPSED_TIME_TOTAL ELAPSED_TIME_DELTA APWAIT_TOTAL APWAIT_DELTA CCWAIT_TOTAL CCWAIT_DELTA
------------------ ------------------ ------------ ------------ ------------ ------------
          11110172           11110172     11106973     11106973          254          254
&nbsp;
SQL&gt;</pre></div></div>

<p>DBA_HIST_SQLSTAT is dead on &#8212; with Elapsed Time Total = 11110172/1000000 = 11.110172 seconds &#8230;  So what&#8217;s happening with ASH then?  Why such a large > 2 times discrepancy?</p>
<p>I have my theory &#8212; I think that because ASH sampling is taken every second half of that seconds is actually taken to process the data and for this reason the TIME_WAITED gets truncated.  Whatever the reason is, one thing is for sure &#8212; ASH.TIME_WAITED, at least in this particular case, cannot be trusted.</p>
<p>The final question &#8230; how do you then use ASH?  How do you arrive at a more or less accurate metrics, specifically the TIME_WAITED?  One way is this &#8212; we know what ASH sampling takes place every second, so instead of relying on the buggy TIME_WAITED values we can rely on the actual number of times that a SQL_ID appeared in ASH &#8230;  If a SQL_ID was trapped by ASH 10 consecutive times with WAIT_TIME=0 (Waiting) we then know for sure that it waited for at least 10 seconds &#8230;</p>
<p><strong>UPDATE Aug 12, 2009</strong></p>
<p>Graham Wood from Oracle explains the issue with ASH: TIME_WAITED in his paper <a href="http://www.oracle.com/technology/products/manageability/database/pdf/twp03/PPT_active_session_history.pdf">Sifting through the ASHes</a> (see Page 35).  He also lists some other &#8220;ASH data gotcha&#8217;s&#8221; on page 27.  What really caught my attention through, was page 36, which explains &#8220;ASH vs AWR/Statpack&#8221; and it specifically says that for &#8220;<strong>Counts/occurrence data</strong>&#8221; analysis you should go to <strong>AWR</strong> not ASH.</p>
<p>And it really makes sense, after all, ASH is sampled every second and while it sounds like &#8220;often enough&#8221; it really isn&#8217;t.  All you have to do is run sql_trace on a busy session and you&#8217;ll see that there&#8217;s a lot that goes on between the 1 second intervals &#8212; all of it would be missed by ASH.  ASH is great at putting spotlight on the &#8220;big issues&#8221;, not so great for subtle, sub second waits which could and do add up to a considerable wait time.</p>
<p>Bottom line for me is that <strong>there&#8217;s no substitute for the good, old sql_trace</strong>, but overall, <strong>ASH is a huge improvement </strong>over what we had or rather didn&#8217;t have before.  It definitely replaces my own monitoring scripts which I&#8217;ve used for many years now, sampling v$session_wait where wait_time=0 every 5 seconds.</p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.dbatoolz.com/t/ash-time_waited-units.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
