<?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>Life in the fast lane... &#187; PostgreSQL</title>
	<atom:link href="http://shoaibmir.wordpress.com/category/postgresql/feed/" rel="self" type="application/rss+xml" />
	<link>http://shoaibmir.wordpress.com</link>
	<description>by Shoaib Mir</description>
	<lastBuildDate>Thu, 01 Mar 2012 23:43:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='shoaibmir.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/d853f2aa84be87f1166bd5a62aa76283?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Life in the fast lane... &#187; PostgreSQL</title>
		<link>http://shoaibmir.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://shoaibmir.wordpress.com/osd.xml" title="Life in the fast lane..." />
	<atom:link rel='hub' href='http://shoaibmir.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Looking for libpq.so.4</title>
		<link>http://shoaibmir.wordpress.com/2010/10/13/looking-for-libpq-so-4/</link>
		<comments>http://shoaibmir.wordpress.com/2010/10/13/looking-for-libpq-so-4/#comments</comments>
		<pubDate>Tue, 12 Oct 2010 23:07:20 +0000</pubDate>
		<dc:creator>shoaibmir</dc:creator>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[libpq.so.4]]></category>
		<category><![CDATA[Slony]]></category>

		<guid isPermaLink="false">http://shoaibmir.wordpress.com/?p=397</guid>
		<description><![CDATA[I had always been building Slony from source, but for the first time I tried using the community version from &#8220;pgrpms.org&#8221;. I was using PostgreSQL version 8.3 so it was really easy to find the correct rpms at http://www.pgrpms.org/8.3/redhat/rhel-5-x86_64/ but as I tried installing Slony package I was hit with an error: "libpq.so.4 not found" [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shoaibmir.wordpress.com&#038;blog=6056447&#038;post=397&#038;subd=shoaibmir&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I had always been building Slony from source, but for the first time I tried using the community version from &#8220;pgrpms.org&#8221;. I was using PostgreSQL version 8.3 so it was really easy to find the correct rpms at <a title="PostgreSQL 8.3 RPM repository" href="http://www.pgrpms.org/8.3/redhat/rhel-5-x86_64/">http://www.pgrpms.org/8.3/redhat/rhel-5-x86_64/</a> but as I tried installing Slony package I was hit with an error:</p>
<pre>"libpq.so.4 not found"</pre>
<p>This looked really weird to me as I already had the libpq library installed as libpq.so.5 but it was still looking for libpq.so.4.</p>
<p>Looking for a solution I started going through the 8.3 RPMs and tried looking for file libpq.so.4 file&#8230;. bingooo!!! I found one which had it. compat-postgresql-libs was the answer to this problem.</p>
<p>After installing that package, Slony got installed successfully without any problems.<br />
&#8211;</p>
<p>Shoaib Mir<br />
shoaibmir[@]gmail.com</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/shoaibmir.wordpress.com/397/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/shoaibmir.wordpress.com/397/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/shoaibmir.wordpress.com/397/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/shoaibmir.wordpress.com/397/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/shoaibmir.wordpress.com/397/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/shoaibmir.wordpress.com/397/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/shoaibmir.wordpress.com/397/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/shoaibmir.wordpress.com/397/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/shoaibmir.wordpress.com/397/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/shoaibmir.wordpress.com/397/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/shoaibmir.wordpress.com/397/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/shoaibmir.wordpress.com/397/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/shoaibmir.wordpress.com/397/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/shoaibmir.wordpress.com/397/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shoaibmir.wordpress.com&#038;blog=6056447&#038;post=397&#038;subd=shoaibmir&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://shoaibmir.wordpress.com/2010/10/13/looking-for-libpq-so-4/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9103cd68b066be8c8715bb5facf86bd2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">shoaibmir</media:title>
		</media:content>
	</item>
		<item>
		<title>(SLONY) cache lookup failed for type</title>
		<link>http://shoaibmir.wordpress.com/2010/10/13/slony-cache-lookup-failed-for-type/</link>
		<comments>http://shoaibmir.wordpress.com/2010/10/13/slony-cache-lookup-failed-for-type/#comments</comments>
		<pubDate>Tue, 12 Oct 2010 22:52:19 +0000</pubDate>
		<dc:creator>shoaibmir</dc:creator>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[cache lookup failed]]></category>
		<category><![CDATA[Slony]]></category>

		<guid isPermaLink="false">http://shoaibmir.wordpress.com/?p=391</guid>
		<description><![CDATA[Just been away from blogging for quite a while now as work had been keeping me extremly busy but finally got sometime today to blog about an interesting problem I saw with Slony yesterday&#8230; While at a customer site, I upgraded them to Slony version 1.2.21 and also during the process re-initialized the cluster. The [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shoaibmir.wordpress.com&#038;blog=6056447&#038;post=391&#038;subd=shoaibmir&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Just been away from blogging for quite a while now as work had been keeping me extremly busy but finally got sometime today to blog about an interesting problem I saw with Slony yesterday&#8230;</p>
<p>While at a customer site, I upgraded them to Slony version 1.2.21 and also during the process re-initialized the cluster. The whole process was done without any problem but right after everything was synched across, one of the Sysadmins saw this error in the database server log file:</p>
<pre>"cache lookup failed for type 27889"</pre>
<p>On doing an INSERT into sl_log_1 table.</p>
<p>Having never seen such a problem before with Slony, it got me a little worried as this was a production database so we had to fix it very quickly.</p>
<p>After doing a little bit of research found out that, by simply restarting the application server which is making connections to the database server will solve the problem. Reason being, the application server had already established a connection to database when we were dropping and re-creating the cluster and that is why it was still looking for old values  that were sitting in the cache. Once we restarted the application server, it was all fine.</p>
<p>&#8211;<br />
Shoaib Mir<br />
shoaibmir[@]gmail.com</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/shoaibmir.wordpress.com/391/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/shoaibmir.wordpress.com/391/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/shoaibmir.wordpress.com/391/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/shoaibmir.wordpress.com/391/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/shoaibmir.wordpress.com/391/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/shoaibmir.wordpress.com/391/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/shoaibmir.wordpress.com/391/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/shoaibmir.wordpress.com/391/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/shoaibmir.wordpress.com/391/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/shoaibmir.wordpress.com/391/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/shoaibmir.wordpress.com/391/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/shoaibmir.wordpress.com/391/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/shoaibmir.wordpress.com/391/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/shoaibmir.wordpress.com/391/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shoaibmir.wordpress.com&#038;blog=6056447&#038;post=391&#038;subd=shoaibmir&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://shoaibmir.wordpress.com/2010/10/13/slony-cache-lookup-failed-for-type/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9103cd68b066be8c8715bb5facf86bd2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">shoaibmir</media:title>
		</media:content>
	</item>
		<item>
		<title>Understanding ‘iostat’ output for database I/O loads</title>
		<link>http://shoaibmir.wordpress.com/2010/06/05/understanding-%e2%80%98iostat%e2%80%99-output-for-database-io-loads/</link>
		<comments>http://shoaibmir.wordpress.com/2010/06/05/understanding-%e2%80%98iostat%e2%80%99-output-for-database-io-loads/#comments</comments>
		<pubDate>Sat, 05 Jun 2010 08:13:31 +0000</pubDate>
		<dc:creator>shoaibmir</dc:creator>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[iostat]]></category>

		<guid isPermaLink="false">http://shoaibmir.wordpress.com/?p=375</guid>
		<description><![CDATA[From the Linux man page: “The iostat command is used for monitoring system input/output device loading by observing the time the devices are active in relation to their average transfer rates. The iostat command generates reports that can be used to change system configuration to better balance the input/output load between physical disks.” Reports that [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shoaibmir.wordpress.com&#038;blog=6056447&#038;post=375&#038;subd=shoaibmir&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>From the Linux man page:</p>
<p><em>“The iostat command is used for monitoring system input/output device loading by observing the time the devices are active in relation to their average transfer rates. The iostat command generates reports that can be used to change system configuration to better balance the input/output load between physical disks.”</em></p>
<p>Reports that we get from ‘iostat’ are really useful but I myself had a little bit of trouble when trying to interpret the results while using the the first time, but since then its my preferred go-to tool when trying to debug disk overloads.</p>
<p>I usually use the iostat command with the following switches:</p>
<pre>iostat –d –x &lt;interval&gt;</pre>
<p>Where…</p>
<p><strong>-d</strong> = gets rid of the CPU stats so that we can easily concentrate on the I/O only</p>
<p><strong>-x</strong> = some additional info like ‘await’ and ‘svctm’ (will discuss them later)</p>
<p><strong> </strong></p>
<p><strong>&lt;interval&gt;</strong> = this is time in seconds, so every number of &lt;interval&gt; seconds you will get a new ‘iostat’ report</p>
<p>Let’s now see a sample output of ‘iostat’:</p>
<p><a href="http://shoaibmir.files.wordpress.com/2010/06/iostat.jpg"><img class="aligncenter size-full wp-image-376" title="iostat" src="http://shoaibmir.files.wordpress.com/2010/06/iostat.jpg?w=600&h=46" alt="" width="600" height="46" /></a></p>
<p>If we look at stats above usually we would look at %util and if we see close to 100% it can identify the problem for a single disk setup, but not in a usual multi-disks scenario.</p>
<p>Columns that we look at it in order to identify the problem will be:</p>
<p><strong>syvctm:</strong> The average service time (in milliseconds) for I/O requests that were issued to the device</p>
<p><strong>await:</strong> The average time (in milliseconds) for I/O requests issued to the device to be served. This includes the time spent by the requests in queue and the time spent servicing them.</p>
<p>This basically means:</p>
<pre> await = syvctm + wait time in queue</pre>
<p>Now using the above we can have a basic rule to identify an overloaded setup:</p>
<p>&#8230;if you can see a lot of difference in values for &#8216;syvctm&#8217; and &#8216;await&#8217; every now and then, that can tell you about I/O requests being going into long waits and this should help you identify the problem.</p>
<p>&#8211;<br />
Shoaib Mir<br />
shoaibmir[a]gmail.com</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/shoaibmir.wordpress.com/375/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/shoaibmir.wordpress.com/375/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/shoaibmir.wordpress.com/375/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/shoaibmir.wordpress.com/375/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/shoaibmir.wordpress.com/375/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/shoaibmir.wordpress.com/375/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/shoaibmir.wordpress.com/375/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/shoaibmir.wordpress.com/375/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/shoaibmir.wordpress.com/375/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/shoaibmir.wordpress.com/375/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/shoaibmir.wordpress.com/375/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/shoaibmir.wordpress.com/375/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/shoaibmir.wordpress.com/375/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/shoaibmir.wordpress.com/375/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shoaibmir.wordpress.com&#038;blog=6056447&#038;post=375&#038;subd=shoaibmir&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://shoaibmir.wordpress.com/2010/06/05/understanding-%e2%80%98iostat%e2%80%99-output-for-database-io-loads/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9103cd68b066be8c8715bb5facf86bd2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">shoaibmir</media:title>
		</media:content>

		<media:content url="http://shoaibmir.files.wordpress.com/2010/06/iostat.jpg" medium="image">
			<media:title type="html">iostat</media:title>
		</media:content>
	</item>
		<item>
		<title>TRUNCATE problems with Slony</title>
		<link>http://shoaibmir.wordpress.com/2010/06/03/truncate-problems-with-slony/</link>
		<comments>http://shoaibmir.wordpress.com/2010/06/03/truncate-problems-with-slony/#comments</comments>
		<pubDate>Thu, 03 Jun 2010 07:07:58 +0000</pubDate>
		<dc:creator>shoaibmir</dc:creator>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Slony]]></category>
		<category><![CDATA[Truncate]]></category>

		<guid isPermaLink="false">http://shoaibmir.wordpress.com/?p=369</guid>
		<description><![CDATA[Slony (http://slony.info/) is great for high availability/load balancing and I have been recommending it to users for years now and haven’t really seen any major problems with it if you have got proper checks on the whole replication setup using proper monitoring with something like Nagios. But well at times there is this annoying thing [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shoaibmir.wordpress.com&#038;blog=6056447&#038;post=369&#038;subd=shoaibmir&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Slony (<a href="http://slony.info/">http://slony.info/</a>) is great for high availability/load balancing and I have been recommending it to users for years now and haven’t really seen any major problems with it if you have got proper checks on the whole replication setup using proper monitoring with something like Nagios.</p>
<p>But well at times there is this annoying thing that always gave me trouble when a user goes and just runs a TRUNCATE on one of the master tables in order to do maintenance and all of the sudden you start getting errors like this on the slave nodes:</p>
<p><code>2010-06-01 11:02:09 ESTERROR  remoteWorkerThread_1: "insert into "public"."table1" ("a","b") values ('1','one');</code></p>
<p><code> </code></p>
<p><code>" ERROR:  duplicate key value violates unique constraint "table1_pkey"</code></p>
<p>The reason behind this is&#8230;</p>
<ul>
<li>You      did a truncate on a table at master node and assumed that this statement      is all replicated to slaves as well</li>
<li>Truncate      event is not triggered like INSERT/UPDATE/DELETE (For PostgreSQL &lt; 8.4) so that means the slave never got it and they still have the old copy of      the table</li>
<li>On      master the table is now empty but the slave table has old records, which      means on inserting new data you might start getting duplicate key      violation error</li>
</ul>
<p>I have used the following approach in the past to solve it&#8230;</p>
<p>Do a TRUNCATE on slaves for the same table and you will then see all those INSERTS/DELETES/UPDATES going through in the Slony logs file that have been queued up since Slony started getting these duplicate key violation problems</p>
<p>In order to avoid these scenarios, you have to keep on checking Slony lag times from sl_status of replication schema and alert if it goes above the dangerous lag limit. If it does, go and check the Slony logs as they usually tell the detailed story.</p>
<p>Another option to avoid doing TRUNCATE is by using table partitioning, which means when you need to drop old data just get rid of the specific partition and drop it out of the Slony cluster as well instead of doing a TRUNCATE. This way it will save you a lot of database routine maintenance like vacuuming as well because you are not deleting data using DELETEs but you are now dropping the whole partition.</p>
<p>I have recently seen trigger support for PostgreSQL 8.4 and above but I am not sure if it’s been implemented in Slony yet or what exactly is the plan on that, but it will be great to have that with Slony. I do have seen Bucardo (<a href="http://blog.endpoint.com/2009/07/bucardo-and-truncate-triggers.html">http://blog.endpoint.com/2009/07/bucardo-and-truncate-triggers.html</a>) supporting truncate with triggers though.</p>
<p>&#8211;<br />
Shoaib Mir<br />
shoaibmir[@]gmail.com</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/shoaibmir.wordpress.com/369/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/shoaibmir.wordpress.com/369/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/shoaibmir.wordpress.com/369/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/shoaibmir.wordpress.com/369/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/shoaibmir.wordpress.com/369/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/shoaibmir.wordpress.com/369/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/shoaibmir.wordpress.com/369/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/shoaibmir.wordpress.com/369/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/shoaibmir.wordpress.com/369/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/shoaibmir.wordpress.com/369/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/shoaibmir.wordpress.com/369/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/shoaibmir.wordpress.com/369/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/shoaibmir.wordpress.com/369/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/shoaibmir.wordpress.com/369/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shoaibmir.wordpress.com&#038;blog=6056447&#038;post=369&#038;subd=shoaibmir&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://shoaibmir.wordpress.com/2010/06/03/truncate-problems-with-slony/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9103cd68b066be8c8715bb5facf86bd2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">shoaibmir</media:title>
		</media:content>
	</item>
		<item>
		<title>Table level auto-vacuum settings</title>
		<link>http://shoaibmir.wordpress.com/2010/05/31/table-level-auto-vacuum-settings/</link>
		<comments>http://shoaibmir.wordpress.com/2010/05/31/table-level-auto-vacuum-settings/#comments</comments>
		<pubDate>Mon, 31 May 2010 09:36:38 +0000</pubDate>
		<dc:creator>shoaibmir</dc:creator>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[ALTER TABLE]]></category>
		<category><![CDATA[autovacuum]]></category>
		<category><![CDATA[CREATE TABLE]]></category>

		<guid isPermaLink="false">http://shoaibmir.wordpress.com/?p=356</guid>
		<description><![CDATA[While working with users on custom auto-vacuum settings, one of the real problems I saw with PostgreSQL 8.3 and below was making them understand the ways to update pg_autovacuum as sometimes little mistakes could cause you a lot of trouble. I had some annoying experiences with those column values for pg_autovacuum at times as well, like [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shoaibmir.wordpress.com&#038;blog=6056447&#038;post=356&#038;subd=shoaibmir&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>While working with users on custom auto-vacuum settings, one of the real problems I saw with PostgreSQL 8.3 and below was making them understand the ways to update pg_autovacuum as sometimes little mistakes could cause you a lot of trouble.</p>
<p>I had some annoying experiences with those column values for pg_autovacuum at times as well, like once I had mistakenly autovacuum_freeze_min_age value set to zero while autovacuum_enabled set to false the auto-vacuum thread still kept doing vacuuming on that table. After doing a little bit of research found out that it had to be set to -1 so it can use the system-wide values and then it would all work. This was all a little confusing for the new users and then the other problem was as you a dump and restore of the database, all those settings are just gone so you will have to do it all over again.</p>
<p>I had been using pg_autovacuum with version 8.3 and just today while I was writing an upgrade plan for a client upgrading databases to 8.4, I just came across this improved custom auto-vacuum feature which lets you simply do a CREATE/ALTER TABLE command and set anything as you like for auto-vacuuming per table using the WITH option and it will also copy all these settings in the dump file (pg_dump output) as well which makes my life so easy while moving databases.</p>
<p>An example of it can be:</p>
<pre>postgres=# \d test
Table "public.test"
Column |       Type        | Modifiers
--------+-------------------+-----------
a      | integer           | not null
b      | character varying |
Indexes:
"test_pkey" PRIMARY KEY, btree (a)
postgres=# ALTER table test SET (autovacuum_vacuum_threshold=50, 
autovacuum_analyze_threshold=50);
ALTER TABLE
--
-- PostgreSQL database dump
--
CREATE TABLE test (
a integer NOT NULL,
b character varying
)
WITH (autovacuum_vacuum_threshold=50, autovacuum_analyze_threshold=50);
--
-- PostgreSQL database dump complete
--</pre>
<p>You can find details for the storage settings that can be set with the CREATE/ALTER TABLE at <a href="http://www.postgresql.org/docs/8.4/static/sql-createtable.html#SQL-CREATETABLE-STORAGE-PARAMETERS">http://www.postgresql.org/docs/8.4/static/sql-createtable.html#SQL-CREATETABLE-STORAGE-PARAMETERS</a></p>
<p>&#8211;<br />
Shoaib Mir<br />
shoaibmir[@]gmail.com</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/shoaibmir.wordpress.com/356/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/shoaibmir.wordpress.com/356/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/shoaibmir.wordpress.com/356/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/shoaibmir.wordpress.com/356/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/shoaibmir.wordpress.com/356/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/shoaibmir.wordpress.com/356/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/shoaibmir.wordpress.com/356/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/shoaibmir.wordpress.com/356/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/shoaibmir.wordpress.com/356/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/shoaibmir.wordpress.com/356/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/shoaibmir.wordpress.com/356/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/shoaibmir.wordpress.com/356/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/shoaibmir.wordpress.com/356/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/shoaibmir.wordpress.com/356/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shoaibmir.wordpress.com&#038;blog=6056447&#038;post=356&#038;subd=shoaibmir&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://shoaibmir.wordpress.com/2010/05/31/table-level-auto-vacuum-settings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9103cd68b066be8c8715bb5facf86bd2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">shoaibmir</media:title>
		</media:content>
	</item>
		<item>
		<title>Using SchemaSpy for DB diagrams</title>
		<link>http://shoaibmir.wordpress.com/2010/05/01/using-schemaspy-for-db-diagrams/</link>
		<comments>http://shoaibmir.wordpress.com/2010/05/01/using-schemaspy-for-db-diagrams/#comments</comments>
		<pubDate>Sat, 01 May 2010 10:04:43 +0000</pubDate>
		<dc:creator>shoaibmir</dc:creator>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[SchemaSpy]]></category>

		<guid isPermaLink="false">http://shoaibmir.wordpress.com/?p=316</guid>
		<description><![CDATA[A couple of months back I came across this very useful tool &#8220;SchemaSpy&#8221; ( http://schemaspy.sourceforge.net/ ) which really helped me out in generating automated (nightly) database diagrams but never got enough time to share it with everyone. &#8220;SchemaSpy is a Java-based tool that analyzes the metadata of a schema in a database and generates a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shoaibmir.wordpress.com&#038;blog=6056447&#038;post=316&#038;subd=shoaibmir&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A couple of months back I came across this very useful tool &#8220;SchemaSpy&#8221; (<a href="http://schemaspy.sourceforge.net/"> http://schemaspy.sourceforge.net/ </a>) which really helped me out in generating automated (nightly) database diagrams but never got enough time to share it with everyone.</p>
<p>&#8220;SchemaSpy is a Java-based tool that analyzes the metadata of a schema in a database and generates a visual representation of it in a browser-displayable format. It lets you click through the hierarchy of database tables via child and parent table relationships as represented by both HTML links and entity-relationship diagrams. It&#8217;s also designed to help resolve the obtuse errors that a database sometimes gives related to failures due to constraints&#8221;</p>
<p>It works great with PostgreSQL and very easy to cron as you just need to execute a single command like this:</p>
<p><code>java -jar schemaSpy.jar -t dbType -db dbName [-s schema] -u user [-p password] -o outputDir</code></p>
<p>&#8230;that will generate very nice and user-friendly DB diagrams and a whole lots of information about the database. You can have a quick look at the sample on <a href="http://schemaspy.sourceforge.net/sample/"> http://schemaspy.sourceforge.net/sample/ </a></p>
<p><strong>Update:</strong> Also found an easy to use GUI for SchemaSpy <a href="http://www.joachim-uhl.de/projekte/schemaspygui/"> http://www.joachim-uhl.de/projekte/schemaspygui/ </a> where you don&#8217;t need to remember all the option but you can easily pick them up from the frontend.</p>
<p>Make sure you grab the latest beta from <a rel="nofollow" href="http://schemaspy.sourceforge.net/schemaSpy.jar">http://schemaspy.sourceforge.net/schemaSpy.jar</a> as mentioned by John Currier.</p>
<p>&#8211;<br />
Shoaib Mir<br />
shoaibmir[@]gmail.com</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/shoaibmir.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/shoaibmir.wordpress.com/316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/shoaibmir.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/shoaibmir.wordpress.com/316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/shoaibmir.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/shoaibmir.wordpress.com/316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/shoaibmir.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/shoaibmir.wordpress.com/316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/shoaibmir.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/shoaibmir.wordpress.com/316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/shoaibmir.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/shoaibmir.wordpress.com/316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/shoaibmir.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/shoaibmir.wordpress.com/316/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shoaibmir.wordpress.com&#038;blog=6056447&#038;post=316&#038;subd=shoaibmir&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://shoaibmir.wordpress.com/2010/05/01/using-schemaspy-for-db-diagrams/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9103cd68b066be8c8715bb5facf86bd2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">shoaibmir</media:title>
		</media:content>
	</item>
		<item>
		<title>Using pg_hba.d folder for HBA rules</title>
		<link>http://shoaibmir.wordpress.com/2010/01/23/using-pg_hba-d-folder-for-hba-rules/</link>
		<comments>http://shoaibmir.wordpress.com/2010/01/23/using-pg_hba-d-folder-for-hba-rules/#comments</comments>
		<pubDate>Sat, 23 Jan 2010 00:11:31 +0000</pubDate>
		<dc:creator>shoaibmir</dc:creator>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[pg_hba]]></category>
		<category><![CDATA[pg_hba.d]]></category>

		<guid isPermaLink="false">http://shoaibmir.wordpress.com/?p=302</guid>
		<description><![CDATA[Its been quite a while since I did post something and that was due to a very busy schedule at work but got lucky today to get a few mins and sharing something I always wanted to write about. We got an environment at work where we have a quite a huge number of databases [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shoaibmir.wordpress.com&#038;blog=6056447&#038;post=302&#038;subd=shoaibmir&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Its been quite a while since I did post something and that was due to a very busy schedule at work but got lucky today to get a few mins and sharing something I always wanted to write about.</p>
<p>We got an environment at work where we have a quite a huge number of databases on each PostgreSQL development database server and it is because of the static images of the production DBs we need to create for QA and Dev most of the time. In such a scenario if we keep on adding rules to the pg_hba.conf file it can be a big mess with around 200-300 lines in there and thats a nightmare to manage for a DBA. </p>
<p>Solution &#8211; What we ended up doing for this was by having a folder pg_hba.d like this:</p>
<p><code><br />
pg_hba.conf<br />
pg_hba.d<br />
postgresql.conf<br />
postmaster.opts<br />
</code></p>
<p>and under pg_hba.d folder:</p>
<p><code><br />
host1-dbuser1-trust.db<br />
host2-dbuser2-md5.db<br />
</code></p>
<p>The above two files then contain the list of databases that need to given access for those hosts.</p>
<p><code><br />
host1-dbuser1-trust.db:<br />
db1<br />
db2<br />
db3<br />
</code></p>
<p>This way you can have host files for each of your staging servers that are used by QA and then have a list of databases that need to be given access from those.</p>
<p>Last step is adding details for using these pg_hba.d files, this can be done in pg_hba.conf file the following way:</p>
<p><code><br />
host    @pg_hba.d/host1-dbuser1-trust.db   dbuser1                       192.168.2.5/32            trust<br />
host    @pg_hba.d/host2-dbuser2-trust.db   dbuser2                       192.168.2.6/32            md5<br />
</code></p>
<p>This way instead of having the whole list of databases in pg_hba.conf file we now just have two entries and making it very easy to manage. When ever you need to give a new database access to those hosts just add it to the specific file for that host under pg_hba.d folder and reload the DB server.</p>
<p>&#8211;<br />
Shoaib Mir<br />
shoaibmir[@]gmail.com</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/shoaibmir.wordpress.com/302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/shoaibmir.wordpress.com/302/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/shoaibmir.wordpress.com/302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/shoaibmir.wordpress.com/302/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/shoaibmir.wordpress.com/302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/shoaibmir.wordpress.com/302/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/shoaibmir.wordpress.com/302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/shoaibmir.wordpress.com/302/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/shoaibmir.wordpress.com/302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/shoaibmir.wordpress.com/302/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/shoaibmir.wordpress.com/302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/shoaibmir.wordpress.com/302/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/shoaibmir.wordpress.com/302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/shoaibmir.wordpress.com/302/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shoaibmir.wordpress.com&#038;blog=6056447&#038;post=302&#038;subd=shoaibmir&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://shoaibmir.wordpress.com/2010/01/23/using-pg_hba-d-folder-for-hba-rules/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9103cd68b066be8c8715bb5facf86bd2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">shoaibmir</media:title>
		</media:content>
	</item>
		<item>
		<title>Scripting within psql</title>
		<link>http://shoaibmir.wordpress.com/2009/11/02/scripting-within-psql/</link>
		<comments>http://shoaibmir.wordpress.com/2009/11/02/scripting-within-psql/#comments</comments>
		<pubDate>Mon, 02 Nov 2009 12:55:45 +0000</pubDate>
		<dc:creator>shoaibmir</dc:creator>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[pgstattuple]]></category>
		<category><![CDATA[PSQL]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://shoaibmir.wordpress.com/?p=261</guid>
		<description><![CDATA[In one of my previous posts I was told of using PSQL instead of shell scripting to make things much simpler. That turned out to a good tip and with some help from my colleague at work I am now so used to PSQL in these kind of scenarios. Just today I had to get [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shoaibmir.wordpress.com&#038;blog=6056447&#038;post=261&#038;subd=shoaibmir&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In one of my previous posts I was told of using PSQL instead of shell scripting to make things much simpler. That turned out to a good tip and with some help from my colleague at work I am now so used to PSQL in these kind of scenarios.</p>
<p>Just today I had to get the dead tuple percentages (using pgstattuple contrib) for tables within all databases on the server and here is how I was to get it done using PSQL and a simple shell script&#8230;.</p>
<pre>#!/bin/bash
PSQL="psql -A -t"
DBLIST=$($PSQL postgres -c "select datname from pg_database
where not datistemplate and datname not in ('postgres')")
for DB in $DBLIST; do
 echo $DB;
 psql $DB  &lt; gettupd.sql &gt; $DB.out
done
exit 0
</pre>
<p><strong>gettupd.sql</strong></p>
<pre>\a
\t
\o /tmp/tupd.sql
select 'SELECT \'' || relname || '\', * from pgstattuple('''||schemaname||
'.'||relname||''');' from pg_stat_user_tables ;
\o
\i /tmp/tupd.sql
\! rm /tmp/tupd.sql
\a
\t
</pre>
<p>PSQL is just the way to go&#8230;  <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>&#8211;<br />
Shoaib Mir<br />
shoaibmir[@]gmail.com</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/shoaibmir.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/shoaibmir.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/shoaibmir.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/shoaibmir.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/shoaibmir.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/shoaibmir.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/shoaibmir.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/shoaibmir.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/shoaibmir.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/shoaibmir.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/shoaibmir.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/shoaibmir.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/shoaibmir.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/shoaibmir.wordpress.com/261/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shoaibmir.wordpress.com&#038;blog=6056447&#038;post=261&#038;subd=shoaibmir&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://shoaibmir.wordpress.com/2009/11/02/scripting-within-psql/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9103cd68b066be8c8715bb5facf86bd2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">shoaibmir</media:title>
		</media:content>
	</item>
		<item>
		<title>A quick way to change index tablespace</title>
		<link>http://shoaibmir.wordpress.com/2009/09/29/a-quick-way-to-change-index-tablespace/</link>
		<comments>http://shoaibmir.wordpress.com/2009/09/29/a-quick-way-to-change-index-tablespace/#comments</comments>
		<pubDate>Tue, 29 Sep 2009 10:26:57 +0000</pubDate>
		<dc:creator>shoaibmir</dc:creator>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[index]]></category>
		<category><![CDATA[move disk]]></category>
		<category><![CDATA[tablepsace]]></category>

		<guid isPermaLink="false">http://shoaibmir.wordpress.com/?p=248</guid>
		<description><![CDATA[On one of the database servers, I had to quickly move all indexes from all the databases on to a different disk in order to free up some space from the main disk. I thought of sharing it so that someone else wanting to do the same thing can get an idea for doing the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shoaibmir.wordpress.com&#038;blog=6056447&#038;post=248&#038;subd=shoaibmir&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>On one of the database servers, I had to quickly move all indexes from all the databases on to a different disk in order to free up some space from the main disk. I thought of sharing it so that someone else wanting to do the same thing can get an idea for doing the same&#8230;.</p>
<p>A quick how to,</p>
<p>First made a query to get all the indexes within a database using the following:</p>
<pre>select pg_namespace.nspname||'.'||pg_class.relname  from pg_class, pg_namespace
where pg_class.relnamespace  = pg_namespace.oid and pg_class.relkind = 'i' and pg_class.relname
not like 'pg_%'</pre>
<p>and then using a simple script, plugging in the the above mentioned query to do an ALTER INDEX for each index by setting the new table space:</p>
<pre>#!/bin/bash
DNAME_LIST=$(psql postgres -A -t -c "select datname from pg_database where
not datistemplate and datname != 'postgres'")
for DATABASE in $DNAME_LIST; do
INAME_LIST=$($PSQL $DATABASE -A -t -c "select pg_namespace.nspname||'.'||pg_class.relname
from pg_class, pg_namespace where
pg_class.relnamespace  = pg_namespace.oid and pg_class.relkind = 'i' and pg_class.relname
not like 'pg_%'")
    ( for INDEX in $INAME_LIST; do echo "ALTER INDEX $INDEX SET TABLESPACE
new_disk_index;"; done ) | psql $DATABASE
done</pre>
<p>&#8211;<br />
Shoaib Mir<br />
shoaibmir[@]gmail.com</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/shoaibmir.wordpress.com/248/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/shoaibmir.wordpress.com/248/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/shoaibmir.wordpress.com/248/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/shoaibmir.wordpress.com/248/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/shoaibmir.wordpress.com/248/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/shoaibmir.wordpress.com/248/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/shoaibmir.wordpress.com/248/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/shoaibmir.wordpress.com/248/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/shoaibmir.wordpress.com/248/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/shoaibmir.wordpress.com/248/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/shoaibmir.wordpress.com/248/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/shoaibmir.wordpress.com/248/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/shoaibmir.wordpress.com/248/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/shoaibmir.wordpress.com/248/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shoaibmir.wordpress.com&#038;blog=6056447&#038;post=248&#038;subd=shoaibmir&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://shoaibmir.wordpress.com/2009/09/29/a-quick-way-to-change-index-tablespace/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9103cd68b066be8c8715bb5facf86bd2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">shoaibmir</media:title>
		</media:content>
	</item>
		<item>
		<title>Row size and Btree index</title>
		<link>http://shoaibmir.wordpress.com/2009/09/23/row-size-and-btree-index/</link>
		<comments>http://shoaibmir.wordpress.com/2009/09/23/row-size-and-btree-index/#comments</comments>
		<pubDate>Wed, 23 Sep 2009 11:10:24 +0000</pubDate>
		<dc:creator>shoaibmir</dc:creator>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[btree]]></category>
		<category><![CDATA[index]]></category>
		<category><![CDATA[row size]]></category>
		<category><![CDATA[text search]]></category>

		<guid isPermaLink="false">http://shoaibmir.wordpress.com/?p=243</guid>
		<description><![CDATA[At work today saw an error while inserting data into a table: ERROR: index row size 2962 exceeds btree maximum, 2713 Looking at the HINT in the error, found out that you cant have the row size of more then 1/3th of the PostgreSQL block size (8K by default) for a btree index on the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shoaibmir.wordpress.com&#038;blog=6056447&#038;post=243&#038;subd=shoaibmir&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>At work today saw an error while inserting data into a table:</p>
<pre>ERROR: index row size 2962 exceeds btree maximum, 2713</pre>
<p>Looking at the HINT in the error, found out that you cant have the row size of more then 1/3th of the PostgreSQL block size (8K by default) for a btree index on the column.</p>
<p>The best is to start using PostgreSQL full text search option for these kind of scenarios as it will be much faster and easier&#8230; but in my case that was not an option so had to somehow get around this problem without using text search engine.</p>
<p>After a little bit of research two possible solutions I could find out were (where column was of text data type):</p>
<p>-  Create a hash index on the same column as it will let you store more then 1/3rd of the block size, but a couple of things you need to consider before you go that route&#8230;</p>
<ul>
<li>It lets you get the data inserted for more then the 1/3rd of the block size but that again has limitation, you cant go above the PG block size and even closer to that.</li>
<li>With Hash indexing you wont be able to use the text pattern matching functions &#8220;LIKE&#8221; and &#8220;ILIKE&#8221;, you are left with &#8220;=&#8221;</li>
</ul>
<p>-  The other solution is to use the partial index where CREATE INDEX  will look something like this&#8230;</p>
<pre>        create index .... where length(clm_name) &lt; 500</pre>
<p>&#8230;this will require changing the queries as well, now you will have to add &#8220;where length(clm_name) &lt; 500&#8243; while doing SELECTS.</p>
<p>&#8211;<br />
Shoaib Mir<br />
shoaibmir[@]gmail.com</p>
<pre></pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/shoaibmir.wordpress.com/243/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/shoaibmir.wordpress.com/243/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/shoaibmir.wordpress.com/243/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/shoaibmir.wordpress.com/243/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/shoaibmir.wordpress.com/243/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/shoaibmir.wordpress.com/243/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/shoaibmir.wordpress.com/243/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/shoaibmir.wordpress.com/243/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/shoaibmir.wordpress.com/243/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/shoaibmir.wordpress.com/243/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/shoaibmir.wordpress.com/243/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/shoaibmir.wordpress.com/243/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/shoaibmir.wordpress.com/243/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/shoaibmir.wordpress.com/243/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shoaibmir.wordpress.com&#038;blog=6056447&#038;post=243&#038;subd=shoaibmir&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://shoaibmir.wordpress.com/2009/09/23/row-size-and-btree-index/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9103cd68b066be8c8715bb5facf86bd2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">shoaibmir</media:title>
		</media:content>
	</item>
	</channel>
</rss>
