<?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>Tanel Poder's blog: Core IT for Geeks and Pros &#187; DTrace</title>
	<atom:link href="http://blog.tanelpoder.com/category/dtrace/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.tanelpoder.com</link>
	<description>Oracle troubleshooting, internals and performance tuning</description>
	<lastBuildDate>Sat, 31 Jul 2010 05:44:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>SystemTap is production supported in Redhat EL5.4</title>
		<link>http://blog.tanelpoder.com/2009/10/25/systemtap-is-production-supported-in-redhat-el5-4/</link>
		<comments>http://blog.tanelpoder.com/2009/10/25/systemtap-is-production-supported-in-redhat-el5-4/#comments</comments>
		<pubDate>Sun, 25 Oct 2009 15:53:45 +0000</pubDate>
		<dc:creator>Tanel Poder</dc:creator>
				<category><![CDATA[Cool stuff]]></category>
		<category><![CDATA[DTrace]]></category>
		<category><![CDATA[Internals]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Troubleshooting]]></category>

		<guid isPermaLink="false">http://blog.tanelpoder.com/?p=467</guid>
		<description><![CDATA[If you don&#8217;t know what SystemTap is &#8211; it&#8217;s the Linux world&#8217;s attempt to build Solaris DTrace style safe dynamic instrumentation into Linux kernel. I&#8217;m not going into religious discussions which one is better here, I have used both SystemTap and DTrace successfully for diagnosing low level issues inside OS kernel, so both are good [...]]]></description>
			<content:encoded><![CDATA[<p>If you don&#8217;t know what SystemTap is &#8211; it&#8217;s the Linux world&#8217;s attempt to build Solaris DTrace style <strong><em>safe</em> <em>dynamic</em></strong> instrumentation into Linux kernel.</p>
<p>I&#8217;m not going into religious discussions which one is better here, I have used both SystemTap and DTrace successfully for diagnosing low level issues inside OS kernel, so both are good enough for me :)</p>
<p>The problem with SystemTap though has been that it&#8217;s not production quality, it&#8217;s rather been a technology preview.</p>
<p>But with RHEL 5.4 part of it has changed, Redhat says following in <a href="http://blog.tanelpoder.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5yZWRoYXQuY29tL2RvY3MvZW4tVVMvUmVkX0hhdF9FbnRlcnByaXNlX0xpbnV4LzUuNC9odG1sL1RlY2huaWNhbF9Ob3Rlcy9zeXN0ZW10YXAuaHRtbA==" target=\"_blank\">this article</a>:</p>
<div>
<p><em>SystemTap is no longer a technology preview, and now has production support. Red Hat recommendeds that users run scripts on development machines before deployment in production environments. Since SystemTap is an optional diagnostic tool, users can easily stop using it in the event of a problem. Options such as <code>-g</code> for Guru mode, and <code>-D*</code> allow users to disable several security checks. Scripts using these options may not be supported.</em></div>
<div>
<p><em>Red Hat plans to fix problems in SystemTap, or the Linux kernel, as they arise in connection with new scripts. In some cases, a fix may include extending the blacklist for known areas of the Linux kernel that are unsafe to probe. All scripts that use probes targeting blacklisted areas will need to be revised.</em></div>
<div>
<p><em>SystemTap users are advised to upgrade to this version.</em></div>
<div><em><br />
</em></div>
<div>
<p>So, at least officially, SystemTap is now supported by Redhat. Well at least as long as you&#8217;re not doing crazy stuff with the -g option, the geek mode ;-)</p></div>
<div>
<p>I would still be very careful before using any SystemTap in production, in fact, in critial environments I wouldn&#8217;t run it at all, unless there is no other option (and you&#8217;re prepared to get a crash + kernel panic).</p></div>
<div>
<p>However the significance of this note is that SystemTap is accepted for production by Redhat in principle. So now it&#8217;s just matter of time until it gets stable and widely used enough to be as practical and useful as DTrace is on Solaris.</p></div>
<div class="facebook_like_button"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.tanelpoder.com%2F2009%2F10%2F25%2Fsystemtap-is-production-supported-in-redhat-el5-4%2F&amp;layout=standard&amp;show-faces=true&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="padding: 0px 0px; border:none; overflow:hidden; width:450px; height:70px;"></iframe></div> <img src="http://blog.tanelpoder.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=467" width="1" height="1" style="display: none;" /><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://blog.tanelpoder.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.tanelpoder.com/2009/10/25/systemtap-is-production-supported-in-redhat-el5-4/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Tracing Oracle SQL plan execution with DTrace</title>
		<link>http://blog.tanelpoder.com/2009/04/24/tracing-oracle-sql-plan-execution-with-dtrace/</link>
		<comments>http://blog.tanelpoder.com/2009/04/24/tracing-oracle-sql-plan-execution-with-dtrace/#comments</comments>
		<pubDate>Fri, 24 Apr 2009 06:11:48 +0000</pubDate>
		<dc:creator>Tanel Poder</dc:creator>
				<category><![CDATA[Cool stuff]]></category>
		<category><![CDATA[DTrace]]></category>
		<category><![CDATA[Internals]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Troubleshooting]]></category>

		<guid isPermaLink="false">http://blog.tanelpoder.com/2009/04/24/tracing-oracle-sql-plan-execution-with-dtrace/</guid>
		<description><![CDATA[SQL is a declarative language &#8211; in other words you just declare what needs to be done and Oracle takes care of the part how it&#8217;s done. However there&#8217;s nothing declarative about the actual SQL execution when it happens. SQL plan is just a tree of kernel rowsource functions executed in a specific order (defined [...]]]></description>
			<content:encoded><![CDATA[<p>SQL is a declarative language &#8211; in other words you just declare <b>what</b> needs to be done and Oracle takes care of the part <b>how</b> it&#8217;s done.</p>
<p>However there&#8217;s nothing declarative about the actual SQL execution when it happens. <b>SQL plan is just a tree of kernel rowsource functions executed in a specific order</b> (defined in child cursor&#8217;s sql area).</p>
<p>The root of SQL plan is where the fetch function (opifch2 for example) gets the rows for passing back to the user (or PL/SQL engine).<br />
The branches are operations like joins, union etc, which don&#8217;t have access to any data themselves and can just call other functions recursively to get rows<br />
The leaves are the execution plan operations without any children, they call data layer to acces actual datablocks. </p>
<p>The first execution plan line (with lowest ID) without any children is the one where data access starts, that&#8217;s the place where first logical IO happens.</p>
<p>A commented exec plan is below:</p>
<pre><code>SQL> select count(*) from all_users;

  COUNT(*)
----------
        35

SQL> @x

PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
SQL_ID  b2zqhgr5tzbpk, child number 0
-------------------------------------
select count(*) from all_users

Plan hash value: 3268326079

--------------------------------------------------------------------------
| Id  | Operation            | Name  | E-Rows |  OMem |  1Mem | Used-Mem |
--------------------------------------------------------------------------
|   1 |  SORT AGGREGATE      |       |      1 |       |       |          |       <b>&lt;- ROOT</b>
|*  2 |   HASH JOIN          |       |     35 |  1517K|  1517K|  637K (0)| <b>&lt;- BRANCH</b>
|*  3 |    HASH JOIN         |       |     35 |  1593K|  1593K| 1361K (0)| <b>&lt;- BRANCH</b>
|   4 |     TABLE ACCESS FULL| TS$   |     13 |       |       |          |   <b>&lt;- LEAF</b>
|*  5 |     TABLE ACCESS FULL| USER$ |     35 |       |       |          |    <b>&lt;- LEAF</b>
|   6 |    TABLE ACCESS FULL | TS$   |     13 |       |       |          |    <b>&lt;- LEAF</b>
--------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   2 - access("U"."TEMPTS#"="TTS"."TS#")
   3 - access("U"."DATATS#"="DTS"."TS#")
   5 - filter("U"."TYPE#"=1)

</code></pre>
<p>I have written about how to map execution plan lines back to kernel functions here:</p>
<p><a href="http://blog.tanelpoder.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2Jsb2cudGFuZWxwb2Rlci5jb20vMjAwOC8wNi8xNS9hZHZhbmNlZC1vcmFjbGUtdHJvdWJsZXNob290aW5nLWd1aWRlLXBhcnQtNi11bmRlcnN0YW5kaW5nLW9yYWNsZS1leGVjdXRpb24tcGxhbnMtd2l0aC1vc19leHBsYWluLw==">http://blog.tanelpoder.com/2008/06/15/advanced-oracle-troubleshooting-guide-part-6-understanding-oracle-execution-plans-with-os_explain/</a></p>
<p>The above approach is based on pstack, mostly useful for demonstrations but has helped me to diagnose one spinning condition in an execution plan once (that&#8217;s the whole reason I came up with this technique).</p>
<p>As I said above, SQL execution just means that the kernel&#8217;s rowsource functions are executed in a loop with order and hierarchy specified in the child cursor&#8217;s execution plan.</p>
<p>So, if you want to learn and really understand the sequence of SQL plan execution &#8211; it&#8217;s dead easy with DTrace. Here&#8217;s what happens when you fetch from the above execution plan:</p>
<p><span id="more-282"></span></p>
<pre><code>solaris02$ dtrace -p 1063 -Fn 'pid$target:oracle:<b>qer*Fetch*</b>:entry pid$target:oracle:<b>qer*Fetch*</b>:return' | tee plan.txt
dtrace: description 'pid$target:oracle:qer*Fetch*:entry pid$target:oracle:qer*Fetch*:return' matched 264 probes
CPU FUNCTION
  1  -&gt; qergsFetch
  1    -&gt; qerhjFetch
  1      -&gt; qerhjFetch
  1        -&gt; qertbFetch
  1        &lt;- qertbFetch
  1        -&gt; qertbFetch
  1        &lt;- qertbFetch
  1      &lt;- qerhjFetch
  1      -&gt; qertbFetch
  1      &lt;- qertbFetch
  1    &lt;- qerhjFetch
  1  &lt;- qergsFetch
^C

</code></pre>
<p>qer*Fetch functions are the Query Execution Runtime (or Rowsource if you like) functions. They are the functions corresponding to lines you see in an execution plan. </p>
<p>So I used the knowledge from Metalink note 175982.1 to write a little sed script which replaces the function name with its description (you need to do this yourself or look into my os_explain shell script):</p>
<pre><code>solaris02$ <b>sed -f os_explain.sed plan.txt</b>
CPU FUNCTION
  1  -&gt; GROUP BY SORT: Fetch
  1    -&gt; HASH JOIN: Fetch
  1      -&gt; HASH JOIN: Fetch
  1        -&gt; TABLE ACCESS: Fetch
  1        &lt;- TABLE ACCESS: Fetch
  1        -&gt; TABLE ACCESS: Fetch
  1        &lt;- TABLE ACCESS: Fetch
  1      &lt;- HASH JOIN: Fetch
  1      -&gt; TABLE ACCESS: Fetch
  1      &lt;- TABLE ACCESS: Fetch
  1    &lt;- HASH JOIN: Fetch
  1  &lt;- GROUP BY SORT: Fetch
solaris02$

</code></pre>
<p>Voila, here&#8217;s the sequence of execution plan line invocations due the fetch.</p>
<p>Of course there&#8217;s more than just that to understand the whole picture, but I hope I demonstrated, tracing plan execution is not a hard topic. If you want more, hire me for a special seminar ;-)</p>
<div class="facebook_like_button"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.tanelpoder.com%2F2009%2F04%2F24%2Ftracing-oracle-sql-plan-execution-with-dtrace%2F&amp;layout=standard&amp;show-faces=true&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="padding: 0px 0px; border:none; overflow:hidden; width:450px; height:70px;"></iframe></div> <img src="http://blog.tanelpoder.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=282" width="1" height="1" style="display: none;" /><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://blog.tanelpoder.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.tanelpoder.com/2009/04/24/tracing-oracle-sql-plan-execution-with-dtrace/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Oracle hidden costs revealed, Part2 &#8211; Using DTrace to find why writes in SYSTEM tablespace are slower than in others</title>
		<link>http://blog.tanelpoder.com/2008/09/02/oracle-hidden-costs-revealed-part2-using-dtrace-to-find-why-writes-in-system-tablespace-are-slower-than-in-others/</link>
		<comments>http://blog.tanelpoder.com/2008/09/02/oracle-hidden-costs-revealed-part2-using-dtrace-to-find-why-writes-in-system-tablespace-are-slower-than-in-others/#comments</comments>
		<pubDate>Mon, 01 Sep 2008 17:16:50 +0000</pubDate>
		<dc:creator>Tanel Poder</dc:creator>
				<category><![CDATA[Administration]]></category>
		<category><![CDATA[DTrace]]></category>
		<category><![CDATA[Internals]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://tanelpoder.wordpress.com/2008/09/02/oracle-hidden-costs-revealed-part2-using-dtrace-to-find-why-writes-in-system-tablespace-are-slower-than-in-others/</guid>
		<description><![CDATA[I have written two posts in one, about a performance issue with writes in system tablespace and introduction of a little DTrace stack sampling script. Have you noticed that DML on tables residing in SYSTEM tablespace is slower than tables in other tablespaces? Here&#8217;s an example, I&#8217;ll create two similar tables, one in USERS tablespace, [...]]]></description>
			<content:encoded><![CDATA[<p><em>I have written two posts in one, about a performance issue with writes in system tablespace and introduction of a little DTrace stack sampling script.<br />
</em></p>
<p>Have you noticed that DML on tables residing in SYSTEM tablespace is slower than tables in other tablespaces?</p>
<p>Here&#8217;s an example, I&#8217;ll create two similar tables, one in USERS tablespace, other in SYSTEM, and inset into the first one (Oracle 10.2.0.3 on Solaris x64):</p>
<pre><code>SQL&gt; create table <strong>t1</strong>(a int) tablespace <strong>USERS</strong>;

Table created.

SQL&gt; create table <strong>t2</strong>(a int) tablespace <strong>SYSTEM</strong>;

Table created.

SQL&gt; exec for i in 1..100000 loop insert into <strong>t1</strong> values(i); end loop;

PL/SQL procedure successfully completed.

Elapsed: 00:00:<strong>03.09</strong>

</code></pre>
<p>Insert into table in USERS tablespace took 3 seconds.</p>
<p>Ok, let&#8217;s commit and flush dirty buffers that they wouldn&#8217;t get on the way of next insert.</p>
<pre><code>SQL&gt; commit;

Commit complete.

Elapsed: 00:00:00.02

SQL&gt; alter system checkpoint; <em>-- checkpointing to flush dirty buffers from previous inserts</em>

System altered.

Elapsed: 00:00:01.34
SQL&gt;

</code></pre>
<p>And now to the insert into the SYSTEM tablespace table:</p>
<pre><code>SQL&gt; exec for i in 1..100000 loop insert into <strong>t2</strong> values(i); end loop;

PL/SQL procedure successfully completed.

Elapsed: 00:00:<strong>08.98</strong>
SQL&gt;

</code></pre>
<p>What?! The same insert took 3 times longer, almost 9 seconds?</p>
<p>Fine! Let&#8217;s troubleshoot it!</p>
<p><span id="more-132"></span></p>
<p><!-- more --></p>
<p>First (as usual) I start from my Snapper for getting a performance snapshot of the session. I ran both inserts again and used Snapper from another session to monitor the insert activity (for brevity I didn&#8217;t monitor all stat counters, but used the sinclude filter to leave only various &#8220;gets&#8221; in from V$SESSTAT).</p>
<p>This is the insert to USERS tablespace table:</p>
<pre><code>SQL&gt; @snapper out,gather=tsw,<strong>sinclude=gets</strong> 10 1 148

-- Session Snapper v1.07 by Tanel Poder ( http://www.tanelpoder.com )

---------------------------------------------------------------------------------------------------------------------------------------------
HEAD,     SID, SNAPSHOT START   ,  SECONDS, TYPE, STATISTIC                               ,         DELTA,  DELTA/SEC,     HDELTA, HDELTA/SEC
---------------------------------------------------------------------------------------------------------------------------------------------
DATA,     148, 20080901 17:20:53,       10, STAT, db block gets                           ,        103448,      10345,    103.45k,     10.34k
DATA,     148, 20080901 17:20:53,       10, STAT, db block gets from cache                ,        103448,      10345,    103.45k,     10.34k
DATA,     148, 20080901 17:20:53,       10, STAT, consistent gets                         ,           495,         49,        495,       49.5
DATA,     148, 20080901 17:20:53,       10, STAT, consistent gets from cache              ,           495,         49,        495,       49.5
DATA,     148, 20080901 17:20:53,       10, STAT, consistent gets - examination           ,           219,         22,        219,       21.9
DATA,     148, 20080901 17:20:53,       10, STAT, no work - consistent read gets          ,            89,          9,         89,        8.9
DATA,     148, 20080901 17:20:53,       10, STAT, rollbacks only - consistent read gets   ,            18,          2,         18,        1.8
DATA,     148, 20080901 17:20:53,       10, STAT, cluster key scan block gets             ,            65,          6,         65,        6.5
DATA,     148, 20080901 17:20:53,       10, TIME, hard parse elapsed time                 ,          4090,        409,     4.09ms,      409us
DATA,     148, 20080901 17:20:53,       10, TIME, PL/SQL compilation elapsed time         ,          3139,        314,     3.14ms,    313.9us
DATA,     148, 20080901 17:20:53,       10, TIME, parse time elapsed                      ,          5131,        513,     5.13ms,    513.1us
DATA,     148, 20080901 17:20:53,       10, TIME, PL/SQL execution elapsed time           ,        174288,      17429,   174.29ms,    17.43ms
<strong>DATA,     148, 20080901 17:20:53,       10, TIME, DB CPU                                  ,       3108026,     310803,      3.11s,    310.8ms
</strong>DATA,     148, 20080901 17:20:53,       10, TIME, sql execute elapsed time                ,       3104607,     310461,       3.1s,   310.46ms
DATA,     148, 20080901 17:20:53,       10, TIME, hard parse (sharing criteria) elapsed ti,          4110,        411,     4.11ms,      411us
<strong>DATA,     148, 20080901 17:20:53,       10, TIME, DB time                                 ,       3108026,     310803,      3.11s,    310.8ms
</strong>DATA,     148, 20080901 17:20:53,       10, WAIT, log file switch completion              ,         71104,       7110,     71.1ms,     7.11ms
DATA,     148, 20080901 17:20:53,       10, WAIT, SQL*Net message to client               ,             3,          0,        3us,       .3us
DATA,     148, 20080901 17:20:53,       10, WAIT, SQL*Net message from client             ,       6684030,     668403,      6.68s,    668.4ms
--  End of snap 1

PL/SQL procedure successfully completed.

</code></pre>
<p>You see, the DB CPU equals to DB time (in other words all the time spent servicing my request in database was spent on CPU, thus there were no waits, blocks involved). And the insert still took roughly 3 seconds.</p>
<p>This is the insert to SYSTEM tablespace table:</p>
<pre><code>SQL&gt; @snapper out,gather=tsw,sinclude=gets 10 1 148

-- Session Snapper v1.07 by Tanel Poder ( http://www.tanelpoder.com )

---------------------------------------------------------------------------------------------------------------------------------------------
HEAD,     SID, SNAPSHOT START   ,  SECONDS, TYPE, STATISTIC                               ,         DELTA,  DELTA/SEC,     HDELTA, HDELTA/SEC
---------------------------------------------------------------------------------------------------------------------------------------------
DATA,     148, 20080901 17:21:23,       11, STAT, db block gets                           ,        <strong>102616</strong>,       9329,    102.62k,      9.33k
DATA,     148, 20080901 17:21:23,       11, STAT, db block gets from cache                ,        102616,       9329,    102.62k,      9.33k
DATA,     148, 20080901 17:21:23,       11, STAT, consistent gets                         ,           <strong>384</strong>,         35,        384,      34.91
DATA,     148, 20080901 17:21:23,       11, STAT, consistent gets from cache              ,           384,         35,        384,      34.91
DATA,     148, 20080901 17:21:23,       11, STAT, consistent gets - examination           ,           218,         20,        218,      19.82
DATA,     148, 20080901 17:21:23,       11, STAT, no work - consistent read gets          ,            94,          9,         94,       8.55
DATA,     148, 20080901 17:21:23,       11, STAT, rollbacks only - consistent read gets   ,            17,          2,         17,       1.55
DATA,     148, 20080901 17:21:23,       11, STAT, cluster key scan block gets             ,            65,          6,         65,       5.91
DATA,     148, 20080901 17:21:23,       11, TIME, hard parse elapsed time                 ,          2350,        214,     2.35ms,   213.64us
DATA,     148, 20080901 17:21:23,       11, TIME, PL/SQL compilation elapsed time         ,          1751,        159,     1.75ms,   159.18us
DATA,     148, 20080901 17:21:23,       11, TIME, parse time elapsed                      ,          3359,        305,     3.36ms,   305.36us
DATA,     148, 20080901 17:21:23,       11, TIME, PL/SQL execution elapsed time           ,        172153,      15650,   172.15ms,    15.65ms
<strong>DATA,     148, 20080901 17:21:23,       11, TIME, DB CPU                                  ,       8751163,     795560,      8.75s,   795.56ms
</strong><strong>DATA,     148, 20080901 17:21:23,       11, TIME, sql execute elapsed time                ,       8749139,     795376,      8.75s,   795.38ms
</strong>DATA,     148, 20080901 17:21:23,       11, TIME, hard parse (sharing criteria) elapsed ti,          2367,        215,     2.37ms,   215.18us
<strong>DATA,     148, 20080901 17:21:23,       11, TIME, DB time                                 ,       8751163,     795560,      8.75s,   795.56ms
</strong>DATA,     148, 20080901 17:21:23,       11, WAIT, SQL*Net message to client               ,             3,          0,        3us,      .27us
DATA,     148, 20080901 17:21:23,       11, WAIT, SQL*Net message from client             ,      -1442849,    -131168,     -1.44s,  -131.17ms
--  End of snap 1

PL/SQL procedure successfully completed.

</code></pre>
<p>You see the DB Time is still equal to DB CPU, thus all response was spent on CPU. Moreover, the time model stats tell me that all the elapsed time was spent executing SQL statements (which makes sense as I&#8217;m running INSERT SQL in a tight loop).</p>
<p>So, for some reason the INSERT SQL statements take almost 3 times longer when inserting to SYSTEM tablespace.</p>
<p>In cases where there is no waiting going on (things like Oracle Wait Interface / WaitProf would not help here), but only difference in CPU time, I normally look into V$SESSTAT counter differences first. But as seen from above, there is no major difference in counters such logical IOs (db block gets, consistent gets) to justify 3x increase in CPU usage (also there was no major difference in other counters which I have excluded for brevity).</p>
<p>So, the obvious next step is to sample the process stack during execution of both statements and see where the difference is. In my previous <a href="http://blog.tanelpoder.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2Jsb2cudGFuZWxwb2Rlci5jb20vMjAwNy8wOS8wNi9hZHZhbmNlZC1vcmFjbGUtdHJvdWJsZXNob290aW5nLWd1aWRlLXBhcnQtMy1tb3JlLWFkdmVudHVyZXMtaW4tcHJvY2Vzcy1zdGFjay8=" target=\"_blank\">posts</a> I&#8217;ve used pstack for getting a few stack samples out of a process and a pstack loop could be used here as well.</p>
<p>But for demo purposes (and convenience) I will use my <a href="http://blog.tanelpoder.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy50YW5lbHBvZGVyLmNvbS9maWxlcy9zY3JpcHRzL3VuaXgvZHN0YWNrcHJvZi5zaA==">DTrace stack sampling script</a> today.</p>
<p>It&#8217;s dead easy to sample user process and kernel stacks using DTrace in Solaris 10 (and MacOS X and FreeBSD too). However the DTrace stack aggregator also takes account of the current program counter offset inside functions when distinguishing between stacks (this means that CPU program counter location <em>main() + 0&#215;10</em> will be different from <em>main() + 0&#215;12</em>). But I don&#8217;t want such granularity, I want to see where the execution was at function level, not instruction level.</p>
<p>So I wrote my script to strip off the PC function offsets from DTrace output and order the stacks the way that most frequently sampled stack &#8220;branch&#8221; is displayed last, in bottom of the output. So, whatever stack and function you see outputted last, is probably the &#8220;troublemaker&#8221;. I still recommend scrolling up and reviewing few other stacks too.</p>
<p>So, I ran the insert to USERS tablespace table again and ran my <a href="http://blog.tanelpoder.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy50YW5lbHBvZGVyLmNvbS9maWxlcy9zY3JpcHRzL3VuaXgvZHN0YWNrcHJvZi5zaA==">dstackprof</a> script on the server process with SPID 859.</p>
<p>This is from the &#8220;well behaving&#8221; process, so normally you should just compare this stack profile to the &#8220;bad behaving&#8221; process stack profile and see if you can spot any major differences in these. I will explain few of the functions on the go.</p>
<pre><code><strong># ./dstackprof.sh 859
</strong>
DStackProf v1.02 by Tanel Poder ( http://www.tanelpoder.com )
Sampling pid 859 for 5 seconds with stack depth of 100 frames...

147 samples with stack below
__________________
kcbchg1_main
kcbchg1                 &lt;- buffer change function in buffer cache layer
ktuchg                    &lt;- undo layer generate change
ktbchg2                  &lt;- block (header) change
kdtchg                    &lt;- data layer generate change
kdtwrp
kdtInsRow              &lt;- data layer row insert function
insrowFastPath
insdrvFastPath
inscovexe
insExecStmtExecIniEngine
insexe                   &lt;- OPI insert execution entry point
opiexe                   &lt;- OPI execute (executing my recursive INSERT INTO statement)
opipls
opiodr
rpidrus                  &lt;- all the RPI functions belong to recursive program interface (which allows making recursive calls in db)
skgmstack
rpidru                    &lt;- these RPI functions (and few OPI ones above) are what PL/SQL context switches physically are
rpiswu2
rpidrv
psddr0                  &lt;- most of the functions starting with "p" are PL/SQL execution ones
psdnal
pevm_EXECC
pfrinstr_EXECC
pfrrun_no_tool
pfrrun
plsql_run
peicnt                    &lt;- PL/SQL execution engine entry point
kkxexe                  &lt;- cursor to PL/SQL execution interface
opiexe                   &lt;- OPI call execution dispatcher
kpoal8
opiodr
ttcpip
opitsk
opiino
opiodr
opidrv
sou2o
opimai_real
main
0xe54ffc

193 samples with stack below
__________________
libc.so.1`times         &lt;-- during these 193 samples the execution was in opiexe (note that
opiexe                   -- it's a recursive OPI call execution (as there's the RPI layer below in the
opipls                    -- stack and there's another opiexe below. The lower opiexe is for executing
opiodr                   -- my PL/SQL anonymous block and upper is for the recursive INSERT statement
rpidrus
skgmstack
rpidru
rpiswu2
rpidrv
psddr0
psdnal
pevm_EXECC
pfrinstr_EXECC
pfrrun_no_tool
pfrrun
plsql_run
peicnt
kkxexe
opiexe
kpoal8
opiodr
ttcpip
opitsk
opiino
opiodr
opidrv
sou2o
opimai_real
main
0xe54ffc

3147 Total samples captured

</code></pre>
<p>Anyway, the two stacks which I have copied here don&#8217;t show anything obvious. And also, see that there were total 3147 samples taken when the process was on CPU. But the execution point was in the &#8220;top&#8221; stack during only 193 samples, which is around 6% of all samples.</p>
<p>As the above stacks come from a well-behaving process, let&#8217;s leave their deeper analysis and just compare them to the bad-behaving process. So, I ran the SYSTEM tablespace insert again (you still remember, we were troubleshooting why inserts into system tablespace were slower, right ;)</p>
<p>The top stack in profile was following:</p>
<pre><code># ./dstackprof.sh <strong>859</strong>

DStackProf v1.02 by Tanel Poder ( http://www.tanelpoder.com )
Sampling pid 859 for 5 seconds with stack depth of 100 frames...

<em>[...some output snipped...]
</em>

917 samples with stack below
__________________
libc.so.1`qsort
kd4_entries_overlap
kdb4chk
kd4chk
kcbchk
<strong>kco_blkchk</strong>    <em>&lt;-- what the heck is this? the name suggests that it's block checking of some kind</em>
kcoapl
kcbapl
kcrfw_redo_gen             &lt;-- also note this function, looks like the block change function (kcbchg) has called
kcbchg1_main                   &lt;-- a function to generate redo on its behalf
kcbchg1
ktuchg
ktbchg2
kdtchg
kdtwrp
kdtInsRow
insrowFastPath
insdrvFastPath
inscovexe
insExecStmtExecIniEngine
insexe
opiexe
opipls
opiodr
rpidrus
skgmstack
rpidru
rpiswu2
rpidrv
psddr0
psdnal
pevm_EXECC
pfrinstr_EXECC
pfrrun_no_tool
pfrrun
plsql_run
peicnt
kkxexe
opiexe
kpoal8
opiodr
ttcpip
opitsk
opiino
opiodr
opidrv
sou2o
opimai_real
main
0xe54ffc

6202 Total samples captured

</code></pre>
<p>As most of the top stacks from the bad behaving process were spending their time somewhere in kco_blkchk() function, it rang a bell &#8211; database block checking!</p>
<p>However it was weird as the <em>db_block_checking</em> parameter was set false in my instance:</p>
<pre><code>SQL&gt; show parameter db_block_checking

NAME                                 TYPE        VALUE
------------------------------------ ----------- -----
db_block_checking                    string      FALSE
SQL&gt;

</code></pre>
<p>After a little digging, I found this parameter:</p>
<pre><code>NAME                          VALUE     DESCRIPTION
----------------------------- --------- -------------------------------------------------------------
_db_always_check_system_ts    TRUE      Always perform block check and checksum for System tablespace

</code></pre>
<p>This parameter makes Oracle (since version 8.1.6) do block structure checking in SYSTEM tablespace even if db_block_checking itself is set to FALSE. Considering the criticality of data dictionary objects, it&#8217;s a good idea.</p>
<p>So, now you might say: <em>so what that there&#8217;s a performance issue, you shouldn&#8217;t keep your application tables in SYSTEM tablespace anyway!</em></p>
<p>Well, I have three words for you: <strong>AUD$, FGA_LOG$, DEF$_AQCALL</strong> :)</p>
<p>If you rely on auditing functionality heavily and especially if you use advanced replication, having the crucial tables (and associated LOB segments) in SYSTEM tablespace can mean quite a hit to your CPUs and system throughput. In which cases you probably would want to explore the option of moving these tables out of system tablespace.</p>
<p><strong>Warning</strong>: before moving anything, consult Metalink or Oracle Support as only few strictly defined ways for moving these object are supported. See notes 731908.1 for Audit and 1037317.6 for Advanced Replication.</p>
<p>So, the key point of this article is that I could have started guessing or setting various events or undocumented parameters for probing Oracle here and there, for figuring out what&#8217;s going on. But I used a simple systematic approach instead. When Oracle Wait Interface and V$SESSTAT counters didn&#8217;t help, looked into process stack next. And this gave me the vital clue (kdo_blkchk) that there&#8217;s block checking going on. And if I hadn&#8217;t figured out the cause myself, I would have had some solid evidence for support.</p>
<p>Note that you don&#8217;t have to use DTrace for this kind of stack profiling (even though it is very convenient). On non-Solaris 10 OS&#8217;es I would use whatever safe stack dump mechanism is available (pstack for example) and post-process the results. I probably wouldn&#8217;t take thousands of samples though, but probably 100 or even less.</p>
<p>Also, if you want to get a complete overview of the process execution profile, you would need to do much more complex aggregations, as you&#8217;d need to aggregate &#8220;child&#8221; branches of stack samples with their &#8220;parents&#8221; (currently the samples of a backtrace &#8220;a-&gt;b-&gt;c&#8221; are not accounted in &#8220;a-&gt;b&#8221; for example). But for my case (just checking if there&#8217;s any major difference between execution profiles) this approach was good enough.</p>
<p>By the way (if you haven&#8217;t given up yet :), check the differences in LatchProfX output. The top is from well-behaving process and bottom one is the bad one:</p>
<pre><code>SQL&gt; @latchprofx sid,name,ksllwnam,ksllwlbl 128 % 1000000

-- LatchProfX 1.06 by Tanel Poder ( http://www.tanelpoder.com )

       SID NAME                                KSLLWNAM                                 KSLLWLBL                   Held       Gets  Held %     Held ms Avg hold ms
---------- ----------------------------------- ---------------------------------------- -------------------- ---------- ---------- ------- ----------- -----------
<strong>       128 redo copy                           kcrfw_redo_gen: nowait                   latch                     49399      48937    4.94     674.790        .014
</strong>       128 cache buffers chains                kcbchg1: kslbegin: bufs not pinned                                  4574       2320     .46      62.481        .027
       128 cache buffers chains                kcbchg1: kslbegin: call CR func                                     2101       1445     .21      28.700        .020
       128 cache buffers chains                kcbgcur_2                                                           1323       1060     .13      18.072        .017
       128 cache buffers chains                kcbnew: new latch again                                              269        243     .03       3.675        .015
       128 simulator lru latch                 kcbs_simulate: simulate set              setid                       170        170     .02       2.322        .014
       128 redo allocation                     kcrfw_redo_gen: redo allocation 1        strand #                     68         13     .01        .929        .071
       128 cache buffers chains                kcbrls_2                                                              29         29     .00        .396        .014
       128 cache buffers chains                kcbgtcr: fast path                                                    25         25     .00        .342        .014
       128 cache buffers chains                kcbgcur: fast path (shr)                                               8          8     .00        .109        .014
       128 cache buffers lru chain             kcbzgws_1                                                              7          7     .00        .096        .014

SQL&gt; @latchprofx sid,name,ksllwnam,ksllwlbl 128 % 1000000

-- LatchProfX 1.06 by Tanel Poder ( http://www.tanelpoder.com )

       SID NAME                                KSLLWNAM                                 KSLLWLBL                   Held       Gets  Held %     Held ms Avg hold ms
---------- ----------------------------------- ---------------------------------------- -------------------- ---------- ---------- ------- ----------- -----------
<strong>       128 redo copy                           kcrfw_redo_gen: nowait                   latch                    356465      79839   35.65    6088.422        .076
</strong>       128 cache buffers chains                kcbchg1: kslbegin: bufs not pinned                                  4704       2233     .47      80.344        .036
       128 cache buffers chains                kcbchg1: kslbegin: call CR func                                     3542       1997     .35      60.497        .030
       128 cache buffers chains                kcbgcur_2                                                           1929       1448     .19      32.947        .023
       128 redo allocation                     kcrfw_redo_gen: redo allocation 1        strand #                   1018         34     .10      17.387        .511
       128 shared pool simulator               kglsim_unpin_simhp: fast path                                        713        713     .07      12.178        .017
       128 simulator lru latch                 kcbs_simulate: simulate set              setid                       266        266     .03       4.543        .017
       128 cache buffers chains                kcbnew: new latch again                                              182        171     .02       3.109        .018
       128 cache buffers chains                kcbgtcr: fast path (cr pin)                                           29         29     .00        .495        .017
       128 cache buffers chains                kcbgtcr: fast path                                                    15         15     .00        .256        .017

</code></pre>
<p>See, how the redo copy latches were held for much longer (both total time and average time of individual hold) when the block checking was enabled. This indicates that in addition to keeping the buffer pinned, also a redo copy latch is held during block checking (if not using an IMU transaction). If you use high-throughput advanced replication, think that CPU usage is too high for work done and can&#8217;t get rid of the redo copy latch contention, this may be a reason.</p>
<div class="facebook_like_button"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.tanelpoder.com%2F2008%2F09%2F02%2Foracle-hidden-costs-revealed-part2-using-dtrace-to-find-why-writes-in-system-tablespace-are-slower-than-in-others%2F&amp;layout=standard&amp;show-faces=true&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="padding: 0px 0px; border:none; overflow:hidden; width:450px; height:70px;"></iframe></div> <img src="http://blog.tanelpoder.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=132" width="1" height="1" style="display: none;" /><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://blog.tanelpoder.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.tanelpoder.com/2008/09/02/oracle-hidden-costs-revealed-part2-using-dtrace-to-find-why-writes-in-system-tablespace-are-slower-than-in-others/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
	</channel>
</rss>
