<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Randomdba's Blog</title>
	<atom:link href="http://randomdba.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://randomdba.wordpress.com</link>
	<description>Just another Oracle DBA weblog</description>
	<lastBuildDate>Sat, 26 Nov 2011 22:03:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='randomdba.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Randomdba's Blog</title>
		<link>http://randomdba.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://randomdba.wordpress.com/osd.xml" title="Randomdba&#039;s Blog" />
	<atom:link rel='hub' href='http://randomdba.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Bind Variable mismatch, nulls and oci</title>
		<link>http://randomdba.wordpress.com/2011/11/24/bind-variable-mismatch-nulls-and-oci/</link>
		<comments>http://randomdba.wordpress.com/2011/11/24/bind-variable-mismatch-nulls-and-oci/#comments</comments>
		<pubDate>Thu, 24 Nov 2011 20:22:59 +0000</pubDate>
		<dc:creator>randomdba</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://randomdba.wordpress.com/?p=91</guid>
		<description><![CDATA[A short post on a frustrating issue that took a while to find the solution to. The developers made a small change to a table allowing nulls in 23 columns previously configured as not null. This resulted in a large number of bind mismatches and child cursors being generated, eventually giving rise to a serious [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randomdba.wordpress.com&amp;blog=6071854&amp;post=91&amp;subd=randomdba&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A short post on a frustrating issue that took a while to find the solution to. The developers made a small change to a table allowing nulls in 23 columns previously configured as not null. This resulted in a large number of bind mismatches and child cursors being generated, eventually giving rise to a serious performance issue.</p>
<p>After much discussion of the issue test cases, being told to tune the database flushing the shared pool finally a developer opened the code and took a look at the problem and found the reason for the bind mismatch was the oci null indicator, when the column value is set null a value of -1 was being passed, when a value was present a null pointer was passed. The optimiser sees these as bind mismatches giving 2^23 combinations of bind settings. Patching the code to pass a zero when a value is present rather than a null pointer prevents the bind mismatch and returned everything to normal.</p>
<p>One other issue found was the test configuration, due to the data distribution in test not generating the same variance in nulls/values in the binds this problem wasn&#8217;t found until the production release making the assorted workarounds necessary.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/randomdba.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/randomdba.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/randomdba.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/randomdba.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/randomdba.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/randomdba.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/randomdba.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/randomdba.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/randomdba.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/randomdba.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/randomdba.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/randomdba.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/randomdba.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/randomdba.wordpress.com/91/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randomdba.wordpress.com&amp;blog=6071854&amp;post=91&amp;subd=randomdba&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://randomdba.wordpress.com/2011/11/24/bind-variable-mismatch-nulls-and-oci/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ce97d7c5b487b5918bb5e8f514d82b08?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">randomdba</media:title>
		</media:content>
	</item>
		<item>
		<title>How expensive are literals?</title>
		<link>http://randomdba.wordpress.com/2011/06/26/how-expensive-are-literals/</link>
		<comments>http://randomdba.wordpress.com/2011/06/26/how-expensive-are-literals/#comments</comments>
		<pubDate>Sun, 26 Jun 2011 22:41:05 +0000</pubDate>
		<dc:creator>randomdba</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://randomdba.wordpress.com/?p=84</guid>
		<description><![CDATA[As a follow-up to my last post I finally got around to writing a small program to demonstrate the difference between bind variables and literals, the test is a simple c++ program the reads a text file and updates 27,000 rows in a single table. The code runs the updates in three different ways. Method [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randomdba.wordpress.com&amp;blog=6071854&amp;post=84&amp;subd=randomdba&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>As a follow-up to my last post I finally got around to writing a small program to demonstrate the difference between bind variables and literals, the test is a simple c++ program the reads a text file and updates 27,000 rows in a single table. The code runs the updates in three different ways.</p>
<p>Method 1: Bulk bind 200 rows at a time into the update statement.</p>
<p>Method 2: Bind 1 row at a time</p>
<p>Method 3: Use literals in the updates.</p>
<p>Tkprof output from the test looks like this.</p>
<pre>Method 1
OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS

call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        2      0.01       0.01          0          0          0           0
Execute    271      5.44       6.05         23      28661      27706       27001
Fetch        0      0.00       0.00          0          0          0           0
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total      273      5.46       6.07         23      28661      27706       27001

Method 2
OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS

call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        2      0.00       0.00          0          0          0           0
Execute  27001     12.19      14.18          0      54015      27826       27001
Fetch        0      0.00       0.00          0          0          0           0
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total    27003     12.19      14.18          0      54015      27826       27001

Method 3
OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS

call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse    27001     19.06      25.33          0          0          0           0
Execute  27001     54.99      66.41          0      54002      27706       27001
Fetch        0      0.00       0.00          0          0          0           0
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total    54002     74.06      91.75          0      54002      27706       27001
</pre>
<p>From this simple test the literals uses 13.5 times as much CPU compared to the first method in cost terms if I need 2 x86 cores of CPU power to power my database for method 1 I need 27 cores for method 3 (assuming it would scale) in cost terms thats 1*£31,839 vs 14*£31,839 or £445,746. aside from the cost there is no way to improve the speed of method 3 and the code is harder to write as well.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/randomdba.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/randomdba.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/randomdba.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/randomdba.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/randomdba.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/randomdba.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/randomdba.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/randomdba.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/randomdba.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/randomdba.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/randomdba.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/randomdba.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/randomdba.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/randomdba.wordpress.com/84/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randomdba.wordpress.com&amp;blog=6071854&amp;post=84&amp;subd=randomdba&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://randomdba.wordpress.com/2011/06/26/how-expensive-are-literals/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ce97d7c5b487b5918bb5e8f514d82b08?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">randomdba</media:title>
		</media:content>
	</item>
		<item>
		<title>Bind Variables, almost right.</title>
		<link>http://randomdba.wordpress.com/2011/06/01/77/</link>
		<comments>http://randomdba.wordpress.com/2011/06/01/77/#comments</comments>
		<pubDate>Wed, 01 Jun 2011 22:39:02 +0000</pubDate>
		<dc:creator>randomdba</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://randomdba.wordpress.com/?p=77</guid>
		<description><![CDATA[Sometimes I get a bit sarcastic with and about developers, this is unfair as for the most part the ones I have worked closely have either been very good oracle developers or very good c++/java/VB6/whatever developers with a real interest in doing things the right way and have been receptive to constructive (but grumpy feedback). [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randomdba.wordpress.com&amp;blog=6071854&amp;post=77&amp;subd=randomdba&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Sometimes I get a bit sarcastic with and about developers, this is unfair as for the most part the ones I have worked closely have either been very good oracle developers or very good c++/java/VB6/whatever developers with a real interest in doing things the right way and have been receptive to constructive (but grumpy feedback).</p>
<p>This gem in a vendors application however brought out the sarcasm.</p>
<pre>Update
  bigwidetable
set
  column_1 = :1, column2 = :2, ..............
  column_125 = :125, column_126 = :126
where
   column_127 = 'GotBoredWithBindVariablesDidWe?';</pre>
<p>I can&#8217;t work the logic out here, the code is already written to use bind variables it took extra code to stick a literal in there, as the application is written in c using the oci libraries these guys are supposed to be rocket surgeons. There isn&#8217;t even a justification based on skewed data column_127 is the primary key so every update updates one row and there is only one plan ever used. Added to that the design of the process is such that the application caches updates then send in 400 at a time , committing after each update just to make sure performance really suffers except for end of day processing where all 27,000 rows are updated at least there is only a single commit during that specific piece.</p>
<p>So far so bad, however the worst impact we see is because we are using Automatic Memory management the shared pool grows larger over time as it tries to cache all the execution plans. After three weeks we get to the point of other processes suffering form either not enough buffers or increases in mutex and library cache latch waits, the solution? restart the database every two weeks and the spfile to reset the values of __db_cache_size and __shared_pool_size. Yes we could use manual memory management but the vendors application compute guide specifies AMM changing to manual memory management is still being assessed by their performance team.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/randomdba.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/randomdba.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/randomdba.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/randomdba.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/randomdba.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/randomdba.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/randomdba.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/randomdba.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/randomdba.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/randomdba.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/randomdba.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/randomdba.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/randomdba.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/randomdba.wordpress.com/77/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randomdba.wordpress.com&amp;blog=6071854&amp;post=77&amp;subd=randomdba&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://randomdba.wordpress.com/2011/06/01/77/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ce97d7c5b487b5918bb5e8f514d82b08?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">randomdba</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL Injection</title>
		<link>http://randomdba.wordpress.com/2011/02/22/sql-injection/</link>
		<comments>http://randomdba.wordpress.com/2011/02/22/sql-injection/#comments</comments>
		<pubDate>Tue, 22 Feb 2011 23:07:00 +0000</pubDate>
		<dc:creator>randomdba</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://randomdba.wordpress.com/?p=70</guid>
		<description><![CDATA[Sometimes I wonder why I still find stuff like this, there are so many articles/blogs/documents about sql injection how does a developer come up with the following&#8230; create or replace function row_count (p_table varchar2) return number is v_str VARCHAR2(1000); v_row NUMBER; BEGIN v_str := &#8216;select count(*) from &#8216;&#124;&#124;p_table; execute immediate v_str into v_row; return v_row; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randomdba.wordpress.com&amp;blog=6071854&amp;post=70&amp;subd=randomdba&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Sometimes I wonder why I still find stuff like this, there are so many articles/blogs/documents about sql injection how does a developer come up with the following&#8230;</p>
<p>create or replace function row_count (p_table varchar2)<br />
return number<br />
is<br />
v_str VARCHAR2(1000);<br />
v_row NUMBER;<br />
BEGIN<br />
v_str := &#8216;select count(*) from &#8216;||p_table;<br />
execute immediate v_str into v_row;<br />
return v_row;<br />
end;<br />
/</p>
<p>My simple explanation of why this is bad was that passing in the parameter &#8216;all_objects,all_objects,all_objects&#8217; will result in a fairly nasty cartesian join and an attacker who knew the names of the database tables could potentially pick a really large table. Run enough copies and it starts to look like a denial of service attack, I&#8217;m pretty sure someone smarter than me could come up with something worse but I would rather not have to think how to defend from sql injection when simply doing it right (with technology from the 90&#8242;s possibly 80&#8242;s) is so much easier.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/randomdba.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/randomdba.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/randomdba.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/randomdba.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/randomdba.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/randomdba.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/randomdba.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/randomdba.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/randomdba.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/randomdba.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/randomdba.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/randomdba.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/randomdba.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/randomdba.wordpress.com/70/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randomdba.wordpress.com&amp;blog=6071854&amp;post=70&amp;subd=randomdba&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://randomdba.wordpress.com/2011/02/22/sql-injection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ce97d7c5b487b5918bb5e8f514d82b08?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">randomdba</media:title>
		</media:content>
	</item>
		<item>
		<title>A single procedure to &#8220;hang&#8221; the database.</title>
		<link>http://randomdba.wordpress.com/2011/02/14/a-single-procedure-to-hang-the-database/</link>
		<comments>http://randomdba.wordpress.com/2011/02/14/a-single-procedure-to-hang-the-database/#comments</comments>
		<pubDate>Mon, 14 Feb 2011 23:26:56 +0000</pubDate>
		<dc:creator>randomdba</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Parallelism]]></category>

		<guid isPermaLink="false">http://randomdba.wordpress.com/?p=65</guid>
		<description><![CDATA[I really enjoy it when people don&#8217;t understand the features they are using it makes life really interesting, automatic parallelism is a great new feature of 11.2 but we found a new and interesting way to break things. As part of the application we are implementing customers may re-request fairly large volumes of data to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randomdba.wordpress.com&amp;blog=6071854&amp;post=65&amp;subd=randomdba&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I really enjoy it when people don&#8217;t understand the features they are using it makes life really interesting, automatic parallelism is a great new feature of 11.2 but we found a new and interesting way to break things. As part of the application we are implementing customers may re-request fairly large volumes of data to limit the impact on the system as a whole the design is such that a cursor is opened and the data returned in chunks of between  500 rows, if two customers execute re-requests at the same time then two cursors are opened cutomer1 gets 500 rows then customer2 gets 500 rows then back to customer1 and so on. If ten customers issue re-requests results are sent back in chunks of 500 to each customer in turn and so on.</p>
<p>The intention is to prevent customers complaining that they are waiting too long to receive data at the same time as preventing re-requests flooding the database and making the other critical parts of the system becoming unresponsive.</p>
<p>Nice Idea but someone didn&#8217;t read enough about automatic parallelism, here is a simple demo, first create a table e.g. (this code has been shamelessly adapted from Jonathan Lewis&#8217; site)</p>
<pre style="padding-left:30px;"><span style="font-family:Arial;font-size:x-small;">create table t1 
nologging 
 as
 with generator as ( 
 select  --+ materialize 
 rownum id 
 from dual 
 connect by
 rownum &lt;=  10000 
 ) 
 select
 rownum                   id, 
 trunc(dbms_random.value(1,1000))    n1, 
 trunc(dbms_random.value(1,1000))     n2, 
 lpad(rownum,30,'0')          small_vc 
 from
 generator    v1, 
 generator   v2 
 where
 rownum &lt;= 100000000;
/
 </span>
<span style="font-family:Arial;font-size:x-small;"> begin
 dbms_stats.gather_table_stats( 
 ownname      =&gt; user, 
 tabname      =&gt;'T1', 
 method_opt    =&gt; 'for all columns size 1'
 ); 
 end; </span>
/</pre>
<p>Then a nice simple piece of pl/sql to demonstrate the issue (database version 11.2.0.1, 8 cores, parallel_server_target set to 64, parallel_min_time_threshold=1 you may need different values to force the behaviour)</p>
<div style="padding-left:30px;"><span style="font-family:Arial;font-size:x-small;">declare<br />
cursor cursor1 is select * from  t1  order by id;<br />
cursor cursor2 is select * from t1  order by  id;<br />
cursor cursor3 is select * from t1  order by  id;<br />
cursor cursor4 is select * from t1  order by  id;<br />
cursor cursor5 is select * from t1  order by  id;<br />
cursor cursor6 is select * from t1  order by  id;<br />
cursor cursor7 is select * from t1  order by  id;<br />
cursor cursor8 is select * from t1  order by  id;<br />
cursor cursor9 is select * from t1  order by  id;<br />
cursor cursor10 is select * from t1  order by id;<br />
id  dbms_sql.number_table;<br />
n1 dbms_sql.number_table;<br />
n2  dbms_sql.number_table;<br />
small_vc  dbms_sql.varchar2_table;<br />
BEGIN<br />
open cursor1;<br />
open  cursor2;<br />
open cursor3;<br />
open cursor4;<br />
open  cursor5;<br />
open cursor6;<br />
open cursor7;<br />
open  cursor8;<br />
open cursor9;<br />
open  cursor10;</p>
<p>loop<br />
fetch cursor1 bulk collect into  id,n1,n2,small_vc limit 500;<br />
fetch cursor2 bulk collect into  id,n1,n2,small_vc limit 500;<br />
fetch cursor3 bulk collect into  id,n1,n2,small_vc limit 500;<br />
fetch cursor4 bulk collect into  id,n1,n2,small_vc limit 500;<br />
fetch cursor5 bulk collect into  id,n1,n2,small_vc limit 500;<br />
fetch cursor6 bulk collect into  id,n1,n2,small_vc limit 500;<br />
fetch cursor7 bulk collect into  id,n1,n2,small_vc limit 500;<br />
fetch cursor8 bulk collect into  id,n1,n2,small_vc limit 500;<br />
fetch cursor9 bulk collect into  id,n1,n2,small_vc limit 500;<br />
fetch cursor10 bulk collect into  id,n1,n2,small_vc limit 500;<br />
exit when  cursor1%notfound;<br />
end loop;</p>
<p>close  cursor1;<br />
close cursor2;<br />
close cursor3;<br />
close  cursor4;<br />
close cursor5;<br />
close cursor6;<br />
close  cursor7;<br />
close cursor8;<br />
close cursor9;<br />
close  cursor10;<br />
End;<br />
/</span></div>
<p>Now execute the stored procedure and wait, and wait, and continue waiting forever&#8230;..</p>
<p>The problem is simple(once we knew what was going on), auto parallelism will queue statements if it can&#8217;t execute with the degree of parallelism requested by about cursor 8 our database was unable to assign the required parallel slaves so it queued the statement, this means no one else ever gets any rows untill we kill the process. Typically what we were seeing was one session waiting on &#8220;PX Queuing: statement queue&#8221; event. unfortunately getting the code fixed is going to be a long slow process so at the moment automatic parallelism and statement queuing are switched off.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/randomdba.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/randomdba.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/randomdba.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/randomdba.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/randomdba.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/randomdba.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/randomdba.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/randomdba.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/randomdba.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/randomdba.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/randomdba.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/randomdba.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/randomdba.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/randomdba.wordpress.com/65/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randomdba.wordpress.com&amp;blog=6071854&amp;post=65&amp;subd=randomdba&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://randomdba.wordpress.com/2011/02/14/a-single-procedure-to-hang-the-database/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ce97d7c5b487b5918bb5e8f514d82b08?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">randomdba</media:title>
		</media:content>
	</item>
		<item>
		<title>Flashback logging only has a 2% performance decrease&#8230;or not.</title>
		<link>http://randomdba.wordpress.com/2010/02/17/flashback-logging-only-has-a-2-performance-decrease-or-not/</link>
		<comments>http://randomdba.wordpress.com/2010/02/17/flashback-logging-only-has-a-2-performance-decrease-or-not/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 00:10:33 +0000</pubDate>
		<dc:creator>randomdba</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://randomdba.wordpress.com/?p=45</guid>
		<description><![CDATA[Firstly apologies to both people who have previously read my blog, things have been a little hectic over the past 12 months working away from home in the Netherlands has taken its toll on my spare time, and weekends are to be spent either with the family or working, things have settled into a more [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randomdba.wordpress.com&amp;blog=6071854&amp;post=45&amp;subd=randomdba&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Firstly apologies to both people who have previously read my blog, things have been a little hectic over the past 12 months working away from home in the Netherlands has taken its toll on my spare time, and weekends are to be spent either with the family or working, things have settled into a more stable pattern now so here goes..</p>
<p>Some background, I&#8217;ve been assigned into a project to configure dataguard on a very busy production system performing a mixed bag of batch processing, messaging and DSS loads. Performance and availability of the system is critical for the business so everyone was happy that when flashback was proposed as an addition to the system they could quote this bit of marketing <a href="http://www.oracle.com/technology/deploy/availability/htdocs/Flashback_Overview.htm">http://www.oracle.com/technology/deploy/availability/htdocs/Flashback_Overview.htm</a> (search for 2% and you will see the bit I mean).  Great everyone was happy then i get moved onto the project to help with configuration and testing and start upsetting people..</p>
<p>Prior to starting the formal tests we have a fairly informal period where we have built the test databases configured the standby got the team used to data guard brokers foibles, failed over, rebuilt the primary using flash back database, performed some switch overs and switch backs, broken the configuration by an ill advised flashback on the primary fixed the configuration switched over a couple more times, then hit a bug (5937899) handily unpublished regarding flashback data guard and switch overs fortunately this was recoverable as we had set guaranteed restore points which is where our problems really got started.</p>
<p>As part of the test plan we have a set of processes to run, the plan is to run everything, measure performance of the network, host o/s, SAN generate awr reports etc and then flashback to our guaranteed restore point alter the configuration and re-run the same processes, giving us data we can compare e.g. no data guard, archive log shipping, lgwr async and finally lgwr sync. The plan was good right up until we tried some Micky Mouse testing with simple scripts creating tables by selecting from dba objects, delete insert commit really simple stuff, so first run through no data guard no flashback everything is good, enable  data guard configure flashback database set a guaranteed restore point, performance nosedives and top 5 wait events looks like</p>
<p>Top 5 Timed Events</p>
<table style="height:188px;" border="1" width="443">
<tbody>
<tr>
<th>Event</th>
<th>Waits</th>
<th>Time(s)</th>
<th>Avg Wait(ms)</th>
<th>% Total Call Time</th>
<th>Wait Class</th>
</tr>
<tr>
<td>log file sync</td>
<td align="right">2,055</td>
<td align="right">557</td>
<td align="right">271</td>
<td align="right">35.7</td>
<td>Commit</td>
</tr>
<tr>
<td>CPU time</td>
<td align="right"></td>
<td align="right">497</td>
<td align="right"></td>
<td align="right">31.8</td>
<td></td>
</tr>
<tr>
<td>db file parallel write</td>
<td align="right">33,547</td>
<td align="right">437</td>
<td align="right">13</td>
<td align="right">28.0</td>
<td>System I/O</td>
</tr>
<tr>
<td>flashback buf free by RVWR</td>
<td align="right">430</td>
<td align="right">402</td>
<td align="right">935</td>
<td align="right">25.7</td>
<td>Other</td>
</tr>
<tr>
<td>log file parallel write</td>
<td align="right">777</td>
<td align="right">96</td>
<td align="right">124</td>
<td align="right">6.2</td>
<td>System I/O</td>
</tr>
</tbody>
</table>
<p>This is not good, the log file sync time isn&#8217;t unexpected (in fact is not much greater than without dataguard or flashback on), but the flashback buf free by RVWR is not something we expected to see at this level.  Finding this really doesn&#8217;t bode well for the rest of the testing and the impact on production, so we start digging around, switch of flash back, configure a restore point with flashback logging not enabled. Until eventually I&#8217;m looking at the session wait events and the flash recovery area at the same time, and notice that all the sessions go into waiting on flashback buf free by RVWR at the same time and this coincides with a new flashback log being created. because of the load we have generated flashback logs are created ~500MB in size, every session we are running to generate load waits while this is happening.</p>
<p>Right so what is the real problem? well its the way we have set things up, with flash back logging enabled and no restore points configured flash back logs will get reused (how soon depends on db_flashback_retention_target) once the system hits a steady state it shouldn&#8217;t be creating new flashback logs just reusing old ones. In our test environment we enable flashback logging and configure a guaranteed restore point so we don&#8217;t ever reuse a flashback log we just create new ones this isn&#8217;t representative of the live system as we will not be setting guaranteed restore points, so our next step is try to find a way to enable flashback to a guaranteed point in test without inflicting the waits we have seen in our quick and dirty testing. testing on a small system the following seems to get around the problem.</p>
<pre style="padding-left:30px;">Configure the test database and standby server.</pre>
<pre style="padding-left:30px;">Set flashback database on, set db_flashback_retention_target to a big number (even the default of 1440 will work)</pre>
<pre style="padding-left:30px;">execute one of our scripts to generate a lot of changes and wait until we have enough flash back logs (yes i know how many is enough?)</pre>
<pre style="padding-left:30px;">set a guaranteed restore point</pre>
<pre style="padding-left:30px;">set db_flashback_retention_target to a small number (&lt;60)
</pre>
<p>what will then happen is the existing flashback logs will be reused removing the extreme waits we are getting waiting on new flashback log files being created while still allowing us to flashback and re-run the production like process tests against the same data.</p>
<p>The real point here isn&#8217;t about flash back logging or a specific process its about testing in our case we have delayed the start of the formal tests by a day but have saved time overall as we will not end up having to re-run tests that take 4-5 hours to complete, well at least not for this reason <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ,  in summary :-</p>
<p>validating your environment before you start time consuming and possibly expensive tests is a good idea</p>
<p>Small fairly crude tests can show up problems in the configuration shortening the test cycle.</p>
<p>Having time to mess about and quickly retry things is invaluable for DBA&#8217;s implementing features that haven&#8217;t been used by the team before.</p>
<p>Never, ever quote a performance figure pulled from marketing material no matter what the source is, always verify in your own environment.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/randomdba.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/randomdba.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/randomdba.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/randomdba.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/randomdba.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/randomdba.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/randomdba.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/randomdba.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/randomdba.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/randomdba.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/randomdba.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/randomdba.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/randomdba.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/randomdba.wordpress.com/45/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randomdba.wordpress.com&amp;blog=6071854&amp;post=45&amp;subd=randomdba&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://randomdba.wordpress.com/2010/02/17/flashback-logging-only-has-a-2-performance-decrease-or-not/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ce97d7c5b487b5918bb5e8f514d82b08?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">randomdba</media:title>
		</media:content>
	</item>
		<item>
		<title>Index Fragmentation &#8211; more thoughts.</title>
		<link>http://randomdba.wordpress.com/2009/03/18/index-fragmentation-more-thoughts/</link>
		<comments>http://randomdba.wordpress.com/2009/03/18/index-fragmentation-more-thoughts/#comments</comments>
		<pubDate>Wed, 18 Mar 2009 20:40:29 +0000</pubDate>
		<dc:creator>randomdba</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://randomdba.wordpress.com/?p=33</guid>
		<description><![CDATA[Looking at my last post I&#8217;m somewhat unsatisfied about the script to create the &#8220;fragmented&#8221; index so I thought I&#8217;d have another go, modifying it to be like this: drop table TEST_FRAG2; create table TEST_FRAG2 (id number not null, value varchar2(10)); insert into TEST_FRAG2 select id,&#8217;stuff&#8217; from (select rownum as id from dual connect by [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randomdba.wordpress.com&amp;blog=6071854&amp;post=33&amp;subd=randomdba&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Looking at my last post I&#8217;m somewhat unsatisfied about the script to create the &#8220;fragmented&#8221; index so I thought I&#8217;d have another go, modifying it to be like this:</p>
<p>drop table TEST_FRAG2;<br />
create table TEST_FRAG2 (id number not null, value varchar2(10));<br />
insert into TEST_FRAG2 select id,&#8217;stuff&#8217; from<br />
(select rownum as id from dual connect by level &lt;=400000)<br />
where mod(trunc(id/400),2)=0;<br />
create unique index TEST_FRAG2_IDX on TEST_FRAG2(id);<br />
insert into TEST_FRAG2 select id,&#8217;stuff&#8217; from<br />
(select rownum as id from dual connect by level &lt;=400000)<br />
where mod(trunc(id/400),2)=1;<br />
commit;</p>
<p>begin<br />
DBMS_STATS.GATHER_TABLE_STATS (ownname =&gt; &#8216;CHRIS&#8217;,tabname =&gt; &#8216;TEST_FRAG2&#8242;,<br />
estimate_percent =&gt; 100,method_opt=&gt; &#8216;FOR ALL COLUMNS SIZE 1&#8242;);<br />
end;</p>
<p>This creates an index which has a similar type of physical fragmentation as the pervious example but a better clustering factor, running the first test again. (I&#8217;m seeing a faster response from disk today, however I wouldn&#8217;t read too muchinto that as my test database is 11g , Oracle E-Linux 5.2 on Oracle VM on the cheapest dell server I could get with one disk and a bunch of third party ram).</p>
<p>alter system flush buffer_cache;<br />
alter session set events &#8217;10046 trace name context forever, level 8&#8242;;<br />
select count(id) from test_frag2 where id &gt;=1000 and id &lt;=20000;<br />
alter session set events &#8217;10046 trace name context off&#8217;;</p>
<p>Taking a look at the trace file shows the following (this is a small sample) type of activity we are reading blocks that are not sequentially placed on disk</p>
<p>WAIT #11: nam=&#8217;db file sequential read&#8217; ela= 42 file#=4 block#=25070 blocks=1 obj#=68308 tim=1236636891337307<br />
WAIT #11: nam=&#8217;db file sequential read&#8217; ela= 27 file#=4 block#=25956 blocks=1 obj#=68308 tim=1236636891337422<br />
WAIT #11: nam=&#8217;db file sequential read&#8217; ela= 27 file#=4 block#=25960 blocks=1 obj#=68308 tim=1236636891337539<br />
WAIT #11: nam=&#8217;db file sequential read&#8217; ela= 26 file#=4 block#=25071 blocks=1 obj#=68308 tim=1236636891337667<br />
WAIT #11: nam=&#8217;db file sequential read&#8217; ela= 29 file#=4 block#=25968 blocks=1 obj#=68308 tim=1236636891337783<br />
WAIT #11: nam=&#8217;db file sequential read&#8217; ela= 26 file#=4 block#=25964 blocks=1 obj#=68308 tim=1236636891337911<br />
WAIT #11: nam=&#8217;db file sequential read&#8217; ela= 26 file#=4 block#=25072 blocks=1 obj#=68308 tim=1236636891338034<br />
WAIT #11: nam=&#8217;db file sequential read&#8217; ela= 28 file#=4 block#=25976 blocks=1 obj#=68308 tim=1236636891338151</p>
<p>then runing the second test</p>
<p>alter system flush buffer_cache;<br />
alter session set events &#8217;10046 trace name context forever, level 8&#8242;;<br />
select count(value) from test_frag2 where id &gt;=1000 and id &lt;=20000;<br />
select count(value) from test_unfrag where id &gt;=1000 and id &lt;=20000;<br />
alter session set events &#8217;10046 trace name context off&#8217;;</p>
<p>now uses the same execution plan as before, looking at the tkproffed output shows the query on test_frag2 doing more work.</p>
<p>select count(value)<br />
from<br />
test_frag2 where id &gt;=1000 and id &lt;=20000</p>
<pre>call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        1      0.00       0.00          0          0          0           0
Execute      1      0.00       0.00          0          0          0           0
Fetch        1      0.01       0.01        108        155          0           1
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        3      0.01       0.01        108        155          0           1</pre>
<p>select count(value)<br />
from<br />
test_unfrag where id &gt;=1000 and id &lt;=20000</p>
<pre>call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        1      0.00       0.00          0          0          0           0
Execute      1      0.00       0.00          0          0          0           0
Fetch        1      0.01       0.01         83         83          0           1
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        3      0.01       0.01         83         83          0           1</pre>
<p>A coalesce on the index TEST_FRAG2_IDX improves things but still we are doing slightly more work, as shown below, a rebuild gives exactly the same result.</p>
<p>select count(value)<br />
from<br />
test_frag2 where id &gt;=1000 and id &lt;=20000</p>
<pre>call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        1      0.00       0.00          0          0          0           0
Execute      1      0.00       0.00          0          0          0           0
Fetch        2      0.02       0.02         85        132          0           1
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        4      0.02       0.02         85        132          0           1</pre>
<p>I&#8217;ll need to take a look at whats going on here but I suspect the extra work is because the table data is scattered accross more blocks rather than anything to do with the index structure</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/randomdba.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/randomdba.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/randomdba.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/randomdba.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/randomdba.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/randomdba.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/randomdba.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/randomdba.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/randomdba.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/randomdba.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/randomdba.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/randomdba.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/randomdba.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/randomdba.wordpress.com/33/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randomdba.wordpress.com&amp;blog=6071854&amp;post=33&amp;subd=randomdba&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://randomdba.wordpress.com/2009/03/18/index-fragmentation-more-thoughts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ce97d7c5b487b5918bb5e8f514d82b08?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">randomdba</media:title>
		</media:content>
	</item>
		<item>
		<title>Index fragmentation &#8211; Just like SQL Server</title>
		<link>http://randomdba.wordpress.com/2009/03/06/index-fragmentation-just-like-sql-server/</link>
		<comments>http://randomdba.wordpress.com/2009/03/06/index-fragmentation-just-like-sql-server/#comments</comments>
		<pubDate>Fri, 06 Mar 2009 00:35:40 +0000</pubDate>
		<dc:creator>randomdba</dc:creator>
				<category><![CDATA[indexes]]></category>
		<category><![CDATA[Oracle]]></category>

		<guid isPermaLink="false">http://randomdba.wordpress.com/?p=25</guid>
		<description><![CDATA[My current project is working for a client consolidating a bunch of SQL server databases into a properly licenced and managed sql serve cluster, Its been a while since I did a lot in SQL Server and it seemed like a good way to refresh some skills I hadn&#8217;t used for  while. One of the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randomdba.wordpress.com&amp;blog=6071854&amp;post=25&amp;subd=randomdba&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>My current project is working for a client consolidating a bunch of SQL server databases into a properly licenced and managed sql serve cluster, Its been a while since I did a lot in SQL Server and it seemed like a good way to refresh some skills I hadn&#8217;t used for  while. One of the big differences is sql server best practices recommends running a maintenance job to rebuild fragmented indexes, current thinking in Oracle is that frequent (and most of the time any) index rebuilds are not required. Index fragmentation in SQL Server has a two specific meanings Internal fragmentation is wasted space in an index the kind of thing you get after heavy deletes of almost all the data in a range of values, the other is external fragmentation where pages are stored out of order on disk  (a more in depth explanation is here <a title="sql index fragmentation" href="http://www.sql-server-performance.com/articles/per/index_fragmentation_p1.aspx" target="_blank">http://www.sql-server-performance.com/articles/per/index_fragmentation_p1.aspx</a>) most of the discussion about oracle indexes discusses the first type of fragmentation but I&#8217;ve seen the second type discussed far less so I figured I&#8217;d see if the same thing happens. first of all to build some test tables and indexes.</p>
<p>drop table TEST_FRAG;<br />
create table TEST_FRAG (id number not null, value varchar2(10));<br />
insert into TEST_FRAG select rownum*2-1, &#8216;Stuff&#8217; from dual connect by level &lt;=200000;<br />
create unique index TEST_FRAG_IDX on TEST_FRAG(id);<br />
insert into TEST_FRAG select rownum*2, &#8216;TEST_FRAG&#8217; from dual connect by level &lt;=200000;</p>
<p>drop table TEST_UNFRAG;<br />
create table TEST_UNFRAG (id number not null, value varchar2(10));<br />
insert into TEST_UNFRAG select rownum, &#8216;Stuff&#8217; from dual connect by level &lt;=400000;<br />
create unique index TEST_UNFRAG_IDX on TEST_UNFRAG(id);<br />
commit;</p>
<p>begin<br />
DBMS_STATS.GATHER_TABLE_STATS (ownname =&gt; &#8216;CHRIS&#8217;,tabname =&gt; &#8216;TEST_FRAG&#8217;,estimate_percent =&gt; 100,method_opt=&gt; &#8216;FOR ALL COLUMNS SIZE 1&#8242;);<br />
DBMS_STATS.GATHER_TABLE_STATS (ownname =&gt; &#8216;CHRIS&#8217;,tabname =&gt; &#8216;TEST_UNFRAG&#8217;,estimate_percent =&gt; 100,method_opt=&gt; &#8216;FOR ALL COLUMNS SIZE 1&#8242;);<br />
end;</p>
<p>This Creates a couple of simple tables and indexes which we can then run some tests on, first of all this:-</p>
<p>alter system flush buffer_cache;<br />
alter session set events &#8217;10046 trace name context forever, level 8&#8242;;<br />
select count(id) from test_frag where id &gt;=1000 and id &lt;=20000;<br />
select count(id) from test_unfrag where id &gt;=1000 and id &lt;=20000;</p>
<p>both take next to no time, taking a look at the traces we can see a small difference, for the first statement we get the following wait events in the trace file.</p>
<p>WAIT #4: nam=&#8217;db file sequential read&#8217; ela= 58 file#=4 block#=19812 blocks=1 obj#=67986 tim=1236296568417821<br />
WAIT #4: nam=&#8217;db file sequential read&#8217; ela= 57 file#=4 block#=18928 blocks=1 obj#=67986 tim=1236296568418122<br />
WAIT #4: nam=&#8217;db file sequential read&#8217; ela= 59 file#=4 block#=19816 blocks=1 obj#=67986 tim=1236296568418396<br />
WAIT #4: nam=&#8217;db file sequential read&#8217; ela= 57 file#=4 block#=18929 blocks=1 obj#=67986 tim=1236296568418700<br />
WAIT #4: nam=&#8217;db file sequential read&#8217; ela= 60 file#=4 block#=19820 blocks=1 obj#=67986 tim=1236296568418972<br />
WAIT #4: nam=&#8217;db file sequential read&#8217; ela= 56 file#=4 block#=18930 blocks=1 obj#=67986 tim=1236296568419259</p>
<p>We can see the range scan is reading blocks from different extents as it progresses through the index for the second table the waits look like this,</p>
<p>WAIT #3: nam=&#8217;db file sequential read&#8217; ela= 46 file#=4 block#=20847 blocks=1 obj#=67988 tim=1236296568430710<br />
WAIT #3: nam=&#8217;db file sequential read&#8217; ela= 48 file#=4 block#=20848 blocks=1 obj#=67988 tim=1236296568430986<br />
WAIT #3: nam=&#8217;db file sequential read&#8217; ela= 58 file#=4 block#=20849 blocks=1 obj#=67988 tim=1236296568431264<br />
WAIT #3: nam=&#8217;db file sequential read&#8217; ela= 58 file#=4 block#=20850 blocks=1 obj#=67988 tim=1236296568431545<br />
WAIT #3: nam=&#8217;db file sequential read&#8217; ela= 56 file#=4 block#=20851 blocks=1 obj#=67988 tim=1236296568431803<br />
WAIT #3: nam=&#8217;db file sequential read&#8217; ela= 56 file#=4 block#=20852 blocks=1 obj#=67988 tim=1236296568432065</p>
<p>Here we are scanning the blocks in order, overall however the total work done is much the same (I got a total of 44 blocks read from the &#8220;Fragmented&#8221; index and 42 from the &#8220;unfragmented&#8221;) and we are not seeing a huge difference in access time as the elapsed time is pretty much the same. the next test gives some different results.</p>
<p>alter system flush buffer_cache;<br />
alter session set events &#8217;10046 trace name context forever, level 8&#8242;;<br />
select count(value) from test_frag where id &gt;=1000 and id &lt;=20000;<br />
select count(value) from test_unfrag where id &gt;=1000 and id &lt;=20000;</p>
<p>Looking in the trace file here shows the first query actually has a completely different execution plan, it does this</p>
<p>Rows     Row Source Operation<br />
&#8212;&#8212;-  &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
1  SORT AGGREGATE (cr=1005 pr=1001 pw=1001 time=0 us)<br />
19001   TABLE ACCESS FULL TEST_FRAG (cr=1005 pr=1001 pw=1001 time=509 us cost=277 size=228024 card=19002)</p>
<p>where the second query does this</p>
<p>Rows     Row Source Operation<br />
&#8212;&#8212;-  &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
1  SORT AGGREGATE (cr=83 pr=83 pw=83 time=0 us)<br />
19001   TABLE ACCESS BY INDEX ROWID TEST_UNFRAG (cr=83 pr=83 pw=83 time=1460 us cost=84 size=190020 card=19002)<br />
19001    INDEX RANGE SCAN TEST_UNFRAG_IDX (cr=42 pr=42 pw=42 time=497 us cost=42 size=0 card=19002)(object id 67988)</p>
<p>Why is this? well the answer lies in the clustering factor because of the way the data was loaded the clustering factor for the first table =400,000 and for the second = 880 (the second index is slightly smaller as well)  this has nothing to do with the placement of the index blocks on disk and everything to do with the slightly bizarre way the data was loaded,  rebuilding the index doesn&#8217;t change the clustering factor so won&#8217;t alter the execution plan unless we manually manipulate the statistics or use hints to force a range scan.</p>
<p>So do we have a similar type of fragmentation to the SQL server definition of External, well we appear too however the impact is not particularly large also in this case we could avoid it by creating the index with a pctfree of 50 and the organisation of the table data is actually the larger factor here we can&#8217;t fix the clustering factor by rebuilding the index only by changing the way we load the data.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/randomdba.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/randomdba.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/randomdba.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/randomdba.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/randomdba.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/randomdba.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/randomdba.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/randomdba.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/randomdba.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/randomdba.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/randomdba.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/randomdba.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/randomdba.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/randomdba.wordpress.com/25/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randomdba.wordpress.com&amp;blog=6071854&amp;post=25&amp;subd=randomdba&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://randomdba.wordpress.com/2009/03/06/index-fragmentation-just-like-sql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ce97d7c5b487b5918bb5e8f514d82b08?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">randomdba</media:title>
		</media:content>
	</item>
		<item>
		<title>Really simple queuing PL/SQL calcuations..</title>
		<link>http://randomdba.wordpress.com/2009/02/21/really-simple-queuing-plsql-calcuations/</link>
		<comments>http://randomdba.wordpress.com/2009/02/21/really-simple-queuing-plsql-calcuations/#comments</comments>
		<pubDate>Sat, 21 Feb 2009 01:30:54 +0000</pubDate>
		<dc:creator>randomdba</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Queuing]]></category>

		<guid isPermaLink="false">http://randomdba.wordpress.com/?p=11</guid>
		<description><![CDATA[A couple of posts by Chen Shapira, (this one barbershop-queue-demo and this one random-thoughts-about-queues)  over at prodlife.wordpress.com regarding queuing in systems and queuing theory piqued my interest. Way back in the beginning of my career in IT I worked in an outsourced  call centre building reports, providing management information etc. one critical piece of this [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randomdba.wordpress.com&amp;blog=6071854&amp;post=11&amp;subd=randomdba&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><!--[if gte mso 9]&gt;  Normal 0       MicrosoftInternetExplorer4  &lt;![endif]--><br />
A couple of posts by Chen Shapira, (this one <a href="http://prodlife.wordpress.com/2009/02/09/barbershop-queue-demo/" target="_blank">barbershop-queue-demo</a> and this one <a href="http://prodlife.wordpress.com/2009/01/27/random-thoughts-about-queues/" target="_blank">random-thoughts-about-queues</a>)  over at prodlife.wordpress.com regarding queuing in systems and queuing theory piqued my interest. Way back in the beginning of my career in IT I worked in an outsourced  call centre building reports, providing management information etc. one critical piece of this work was calculating requred staffing levels. A lot of this was based on a couple of pieces of maths the ErlangB and ErlangC Formulas as part of the reporting I ended up producing some PL/SQL to perform these calculations its not the best but if your interested its here <a href="http://randomdba.files.wordpress.com/2009/02/queuing_calc_plsql.doc">queuing_calc_plsql</a>.</p>
<p>This is based on the Excel erlangc calculator written by Lester Bromley at <a href="http://www.erlang.co.uk" target="_blank">www.erlang.co.uk</a> however my code has a couple of additional caveats, there is no error or input checking in the pl/sql I may add it a some point but then again I may not, it is therefore possible to get nonsensical responses or divide by zero errors.</p>
<p>Servicetime is defined in the functions as the time spent queuing not the queuing time+transaction time.</p>
<p>the PL/sql functions I wrote allow you to specify an interval rather than use a default of one hour, also the orgonal provides far more functions than i translated, I&#8217;ll probably get around to the others at some point but it may take a while.</p>
<p>The same conditions apply, you can use any of this code you like however do not sell rent or lease it out, also its provided as is and I&#8217;m not responsible for any loss or damages if its faulty or provides incorrect answers, also if you want to modify re-code into a different language feel free but it would be polite to contact Lester prior to publishing anything based on this as the original work is his.</p>
<p>Anyway back to the point, Chens post got me too thinking could this stuff be useful in an OTLP environment, my thoughts are possibly. It should be possible to estimate the number of cpus based on a given volume of transactions, cpu time required for each transaction and the desired service level. I suspect the model won&#8217;t be perfect as cpu usage for a transaction may be split into multiple chunks however hopefully I&#8217;ll get some time to produce a test case/simulation and see if it works aver the next week or so, if anyone has any bright ideas let me know..</p>
<p class="MsoNormal">Chris</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/randomdba.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/randomdba.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/randomdba.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/randomdba.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/randomdba.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/randomdba.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/randomdba.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/randomdba.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/randomdba.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/randomdba.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/randomdba.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/randomdba.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/randomdba.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/randomdba.wordpress.com/11/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randomdba.wordpress.com&amp;blog=6071854&amp;post=11&amp;subd=randomdba&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://randomdba.wordpress.com/2009/02/21/really-simple-queuing-plsql-calcuations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ce97d7c5b487b5918bb5e8f514d82b08?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">randomdba</media:title>
		</media:content>
	</item>
		<item>
		<title>I didn&#8217;t do It</title>
		<link>http://randomdba.wordpress.com/2009/01/06/i-didnt-do-it/</link>
		<comments>http://randomdba.wordpress.com/2009/01/06/i-didnt-do-it/#comments</comments>
		<pubDate>Tue, 06 Jan 2009 19:41:46 +0000</pubDate>
		<dc:creator>randomdba</dc:creator>
				<category><![CDATA[Oracle]]></category>

		<guid isPermaLink="false">http://randomdba.wordpress.com/?p=6</guid>
		<description><![CDATA[A recent incident at home reminded me of an interaction I had a few months ago with a developer, first the incident at home&#8230; I&#8217;d been working on my laptop in the back room (commenly refered to as the X-box room, the office, and occasionally the pit), having finished I left the laptop on the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randomdba.wordpress.com&amp;blog=6071854&amp;post=6&amp;subd=randomdba&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A recent incident at home reminded me of an interaction I had a few months ago with a developer, first the incident at home&#8230;</p>
<p>I&#8217;d been working on my laptop in the back room (commenly refered to as the X-box room, the office, and occasionally the pit), having finished I left the laptop on the floor open and wne toff to do something else. An hour or so later whillst my son was playing the xbox I hear a loud crash from the back room and as &#8220;what was that&#8221; the reply came back &#8220;nothing&#8221;, obviously this wasn&#8217;t true and on investigating I found that the metal box file I&#8217;d left on the couch had fallen off and landed on the laptop leaving a really impressive scratch on the screen. Whats interesting is the reaction this caused the instantaneous denial that anything had happened and a desire to avoid being in trouble led to a response of &#8220;nothing&#8221; and whillst I was angry it was obvious that it was my own fault as I should have put the laptop away rather than leave it lying out.</p>
<p>OK now how was this similar to the interaction at work, well basically we put a new application release containng a significant number of changes of an into a test enviroment, the system being primarily a batch driven data warehouse the initial results all looked good all the package updates worked so everyone went home happy. Next day everything was fine too the overnight loads completed slightly faster than previously everyones happy. Next day  I get a call</p>
<p>Developer: &#8220;The overnight batch hasn&#8217;t finnished can you see whats wrong with the database?&#8221;</p>
<p>Me: &#8220;how far has it got?&#8221;</p>
<p>Developer: &#8220;its still loading the security reference tables rigth at the start of the batch&#8221;</p>
<p>Me: &#8220;OK I&#8217;ll take a look, did you make any changes to this? I thought the changes where in the widget data loads&#8221;</p>
<p>Develper: &#8220;we didn&#8217;t chnage any of this code in this release&#8221;</p>
<p>So its off into an investigation of why we suddenly have a performance problem, we start with the usual checks nothing in the alert log, no hardware issues reported, nothing in the messages logs. A look at whats actually running shows the process id inserting into the second of a set of tables used for row level security, and checking the explain plan shows its using a really inificent execution path.</p>
<p>A review of the process shows that we load the first of two tables with about 10 million rows then load te second with around 35 million rows based on the first table joined to some other static tables. reviewing these We find there are no stats on the first table, at tis point I&#8217;m starting to get an idea of whats going on so looking at the code it looks like this.</p>
<p>Truncate table a;</p>
<p>truncatete table b;</p>
<p>select blah,blah, blah into table a from &#8230;;</p>
<p>insert a.blah,a.blah,&#8230;  into table b from a, &#8230;;</p>
<p>commit;</p>
<p>A quick dig into the code repository shows this has been changed the two truncates used to be deletes, this explains a coupe of things, the first loads where faster as removing the data from the look up tables is now a truncatete so doesn&#8217;t generate the undo that it used too however this has coincided with the gather stats job so the statistics show table a has zero rows instead of 10 million. So the following set of loads started to use a really bad execution path full scanning table a for every row inserted into table b. Mystery solved and fixed by adding a gather stats after the data is loaded into each table  (alternatively we could have locked the stats).</p>
<p>What does this show? well you shouldd always tell your DBA the truth as it may save time also we really are not trying to shift blame when we ask questions about things changing its a tool that allows us to narrow the range of our search to the problem. Also avoid a culture of blame as it leads to individuals covering things up meaning you find out something is going wrong much later when it may be too late to fix the problem or cost much more to put right.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/randomdba.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/randomdba.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/randomdba.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/randomdba.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/randomdba.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/randomdba.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/randomdba.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/randomdba.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/randomdba.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/randomdba.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/randomdba.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/randomdba.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/randomdba.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/randomdba.wordpress.com/6/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randomdba.wordpress.com&amp;blog=6071854&amp;post=6&amp;subd=randomdba&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://randomdba.wordpress.com/2009/01/06/i-didnt-do-it/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ce97d7c5b487b5918bb5e8f514d82b08?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">randomdba</media:title>
		</media:content>
	</item>
	</channel>
</rss>
