From pgsql-hackers-owner@postgresql.org  Fri Sep 30 22:44:29 2005
X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 5252DD9CF4
	for <pgsql-hackers-postgresql.org@localhost.postgresql.org>;
	Fri, 30 Sep 2005 22:44:25 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 58465-09
	for <pgsql-hackers-postgresql.org@localhost.postgresql.org>;
	Sat,  1 Oct 2005 01:44:20 +0000 (GMT)
Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.198])
	by svr1.postgresql.org (Postfix) with ESMTP id 02091D9CF2
	for <pgsql-hackers@postgresql.org>;
	Fri, 30 Sep 2005 22:44:22 -0300 (ADT)
Received: by xproxy.gmail.com with SMTP id t15so25792wxc
	for <pgsql-hackers@postgresql.org>;
	Fri, 30 Sep 2005 18:44:27 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references;
	b=P/udTqE9F/zpzG82dv8nSnIsBf6ICvrrpfeiAU6e1H65llK+HXMWNgMrVY+uZWig+jFmkqfHVd8TJmwtJI4jNfZD6Vy4LFvbf4b6+VCiu+teS7bsezl1X2IF0mug70KhZNIeBc99ETVKD346U93UTF0CrndFBY+CNN+a7Way2dw=
Received: by 10.70.118.6 with SMTP id q6mr1109255wxc;
	Fri, 30 Sep 2005 18:44:26 -0700 (PDT)
Received: by 10.70.76.1 with HTTP; Fri, 30 Sep 2005 18:44:26 -0700 (PDT)
Message-ID: <e692861c0509301844w51280e3axbf8ba0a276f27856@mail.gmail.com>
Date: Fri, 30 Sep 2005 21:44:26 -0400
From: Gregory Maxwell <gmaxwell@gmail.com>
Reply-To: Gregory Maxwell <gmaxwell@gmail.com>
To: Ron Peacetree <rjpeace@earthlink.net>
Subject: Re: [PERFORM] A Better External Sort?
Cc: josh@agliodbs.com, pgsql-hackers@postgresql.org,
	pgsql-performance@postgresql.org
In-Reply-To: 
 <22251764.1128123609842.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
References: 
 <22251764.1128123609842.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.148 required=5 tests=[AWL=-0.124, RCVD_BY_IP=0.024,
	RISK_FREE=0.247]
X-Spam-Level: 
X-Archive-Number: 200509/1460
X-Sequence-Number: 73857

On 9/30/05, Ron Peacetree <rjpeace@earthlink.net> wrote:
> 4=3D I'm sure we are paying all sorts of nasty overhead for essentially
> emulating the pg "filesystem" inside another filesystem.  That means
> ~2x as much overhead to access a particular piece of data.
>
> The simplest solution is for us to implement a new VFS compatible
> filesystem tuned to exactly our needs: pgfs.
>
> We may be able to avoid that by some amount of hacking or
> modifying of the current FSs we use, but I suspect it would be more
> work for less ROI.

On this point, Reiser4 fs already implements a number of things which
would be desirable for PostgreSQL. For example: write()s to reiser4
filesystems are atomic, so there is no risk of torn pages (this is
enabled because reiser4 uses WAFL like logging where data is not
overwritten but rather relocated). The filesystem is modular and
extensible so it should be easy to add whatever additional semantics
are needed.  I would imagine that all that would be needed is some
more atomicity operations (single writes are already atomic, but I'm
sure it would be useful to batch many writes into a transaction),some
layout and packing controls, and some flush controls.  A step further
would perhaps integrate multiversioning directly into the FS (the
wandering logging system provides the write side of multiversioning, a
little read side work would be required.). More importantly: the file
system was intended to be extensible for this sort of application.

It might make a good 'summer of code' project for someone next year,
... presumably by then reiser4 will have made it into the mainline
kernel by then. :)

From pgsql-hackers-owner@postgresql.org  Fri Sep 30 23:07:20 2005
X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id E3D1AD9D13
	for <pgsql-hackers-postgresql.org@localhost.postgresql.org>;
	Fri, 30 Sep 2005 23:07:16 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 72084-06
	for <pgsql-hackers-postgresql.org@localhost.postgresql.org>;
	Sat,  1 Oct 2005 02:07:10 +0000 (GMT)
Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.207])
	by svr1.postgresql.org (Postfix) with ESMTP id 45CBED9D10
	for <pgsql-hackers@postgresql.org>;
	Fri, 30 Sep 2005 23:07:11 -0300 (ADT)
Received: by xproxy.gmail.com with SMTP id t15so26872wxc
	for <pgsql-hackers@postgresql.org>;
	Fri, 30 Sep 2005 19:07:16 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references;
	b=BCMDnLSIlQjE/e7n2+1hPlLAcMfoai4UndL+DtWgxn1p28GtQGo+hWYA83VJqbm2KjyxUZgTW0eEAQbhzhXSW5bjQFbTITwSApj6SINeWRVppg8jAfEx0j+BzPlaonrjk6TOIS4S7m2Iw6/UvAyHJaA4c6MuqyNA3WW6PDuyY7I=
Received: by 10.70.53.14 with SMTP id b14mr1133980wxa;
	Fri, 30 Sep 2005 19:07:16 -0700 (PDT)
Received: by 10.70.76.1 with HTTP; Fri, 30 Sep 2005 19:07:16 -0700 (PDT)
Message-ID: <e692861c0509301907r7f1cd5b8h8b2b1f3a85321313@mail.gmail.com>
Date: Fri, 30 Sep 2005 22:07:16 -0400
From: Gregory Maxwell <gmaxwell@gmail.com>
Reply-To: Gregory Maxwell <gmaxwell@gmail.com>
To: Ron Peacetree <rjpeace@earthlink.net>
Subject: Re: [PERFORM] A Better External Sort?
Cc: "Jeffrey W. Baker" <jwbaker@acm.org>,
	pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org
In-Reply-To: 
 <21402654.1127923414088.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
References: 
 <21402654.1127923414088.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.086 required=5 tests=[AWL=0.062, RCVD_BY_IP=0.024]
X-Spam-Level: 
X-Archive-Number: 200509/1461
X-Sequence-Number: 73858

On 9/28/05, Ron Peacetree <rjpeace@earthlink.net> wrote:
> 2=3D We use my method to sort two different tables.  We now have these
> very efficient representations of a specific ordering on these tables.  A
> join operation can now be done using these Btrees rather than the
> original data tables that involves less overhead than many current
> methods.

If we want to make joins very fast we should implement them using RD
trees. For the example cases where a join against a very large table
will produce a much smaller output, a RD tree will provide pretty much
the optimal behavior at a very low memory cost.

On the subject of high speed tree code for in-core applications, you
should check out http://judy.sourceforge.net/ . The performance
(insert, remove, lookup, AND storage) is really quite impressive.
Producing cache friendly code is harder than one might expect, and it
appears the judy library has already done a lot of the hard work.=20
Though it is *L*GPLed, so perhaps that might scare some here away from
it. :) and good luck directly doing joins with a LC-TRIE. ;)

From pgsql-performance-owner@postgresql.org  Wed Oct  5 03:43:31 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 369DCD9CFA;
	Sat,  1 Oct 2005 02:32:20 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 47402-05; Sat,  1 Oct 2005 05:32:17 +0000 (GMT)
Received: from postal.corporate.connx.com (postal.corporate.connx.com
	[65.212.159.187])
	by svr1.postgresql.org (Postfix) with SMTP id 10C82D9CF4;
	Sat,  1 Oct 2005 02:32:17 -0300 (ADT)
X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0
Content-class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Subject: Re: [HACKERS] A Better External Sort?
Date: Fri, 30 Sep 2005 22:32:15 -0700
Message-ID: 
 <D425483C2C5C9F49B5B7A41F8944154757D147@postal.corporate.connx.com>
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
Thread-Topic: [HACKERS] [PERFORM] A Better External Sort?
Thread-Index: AcXGLdsZ4uHXXYPVTvOGFjofAdsffwAG5ZfA
From: "Dann Corbit" <DCorbit@connx.com>
To: "Gregory Maxwell" <gmaxwell@gmail.com>,
	"Ron Peacetree" <rjpeace@earthlink.net>
Cc: "Jeffrey W. Baker" <jwbaker@acm.org>,
	<pgsql-hackers@postgresql.org>, <pgsql-performance@postgresql.org>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.012 required=5 tests=[AWL=0.012]
X-Spam-Level: 
X-Archive-Number: 200510/77
X-Sequence-Number: 14845

Judy definitely rates a WOW!!

> -----Original Message-----
> From: pgsql-hackers-owner@postgresql.org [mailto:pgsql-hackers-
> owner@postgresql.org] On Behalf Of Gregory Maxwell
> Sent: Friday, September 30, 2005 7:07 PM
> To: Ron Peacetree
> Cc: Jeffrey W. Baker; pgsql-hackers@postgresql.org; pgsql-
> performance@postgresql.org
> Subject: Re: [HACKERS] [PERFORM] A Better External Sort?
>=20
> On 9/28/05, Ron Peacetree <rjpeace@earthlink.net> wrote:
> > 2=3D We use my method to sort two different tables.  We now have =
these
> > very efficient representations of a specific ordering on these
tables.
> A
> > join operation can now be done using these Btrees rather than the
> > original data tables that involves less overhead than many current
> > methods.
>=20
> If we want to make joins very fast we should implement them using RD
> trees. For the example cases where a join against a very large table
> will produce a much smaller output, a RD tree will provide pretty much
> the optimal behavior at a very low memory cost.
>=20
> On the subject of high speed tree code for in-core applications, you
> should check out http://judy.sourceforge.net/ . The performance
> (insert, remove, lookup, AND storage) is really quite impressive.
> Producing cache friendly code is harder than one might expect, and it
> appears the judy library has already done a lot of the hard work.
> Though it is *L*GPLed, so perhaps that might scare some here away from
> it. :) and good luck directly doing joins with a LC-TRIE. ;)
>=20
> ---------------------------(end of
broadcast)---------------------------
> TIP 6: explain analyze is your friend

From pgsql-performance-owner@postgresql.org  Sat Oct  1 03:02:15 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id D921AD7EB3;
	Sat,  1 Oct 2005 03:02:08 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 53122-03; Sat,  1 Oct 2005 06:02:05 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id 7AE19D6D8D;
	Sat,  1 Oct 2005 03:02:04 -0300 (ADT)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j9161w0q005710;
	Sat, 1 Oct 2005 02:01:58 -0400 (EDT)
To: "Jeffrey W. Baker" <jwbaker@acm.org>
Cc: Luke Lonergan <llonergan@greenplum.com>, Josh Berkus <josh@agliodbs.com>,
	Ron Peacetree <rjpeace@earthlink.net>, pgsql-hackers@postgresql.org,
	pgsql-performance@postgresql.org
Subject: Re: [HACKERS] A Better External Sort? 
In-reply-to: <1128015863.11474.9.camel@noodles> 
References: <BF616D3C.104C3%llonergan@greenplum.com>
	<1128015863.11474.9.camel@noodles>
Comments: In-reply-to "Jeffrey W. Baker" <jwbaker@acm.org>
	message dated "Thu, 29 Sep 2005 10:44:23 -0700"
Date: Sat, 01 Oct 2005 02:01:58 -0400
Message-ID: <5709.1128146518@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/1
X-Sequence-Number: 14769

"Jeffrey W. Baker" <jwbaker@acm.org> writes:
> I think the largest speedup will be to dump the multiphase merge and
> merge all tapes in one pass, no matter how large M.  Currently M is
> capped at 6, so a sort of 60GB with 1GB sort memory needs 13 passes over
> the tape.  It could be done in a single pass heap merge with N*log(M)
> comparisons, and, more importantly, far less input and output.

I had more or less despaired of this thread yielding any usable ideas
:-( but I think you have one here.  The reason the current code uses a
six-way merge is that Knuth's figure 70 (p. 273 of volume 3 first
edition) shows that there's not much incremental gain from using more
tapes ... if you are in the regime where number of runs is much greater
than number of tape drives.  But if you can stay in the regime where
only one merge pass is needed, that is obviously a win.

I don't believe we can simply legislate that there be only one merge
pass.  That would mean that, if we end up with N runs after the initial
run-forming phase, we need to fit N tuples in memory --- no matter how
large N is, or how small work_mem is.  But it seems like a good idea to
try to use an N-way merge where N is as large as work_mem will allow.
We'd not have to decide on the value of N until after we've completed
the run-forming phase, at which time we've already seen every tuple
once, and so we can compute a safe value for N as work_mem divided by
largest_tuple_size.  (Tape I/O buffers would have to be counted too
of course.)

It's been a good while since I looked at the sort code, and so I don't
recall if there are any fundamental reasons for having a compile-time-
constant value of the merge order rather than choosing it at runtime.
My guess is that any inefficiencies added by making it variable would
be well repaid by the potential savings in I/O.

			regards, tom lane

From pgsql-performance-owner@postgresql.org  Wed Oct  5 03:37:43 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 7FB39D7EB3;
	Sat,  1 Oct 2005 03:32:42 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 58489-06; Sat,  1 Oct 2005 06:32:40 +0000 (GMT)
Received: from postal.corporate.connx.com (postal.corporate.connx.com
	[65.212.159.187])
	by svr1.postgresql.org (Postfix) with SMTP id 8B836D6D8D;
	Sat,  1 Oct 2005 03:32:39 -0300 (ADT)
X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0
Content-class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Subject: Re: [HACKERS] A Better External Sort? 
Date: Fri, 30 Sep 2005 23:32:40 -0700
Message-ID: 
 <D425483C2C5C9F49B5B7A41F8944154757D148@postal.corporate.connx.com>
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
Thread-Topic: [HACKERS] [PERFORM] A Better External Sort? 
Thread-Index: AcXGTlwvegh+E2+HQM6cqg7NgYTj3gAAqDpQ
From: "Dann Corbit" <DCorbit@connx.com>
To: "Tom Lane" <tgl@sss.pgh.pa.us>,
	"Jeffrey W. Baker" <jwbaker@acm.org>
Cc: "Luke Lonergan" <llonergan@greenplum.com>,
	"Josh Berkus" <josh@agliodbs.com>, "Ron Peacetree" <rjpeace@earthlink.net>,
	<pgsql-hackers@postgresql.org>, <pgsql-performance@postgresql.org>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.012 required=5 tests=[AWL=0.012]
X-Spam-Level: 
X-Archive-Number: 200510/76
X-Sequence-Number: 14844

> -----Original Message-----
> From: pgsql-hackers-owner@postgresql.org [mailto:pgsql-hackers-
> owner@postgresql.org] On Behalf Of Tom Lane
> Sent: Friday, September 30, 2005 11:02 PM
> To: Jeffrey W. Baker
> Cc: Luke Lonergan; Josh Berkus; Ron Peacetree; pgsql-
> hackers@postgresql.org; pgsql-performance@postgresql.org
> Subject: Re: [HACKERS] [PERFORM] A Better External Sort?
>=20
> "Jeffrey W. Baker" <jwbaker@acm.org> writes:
> > I think the largest speedup will be to dump the multiphase merge and
> > merge all tapes in one pass, no matter how large M.  Currently M is
> > capped at 6, so a sort of 60GB with 1GB sort memory needs 13 passes
over
> > the tape.  It could be done in a single pass heap merge with
N*log(M)
> > comparisons, and, more importantly, far less input and output.
>=20
> I had more or less despaired of this thread yielding any usable ideas
> :-( but I think you have one here. =20

I believe I made the exact same suggestion several days ago.

>The reason the current code uses a
> six-way merge is that Knuth's figure 70 (p. 273 of volume 3 first
> edition) shows that there's not much incremental gain from using more
> tapes ... if you are in the regime where number of runs is much
greater
> than number of tape drives.  But if you can stay in the regime where
> only one merge pass is needed, that is obviously a win.
>=20
> I don't believe we can simply legislate that there be only one merge
> pass.  That would mean that, if we end up with N runs after the
initial
> run-forming phase, we need to fit N tuples in memory --- no matter how
> large N is, or how small work_mem is.  But it seems like a good idea
to
> try to use an N-way merge where N is as large as work_mem will allow.
> We'd not have to decide on the value of N until after we've completed
> the run-forming phase, at which time we've already seen every tuple
> once, and so we can compute a safe value for N as work_mem divided by
> largest_tuple_size.  (Tape I/O buffers would have to be counted too
> of course.)

You only need to hold the sort column(s) in memory, except for the queue
you are exhausting at the time.  [And of those columns, only the values
for the smallest one in a sub-list.]  Of course, the more data from each
list that you can hold at once, the fewer the disk reads and seeks.

Another idea (not sure if it is pertinent):
Instead of having a fixed size for the sort buffers, size it to the
query.  Given a total pool of size M, give a percentage according to the
difficulty of the work to perform.  So a query with 3 small columns and
a cardinality of 1000 gets a small percentage and a query with 10 GB of
data gets a big percentage of available sort mem.
=20
> It's been a good while since I looked at the sort code, and so I don't
> recall if there are any fundamental reasons for having a compile-time-
> constant value of the merge order rather than choosing it at runtime.
> My guess is that any inefficiencies added by making it variable would
> be well repaid by the potential savings in I/O.
>=20
> 			regards, tom lane
>=20
> ---------------------------(end of
broadcast)---------------------------
> TIP 6: explain analyze is your friend

From pgsql-performance-owner@postgresql.org  Sat Oct  1 06:29:36 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 75935D7EB3;
	Sat,  1 Oct 2005 06:29:33 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 96623-04; Sat,  1 Oct 2005 09:29:29 +0000 (GMT)
Received: from smtp.nildram.co.uk (smtp.nildram.co.uk [195.112.4.54])
	by svr1.postgresql.org (Postfix) with ESMTP id 0C161D9CFC;
	Sat,  1 Oct 2005 06:29:29 -0300 (ADT)
Received: from 192.168.0.3 (unknown [84.12.173.204])
	by smtp.nildram.co.uk (Postfix) with ESMTP
	id 66DB2251DDE; Sat,  1 Oct 2005 10:29:29 +0100 (BST)
Subject: Re: [HACKERS] A Better External Sort?
From: Simon Riggs <simon@2ndquadrant.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: "Jeffrey W. Baker" <jwbaker@acm.org>,
	Luke Lonergan <llonergan@greenplum.com>, Josh Berkus <josh@agliodbs.com>,
	Ron Peacetree <rjpeace@earthlink.net>, pgsql-hackers@postgresql.org,
	pgsql-performance@postgresql.org
In-Reply-To: <5709.1128146518@sss.pgh.pa.us>
References: <BF616D3C.104C3%llonergan@greenplum.com>
	<1128015863.11474.9.camel@noodles>  <5709.1128146518@sss.pgh.pa.us>
Content-Type: text/plain
Organization: 2nd Quadrant
Date: Sat, 01 Oct 2005 10:29:52 +0100
Message-Id: <1128158992.3717.29.camel@localhost.localdomain>
Mime-Version: 1.0
X-Mailer: Evolution 2.0.2 (2.0.2-3) 
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.126 required=5 tests=[AWL=0.076,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/3
X-Sequence-Number: 14771

On Sat, 2005-10-01 at 02:01 -0400, Tom Lane wrote:
> "Jeffrey W. Baker" <jwbaker@acm.org> writes:
> > I think the largest speedup will be to dump the multiphase merge and
> > merge all tapes in one pass, no matter how large M.  Currently M is
> > capped at 6, so a sort of 60GB with 1GB sort memory needs 13 passes over
> > the tape.  It could be done in a single pass heap merge with N*log(M)
> > comparisons, and, more importantly, far less input and output.
> 
> I had more or less despaired of this thread yielding any usable ideas
> :-( but I think you have one here.  The reason the current code uses a
> six-way merge is that Knuth's figure 70 (p. 273 of volume 3 first
> edition) shows that there's not much incremental gain from using more
> tapes ... if you are in the regime where number of runs is much greater
> than number of tape drives.  But if you can stay in the regime where
> only one merge pass is needed, that is obviously a win.
> 
> I don't believe we can simply legislate that there be only one merge
> pass.  That would mean that, if we end up with N runs after the initial
> run-forming phase, we need to fit N tuples in memory --- no matter how
> large N is, or how small work_mem is.  But it seems like a good idea to
> try to use an N-way merge where N is as large as work_mem will allow.
> We'd not have to decide on the value of N until after we've completed
> the run-forming phase, at which time we've already seen every tuple
> once, and so we can compute a safe value for N as work_mem divided by
> largest_tuple_size.  (Tape I/O buffers would have to be counted too
> of course.)
> 
> It's been a good while since I looked at the sort code, and so I don't
> recall if there are any fundamental reasons for having a compile-time-
> constant value of the merge order rather than choosing it at runtime.
> My guess is that any inefficiencies added by making it variable would
> be well repaid by the potential savings in I/O.

Well, perhaps Knuth is not untouchable!

So we merge R runs with N variable rather than N=6.

Pick N so that N >= 6 and N <= R, with N limited by memory, sufficient
to allow long sequential reads from the temp file.

Looking at the code, in selectnewtape() we decide on the connection
between run number and tape number. This gets executed during the
writing of initial runs, which was OK when the run->tape mapping was
known ahead of time because of fixed N.

To do this it sounds like we'd be better to write each run out to its
own personal runtape, taking the assumption that N is very large. Then
when all runs are built, re-assign the run numbers to tapes for the
merge. That is likely to be a trivial mapping unless N isn't large
enough to fit in memory. That idea should be easily possible because the
tape numbers were just abstract anyway.

Right now, I can't see any inefficiencies from doing this. It uses
memory better and Knuth shows that using more tapes is better anyhow.
Keeping track of more tapes isn't too bad, even for hundreds or even
thousands of runs/tapes.

Tom, its your idea, so you have first dibs. I'm happy to code this up if
you choose not to, once I've done my other immediate chores.

That just leaves these issues for a later time:
- CPU and I/O interleaving
- CPU cost of abstract data type comparison operator invocation

Best Regards, Simon Riggs



From pgsql-general-owner@postgresql.org  Sat Oct  1 07:01:10 2005
X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 311E3D9D3E
	for <pgsql-general-postgresql.org@localhost.postgresql.org>;
	Sat,  1 Oct 2005 07:01:07 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 99483-06
	for <pgsql-general-postgresql.org@localhost.postgresql.org>;
	Sat,  1 Oct 2005 10:01:01 +0000 (GMT)
Received: from qproxy.gmail.com (qproxy.gmail.com [72.14.204.205])
	by svr1.postgresql.org (Postfix) with ESMTP id 24030D9D20
	for <pgsql-general@postgresql.org>;
	Sat,  1 Oct 2005 07:01:01 -0300 (ADT)
Received: by qproxy.gmail.com with SMTP id q10so57900qbq
	for <pgsql-general@postgresql.org>;
	Sat, 01 Oct 2005 03:01:04 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:references;
	b=YWOphVT45xsRrUwlMgAlvZ0+DAEOi55UZshtJFFX6D9zkKSxTIeoqFIVYN005RYW61Y+PbQCa8yQYtMlT2Fgf5erDXWGC9Kg0NhI4YIfieO4JJQfW1rb+C4moMyyW2wXJQOm3rmF0qW9zQ7E0fPxEgCVT7QLLLBvLlF3MNjQYII=
Received: by 10.64.213.15 with SMTP id l15mr1422942qbg;
	Sat, 01 Oct 2005 03:01:04 -0700 (PDT)
Received: by 10.64.195.4 with HTTP; Sat, 1 Oct 2005 03:01:04 -0700 (PDT)
Message-ID: <9e4684ce0510010301ibfafcb2l10e5344b798433b4@mail.gmail.com>
Date: Sat, 1 Oct 2005 12:01:04 +0200
From: hubert depesz lubaczewski <depesz@gmail.com>
Reply-To: hubert depesz lubaczewski <depesz@gmail.com>
To: "Jim C. Nasby" <jnasby@pervasive.com>
Subject: Re: database bloat, but vacuums are done,
 and fsm seems to be setup ok
Cc: PostgreSQL General <pgsql-general@postgresql.org>,
	pgsqlperform <pgsql-performance@postgresql.org>
In-Reply-To: <20050930193459.GC40138@pervasive.com>
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="----=_Part_6602_30473026.1128160864130"
References: <9e4684ce05092800075d37d0cc@mail.gmail.com>
	<20050930193459.GC40138@pervasive.com>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=2.208 required=5 tests=[AWL=-0.152, HTML_20_30=0.504,
	HTML_MESSAGE=0.001, RCVD_BY_IP=0.024,
	RCVD_IN_BL_SPAMCOP_NET=1.832]
X-Spam-Level: **
X-Archive-Number: 200510/1
X-Sequence-Number: 84230

------=_Part_6602_30473026.1128160864130
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

On 9/30/05, Jim C. Nasby <jnasby@pervasive.com> wrote:
>
> Looks like it's definately an issue with index bloat. Note that it's
> normal to have some amount of empty space depending on vacuum and update
> frequency, so 15G -> 20G isn't terribly surprising. I would suggest
> using pg_autovacuum instead of the continuous vacuum; it's very possible
> that some of your tables need more frequent vacuuming than they're
> getting now. If you go this route, you might want to change the default
> settings a bit to make pg_autovacuum more agressive.



actually i have a very bad experience with autovaccum - of course it is
because i dont know how to setup it correctly, but for me it's just easier
to setup continuos vacuums. and i know which tables are frequently updated,
so i setup additional vacuums on them.

Also, I'd suggest posting to -hackers about the index bloat. Would you
> be able to make a filesystem copy (ie: tar -cjf database.tar.bz2
> $PGDATA) available? It might also be useful to keep an eye on index size
> in pg_class.relpages and see exactly what indexes are bloating.



i'm watching it right now (which indices are bloating), but i cannot send
copy of pgdata - it contains very sensitive information.
depesz

------=_Part_6602_30473026.1128160864130
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

On 9/30/05, <b class=3D"gmail_sendername">Jim C. Nasby</b> &lt;<a href=3D"m=
ailto:jnasby@pervasive.com">jnasby@pervasive.com</a>&gt; wrote:<div><span c=
lass=3D"gmail_quote"></span><blockquote class=3D"gmail_quote" style=3D"bord=
er-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-l=
eft: 1ex;">
Looks like it's definately an issue with index bloat. Note that it's<br>nor=
mal to have some amount of empty space depending on vacuum and update<br>fr=
equency, so 15G -&gt; 20G isn't terribly surprising. I would suggest<br>
using pg_autovacuum instead of the continuous vacuum; it's very possible<br=
>that some of your tables need more frequent vacuuming than they're<br>gett=
ing now. If you go this route, you might want to change the default<br>
settings a bit to make pg_autovacuum more agressive.</blockquote><div><br>
<br>
actually i have a very bad experience with autovaccum - of course it is
because i dont know how to setup it correctly, but for me it's just
easier to setup continuos vacuums. and i know which tables are
frequently updated, so i setup additional vacuums on them.<br>
&nbsp;</div><br><blockquote class=3D"gmail_quote" style=3D"border-left: 1px=
 solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">A=
lso, I'd suggest posting to -hackers about the index bloat. Would you<br>be=
 able to make a filesystem copy (ie: tar -cjf=20
database.tar.bz2<br>$PGDATA) available? It might also be useful to keep an =
eye on index size<br>in pg_class.relpages and see exactly what indexes are =
bloating.</blockquote><div><br>
<br>
i'm watching it right now (which indices are bloating), but i cannot
send copy of pgdata - it contains very sensitive information.<br>
&nbsp;</div></div>depesz<br>

------=_Part_6602_30473026.1128160864130--

From pgsql-performance-owner@postgresql.org  Wed Oct  5 03:50:51 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 51FA1D9D02;
	Sat,  1 Oct 2005 11:04:00 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 58376-03; Sat,  1 Oct 2005 14:03:53 +0000 (GMT)
Received: from mail.skype.net (mail.skype.net [195.215.8.149])
	by svr1.postgresql.org (Postfix) with ESMTP id 8B8CDD9D61;
	Sat,  1 Oct 2005 11:03:54 -0300 (ADT)
Received: from localhost (localhost.localdomain [127.0.0.1])
	by mail.skype.net (Postfix) with ESMTP id 084FA4DDD3;
	Sat,  1 Oct 2005 16:03:58 +0200 (CEST)
Received: from [10.10.10.50] (217-159-136-226-dsl.kt.estpak.ee
	[217.159.136.226])
	by mail.skype.net (Postfix) with ESMTP id 2652C4DD7D;
	Sat,  1 Oct 2005 16:03:57 +0200 (CEST)
Subject: Re: [HACKERS] A Better External Sort?
From: Hannu Krosing <hannu@skype.net>
To: Luke Lonergan <llonergan@greenplum.com>
Cc: Ron Peacetree <rjpeace@earthlink.net>,
	Josh Berkus <josh@agliodbs.com>, pgsql-hackers@postgresql.org,
	pgsql-performance@postgresql.org
In-Reply-To: <BF62F06E.10617%llonergan@greenplum.com>
References: <BF62F06E.10617%llonergan@greenplum.com>
Content-Type: text/plain
Date: Sat, 01 Oct 2005 17:03:52 +0300
Message-Id: <1128175432.5359.11.camel@fuji.krosing.net>
Mime-Version: 1.0
X-Mailer: Evolution 2.0.4 (2.0.4-6) 
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0 required=5 tests=[none]
X-Spam-Level: 
X-Archive-Number: 200510/81
X-Sequence-Number: 14849

On R, 2005-09-30 at 13:38 -0700, Luke Lonergan wrote:

> 
> Bulk loading speed is irrelevant here - that is dominated by parsing, which
> we have covered copiously (har har) previously and have sped up by 500%,
> which still makes Postgres < 1/2 the loading speed of MySQL.

Is this < 1/2 of MySQL with WAL on different spindle and/or WAL
disabled ?

-- 
Hannu Krosing <hannu@skype.net>


From pgsql-performance-owner@postgresql.org  Sat Oct  1 11:22:42 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 72BCFD9D66;
	Sat,  1 Oct 2005 11:22:40 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 62348-04; Sat,  1 Oct 2005 14:22:34 +0000 (GMT)
Received: from pop-knobcone.atl.sa.earthlink.net
	(pop-knobcone.atl.sa.earthlink.net [207.69.195.64])
	by svr1.postgresql.org (Postfix) with ESMTP id 9B9C0D9D62;
	Sat,  1 Oct 2005 11:22:35 -0300 (ADT)
Received: from elwamui-polski.atl.sa.earthlink.net ([209.86.224.45])
	by pop-knobcone.atl.sa.earthlink.net with esmtp (Exim 3.36 #10)
	id 1ELiG8-0002EY-00; Sat, 01 Oct 2005 10:22:40 -0400
Message-ID: 
 <25552174.1128176560482.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
Date: Sat, 1 Oct 2005 10:22:40 -0400 (EDT)
From: Ron Peacetree <rjpeace@earthlink.net>
Reply-To: Ron Peacetree <rjpeace@earthlink.net>
To: pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org
Subject: Re: [HACKERS] A Better External Sort?
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: Earthlink Zoo Mail 1.0
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.258 required=5 tests=[AWL=-0.116,
	DNS_FROM_RFC_ABUSE=0.374]
X-Spam-Level: 
X-Archive-Number: 200510/5
X-Sequence-Number: 14773

*blink* Tapes?!  I thought that was a typo...
If our sort is code based on sorting tapes, we've made a mistake.  HDs
are not tapes, and Polyphase Merge Sort and it's brethren are not the
best choices for HD based sorts.

Useful references to this point:
Knuth, Vol 3 section 5.4.9, (starts p356 of 2ed)   
Tharp, ISBN 0-471-60521-2, starting p352
Folk, Zoellick, and Riccardi, ISBN 0-201-87401-6, chapter 8 (starts p289)

The winners of the "Daytona" version of Jim Gray's sorting contest, for
general purpose external sorting algorithms that are of high enough quality
to be offered commercially, also demonstrate a number of better ways to
attack external sorting using HDs.

The big take aways from all this are:
1= As in Polyphase Merge Sort, optimum External HD Merge Sort
performance is obtained by using Replacement Selection and creating
buffers of different lengths for later merging.  The values are different.

2= Using multiple HDs split into different functions, IOW _not_ simply
as RAIDs, is a big win.
A big enough win that we should probably consider having a config option
to pg that allows the use of HD(s) or RAID set(s) dedicated as temporary
work area(s).
 
3= If the Key is small compared record size, Radix or Distribution
Counting based algorithms are worth considering.

The good news is all this means it's easy to demonstrate that we can
improve the performance of our sorting functionality.

Assuming we get the abyssmal physical IO performance fixed...
(because until we do, _nothing_ is going to help us as much)

Ron 


-----Original Message-----
From: Tom Lane <tgl@sss.pgh.pa.us>
Sent: Oct 1, 2005 2:01 AM
Subject: Re: [HACKERS] [PERFORM] A Better External Sort? 

"Jeffrey W. Baker" <jwbaker@acm.org> writes:
> I think the largest speedup will be to dump the multiphase merge and
> merge all tapes in one pass, no matter how large M.  Currently M is
> capped at 6, so a sort of 60GB with 1GB sort memory needs 13 passes over
> the tape.  It could be done in a single pass heap merge with N*log(M)
> comparisons, and, more importantly, far less input and output.

I had more or less despaired of this thread yielding any usable ideas
:-( but I think you have one here.  The reason the current code uses a
six-way merge is that Knuth's figure 70 (p. 273 of volume 3 first
edition) shows that there's not much incremental gain from using more
tapes ... if you are in the regime where number of runs is much greater
than number of tape drives.  But if you can stay in the regime where
only one merge pass is needed, that is obviously a win.

I don't believe we can simply legislate that there be only one merge
pass.  That would mean that, if we end up with N runs after the initial
run-forming phase, we need to fit N tuples in memory --- no matter how
large N is, or how small work_mem is.  But it seems like a good idea to
try to use an N-way merge where N is as large as work_mem will allow.
We'd not have to decide on the value of N until after we've completed
the run-forming phase, at which time we've already seen every tuple
once, and so we can compute a safe value for N as work_mem divided by
largest_tuple_size.  (Tape I/O buffers would have to be counted too
of course.)

It's been a good while since I looked at the sort code, and so I don't
recall if there are any fundamental reasons for having a compile-time-
constant value of the merge order rather than choosing it at runtime.
My guess is that any inefficiencies added by making it variable would
be well repaid by the potential savings in I/O.

From pgsql-performance-owner@postgresql.org  Wed Oct  5 03:57:40 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 97A90D8C10;
	Sat,  1 Oct 2005 12:19:32 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 66787-10; Sat,  1 Oct 2005 15:19:30 +0000 (GMT)
Received: from trolak.mydnsbox2.com (ns1.mydnsbox2.com [207.44.142.118])
	by svr1.postgresql.org (Postfix) with ESMTP id 960C4D7EB3;
	Sat,  1 Oct 2005 12:19:28 -0300 (ADT)
Received: from [192.168.1.103] (cpe-024-211-165-134.nc.res.rr.com
	[24.211.165.134]) (authenticated (0 bits))
	by trolak.mydnsbox2.com (8.11.6/8.11.6) with ESMTP id j91EalM03385;
	Sat, 1 Oct 2005 09:36:47 -0500
Message-ID: <433EA8FE.8050103@dunslane.net>
Date: Sat, 01 Oct 2005 11:19:26 -0400
From: Andrew Dunstan <andrew@dunslane.net>
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US;
	rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: Ron Peacetree <rjpeace@earthlink.net>
Cc: pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org
Subject: Re: [HACKERS] A Better External Sort?
References: 
 <25552174.1128176560482.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
In-Reply-To: 
 <25552174.1128176560482.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.038 required=5 tests=[AWL=0.038]
X-Spam-Level: 
X-Archive-Number: 200510/85
X-Sequence-Number: 14853



Ron Peacetree wrote:

>The good news is all this means it's easy to demonstrate that we can
>improve the performance of our sorting functionality.
>
>Assuming we get the abyssmal physical IO performance fixed...
>(because until we do, _nothing_ is going to help us as much)
>
>  
>

I for one would be paying more attention if such a demonstration were 
forthcoming, in the form of a viable patch and some benchmark results.

cheers

andrew

From pgsql-performance-owner@postgresql.org  Sat Oct  1 12:48:22 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 9DC00D8BE2;
	Sat,  1 Oct 2005 12:45:54 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 77673-07; Sat,  1 Oct 2005 15:45:52 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id 7BD6BD7EB3;
	Sat,  1 Oct 2005 12:45:51 -0300 (ADT)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j91FiFqX008644;
	Sat, 1 Oct 2005 11:44:15 -0400 (EDT)
To: Josh Berkus <josh@agliodbs.com>
Cc: "Jeffrey W. Baker" <jwbaker@acm.org>,
	Ron Peacetree <rjpeace@earthlink.net>, pgsql-hackers@postgresql.org,
	pgsql-performance@postgresql.org
Subject: Re: [HACKERS] A Better External Sort? 
In-reply-to: <433C1C2D.7090908@agliodbs.com> 
References: 
 <21402654.1127923414088.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
	<1127968040.8954.12.camel@noodles> <433C1C2D.7090908@agliodbs.com>
Comments: In-reply-to Josh Berkus <josh@agliodbs.com>
	message dated "Thu, 29 Sep 2005 09:54:05 -0700"
Date: Sat, 01 Oct 2005 11:44:15 -0400
Message-ID: <8643.1128181455@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/6
X-Sequence-Number: 14774

Josh Berkus <josh@agliodbs.com> writes:
> The biggest single area where I see PostgreSQL external sort sucking is 
>   on index creation on large tables.   For example, for free version of 
> TPCH, it takes only 1.5 hours to load a 60GB Lineitem table on OSDL's 
> hardware, but over 3 hours to create each index on that table.  This 
> means that over all our load into TPCH takes 4 times as long to create 
> the indexes as it did to bulk load the data.
> ...
> Following an index creation, we see that 95% of the time required is the 
> external sort, which averages 2mb/s.  This is with seperate drives for 
> the WAL, the pg_tmp, the table and the index.  I've confirmed that 
> increasing work_mem beyond a small minimum (around 128mb) had no benefit 
> on the overall index creation speed.

These numbers don't seem to add up.  You have not provided any details
about the index key datatypes or sizes, but I'll take a guess that the
raw data for each index is somewhere around 10GB.  The theory says that
the runs created during the first pass should on average be about twice
work_mem, so at 128mb work_mem there should be around 40 runs to be
merged, which would take probably three passes with six-way merging.
Raising work_mem to a gig should result in about five runs, needing only
one pass, which is really going to be as good as it gets.  If you could
not see any difference then I see little hope for the idea that reducing
the number of merge passes will help.

Umm ... you were raising maintenance_work_mem, I trust, not work_mem?

We really need to get some hard data about what's going on here.  The
sort code doesn't report any internal statistics at the moment, but it
would not be hard to whack together a patch that reports useful info
in the form of NOTICE messages or some such.

			regards, tom lane

From pgsql-performance-owner@postgresql.org  Sat Oct  1 13:17:52 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 4257ED9D5F;
	Sat,  1 Oct 2005 13:17:50 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 91966-02; Sat,  1 Oct 2005 16:17:48 +0000 (GMT)
Received: from stark.xeocode.com (stark.xeocode.com [216.58.44.227])
	by svr1.postgresql.org (Postfix) with ESMTP id AAEF3D9D5C;
	Sat,  1 Oct 2005 13:17:45 -0300 (ADT)
Received: from localhost ([127.0.0.1] helo=stark.xeocode.com)
	by stark.xeocode.com with smtp (Exim 3.36 #1 (Debian))
	id 1ELk33-0005CR-00; Sat, 01 Oct 2005 12:17:17 -0400
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: "Jeffrey W. Baker" <jwbaker@acm.org>,
	Luke Lonergan <llonergan@greenplum.com>, Josh Berkus <josh@agliodbs.com>,
	Ron Peacetree <rjpeace@earthlink.net>, pgsql-hackers@postgresql.org,
	pgsql-performance@postgresql.org
Subject: Re: [HACKERS] A Better External Sort?
References: <BF616D3C.104C3%llonergan@greenplum.com>
	<1128015863.11474.9.camel@noodles> <5709.1128146518@sss.pgh.pa.us>
In-Reply-To: <5709.1128146518@sss.pgh.pa.us>
From: Greg Stark <gsstark@mit.edu>
Organization: The Emacs Conspiracy; member since 1992
Date: 01 Oct 2005 12:17:17 -0400
Message-ID: <87r7b5ciuq.fsf@stark.xeocode.com>
Lines: 33
User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.011 required=5 tests=[AWL=0.011]
X-Spam-Level: 
X-Archive-Number: 200510/7
X-Sequence-Number: 14775


Tom Lane <tgl@sss.pgh.pa.us> writes:

> "Jeffrey W. Baker" <jwbaker@acm.org> writes:
> > I think the largest speedup will be to dump the multiphase merge and
> > merge all tapes in one pass, no matter how large M.  Currently M is
> > capped at 6, so a sort of 60GB with 1GB sort memory needs 13 passes over
> > the tape.  It could be done in a single pass heap merge with N*log(M)
> > comparisons, and, more importantly, far less input and output.
> 
> I had more or less despaired of this thread yielding any usable ideas
> :-( but I think you have one here.  The reason the current code uses a
> six-way merge is that Knuth's figure 70 (p. 273 of volume 3 first
> edition) shows that there's not much incremental gain from using more
> tapes ... if you are in the regime where number of runs is much greater
> than number of tape drives.  But if you can stay in the regime where
> only one merge pass is needed, that is obviously a win.

Is that still true when the multiple tapes are being multiplexed onto a single
actual file on disk?

That brings up one of my pet features though. The ability to declare multiple
temporary areas on different spindles and then have them be used on a rotating
basis. So a sort could store each tape on a separate spindle and merge them
together at full sequential i/o speed.

This would make the tradeoff between multiway merges and many passes even
harder to find though. The broader the multiway merges the more sort areas
would be used which would increase the likelihood of another sort using the
same sort area and hurting i/o performance.

-- 
greg


From pgsql-performance-owner@postgresql.org  Wed Oct  5 03:50:14 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id D2C3FD9720;
	Sat,  1 Oct 2005 13:19:51 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 85453-06; Sat,  1 Oct 2005 16:19:49 +0000 (GMT)
Received: from svana.org (svana.org [203.20.62.76])
	by svr1.postgresql.org (Postfix) with ESMTP id 8992BD96E2;
	Sat,  1 Oct 2005 13:19:49 -0300 (ADT)
Received: from kleptog by svana.org with local (Exim 3.35 #1 (Debian))
	id 1ELk5O-0004dq-00; Sun, 02 Oct 2005 02:19:42 +1000
Date: Sat, 1 Oct 2005 18:19:41 +0200
From: Martijn van Oosterhout <kleptog@svana.org>
To: Ron Peacetree <rjpeace@earthlink.net>
Cc: pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org
Subject: Re: [HACKERS] A Better External Sort?
Message-ID: <20051001161936.GE13830@svana.org>
Reply-To: Martijn van Oosterhout <kleptog@svana.org>
References: 
 <25552174.1128176560482.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
Mime-Version: 1.0
Content-Type: multipart/signed; micalg=pgp-sha1;
	protocol="application/pgp-signature"; boundary="N1GIdlSm9i+YlY4t"
Content-Disposition: inline
In-Reply-To: 
 <25552174.1128176560482.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
User-Agent: Mutt/1.3.28i
X-PGP-Key-ID: Length=1024; ID=0x0DC67BE6
X-PGP-Key-Fingerprint: 295F A899 A81A 156D B522  48A7 6394 F08A 0DC6 7BE6
X-PGP-Key-URL: <http://svana.org/kleptog/0DC67BE6.pgp.asc>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.008 required=5 tests=[AWL=0.008]
X-Spam-Level: 
X-Archive-Number: 200510/80
X-Sequence-Number: 14848


--N1GIdlSm9i+YlY4t
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Sat, Oct 01, 2005 at 10:22:40AM -0400, Ron Peacetree wrote:
> Assuming we get the abyssmal physical IO performance fixed...
> (because until we do, _nothing_ is going to help us as much)

I'm still not convinced this is the major problem. For example, in my
totally unscientific tests on an oldish machine I have here:

Direct filesystem copy to /dev/null
21MB/s    10% user 50% system  (dual cpu, so the system is using a whole CP=
U)

COPY TO /dev/null WITH binary
13MB/s    55% user 45% system  (ergo, CPU bound)

COPY TO /dev/null
4.4MB/s   60% user 40% system

\copy to /dev/null in psql
6.5MB/s   60% user 40% system

This machine is a bit strange setup, not sure why fs copy is so slow.
As to why \copy is faster than COPY, I have no idea, but it is
repeatable. And actually turning the tuples into a printable format is
the most expensive. But it does point out that the whole process is
probably CPU bound more than anything else.

So, I don't think physical I/O is the problem. It's something further
up the call tree. I wouldn't be surprised at all it it had to do with
the creation and destruction of tuples. The cost of comparing tuples
should not be underestimated.
--=20
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

--N1GIdlSm9i+YlY4t
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQFDPrcXIB7bNG8LQkwRAulpAJ9Qk9yKddvygb0qb5BofJy6dD4yTwCfRTXG
GuqPRZ9u7pNqZet021m5h34=
=0vBS
-----END PGP SIGNATURE-----

--N1GIdlSm9i+YlY4t--

From pgsql-performance-owner@postgresql.org  Sat Oct  1 13:39:04 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 30081D9D71;
	Sat,  1 Oct 2005 13:39:03 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 91732-10; Sat,  1 Oct 2005 16:39:01 +0000 (GMT)
Received: from pop-knobcone.atl.sa.earthlink.net
	(pop-knobcone.atl.sa.earthlink.net [207.69.195.64])
	by svr1.postgresql.org (Postfix) with ESMTP id 8E8C1D9D70;
	Sat,  1 Oct 2005 13:39:00 -0300 (ADT)
Received: from elwamui-polski.atl.sa.earthlink.net ([209.86.224.45])
	by pop-knobcone.atl.sa.earthlink.net with esmtp (Exim 3.36 #10)
	id 1ELkNz-0003CS-00; Sat, 01 Oct 2005 12:38:55 -0400
Message-ID: 
 <31843561.1128184735397.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
Date: Sat, 1 Oct 2005 12:38:55 -0400 (EDT)
From: Ron Peacetree <rjpeace@earthlink.net>
Reply-To: Ron Peacetree <rjpeace@earthlink.net>
To: Andrew Dunstan <andrew@dunslane.net>,
	pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org
Subject: Re: [HACKERS] A Better External Sort?
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: Earthlink Zoo Mail 1.0
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.257 required=5 tests=[AWL=-0.117,
	DNS_FROM_RFC_ABUSE=0.374]
X-Spam-Level: 
X-Archive-Number: 200510/8
X-Sequence-Number: 14776

As I posted earlier, I'm looking for code to base a prototype on now.
I'll test it outside pg to make sure it is bug free and performs as
promised before I hand it off to the core pg developers.

Someone else is going to have to merge it into the pg code base
since I don't know the code intimately enough to make changes this
deep in the core functionality, nor is there enough time for me to
do so if we are going to be timely enough get this into 8.2
(and no, I can't devote 24x7 to doing pg development unless
someone is going to replace my current ways of paying my bills so
that I can.)

Ron
 

-----Original Message-----
From: Andrew Dunstan <andrew@dunslane.net>
Sent: Oct 1, 2005 11:19 AM
To: Ron Peacetree <rjpeace@earthlink.net>
Subject: Re: [HACKERS] [PERFORM] A Better External Sort?



Ron Peacetree wrote:

>The good news is all this means it's easy to demonstrate that we can
>improve the performance of our sorting functionality.
>
>Assuming we get the abyssmal physical IO performance fixed...
>(because until we do, _nothing_ is going to help us as much)
>
>  
>

I for one would be paying more attention if such a demonstration were 
forthcoming, in the form of a viable patch and some benchmark results.

cheers

andrew


From pgsql-performance-owner@postgresql.org  Sat Oct  1 14:42:55 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 680AED8BE2;
	Sat,  1 Oct 2005 14:42:49 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 04542-06; Sat,  1 Oct 2005 17:42:35 +0000 (GMT)
Received: from pop-knobcone.atl.sa.earthlink.net
	(pop-knobcone.atl.sa.earthlink.net [207.69.195.64])
	by svr1.postgresql.org (Postfix) with ESMTP id 132E2D973D;
	Sat,  1 Oct 2005 14:42:35 -0300 (ADT)
Received: from elwamui-polski.atl.sa.earthlink.net ([209.86.224.45])
	by pop-knobcone.atl.sa.earthlink.net with esmtp (Exim 3.36 #10)
	id 1ELlNY-0000Ae-00; Sat, 01 Oct 2005 13:42:32 -0400
Message-ID: 
 <18329659.1128188552696.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
Date: Sat, 1 Oct 2005 13:42:32 -0400 (EDT)
From: Ron Peacetree <rjpeace@earthlink.net>
Reply-To: Ron Peacetree <rjpeace@earthlink.net>
To: Martijn van Oosterhout <kleptog@svana.org>,
	pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org
Subject: Re: [HACKERS] A Better External Sort?
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: Earthlink Zoo Mail 1.0
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.257 required=5 tests=[AWL=-0.117,
	DNS_FROM_RFC_ABUSE=0.374]
X-Spam-Level: 
X-Archive-Number: 200510/9
X-Sequence-Number: 14777

You have not said anything about what HW, OS version, and pg version
used here, but even at that can't you see that something Smells Wrong?

The most common CPUs currently shipping have clock rates of ~2-3GHz
and have 8B-16B internal pathways.  SPARCs and other like CPUs are
clocked slower but have 16B-32B internal pathways.  In short, these
CPU's have an internal bandwidth of 16+ GBps.

The most common currently shipping mainboards have 6.4GBps RAM
subsystems.  ITRW, their peak is ~80% of that, or ~5.1GBps.

In contrast, the absolute peak bandwidth of a 133MHx 8B PCI-X bus is
1GBps, and ITRW it peaks at ~800-850MBps.  Should anyone ever build
a RAID system that can saturate a PCI-Ex16 bus, that system will be
maxing ITRW at ~3.2GBps.

CPUs should NEVER be 100% utilized during copy IO.  They should be
idling impatiently waiting for the next piece of data to finish being
processed even when the RAM IO subsystem is pegged; and they
definitely should be IO starved rather than CPU bound when doing
HD IO.

Those IO rates are also alarming in all but possibly the first case.  A
single ~50MBps HD doing 21MBps isn't bad, but for even a single
~80MBps HD it starts to be of concern.  If any these IO rates came
from any reasonable 300+MBps RAID array, then they are BAD.

What your simple experiment really does is prove We Have A
Problem (tm) with our IO code at either or both of the OS or the pg
level(s).

Ron

     
-----Original Message-----
From: Martijn van Oosterhout <kleptog@svana.org>
Sent: Oct 1, 2005 12:19 PM
Subject: Re: [HACKERS] [PERFORM] A Better External Sort?

On Sat, Oct 01, 2005 at 10:22:40AM -0400, Ron Peacetree wrote:
> Assuming we get the abyssmal physical IO performance fixed...
> (because until we do, _nothing_ is going to help us as much)

I'm still not convinced this is the major problem. For example, in my
totally unscientific tests on an oldish machine I have here:

Direct filesystem copy to /dev/null
21MB/s    10% user 50% system  (dual cpu, so the system is using a whole CPU)

COPY TO /dev/null WITH binary
13MB/s    55% user 45% system  (ergo, CPU bound)

COPY TO /dev/null
4.4MB/s   60% user 40% system

\copy to /dev/null in psql
6.5MB/s   60% user 40% system

This machine is a bit strange setup, not sure why fs copy is so slow.
As to why \copy is faster than COPY, I have no idea, but it is
repeatable. And actually turning the tuples into a printable format is
the most expensive. But it does point out that the whole process is
probably CPU bound more than anything else.

So, I don't think physical I/O is the problem. It's something further
up the call tree. I wouldn't be surprised at all it it had to do with
the creation and destruction of tuples. The cost of comparing tuples
should not be underestimated.

From pgsql-performance-owner@postgresql.org  Sat Oct  1 16:51:19 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 3A6FBD9760;
	Sat,  1 Oct 2005 16:51:13 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 35158-03; Sat,  1 Oct 2005 19:51:09 +0000 (GMT)
Received: from sj1-exch-01.us.corp.kailea.com (mail.ragingnet.net
	[209.249.149.2])
	by svr1.postgresql.org (Postfix) with ESMTP id F342DD9741;
	Sat,  1 Oct 2005 16:51:06 -0300 (ADT)
X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0
Content-class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Subject: Re: [HACKERS] Query in SQL statement
Date: Sat, 1 Oct 2005 12:51:08 -0700
Message-ID: 
 <DB28E9B548192448A4E8C8A3C1B1E475611D35@sj1-exch-01.us.corp.kailea.com>
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
Thread-Topic: [PERFORM] [HACKERS] Query in SQL statement
Thread-Index: AcXGGgl5h7kxFd3zRfOrV6tfg74XGwApLZAw
From: "Roger Hand" <RHand@kailea.com>
To: "Jim C. Nasby" <jnasby@pervasive.com>,
	"Christopher Kings-Lynne" <chriskl@familyhealth.com.au>
Cc: "R, Rajesh (STSD)" <rajesh.r2@hp.com>,
	<pgsql-hackers@postgresql.org>, <pgsql-performance@postgresql.org>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.073 required=5 tests=[AWL=0.023,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/10
X-Sequence-Number: 14778

> -----Original Message-----
> From: pgsql-performance-owner@postgresql.org
> [mailto:pgsql-performance-owner@postgresql.org]On Behalf Of Jim C. =
Nasby
> Sent: Friday, September 30, 2005 4:49 PM
> Subject: Re: [PERFORM] [HACKERS] Query in SQL statement
=20
> I suggest ditching the CamelCase and going with underline_seperators.
> I'd also not use the bareword id, instead using bad_user_id. And I'd
> name the table bad_user. But that's just me. :)

I converted a db from MS SQL, where tables and fields were CamelCase, =
and=20
just lowercased the ddl to create the tables.

So table and fields names were all created in lowercase, but I didn't =
have to change
any of the application code: the SELECT statements worked fine with =
mixed case.

-- sample DDL
CREATE TABLE testtable
(
  fieldone int4
)=20
insert into TestTable (fieldone) values (11);

-- These statements will both work:

-- lowercase
SELECT fieldone FROM testtable;

-- CamelCase
SELECT FieldOne FROM TestTable;

-Roger

> Jim C. Nasby, Sr. Engineering Consultant      jnasby@pervasive.com

From pgsql-performance-owner@postgresql.org  Wed Oct  5 03:55:44 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 1DAB8D9739
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat,  1 Oct 2005 17:33:06 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 45128-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat,  1 Oct 2005 20:33:03 +0000 (GMT)
Received: from news.hub.org (news.hub.org [200.46.204.72])
	by svr1.postgresql.org (Postfix) with ESMTP id B33B1D976B
	for <pgsql-performance@postgresql.org>;
	Sat,  1 Oct 2005 17:33:04 -0300 (ADT)
Received: from news.hub.org (news.hub.org [200.46.204.72])
	by news.hub.org (8.13.1/8.13.1) with ESMTP id j91KX2M7048688
	for <pgsql-performance@postgresql.org>; Sat, 1 Oct 2005 20:33:02 GMT
	(envelope-from news@news.hub.org)
Received: (from news@localhost)
	by news.hub.org (8.13.1/8.13.1/Submit) id j91K8aOY042864
	for pgsql-performance@postgresql.org; Sat, 1 Oct 2005 20:08:36 GMT
	(envelope-from news)
From: "AL� �EL�K" <ali@verus.com.tr>
X-Newsgroups: pgsql.performance
Subject: Which one FreeBSD or Linux
Date: Sat, 1 Oct 2005 23:08:31 +0300
Organization: Hub.Org Networking Services
Lines: 3
Message-ID: <dhmqc3$19rf$1@news.hub.org>
X-Complaints-To: usenet@news.hub.org
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
To: pgsql-performance@postgresql.org
X-Virus-Scanned: by amavisd-new at hub.org
X-Amavis-Alert: BAD HEADER Non-encoded 8-bit data (char DD hex) in message
	header 'From': From: "AL\335 \307EL\335K" <ali@ve...
X-Spam-Status: No, hits=-1.052 required=5 tests=[ALL_TRUSTED=-2.82, AWL=0.583,
	PRIORITY_NO_NAME=1.185]
X-Spam-Level: 
X-Archive-Number: 200510/83
X-Sequence-Number: 14851

FreeBSD or Linux , which system has better performance for PostgreSQL 



From pgsql-performance-owner@postgresql.org  Sat Oct  1 18:15:53 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 18BDDD97A7;
	Sat,  1 Oct 2005 18:15:50 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 55778-01; Sat,  1 Oct 2005 21:15:47 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id 1972CD97A5;
	Sat,  1 Oct 2005 18:15:47 -0300 (ADT)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j91LFP4O028303;
	Sat, 1 Oct 2005 17:15:26 -0400 (EDT)
To: "Roger Hand" <RHand@kailea.com>
Cc: "Jim C. Nasby" <jnasby@pervasive.com>,
	"Christopher Kings-Lynne" <chriskl@familyhealth.com.au>,
	"R,     Rajesh (STSD)" <rajesh.r2@hp.com>,
	pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org
Subject: Re: [HACKERS] Query in SQL statement 
In-reply-to: 
 <DB28E9B548192448A4E8C8A3C1B1E475611D35@sj1-exch-01.us.corp.kailea.com>
References: 
 <DB28E9B548192448A4E8C8A3C1B1E475611D35@sj1-exch-01.us.corp.kailea.com>
Comments: In-reply-to "Roger Hand" <RHand@kailea.com>
	message dated "Sat, 01 Oct 2005 12:51:08 -0700"
Date: Sat, 01 Oct 2005 17:15:25 -0400
Message-ID: <28302.1128201325@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/11
X-Sequence-Number: 14779

"Roger Hand" <RHand@kailea.com> writes:
>> I suggest ditching the CamelCase and going with underline_seperators.
>> I'd also not use the bareword id, instead using bad_user_id. And I'd
>> name the table bad_user. But that's just me. :)

> I converted a db from MS SQL, where tables and fields were CamelCase, and 
> just lowercased the ddl to create the tables.
> So table and fields names were all created in lowercase, but I didn't have to change
> any of the application code: the SELECT statements worked fine with mixed case.

Yeah, the only time this stuff really bites you is if the application
sometimes double-quotes mixed-case names and sometimes doesn't.  If it's
consistent then you don't have an issue ...

			regards, tom lane

From pgsql-hackers-owner@postgresql.org  Sat Oct  1 18:56:20 2005
X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 3DBDDD9D7A
	for <pgsql-hackers-postgresql.org@localhost.postgresql.org>;
	Sat,  1 Oct 2005 18:56:18 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 60812-02
	for <pgsql-hackers-postgresql.org@localhost.postgresql.org>;
	Sat,  1 Oct 2005 21:56:10 +0000 (GMT)
Received: from svana.org (svana.org [203.20.62.76])
	by svr1.postgresql.org (Postfix) with ESMTP id 3809AD9787
	for <pgsql-hackers@postgresql.org>;
	Sat,  1 Oct 2005 18:56:10 -0300 (ADT)
Received: from kleptog by svana.org with local (Exim 3.35 #1 (Debian))
	id 1ELpKx-0005ne-00; Sun, 02 Oct 2005 07:56:07 +1000
Date: Sat, 1 Oct 2005 23:56:07 +0200
From: Martijn van Oosterhout <kleptog@svana.org>
To: Ron Peacetree <rjpeace@earthlink.net>
Cc: pgsql-hackers@postgresql.org
Subject: Re: [PERFORM] A Better External Sort?
Message-ID: <20051001215602.GG13830@svana.org>
Reply-To: Martijn van Oosterhout <kleptog@svana.org>
References: 
 <18329659.1128188552696.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
Mime-Version: 1.0
Content-Type: multipart/signed; micalg=pgp-sha1;
	protocol="application/pgp-signature"; boundary="QWpDgw58+k1mSFBj"
Content-Disposition: inline
In-Reply-To: 
 <18329659.1128188552696.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
User-Agent: Mutt/1.3.28i
X-PGP-Key-ID: Length=1024; ID=0x0DC67BE6
X-PGP-Key-Fingerprint: 295F A899 A81A 156D B522  48A7 6394 F08A 0DC6 7BE6
X-PGP-Key-URL: <http://svana.org/kleptog/0DC67BE6.pgp.asc>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.008 required=5 tests=[AWL=0.008]
X-Spam-Level: 
X-Archive-Number: 200510/56
X-Sequence-Number: 73915


--QWpDgw58+k1mSFBj
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

[removed -performance, not subscribed]

On Sat, Oct 01, 2005 at 01:42:32PM -0400, Ron Peacetree wrote:
> You have not said anything about what HW, OS version, and pg version
> used here, but even at that can't you see that something Smells Wrong?

Somewhat old machine running 7.3 on Linux 2.4. Not exactly speed
daemons but it's still true that the whole process would be CPU bound
*even* if the O/S could idle while it's waiting. PostgreSQL used a
*whole CPU* which is its limit. My point is that trying to reduce I/O
by increasing CPU usage is not going to be benficial, we need CPU usage
down also.

Anyway, to bring some real info I just profiled PostgreSQL 8.1beta
doing an index create on a 2960296 row table (3 columns, table size
317MB).

The number 1 bottleneck with 41% of user time is comparetup_index. It
was called 95,369,361 times (about 2*ln(N)*N). It used 3 tapes. Another
15% of time went to tuplesort_heap_siftup.

The thing is, I can't see anything in comparetup_index() that could
take much time. The actual comparisons are accounted elsewhere
(inlineApplySortFunction) which amounted to <10% of total time. Since
nocache_index_getattr doesn't feature I can't imagine index_getattr
being a big bottleneck. Any ideas what's going on here?

Other interesting features:
- ~4 memory allocations per tuple, nearly all of which were explicitly
freed
- Things I though would be expensive, like: heapgettup and
myFunctionCall2 didn't really count for much.

Have a nice weekend,

  %   cumulative   self              self     total          =20
 time   seconds   seconds    calls   s/call   s/call  name   =20
 43.63    277.81   277.81 95370055     0.00     0.00  comparetup_index
 16.24    381.24   103.43  5920592     0.00     0.00  tuplesort_heap_siftup
  3.76    405.17    23.93 95370055     0.00     0.00  inlineApplySortFuncti=
on
  3.18    425.42    20.26 95370056     0.00     0.00  btint4cmp
  2.82    443.37    17.95 11856219     0.00     0.00  AllocSetAlloc
  2.52    459.44    16.07 95370055     0.00     0.00  myFunctionCall2
  1.71    470.35    10.91  2960305     0.00     0.00  heapgettup
  1.26    478.38     8.03 11841204     0.00     0.00  GetMemoryChunkSpace
  1.14    485.67     7.29  5920592     0.00     0.00  tuplesort_heap_insert
  1.11    492.71     7.04  2960310     0.00     0.00  index_form_tuple
  1.09    499.67     6.96 11855105     0.00     0.00  AllocSetFree
  0.97    505.83     6.17 23711355     0.00     0.00  AllocSetFreeIndex
  0.84    511.19     5.36  5920596     0.00     0.00  LogicalTapeWrite
  0.84    516.51     5.33  2960314     0.00     0.00  slot_deform_tuple
--=20
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

--QWpDgw58+k1mSFBj
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQFDPwXxIB7bNG8LQkwRAmA3AJ0SJrScvMeXv99OsRZivZcxojUfhgCgiLzQ
adITHNOK9MrxSou0G5gNFko=
=PdSb
-----END PGP SIGNATURE-----

--QWpDgw58+k1mSFBj--

From pgsql-hackers-owner@postgresql.org  Sun Oct  2 00:26:13 2005
X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 00C82D9806
	for <pgsql-hackers-postgresql.org@localhost.postgresql.org>;
	Sun,  2 Oct 2005 00:26:11 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 38141-06
	for <pgsql-hackers-postgresql.org@localhost.postgresql.org>;
	Sun,  2 Oct 2005 03:26:09 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id 5A3EBD8EB7
	for <pgsql-hackers@postgresql.org>;
	Sun,  2 Oct 2005 00:26:09 -0300 (ADT)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j923Q7RG029838;
	Sat, 1 Oct 2005 23:26:07 -0400 (EDT)
To: Martijn van Oosterhout <kleptog@svana.org>
Cc: Ron Peacetree <rjpeace@earthlink.net>,
	pgsql-hackers@postgresql.org
Subject: Re: [PERFORM] A Better External Sort? 
In-reply-to: <20051001215602.GG13830@svana.org> 
References: 
 <18329659.1128188552696.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
	<20051001215602.GG13830@svana.org>
Comments: In-reply-to Martijn van Oosterhout <kleptog@svana.org>
	message dated "Sat, 01 Oct 2005 23:56:07 +0200"
Date: Sat, 01 Oct 2005 23:26:07 -0400
Message-ID: <29837.1128223567@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/57
X-Sequence-Number: 73916

Martijn van Oosterhout <kleptog@svana.org> writes:
> Anyway, to bring some real info I just profiled PostgreSQL 8.1beta
> doing an index create on a 2960296 row table (3 columns, table size
> 317MB).

3 columns in the index you mean?  What were the column datatypes?
Any null values?

> The number 1 bottleneck with 41% of user time is comparetup_index.
> ...
> The thing is, I can't see anything in comparetup_index() that could
> take much time.

The index_getattr and heap_getattr macros can be annoyingly expensive.

			regards, tom lane

From pgsql-hackers-owner@postgresql.org  Sun Oct  2 09:47:48 2005
X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id EFA14D98E5
	for <pgsql-hackers-postgresql.org@localhost.postgresql.org>;
	Sun,  2 Oct 2005 09:32:53 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 56700-10
	for <pgsql-hackers-postgresql.org@localhost.postgresql.org>;
	Sun,  2 Oct 2005 12:32:49 +0000 (GMT)
Received: from svana.org (svana.org [203.20.62.76])
	by svr1.postgresql.org (Postfix) with ESMTP id 98FA2D98C9
	for <pgsql-hackers@postgresql.org>;
	Sun,  2 Oct 2005 09:32:50 -0300 (ADT)
Received: from kleptog by svana.org with local (Exim 3.35 #1 (Debian))
	id 1EM31J-0008PT-00; Sun, 02 Oct 2005 22:32:45 +1000
Date: Sun, 2 Oct 2005 14:32:45 +0200
From: Martijn van Oosterhout <kleptog@svana.org>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Ron Peacetree <rjpeace@earthlink.net>,
	pgsql-hackers@postgresql.org
Subject: Re: [PERFORM] A Better External Sort?
Message-ID: <20051002123240.GA30492@svana.org>
Reply-To: Martijn van Oosterhout <kleptog@svana.org>
References: 
 <18329659.1128188552696.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
	<20051001215602.GG13830@svana.org> <29837.1128223567@sss.pgh.pa.us>
Mime-Version: 1.0
Content-Type: multipart/signed; micalg=pgp-sha1;
	protocol="application/pgp-signature"; boundary="SUOF0GtieIMvvwua"
Content-Disposition: inline
In-Reply-To: <29837.1128223567@sss.pgh.pa.us>
User-Agent: Mutt/1.3.28i
X-PGP-Key-ID: Length=1024; ID=0x0DC67BE6
X-PGP-Key-Fingerprint: 295F A899 A81A 156D B522  48A7 6394 F08A 0DC6 7BE6
X-PGP-Key-URL: <http://svana.org/kleptog/0DC67BE6.pgp.asc>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.008 required=5 tests=[AWL=0.008]
X-Spam-Level: 
X-Archive-Number: 200510/63
X-Sequence-Number: 73922


--SUOF0GtieIMvvwua
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Sat, Oct 01, 2005 at 11:26:07PM -0400, Tom Lane wrote:
> Martijn van Oosterhout <kleptog@svana.org> writes:
> > Anyway, to bring some real info I just profiled PostgreSQL 8.1beta
> > doing an index create on a 2960296 row table (3 columns, table size
> > 317MB).
>=20
> 3 columns in the index you mean?  What were the column datatypes?
> Any null values?

Nope, three columns in the table, one column in the index, no nulls.
The indexed column was integer. I did it once with around 6500 values
repeated over and over, lots of duplicate kays. And once on a serial
column but it made no descernable difference either way. Although the
comparison function was called less (only 76 million times), presumably
because it was mostly sorted already.

> > The number 1 bottleneck with 41% of user time is comparetup_index.
> > ...
> > The thing is, I can't see anything in comparetup_index() that could
> > take much time.
>=20
> The index_getattr and heap_getattr macros can be annoyingly expensive.

And yet they are optimised for the common case. nocache_index_getattr
was only called 7 times, which is about what you expect. I'm getting
annotated output now, to determine which line takes the time...
Actually, my previous profile overstated stuff a bit. Profiling turned
off optimisation so I put it back and you get better results but the
order doesn't change much. By line results are below.

The top two are the index_getattr calls in comparetup_index. Third and
fourth are the HEAPCOMPARES in tuplesort_heap_siftup. Then comes the
inlineApplySortFunction call (which isn't being inlined, despite
suggesting it should be, -Winline warns about this).

Looks to me that there are no real gains to be made in this function.
What is needed is an algorithmic change to call this function less
often...

Have a nice weekend,

  %   cumulative   self              self     total          =20
 time   seconds   seconds    calls  ms/call  ms/call  name   =20
  9.40     22.56    22.56                             comparetup_index (tup=
lesort.c:2042 @ 8251060)
  5.07     34.73    12.17                             comparetup_index (tup=
lesort.c:2043 @ 82510c0)
  4.73     46.09    11.36                             tuplesort_heap_siftup=
 (tuplesort.c:1648 @ 825074d)
  3.48     54.45     8.36                             tuplesort_heap_siftup=
 (tuplesort.c:1661 @ 82507a9)
  2.80     61.18     6.73                             comparetup_index (tup=
lesort.c:2102 @ 8251201)
  2.68     67.62     6.44                             comparetup_index (tup=
lesort.c:2048 @ 8251120)
  2.16     72.82     5.20                             tuplesort_heap_siftup=
 (tuplesort.c:1652 @ 825076d)
  1.88     77.34     4.52 76025782     0.00     0.00  comparetup_index (tup=
lesort.c:2016 @ 8251010)
  1.82     81.70     4.36 76025782     0.00     0.00  inlineApplySortFuncti=
on (tuplesort.c:1833 @ 8251800)
  1.73     85.85     4.15                             readtup_heap (tupleso=
rt.c:2000 @ 8250fd8)
  1.67     89.86     4.01                             AllocSetAlloc (aset.c=
:568 @ 824bec0)
  1.61     93.72     3.86                             comparetup_index (tup=
lesort.c:2025 @ 825102f)
  1.47     97.25     3.53 76025785     0.00     0.00  btint4cmp (nbtcompare=
.c:74 @ 80924a0)
  1.11     99.92     2.67                             readtup_datum (tuples=
ort.c:2224 @ 82517c4)
  1.10    102.55     2.64                             comparetup_index (tup=
lesort.c:2103 @ 82511e7)

  %   cumulative   self              self     total          =20
 time   seconds   seconds    calls   s/call   s/call  name   =20
 28.34     68.01    68.01 76025782     0.00     0.00  comparetup_index
 13.56    100.54    32.53  7148934     0.00     0.00  tuplesort_heap_siftup
  8.66    121.33    20.79 76025782     0.00     0.00  inlineApplySortFuncti=
on
  4.43    131.96    10.63 13084567     0.00     0.00  AllocSetAlloc
  3.73    140.90     8.94 76025785     0.00     0.00  btint4cmp
  2.15    146.07     5.17  6095625     0.00     0.00  LWLockAcquire
  2.02    150.92     4.85  2960305     0.00     0.00  heapgettup
  1.98    155.66     4.74  7148934     0.00     0.00  tuplesort_heap_insert
  1.78    159.94     4.28  2960312     0.00     0.00  slot_deform_tuple
  1.73    164.09     4.15                             readtup_heap
  1.67    168.09     4.00  6095642     0.00     0.00  LWLockRelease
  1.53    171.76     3.68  2960308     0.00     0.00  index_form_tuple
  1.44    175.21     3.45 13083442     0.00     0.00  AllocSetFree
  1.28    178.28     3.07  8377285     0.00     0.00  LogicalTapeWrite
  1.25    181.29     3.01  8377285     0.00     0.00  LogicalTapeRead
  1.11    183.96     2.67                             readtup_datum
  1.06    186.51     2.55        1     2.55   123.54  IndexBuildHeapScan

--=20
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

--SUOF0GtieIMvvwua
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQFDP9NnIB7bNG8LQkwRAh0TAJ0UnvSw9wBY+EdineD6QSWRUGh2EwCfVwq1
GVyJz5jgohzQzP6inojA9G4=
=s43K
-----END PGP SIGNATURE-----

--SUOF0GtieIMvvwua--

From pgsql-hackers-owner@postgresql.org  Sun Oct  2 17:41:15 2005
X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 301ABD9CC0
	for <pgsql-hackers-postgresql.org@localhost.postgresql.org>;
	Sun,  2 Oct 2005 16:38:59 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 54987-05
	for <pgsql-hackers-postgresql.org@localhost.postgresql.org>;
	Sun,  2 Oct 2005 19:38:53 +0000 (GMT)
Received: from svana.org (svana.org [203.20.62.76])
	by svr1.postgresql.org (Postfix) with ESMTP id E6687D950A
	for <pgsql-hackers@postgresql.org>;
	Sun,  2 Oct 2005 16:38:50 -0300 (ADT)
Received: from kleptog by svana.org with local (Exim 3.35 #1 (Debian))
	id 1EM9fX-0001Rr-00; Mon, 03 Oct 2005 05:38:43 +1000
Date: Sun, 2 Oct 2005 21:38:43 +0200
From: Martijn van Oosterhout <kleptog@svana.org>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Ron Peacetree <rjpeace@earthlink.net>,
	pgsql-hackers@postgresql.org
Subject: Re: [PERFORM] A Better External Sort?
Message-ID: <20051002193835.GJ30492@svana.org>
Reply-To: Martijn van Oosterhout <kleptog@svana.org>
References: 
 <18329659.1128188552696.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
	<20051001215602.GG13830@svana.org> <29837.1128223567@sss.pgh.pa.us>
	<20051002123240.GA30492@svana.org>
Mime-Version: 1.0
Content-Type: multipart/signed; micalg=pgp-sha1;
	protocol="application/pgp-signature"; boundary="opg8F0UgoHELSI+9"
Content-Disposition: inline
In-Reply-To: <20051002123240.GA30492@svana.org>
User-Agent: Mutt/1.3.28i
X-PGP-Key-ID: Length=1024; ID=0x0DC67BE6
X-PGP-Key-Fingerprint: 295F A899 A81A 156D B522  48A7 6394 F08A 0DC6 7BE6
X-PGP-Key-URL: <http://svana.org/kleptog/0DC67BE6.pgp.asc>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.008 required=5 tests=[AWL=0.008]
X-Spam-Level: 
X-Archive-Number: 200510/70
X-Sequence-Number: 73929


--opg8F0UgoHELSI+9
Content-Type: multipart/mixed; boundary="4vpci17Ql0Nrbul2"
Content-Disposition: inline


--4vpci17Ql0Nrbul2
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Ok, I tried two optimisations:

1. By creating a special version of comparetup_index for single key
integer indexes. Create an index_get_attr with byval and len args. By
using fetch_att and specifying the values at compile time, gcc
optimises the whole call to about 12 instructions of assembly rather
than the usual mess.

2. By specifying: -Winline -finline-limit-1500 (only on tuplesort.c).
This causes inlineApplySortFunction() to be inlined, like the code
obviously expects it to be.

default build (baseline)                    235 seconds
-finline only                               217 seconds (7% better)
comparetup_index_fastbyval4 only            221 seconds (6% better)
comparetup_index_fastbyval4 and -finline    203 seconds (13.5% better)

This is indexing the integer sequence column on a 2.7 million row
table. The times are as given by gprof and so exclude system call time.

Basically, I recommend adding "-Winline -finline-limit-1500" to the
default build while we discuss other options.

comparetup_index_fastbyval4 patch attached per example.
--=20
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

--4vpci17Ql0Nrbul2
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="fastindex.patch"
Content-Transfer-Encoding: quoted-printable

--- pgsql-clean/src/include/access/itup.h	2005-10-02 21:30:20.327464320 +02=
00
+++ pgsql-sort/src/include/access/itup.h	2005-10-02 16:04:00.000000000 +0200
@@ -126,6 +126,34 @@
 	) \
 )
=20
+#define index_get_attr(tup, attnum, tupleDesc, attbyval, attlen, isnull) \
+( \
+	AssertMacro(PointerIsValid(isnull) && (attnum) > 0), \
+	*(isnull) =3D false, \
+	!IndexTupleHasNulls(tup) ? \
+	( \
+		(tupleDesc)->attrs[(attnum)-1]->attcacheoff >=3D 0 ? \
+		( \
+			fetch_att((char *) (tup) + IndexInfoFindDataOffset((tup)->t_info) \
+				+ (tupleDesc)->attrs[(attnum)-1]->attcacheoff, attbyval, attlen) \
+		) \
+		: \
+			nocache_index_getattr((tup), (attnum), (tupleDesc), (isnull)) \
+	) \
+	: \
+	( \
+		(att_isnull((attnum)-1, (char *)(tup) + sizeof(IndexTupleData))) ? \
+		( \
+			*(isnull) =3D true, \
+			(Datum)NULL \
+		) \
+		: \
+		( \
+			nocache_index_getattr((tup), (attnum), (tupleDesc), (isnull)) \
+		) \
+	) \
+)
+
=20
 /* routines in indextuple.c */
 extern IndexTuple index_form_tuple(TupleDesc tupleDescriptor,
--- pgsql-clean/src/backend/utils/sort/tuplesort.c	2005-09-24 23:23:39.0000=
00000 +0200
+++ pgsql-sort/src/backend/utils/sort/tuplesort.c	2005-10-02 21:29:39.34908=
6302 +0200
@@ -375,6 +375,8 @@
 			 unsigned int len);
 static int comparetup_index(Tuplesortstate *state,
 				 const void *a, const void *b);
+static int comparetup_index_fastbyval4(Tuplesortstate *state,
+				 const void *a, const void *b);
 static void *copytup_index(Tuplesortstate *state, void *tup);
 static void writetup_index(Tuplesortstate *state, int tapenum, void *tup);
 static void *readtup_index(Tuplesortstate *state, int tapenum,
@@ -498,8 +500,12 @@
 					  int workMem, bool randomAccess)
 {
 	Tuplesortstate *state =3D tuplesort_begin_common(workMem, randomAccess);
+	TupleDesc	tupDes =3D RelationGetDescr(indexRel);
=20
-	state->comparetup =3D comparetup_index;
+	if( tupDes->natts =3D=3D 1 && tupDes->attrs[0]->attbyval =3D=3D 1 && tupD=
es->attrs[0]->attlen =3D=3D 4 )
+		state->comparetup =3D comparetup_index_fastbyval4;
+	else
+		state->comparetup =3D comparetup_index;
 	state->copytup =3D copytup_index;
 	state->writetup =3D writetup_index;
 	state->readtup =3D readtup_index;
@@ -2102,6 +2108,92 @@
 	return 0;
 }
=20
+static int
+comparetup_index_fastbyval4(Tuplesortstate *state, const void *a, const vo=
id *b)
+{
+	/*
+	 * This is almost the same as _bt_tuplecompare(), but we need to keep
+	 * track of whether any null fields are present.  Also see the special
+	 * treatment for equal keys at the end.
+	 */
+	IndexTuple	tuple1 =3D (IndexTuple) a;
+	IndexTuple	tuple2 =3D (IndexTuple) b;
+	Relation	rel =3D state->indexRel;
+	ScanKey		scankey =3D state->indexScanKey;
+	TupleDesc	tupDes;
+	bool		equal_hasnull =3D false;
+
+	tupDes =3D RelationGetDescr(rel);
+
+	ScanKey		entry =3D &scankey[0];
+	Datum		datum1,
+					datum2;
+	bool		isnull1,
+					isnull2;
+	int32		compare;
+
+	datum1 =3D index_get_attr(tuple1, 1, tupDes, 1, 4, &isnull1);
+	datum2 =3D index_get_attr(tuple2, 1, tupDes, 1, 4, &isnull2);
+
+	/* see comments about NULLs handling in btbuild */
+
+	/* the comparison function is always of CMP type */
+	compare =3D inlineApplySortFunction(&entry->sk_func, SORTFUNC_CMP,
+									  datum1, isnull1,
+									  datum2, isnull2);
+
+	if (compare !=3D 0)
+		return (int) compare;		/* done when we find unequal
+										 * attributes */
+
+	/* they are equal, so we only need to examine one null flag */
+	if (isnull1)
+		equal_hasnull =3D true;
+
+	/*
+	 * If btree has asked us to enforce uniqueness, complain if two equal
+	 * tuples are detected (unless there was at least one NULL field).
+	 *
+	 * It is sufficient to make the test here, because if two tuples are
+	 * equal they *must* get compared at some stage of the sort ---
+	 * otherwise the sort algorithm wouldn't have checked whether one must
+	 * appear before the other.
+	 *
+	 * Some rather brain-dead implementations of qsort will sometimes call
+	 * the comparison routine to compare a value to itself.  (At this
+	 * writing only QNX 4 is known to do such silly things.)  Don't raise
+	 * a bogus error in that case.
+	 */
+	if (state->enforceUnique && !equal_hasnull && tuple1 !=3D tuple2)
+		ereport(ERROR,
+				(errcode(ERRCODE_UNIQUE_VIOLATION),
+				 errmsg("could not create unique index"),
+				 errdetail("Table contains duplicated values.")));
+
+	/*
+	 * If key values are equal, we sort on ItemPointer.  This does not
+	 * affect validity of the finished index, but it offers cheap
+	 * insurance against performance problems with bad qsort
+	 * implementations that have trouble with large numbers of equal keys.
+	 */
+	{
+		BlockNumber blk1 =3D ItemPointerGetBlockNumber(&tuple1->t_tid);
+		BlockNumber blk2 =3D ItemPointerGetBlockNumber(&tuple2->t_tid);
+
+		if (blk1 !=3D blk2)
+			return (blk1 < blk2) ? -1 : 1;
+	}
+	{
+		OffsetNumber pos1 =3D ItemPointerGetOffsetNumber(&tuple1->t_tid);
+		OffsetNumber pos2 =3D ItemPointerGetOffsetNumber(&tuple2->t_tid);
+
+		if (pos1 !=3D pos2)
+			return (pos1 < pos2) ? -1 : 1;
+	}
+
+	return 0;
+}
+
 static void *
 copytup_index(Tuplesortstate *state, void *tup)
 {

--4vpci17Ql0Nrbul2--

--opg8F0UgoHELSI+9
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQFDQDc6IB7bNG8LQkwRAskpAJ4oX70LIkeobYjuwjbz/pqwCHfxUACgijKl
vxCH8Kf9KpoKYYQecGqdtpg=
=M3LE
-----END PGP SIGNATURE-----

--opg8F0UgoHELSI+9--

From pgsql-performance-owner@postgresql.org  Mon Oct  3 08:02:33 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 1C4BFD9E25
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon,  3 Oct 2005 08:02:32 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 70238-09
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon,  3 Oct 2005 11:02:27 +0000 (GMT)
Received: from cassarossa.samfundet.no (cassarossa.samfundet.no
	[129.241.93.19])
	by svr1.postgresql.org (Postfix) with ESMTP id 2B6A6D9E19
	for <pgsql-performance@postgresql.org>;
	Mon,  3 Oct 2005 08:02:28 -0300 (ADT)
Received: from trofast.ipv6.sesse.net ([2001:700:300:dc03:20e:cff:fe36:a766]
	helo=trofast.sesse.net)
	by cassarossa.samfundet.no with esmtp (Exim 4.50) id 1EMO5U-00072f-OL
	for pgsql-performance@postgresql.org; Mon, 03 Oct 2005 13:02:30 +0200
Received: from sesse by trofast.sesse.net with local (Exim 3.36 #1 (Debian))
	id 1EMO5S-0007Lt-00
	for <pgsql-performance@postgresql.org>; Mon, 03 Oct 2005 13:02:26 +0200
Date: Mon, 3 Oct 2005 13:02:26 +0200
From: "Steinar H. Gunderson" <sgunderson@bigfoot.com>
To: pgsql-performance@postgresql.org
Subject: Ultra-cheap NVRAM device
Message-ID: <20051003110226.GA26883@uio.no>
Mail-Followup-To: pgsql-performance@postgresql.org
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
X-Operating-System: Linux 2.6.11.8 on a i686
X-Message-Flag: Outlook? --> http://www.mozilla.org/products/thunderbird/
User-Agent: Mutt/1.5.10i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.013 required=5 tests=[AWL=0.013]
X-Spam-Level: 
X-Archive-Number: 200510/12
X-Sequence-Number: 14780

I thought this might be interesting, not the least due to the extremely low
price ($150 + the price of regular DIMMs):

  http://www.tomshardware.com/storage/20050907/index.html

Anybody know a good reason why you can't put a WAL on this, and enjoy a hefty
speed boost for a fraction of the price of a traditional SSD? (Yes, it's
SATA, not PCI, so the throughput is not all that impressive -- but still,
it's got close to zero seek time.)

/* Steinar */
-- 
Homepage: http://www.sesse.net/

From pgsql-performance-owner@postgresql.org  Mon Oct  3 09:27:16 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 9ECFED9A6B
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon,  3 Oct 2005 09:27:15 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 94605-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon,  3 Oct 2005 12:27:11 +0000 (GMT)
Received: from pc7.berlin.powerweb.de (pc7.berlin.powerweb.de [62.67.228.13])
	by svr1.postgresql.org (Postfix) with ESMTP id 7F2D5D8B43
	for <pgsql-performance@postgresql.org>;
	Mon,  3 Oct 2005 09:27:11 -0300 (ADT)
Received: from [192.168.2.102] (p54ADB70A.dip0.t-ipconnect.de [84.173.183.10])
	by pc7.berlin.powerweb.de (8.9.3p3/8.9.3) with ESMTP id OAA16825
	for <pgsql-performance@postgresql.org>; Mon, 3 Oct 2005 14:27:11 +0200
Message-ID: <434123CA.2020708@sector-x.de>
Date: Mon, 03 Oct 2005 14:27:54 +0200
From: Harald Lau <harald@sector-x.de>
Organization: Sector-X GmbH
User-Agent: Mozilla Thunderbird 1.0.7 (Windows/20050923)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: pgsql-performance@postgresql.org
Subject: URGENT: pg_statistic_relid_att_index has gone
References: <20051003110226.GA26883@uio.no>
In-Reply-To: <20051003110226.GA26883@uio.no>
X-Enigmail-Version: 0.92.0.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0 required=5 tests=[none]
X-Spam-Level: 
X-Archive-Number: 200510/13
X-Sequence-Number: 14781

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

on a 7.2 System (Suse-Linux) I got an error "duplicate key in unique
index pg_statistic_relid_att_index" (think it was while vacuuming)

I REINDEXd the database.
Now the table pg_statistic_relid_att_index is completely gone.

Has anybody an advise?

tia,
Harald
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (MingW32)
Comment: GnuPT 2.7.2

iQEVAwUBQ0Ejx3fX3+fgcdKcAQIVoQf+MFnt+U65FPNxQjHwZ15eT13NwBoCsOE9
d3nFaKTG58SmI9QziMt1Tpo+pD89LMQZacnCRDv/M3Tz6ruSQaPIsxS6m1evKjq7
7ixSRCwD+41C2x27qSRZDOEUt6AvG5xfSv43NxJQNS/zB+/TnQ3wGXzwdRrRQiQE
Mv6DXv5s+3Wrbg9qG78Xn3mHOGGySFSG1x9ItUoST+jC6a7rOl5YL3wDCacdgve/
pzq3fe6+JYjEQyKFxEzZYJidsWvr9C7EKfc321PYBscuPNyGMU1Vohe8kDYFbyeG
L23jXPV8c7WO2w4aQMdQr6V9YXtnBeMgGdAFjo4My29xbdepkwOUvw==
=I8Ax
-----END PGP SIGNATURE-----

From pgsql-performance-owner@postgresql.org  Mon Oct  3 11:00:23 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 5FCD0D9E6E
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon,  3 Oct 2005 11:00:21 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 20555-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon,  3 Oct 2005 14:00:15 +0000 (GMT)
Received: from pc7.berlin.powerweb.de (pc7.berlin.powerweb.de [62.67.228.13])
	by svr1.postgresql.org (Postfix) with ESMTP id ABCDFD9E61
	for <pgsql-performance@postgresql.org>;
	Mon,  3 Oct 2005 11:00:16 -0300 (ADT)
Received: from [192.168.2.102] (p54ADB70A.dip0.t-ipconnect.de [84.173.183.10])
	by pc7.berlin.powerweb.de (8.9.3p3/8.9.3) with ESMTP id QAA27012
	for <pgsql-performance@postgresql.org>; Mon, 3 Oct 2005 16:00:19 +0200
Message-ID: <4341399E.3040205@sector-x.de>
Date: Mon, 03 Oct 2005 16:01:02 +0200
From: Harald Lau <harald@sector-x.de>
Organization: Sector-X GmbH
User-Agent: Mozilla Thunderbird 1.0.7 (Windows/20050923)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: pgsql-performance@postgresql.org
Subject: Re: URGENT: pg_statistic_relid_att_index has gone
References: <20051003110226.GA26883@uio.no> <434123CA.2020708@sector-x.de>
In-Reply-To: <434123CA.2020708@sector-x.de>
X-Enigmail-Version: 0.92.0.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0 required=5 tests=[none]
X-Spam-Level: 
X-Archive-Number: 200510/14
X-Sequence-Number: 14782

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

> on a 7.2 System (Suse-Linux) I got an error "duplicate key in unique
> index pg_statistic_relid_att_index" (think it was while vacuuming)
> 
> I REINDEXd the database.
> Now the table pg_statistic_relid_att_index is completely gone.

go searching the internet first, man ...
Surprisingly I'm not the first one having such a breakdown

Found a solution provided by Tom Lane:
http://www.xy1.org/pgsql-general@postgresql.org/msg04568.html

Seems to work, many thanks

Sorry for the overhasty question
Harald
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (MingW32)
Comment: GnuPT 2.7.2

iQEVAwUBQ0E5nXfX3+fgcdKcAQJWsgf+JvgWRjgl/RLBzGd8wNt7x6/VngGOzdpT
4E3OgbrGuAPEC3INkMLTLRU2hVvjRqgkNaWS2YlXpFmlAff6czGeSbwXv4vDiiH7
AYHpONACLgr8jcHohS0kmylqu/3QYSsmRBDOTOCNms1iMEmJZvpru9YJpSEjwWUL
/n5pu5lurcpU+VGLTCikin5UnsNWmQzsegz+f2co3UuTDHIUER+W2538Fb9iiZBD
P9TCI972U+oC2YTg+Puh22jPfS1gG7EHUxKt/XbE9klca1AnCdJX6LdsIh7vdMhw
6u8JzaaAz9nHtqYFpClkEpnkp9KEohw/uQyDUCB7FK//MRtSWx+MPw==
=52pe
-----END PGP SIGNATURE-----

From pgsql-performance-owner@postgresql.org  Mon Oct  3 11:08:27 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 88756D99B7
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon,  3 Oct 2005 11:08:11 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 18379-10
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon,  3 Oct 2005 14:08:07 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id C126DD9E73
	for <pgsql-performance@postgresql.org>;
	Mon,  3 Oct 2005 11:08:09 -0300 (ADT)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j93E8EVL021821;
	Mon, 3 Oct 2005 10:08:14 -0400 (EDT)
To: Harald Lau <harald@sector-x.de>
Cc: pgsql-performance@postgresql.org
Subject: Re: URGENT: pg_statistic_relid_att_index has gone 
In-reply-to: <434123CA.2020708@sector-x.de> 
References: <20051003110226.GA26883@uio.no> <434123CA.2020708@sector-x.de>
Comments: In-reply-to Harald Lau <harald@sector-x.de>
	message dated "Mon, 03 Oct 2005 14:27:54 +0200"
Date: Mon, 03 Oct 2005 10:08:14 -0400
Message-ID: <21820.1128348494@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/15
X-Sequence-Number: 14783

Harald Lau <harald@sector-x.de> writes:
> on a 7.2 System (Suse-Linux) I got an error "duplicate key in unique
> index pg_statistic_relid_att_index" (think it was while vacuuming)
> I REINDEXd the database.
> Now the table pg_statistic_relid_att_index is completely gone.
> Has anybody an advise?

Dump, initdb, reload.  You've probably got more problems than just
that.  This might be a good time to update to something newer than
PG 7.2, too.

			regards, tom lane

From pgsql-performance-owner@postgresql.org  Wed Oct  5 03:35:27 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 2C138D9A74
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon,  3 Oct 2005 12:14:24 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 37807-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon,  3 Oct 2005 15:14:22 +0000 (GMT)
Received: from floppy.pyrenet.fr (news.pyrenet.fr [194.116.145.2])
	by svr1.postgresql.org (Postfix) with ESMTP id 03099D9A50
	for <pgsql-performance@postgresql.org>;
	Mon,  3 Oct 2005 12:14:20 -0300 (ADT)
Received: by floppy.pyrenet.fr (Postfix, from userid 106)
	id 0DF8431F51; Mon,  3 Oct 2005 17:14:18 +0200 (MET DST)
From: "jan.aerts@bbsrc.ac.uk" <jan.aerts@gmail.com>
X-Newsgroups: pgsql.performance
Subject: index on custom function; explain
Date: 3 Oct 2005 08:14:11 -0700
Organization: http://groups.google.com
Lines: 121
Message-ID: <1128352451.312090.37640@g44g2000cwa.googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
X-Complaints-To: groups-abuse@google.com
User-Agent: G2/0.2
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB;
	rv:1.7.8) Gecko/20050511 Firefox/1.0.4,gzip(gfe),gzip(gfe)
X-HTTP-Via: 1.1 arcl11.cc.bbsrc.ac.uk:8080 (squid/2.5.STABLE9)
Complaints-To: groups-abuse@google.com
Injection-Info: g44g2000cwa.googlegroups.com; posting-host=149.155.96.6;
	posting-account=Qght7Q0AAACFr4FK4UX3lLicX5ApbR8D
To: pgsql-performance@postgresql.org
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0 required=5 tests=[none]
X-Spam-Level: 
X-Archive-Number: 200510/74
X-Sequence-Number: 14842

Hi,

I'm trying to include a custom function in my SQL-queries, which
unfortunately leaves the server hanging...

I basically search through two tables:
* TABLE_MAPPING: lists that 'abc' is mapped to 'def'
  id1 | name1 | id2 | name2
  -------------------------
  1   | abc   | 2   | def
  3   | uvw   | 4   | xyz
This data means that 'abc' is mapped_to 'def', and 'uvw' is mapped_to
'xyz'. About 1,500,000 records in total.

* TABLE ALIASES: lists different aliases of the same thing
  id1 | name1 | id2 | name2
  -------------------------
  3   | uvw   | 2   | def
This data means that 'uvw' and 'def' are essentially the same thing.
About 820,000 records in total.

I have indexes on all columns of the above tables.

Based on the two tables above, 'abc' is indirectly mapped_to 'xyz' as
well (through 'def' also-known-as 'uvw').

I wrote this little function: aliases_of
CREATE FUNCTION aliases_of(INTEGER) RETURNS SETOF integer
AS 'SELECT $1
    UNION
    SELECT id1 FROM aliases WHERE id2 = $1
    UNION
    SELECT id2 FROM aliases WHERE id1 = $1
    '
LANGUAGE SQL
STABLE;

A simple SELECT aliases_of(2) shows:
  aliases_of
  ----------
  2
  3

Now, when I want to traverse the aliases, I would write a query as
follows:
SELECT m1.name1, m1.name2, m2.name1, m2.name2
FROM mappings m1, mappings m2
WHERE m1.name1 = 'abc'
AND m2.name1 IN (SELECT aliases_of(m1.name2));

Unfortunately, this query seems to keep running and to never stop...


An EXPLAIN of the above query shows:
QUERY PLAN
-----------------------------------------------------------------------------
 Nested Loop  (cost=0.00..118379.45 rows=1384837 width=80)
   Join Filter: (subplan)
   ->  Index Scan using ind_cmappings_object1_id on c_mappings m1
(cost=0.00..7.08 rows=2 width=40)
         Index Cond: (name1 = 'abc')
   ->  Seq Scan on c_mappings m2  (cost=0.00..35935.05 rows=1423805
width=40)
   SubPlan
     ->  Result  (cost=0.00..0.01 rows=1 width=0)
(7 rows)

Strangely enough, I _do_ get output when I type the following query:
SELECT m1.name1, m1.name2, m2.name1, m2.name2
FROM mappings m1, mappings m2
WHERE m1.name1 = 'abc'
AND m2.name1 IN (
  SELECT m1.name2
  UNION
  SELECT name2 FROM aliases WHERE name1 = m1.name2
  UNION
  SELECT name1 FROM aliases WHERE name2 = m2.name1
);

The EXPLAIN for this query is:
                                                       QUERY PLAN
-------------------------------------------------------------------------------
 Nested Loop  (cost=0.00..36712030.90 rows=1384837 width=80)
   Join Filter: (subplan)
   ->  Index Scan using ind_cmappings_object1_id on c_mappings m1
(cost=0.00..7.08 rows=2 width=40)
         Index Cond: (object1_id = 16575564)
   ->  Seq Scan on c_mappings m2  (cost=0.00..35935.05 rows=1423805
width=40)
   SubPlan
     ->  Unique  (cost=13.21..13.23 rows=1 width=4)
           ->  Sort  (cost=13.21..13.22 rows=3 width=4)
                 Sort Key: object2_id
                 ->  Append  (cost=0.00..13.18 rows=3 width=4)
                       ->  Subquery Scan "*SELECT* 1"  (cost=0.00..0.01
rows=1 width=0)
                             ->  Result  (cost=0.00..0.01 rows=1
width=0)
                       ->  Subquery Scan "*SELECT* 2"  (cost=0.00..5.92
rows=1 width=4)
                             ->  Index Scan using
ind_caliases_object2_id on c_aliases  (cost=0.00..5.92 rows=1 width=4)
                                   Index Cond: (object2_id = $0)
                       ->  Subquery Scan "*SELECT* 3"  (cost=0.00..7.25
rows=1 width=4)
                             ->  Index Scan using
ind_caliases_object1_id on c_aliases  (cost=0.00..7.25 rows=1 width=4)
                                   Index Cond: (object1_id = $0)
(18 rows)

So my questions are:
* Does anyone have any idea how I can integrate a function that lists
all aliases for a given name into such a mapping query?
* Does the STABLE keyword in the function definition make the function
to read all its data into memory?
* Is there a way to let postgres use an "Index scan" on that function
instead of a "seq scan"?

Any help very much appreciated,
Jan Aerts


From pgsql-performance-owner@postgresql.org  Mon Oct  3 12:48:05 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id AA376D83DE
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon,  3 Oct 2005 12:48:03 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 44871-06
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon,  3 Oct 2005 15:47:57 +0000 (GMT)
Received: from e5.ny.us.ibm.com (e5.ny.us.ibm.com [32.97.182.145])
	by svr1.postgresql.org (Postfix) with ESMTP id 5E052D7E1D
	for <pgsql-performance@postgresql.org>;
	Mon,  3 Oct 2005 12:47:56 -0300 (ADT)
Received: from d01relay02.pok.ibm.com (d01relay02.pok.ibm.com [9.56.227.234])
	by e5.ny.us.ibm.com (8.12.11/8.12.11) with ESMTP id j93FltVB023129
	for <pgsql-performance@postgresql.org>; Mon, 3 Oct 2005 11:47:55 -0400
Received: from d01av02.pok.ibm.com (d01av02.pok.ibm.com [9.56.224.216])
	by d01relay02.pok.ibm.com (8.12.10/NCO/VERS6.7) with ESMTP id
	j93FltVc091174
	for <pgsql-performance@postgresql.org>; Mon, 3 Oct 2005 11:47:55 -0400
Received: from d01av02.pok.ibm.com (loopback [127.0.0.1])
	by d01av02.pok.ibm.com (8.12.11/8.13.3) with ESMTP id j93FltIF013555
	for <pgsql-performance@postgresql.org>; Mon, 3 Oct 2005 11:47:55 -0400
Received: from d01ml255.pok.ibm.com (d01ml255.pok.ibm.com [9.56.227.128])
	by d01av02.pok.ibm.com (8.12.11/8.12.11) with ESMTP id j93FltlD013550
	for <pgsql-performance@postgresql.org>; Mon, 3 Oct 2005 11:47:55 -0400
Subject: Alternative to a temporary table
To: pgsql-performance@postgresql.org
X-Mailer: Lotus Notes Release 6.0.2CF1 June 9, 2003
Message-ID: 
 <OF771CB730.CDE13F6F-ON8525708F.0056A621-8525708F.0056C7BC@us.ibm.com>
From: Steven Rosenstein <srosenst@us.ibm.com>
Date: Mon, 3 Oct 2005 11:47:52 -0400
X-MIMETrack: Serialize by Router on D01ML255/01/M/IBM(Release 6.53HF103 |
	November 15, 2004) at 10/03/2005 11:47:54
MIME-Version: 1.0
Content-type: text/plain; charset=US-ASCII
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.306 required=5 tests=[AWL=-0.068,
	DNS_FROM_RFC_ABUSE=0.374]
X-Spam-Level: 
X-Archive-Number: 200510/16
X-Sequence-Number: 14784





I have a PHP web-based application where a temporary list of servers and
their characteristics (each represented by a unique numeric server_id) is
extracted from a master server list based on a number of dynamic and
user-selected criteria (can the user view the server, is it on-line, is it
a member of a specific group, etc).  Once the user selects the set of
criteria (and servers), it rarely change during the rest of the browser
session.  The resulting temporary list of servers is then joined against
other tables with different sets of information about each of the servers,
based on the server_id.

I currently create a temporary table to hold the selected server_id's and
characteristics.  I then join this temp table with other data tables to
produce my reports.  My reason for using the temporary table method is that
the SQL for the initial server selection is dynamically created based on
the user's selections, and is complex enough that it does not lend itself
to being easily incorporated into any of the other data extraction queries
(which may also contain dynamic filtering).

Unfortunately, the PHP connection to the database does not survive from
webscreen to webscreen, so I have to re-generate the temporary server_id
table each time it is needed for a report screen.  An idea I had to make
this process more efficient was instead of re-creating the temporary table
over and over each time it is needed, do a one-time extraction of the list
of user-selected server_id's, store the list in a PHP global variable, and
then use the list in a dynamically-created WHERE clause in the rest of the
queries.  The resulting query would look something like

     SELECT *
     FROM some_data_table
     WHERE server_id IN (sid1,sid5,sid6,sid17,sid24...)

Simple enough, however in rare cases the list of server_id's can range
between 6,000 and 10,000.

My question to the group is, can having so many values in a WHERE/IN clause
effect query performance?  Am I being naive about this and is there a
different, better way?  The server_id field is of course indexed, but it is
possible that the list of selected sid's can contain almost all of the
values in the some_data_table server_id index (in the situation where _all_
of the records are requested I wouldn't use the WHERE clause in the query).
The some_data_table can contain millions of records for thousands of
servers, so every bit of efficiency helps.

If this is not the proper group for this kind of question, please point me
in the right direction.

Thanks!
--- Steve
___________________________________________________________________________________

Steven Rosenstein
IT Architect/Developer | IBM Virtual Server Administration
Voice/FAX: 845-689-2064 | Cell: 646-345-6978 | Tieline: 930-6001
Text Messaging: 6463456978 @ mobile.mycingular.com
Email: srosenst @ us.ibm.com

"Learn from the mistakes of others because you can't live long enough to
make them all yourself." -- Eleanor Roosevelt


From pgsql-performance-owner@postgresql.org  Mon Oct  3 13:23:19 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 509D6D9E60
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon,  3 Oct 2005 13:22:45 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 56689-10
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon,  3 Oct 2005 16:22:43 +0000 (GMT)
Received: from gp.word-to-the-wise.com (gp.word-to-the-wise.com
 [64.71.176.18])
	by svr1.postgresql.org (Postfix) with ESMTP id 86F1FD9E5F
	for <pgsql-performance@postgresql.org>;
	Mon,  3 Oct 2005 13:22:42 -0300 (ADT)
Received: by gp.word-to-the-wise.com (Postfix, from userid 500)
	id 1BA4C8FC07D; Mon,  3 Oct 2005 09:20:10 -0700 (PDT)
Date: Mon, 3 Oct 2005 09:20:10 -0700
From: Steve Atkins <steve@blighty.com>
To: pgsql-performance@postgresql.org
Subject: Re: Alternative to a temporary table
Message-ID: <20051003162010.GB4839@gp.word-to-the-wise.com>
References: 
 <OF771CB730.CDE13F6F-ON8525708F.0056A621-8525708F.0056C7BC@us.ibm.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: 
 <OF771CB730.CDE13F6F-ON8525708F.0056A621-8525708F.0056C7BC@us.ibm.com>
User-Agent: Mutt/1.4.1i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.886 required=5 tests=[AWL=-0.490,
	DNS_FROM_RFC_POST=1.376]
X-Spam-Level: 
X-Archive-Number: 200510/17
X-Sequence-Number: 14785

On Mon, Oct 03, 2005 at 11:47:52AM -0400, Steven Rosenstein wrote:

> I currently create a temporary table to hold the selected server_id's and
> characteristics.  I then join this temp table with other data tables to
> produce my reports.  My reason for using the temporary table method is that
> the SQL for the initial server selection is dynamically created based on
> the user's selections, and is complex enough that it does not lend itself
> to being easily incorporated into any of the other data extraction queries
> (which may also contain dynamic filtering).
> 
> Unfortunately, the PHP connection to the database does not survive from
> webscreen to webscreen, so I have to re-generate the temporary server_id
> table each time it is needed for a report screen.  An idea I had to make
> this process more efficient was instead of re-creating the temporary table
> over and over each time it is needed, do a one-time extraction of the list
> of user-selected server_id's, store the list in a PHP global variable, and
> then use the list in a dynamically-created WHERE clause in the rest of the
> queries.  The resulting query would look something like
> 
>      SELECT *
>      FROM some_data_table
>      WHERE server_id IN (sid1,sid5,sid6,sid17,sid24...)
> 
> Simple enough, however in rare cases the list of server_id's can range
> between 6,000 and 10,000.
> 
> My question to the group is, can having so many values in a WHERE/IN clause
> effect query performance? 

Probably, yes. As always, benchmark a test case, but last time I
checked (in 7.4) you'd be better creating a new temporary table for
every query than use an IN list that long. It's a lot better in 8.0, I
believe, so you should benchmark it there.

> Am I being naive about this and is there a
> different, better way?  The server_id field is of course indexed, but it is
> possible that the list of selected sid's can contain almost all of the
> values in the some_data_table server_id index (in the situation where _all_
> of the records are requested I wouldn't use the WHERE clause in the query).
> The some_data_table can contain millions of records for thousands of
> servers, so every bit of efficiency helps.

Don't use a temporary table. Instead use a permanent table that
contains the server ids you need and the PHP session token. Then you
can create your list of server_ids once and insert it into that table
associated with your sessionid. Then future queries can be simple
joins against that table.

    SELECT some_data_table.*
    FROM some_data_table, session_table
    WHERE some_data_table.server_id = session_table.server_id
      AND session_table.session_id = 'foobar'

You'd need a reaper process to delete old data from that table to
prevent it from growing without limit, and probably a table associating
session start time with sessionid to make reaping easier.

Cheers,
  Steve

From pgsql-performance-owner@postgresql.org  Mon Oct  3 14:15:14 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 09CC5D9E6D
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon,  3 Oct 2005 14:15:13 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 72136-04
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon,  3 Oct 2005 17:15:10 +0000 (GMT)
Received: from crestone.coronasolutions.com (crestone.coronasolutions.com
	[66.45.104.24])
	by svr1.postgresql.org (Postfix) with ESMTP id 34925D9A9F
	for <pgsql-performance@postgresql.org>;
	Mon,  3 Oct 2005 14:15:09 -0300 (ADT)
Received: from localhost (localhost.localdomain [127.0.0.1])
	by crestone.coronasolutions.com (Postfix) with ESMTP id 370BA64415A
	for <pgsql-performance@postgresql.org>;
	Mon,  3 Oct 2005 11:15:07 -0600 (MDT)
Received: from crestone.coronasolutions.com ([127.0.0.1])
	by localhost (crestone.coronasolutions.com [127.0.0.1]) (amavisd-new,
	port 10024)
	with ESMTP id 16376-04 for <pgsql-performance@postgresql.org>;
	Mon, 3 Oct 2005 11:15:03 -0600 (MDT)
Received: from [192.168.1.2] (c-67-165-220-189.hsd1.co.comcast.net
	[67.165.220.189]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
	(No client certificate requested)
	by crestone.coronasolutions.com (Postfix) with ESMTP id CAF0E644146
	for <pgsql-performance@postgresql.org>;
	Mon,  3 Oct 2005 11:15:03 -0600 (MDT)
Mime-Version: 1.0 (Apple Message framework v734)
In-Reply-To: <20051003110226.GA26883@uio.no>
References: <20051003110226.GA26883@uio.no>
Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed
Message-Id: <D996B9B6-ADB1-4D38-B832-49D0C11DF0B4@drivefaster.net>
Content-Transfer-Encoding: 7bit
From: Dan Harris <fbsd@drivefaster.net>
Subject: Re: Ultra-cheap NVRAM device
Date: Mon, 3 Oct 2005 11:15:03 -0600
To: pgsql-performance@postgresql.org
X-Mailer: Apple Mail (2.734)
X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at drivefaster.net
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0 required=5 tests=[none]
X-Spam-Level: 
X-Archive-Number: 200510/18
X-Sequence-Number: 14786


On Oct 3, 2005, at 5:02 AM, Steinar H. Gunderson wrote:

> I thought this might be interesting, not the least due to the  
> extremely low
> price ($150 + the price of regular DIMMs):
>
>
>

This has been posted before, and the main reason nobody got very  
excited is that:

a) it only uses the PCI bus to provide power to the device, not for I/O
b) It is limited to SATA bandwidth
c) The benchmarks did not prove it to be noticeably faster than a  
good single SATA drive

A few of us were really excited at first too, until seeing the  
benchmarks..

-Dan



From pgsql-performance-owner@postgresql.org  Mon Oct  3 14:21:39 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id BD7B3D9A20
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon,  3 Oct 2005 14:21:37 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 72061-06
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon,  3 Oct 2005 17:21:33 +0000 (GMT)
Received: from crestone.coronasolutions.com (crestone.coronasolutions.com
	[66.45.104.24])
	by svr1.postgresql.org (Postfix) with ESMTP id 229D9D94F8
	for <pgsql-performance@postgresql.org>;
	Mon,  3 Oct 2005 14:21:34 -0300 (ADT)
Received: from localhost (localhost.localdomain [127.0.0.1])
	by crestone.coronasolutions.com (Postfix) with ESMTP id B1704644146
	for <pgsql-performance@postgresql.org>;
	Mon,  3 Oct 2005 11:21:34 -0600 (MDT)
Received: from crestone.coronasolutions.com ([127.0.0.1])
	by localhost (crestone.coronasolutions.com [127.0.0.1]) (amavisd-new,
	port 10024)
	with ESMTP id 16476-10 for <pgsql-performance@postgresql.org>;
	Mon, 3 Oct 2005 11:21:32 -0600 (MDT)
Received: from [192.168.1.2] (c-67-165-220-189.hsd1.co.comcast.net
	[67.165.220.189]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
	(No client certificate requested)
	by crestone.coronasolutions.com (Postfix) with ESMTP id AA876644107
	for <pgsql-performance@postgresql.org>;
	Mon,  3 Oct 2005 11:21:32 -0600 (MDT)
Mime-Version: 1.0 (Apple Message framework v734)
In-Reply-To: <20051003110226.GA26883@uio.no>
References: <20051003110226.GA26883@uio.no>
Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed
Message-Id: <08A56EA3-94AD-4F44-88B3-FF8A7EC56B2B@drivefaster.net>
Content-Transfer-Encoding: 7bit
From: Dan Harris <fbsd@drivefaster.net>
Subject: Re: Ultra-cheap NVRAM device
Date: Mon, 3 Oct 2005 11:21:30 -0600
To: pgsql-performance@postgresql.org
X-Mailer: Apple Mail (2.734)
X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at drivefaster.net
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0 required=5 tests=[none]
X-Spam-Level: 
X-Archive-Number: 200510/19
X-Sequence-Number: 14787


On Oct 3, 2005, at 5:02 AM, Steinar H. Gunderson wrote:

> I thought this might be interesting, not the least due to the  
> extremely low
> price ($150 + the price of regular DIMMs):
>
>

Replying before my other post came through.. It looks like their  
benchmarks are markedly improved since the last article I read on  
this.  There may be more interest now..

-Dan


From pgsql-performance-owner@postgresql.org  Mon Oct  3 14:36:20 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id A3759D99F6
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon,  3 Oct 2005 14:36:19 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 79621-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon,  3 Oct 2005 17:36:17 +0000 (GMT)
Received: from gghcwest.com (adsl-71-128-90-172.dsl.pltn13.pacbell.net
	[71.128.90.172])
	by svr1.postgresql.org (Postfix) with ESMTP id 2DD09D94F8
	for <pgsql-performance@postgresql.org>;
	Mon,  3 Oct 2005 14:36:14 -0300 (ADT)
Received: from toonses.gghcwest.com (toonses.gghcwest.com [192.168.168.115])
	by gghcwest.com (8.12.10/8.12.9) with ESMTP id j93HaAmd027481
	for <pgsql-performance@postgresql.org>; Mon, 3 Oct 2005 10:36:11 -0700
Received: from jwb by toonses.gghcwest.com with local (Exim 4.52)
	id 1EMUEV-0007Fk-H8
	for pgsql-performance@postgresql.org; Mon, 03 Oct 2005 10:36:11 -0700
Subject: Re: Ultra-cheap NVRAM device
From: "Jeffrey W. Baker" <jwbaker@acm.org>
To: pgsql-performance@postgresql.org
In-Reply-To: <D996B9B6-ADB1-4D38-B832-49D0C11DF0B4@drivefaster.net>
References: <20051003110226.GA26883@uio.no>
	<D996B9B6-ADB1-4D38-B832-49D0C11DF0B4@drivefaster.net>
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Date: Mon, 03 Oct 2005 10:36:11 -0700
Message-Id: <1128360971.27580.2.camel@toonses.gghcwest.com>
Mime-Version: 1.0
X-Mailer: Evolution 2.4.0 
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=-0.459 required=5 tests=[AWL=-0.509,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/20
X-Sequence-Number: 14788

On Mon, 2005-10-03 at 11:15 -0600, Dan Harris wrote:
> On Oct 3, 2005, at 5:02 AM, Steinar H. Gunderson wrote:
> 
> > I thought this might be interesting, not the least due to the  
> > extremely low
> > price ($150 + the price of regular DIMMs):
> >
> >
> >
> 
> This has been posted before, and the main reason nobody got very  
> excited is that:
> 
> a) it only uses the PCI bus to provide power to the device, not for I/O
> b) It is limited to SATA bandwidth
> c) The benchmarks did not prove it to be noticeably faster than a  
> good single SATA drive
> 
> A few of us were really excited at first too, until seeing the  
> benchmarks..

Also, no ECC support.  You'd be crazy to use it for anything.

-jwb

From pgsql-performance-owner@postgresql.org  Mon Oct  3 15:01:16 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id B3B9ED9E1C
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon,  3 Oct 2005 15:01:14 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 82654-04
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon,  3 Oct 2005 18:01:12 +0000 (GMT)
Received: from pop-altamira.atl.sa.earthlink.net
	(pop-altamira.atl.sa.earthlink.net [207.69.195.62])
	by svr1.postgresql.org (Postfix) with ESMTP id 8B79ED9E19
	for <pgsql-performance@postgresql.org>;
	Mon,  3 Oct 2005 15:01:11 -0300 (ADT)
Received: from elwamui-polski.atl.sa.earthlink.net ([209.86.224.45])
	by pop-altamira.atl.sa.earthlink.net with esmtp (Exim 3.36 #10)
	id 1EMUbl-0006zF-00; Mon, 03 Oct 2005 14:00:13 -0400
Message-ID: 
 <30603906.1128362413580.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
Date: Mon, 3 Oct 2005 14:00:13 -0400 (EDT)
From: Ron Peacetree <rjpeace@earthlink.net>
Reply-To: Ron Peacetree <rjpeace@earthlink.net>
To: Dan Harris <fbsd@drivefaster.net>,
	pgsql-performance@postgresql.org
Subject: Re: Ultra-cheap NVRAM device
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: Earthlink Zoo Mail 1.0
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.256 required=5 tests=[AWL=-0.118,
	DNS_FROM_RFC_ABUSE=0.374]
X-Spam-Level: 
X-Archive-Number: 200510/21
X-Sequence-Number: 14789

Nah.  It's still not right.  It needs:
1= full PCI, preferably at least 64b 133MHz PCI-X, bandwidth.
A RAM card should blow the doors off the fastest commodity
RAID setup you can build.
2= 8-16 DIMM slots
3= a standard battery type that I can pick up spares for easily
4= ECC support

If it had all those features, I'd buy it at even 2x or possibly
even 3x it's current price.

8, 16, or 32GB (using 1, 2, or 4GB DIMMs respectively in an 8 slot
form factor) of very fast temporary work memory (sorting
 anyone ;-) ).  Yum.

Ron

-----Original Message-----
From: Dan Harris <fbsd@drivefaster.net>
Sent: Oct 3, 2005 1:21 PM
To: pgsql-performance@postgresql.org
Subject: Re: [PERFORM] Ultra-cheap NVRAM device


On Oct 3, 2005, at 5:02 AM, Steinar H. Gunderson wrote:

> I thought this might be interesting, not the least due to the  
> extremely low
> price ($150 + the price of regular DIMMs):
>
>

Replying before my other post came through.. It looks like their  
benchmarks are markedly improved since the last article I read on  
this.  There may be more interest now..

-Dan


---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend


From pgsql-performance-owner@postgresql.org  Mon Oct  3 16:06:22 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 3D187D94F8
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon,  3 Oct 2005 16:06:20 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 50681-04
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon,  3 Oct 2005 19:06:17 +0000 (GMT)
Received: from yertle.kcilink.com (yertle.kcilink.com [65.205.34.180])
	by svr1.postgresql.org (Postfix) with ESMTP id 8CD6AD7E1D
	for <pgsql-performance@postgresql.org>;
	Mon,  3 Oct 2005 16:06:16 -0300 (ADT)
Received: from [192.168.7.103] (host-103.int.kcilink.com [192.168.7.103])
	by yertle.kcilink.com (Postfix) with ESMTP id 275F4B814
	for <pgsql-performance@postgresql.org>;
	Mon,  3 Oct 2005 15:06:16 -0400 (EDT)
Mime-Version: 1.0 (Apple Message framework v734)
In-Reply-To: <20051003110226.GA26883@uio.no>
References: <20051003110226.GA26883@uio.no>
Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed
Message-Id: <DAA747F6-20F7-4187-8EE4-70447F5A268A@khera.org>
Content-Transfer-Encoding: 7bit
From: Vivek Khera <vivek@khera.org>
Subject: Re: Ultra-cheap NVRAM device
Date: Mon, 3 Oct 2005 15:06:15 -0400
To: Postgresql Performance <pgsql-performance@postgresql.org>
X-Mailer: Apple Mail (2.734)
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.031 required=5 tests=[AWL=0.031]
X-Spam-Level: 
X-Archive-Number: 200510/22
X-Sequence-Number: 14790

On Oct 3, 2005, at 7:02 AM, Steinar H. Gunderson wrote:

> Anybody know a good reason why you can't put a WAL on this, and  
> enjoy a hefty
> speed boost for a fraction of the price of a traditional SSD? (Yes,  
> it's
> SATA, not PCI, so the throughput is not all that impressive -- but  
> still,
> it's got close to zero seek time.)
>

old news.  discussed here a while back.

the board you see has no ECC.  Would you trust > 1GB RAM to not have  
ECC for more than 1 month?  You're almost guaranteed at least 1 bit  
error.


From pgsql-performance-owner@postgresql.org  Mon Oct  3 17:31:40 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 47759D9F15;
	Mon,  3 Oct 2005 17:30:14 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 27426-06; Mon,  3 Oct 2005 20:30:09 +0000 (GMT)
Received: from davinci.ethosmedia.com (server227.ethosmedia.com
	[209.128.84.227])
	by svr1.postgresql.org (Postfix) with ESMTP id 14128D9F0B;
	Mon,  3 Oct 2005 17:30:09 -0300 (ADT)
X-EthosMedia-Virus-Scanned: no infections found
Received: from [64.81.245.111] (account josh@agliodbs.com HELO
	temoku.sf.agliodbs.com)
	by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.1.8)
	with ESMTP id 8192091; Mon, 03 Oct 2005 13:32:35 -0700
From: Josh Berkus <josh@agliodbs.com>
Reply-To: josh@agliodbs.com
Organization: Aglio Database Solutions
To: pgsql-hackers@postgresql.org
Subject: Re: [HACKERS] A Better External Sort?
Date: Mon, 3 Oct 2005 13:34:01 -0700
User-Agent: KMail/1.8
Cc: Michael Stone <mstone+postgres@mathom.us>,
 pgsql-performance@postgresql.org
References: 
 <31833713.1128111650174.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
	<200509301341.22795.josh@agliodbs.com>
	<20050930231032.GQ2241@mathom.us>
In-Reply-To: <20050930231032.GQ2241@mathom.us>
MIME-Version: 1.0
Content-Type: text/plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Message-Id: <200510031334.02030.josh@agliodbs.com>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.046 required=5 tests=[AWL=-0.004,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/24
X-Sequence-Number: 14792

Michael,

> >Realistically, you can't do better than about 25MB/s on a
> > single-threaded I/O on current Linux machines,
>
> What on earth gives you that idea? Did you drop a zero?

Nope, LOTS of testing, at OSDL, GreenPlum and Sun.   For comparison, A 
Big-Name Proprietary Database doesn't get much more than that either.

-- 
--Josh

Josh Berkus
Aglio Database Solutions
San Francisco

From pgsql-performance-owner@postgresql.org  Mon Oct  3 17:39:44 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 87945D9E27;
	Mon,  3 Oct 2005 17:36:38 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 30440-01; Mon,  3 Oct 2005 20:36:35 +0000 (GMT)
Received: from davinci.ethosmedia.com (server227.ethosmedia.com
	[209.128.84.227])
	by svr1.postgresql.org (Postfix) with ESMTP id CB23BD9E0E;
	Mon,  3 Oct 2005 17:36:36 -0300 (ADT)
X-EthosMedia-Virus-Scanned: no infections found
Received: from [64.81.245.111] (account josh@agliodbs.com HELO
	temoku.sf.agliodbs.com)
	by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.1.8)
	with ESMTP id 8192127; Mon, 03 Oct 2005 13:39:02 -0700
From: Josh Berkus <josh@agliodbs.com>
Reply-To: josh@agliodbs.com
Organization: Aglio Database Solutions
To: Tom Lane <tgl@sss.pgh.pa.us>
Subject: Re: [HACKERS] A Better External Sort?
Date: Mon, 3 Oct 2005 13:40:29 -0700
User-Agent: KMail/1.8
Cc: "Jeffrey W. Baker" <jwbaker@acm.org>,
	Ron Peacetree <rjpeace@earthlink.net>, pgsql-hackers@postgresql.org,
	pgsql-performance@postgresql.org
References: 
 <21402654.1127923414088.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
	<433C1C2D.7090908@agliodbs.com> <8643.1128181455@sss.pgh.pa.us>
In-Reply-To: <8643.1128181455@sss.pgh.pa.us>
MIME-Version: 1.0
Content-Type: text/plain;
  charset="utf-8"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Message-Id: <200510031340.29376.josh@agliodbs.com>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.046 required=5 tests=[AWL=-0.004,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/25
X-Sequence-Number: 14793

Tom,

> Raising work_mem to a gig should result in about five runs, needing only
> one pass, which is really going to be as good as it gets.  If you could
> not see any difference then I see little hope for the idea that reducing
> the number of merge passes will help.

Right.  It *should have*, but didn't seem to.    Example of a simple sort 
test of 100 million random-number records

1M   3294 seconds
  16M   1107 seconds
  256M   1209 seconds
  512M   1174 seconds
  512M with 'not null' for column that is indexed  1168 seconds

> Umm ... you were raising maintenance_work_mem, I trust, not work_mem?

Yes.

>
> We really need to get some hard data about what's going on here.  The
> sort code doesn't report any internal statistics at the moment, but it
> would not be hard to whack together a patch that reports useful info
> in the form of NOTICE messages or some such.

Yeah, I'll do this as soon as the patch is finished.   Always useful to 
gear up the old TPC-H.

-- 
--Josh

Josh Berkus
Aglio Database Solutions
San Francisco

From pgsql-performance-owner@postgresql.org  Mon Oct  3 17:43:42 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 78C94D9EB0;
	Mon,  3 Oct 2005 17:42:41 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 29216-06; Mon,  3 Oct 2005 20:42:37 +0000 (GMT)
Received: from gghcwest.com (adsl-71-128-90-172.dsl.pltn13.pacbell.net
	[71.128.90.172])
	by svr1.postgresql.org (Postfix) with ESMTP id 2D7DDD9EB3;
	Mon,  3 Oct 2005 17:42:37 -0300 (ADT)
Received: from toonses.gghcwest.com (toonses.gghcwest.com [192.168.168.115])
	by gghcwest.com (8.12.10/8.12.9) with ESMTP id j93KgUmd027368;
	Mon, 3 Oct 2005 13:42:31 -0700
Received: from jwb by toonses.gghcwest.com with local (Exim 4.52)
	id 1EMX8q-0007Vv-5b; Mon, 03 Oct 2005 13:42:32 -0700
Subject: Re: [HACKERS] A Better External Sort?
From: "Jeffrey W. Baker" <jwbaker@acm.org>
To: josh@agliodbs.com
Cc: pgsql-hackers@postgresql.org, Michael Stone <mstone+postgres@mathom.us>,
	pgsql-performance@postgresql.org
In-Reply-To: <200510031334.02030.josh@agliodbs.com>
References: 
 <31833713.1128111650174.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
	<200509301341.22795.josh@agliodbs.com>
	<20050930231032.GQ2241@mathom.us>
	<200510031334.02030.josh@agliodbs.com>
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Date: Mon, 03 Oct 2005 13:42:31 -0700
Message-Id: <1128372151.28509.1.camel@toonses.gghcwest.com>
Mime-Version: 1.0
X-Mailer: Evolution 2.4.0 
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=-0.415 required=5 tests=[AWL=-0.465,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/26
X-Sequence-Number: 14794

On Mon, 2005-10-03 at 13:34 -0700, Josh Berkus wrote:
> Michael,
> 
> > >Realistically, you can't do better than about 25MB/s on a
> > > single-threaded I/O on current Linux machines,
> >
> > What on earth gives you that idea? Did you drop a zero?
> 
> Nope, LOTS of testing, at OSDL, GreenPlum and Sun.   For comparison, A 
> Big-Name Proprietary Database doesn't get much more than that either.

I find this claim very suspicious.  I get single-threaded reads in
excess of 1GB/sec with XFS and > 250MB/sec with ext3.  

-jwb

From pgsql-performance-owner@postgresql.org  Mon Oct  3 18:14:58 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 39169D9EEB;
	Mon,  3 Oct 2005 18:14:55 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 34956-06; Mon,  3 Oct 2005 21:14:50 +0000 (GMT)
Received: from davinci.ethosmedia.com (server227.ethosmedia.com
	[209.128.84.227])
	by svr1.postgresql.org (Postfix) with ESMTP id 0D5ACD9AA1;
	Mon,  3 Oct 2005 18:14:51 -0300 (ADT)
X-EthosMedia-Virus-Scanned: no infections found
Received: from [63.195.55.98] (account josh@agliodbs.com HELO spooky)
	by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.1.8)
	with ESMTP id 8192379; Mon, 03 Oct 2005 14:17:17 -0700
From: Josh Berkus <josh@agliodbs.com>
Organization: Aglio Database Solutions
To: "Jeffrey W. Baker" <jwbaker@acm.org>
Subject: Re: [HACKERS] A Better External Sort?
Date: Mon, 3 Oct 2005 14:16:15 -0700
User-Agent: KMail/1.8
Cc: pgsql-hackers@postgresql.org, Michael Stone <mstone+postgres@mathom.us>,
	pgsql-performance@postgresql.org
References: 
 <31833713.1128111650174.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
	<200510031334.02030.josh@agliodbs.com>
	<1128372151.28509.1.camel@toonses.gghcwest.com>
In-Reply-To: <1128372151.28509.1.camel@toonses.gghcwest.com>
MIME-Version: 1.0
Content-Type: text/plain;
  charset="utf-8"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Message-Id: <200510031416.15620.josh@agliodbs.com>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.011 required=5 tests=[AWL=0.011]
X-Spam-Level: 
X-Archive-Number: 200510/27
X-Sequence-Number: 14795

Jeff,

> > Nope, LOTS of testing, at OSDL, GreenPlum and Sun.   For comparison, A
> > Big-Name Proprietary Database doesn't get much more than that either.
>
> I find this claim very suspicious.  I get single-threaded reads in
> excess of 1GB/sec with XFS and > 250MB/sec with ext3.

Database reads?  Or raw FS reads?  It's not the same thing.

Also, we're talking *write speed* here, not read speed.

I also find *your* claim suspicious, since there's no way XFS is 300% faster 
than ext3 for the *general* case.

-- 
Josh Berkus
Aglio Database Solutions
San Francisco

From pgsql-performance-owner@postgresql.org  Mon Oct  3 18:19:44 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 58EBBD9EC2;
	Mon,  3 Oct 2005 18:18:47 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 35013-08; Mon,  3 Oct 2005 21:18:44 +0000 (GMT)
Received: from pop-altamira.atl.sa.earthlink.net
	(pop-altamira.atl.sa.earthlink.net [207.69.195.62])
	by svr1.postgresql.org (Postfix) with ESMTP id 509E6D9ED8;
	Mon,  3 Oct 2005 18:18:44 -0300 (ADT)
Received: from elwamui-polski.atl.sa.earthlink.net ([209.86.224.45])
	by pop-altamira.atl.sa.earthlink.net with esmtp (Exim 3.36 #10)
	id 1EMXht-0005Pr-00; Mon, 03 Oct 2005 17:18:45 -0400
Message-ID: 
 <7911802.1128374325231.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
Date: Mon, 3 Oct 2005 17:18:45 -0400 (EDT)
From: Ron Peacetree <rjpeace@earthlink.net>
Reply-To: Ron Peacetree <rjpeace@earthlink.net>
To: "Jeffrey W. Baker" <jwbaker@acm.org>,
	pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org
Subject: Re: [HACKERS] A Better External Sort?
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: Earthlink Zoo Mail 1.0
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.257 required=5 tests=[AWL=-0.117,
	DNS_FROM_RFC_ABUSE=0.374]
X-Spam-Level: 
X-Archive-Number: 200510/28
X-Sequence-Number: 14796

Jeff, are those _burst_ rates from HD buffer or _sustained_ rates from
actual HD media?  Rates from IO subsystem buffer or cache are
usually considerably higher than Average Sustained Transfer Rate.

Also, are you measuring _raw_ HD IO (bits straight off the platters, no
FS or other overhead) or _cooked_ HD IO (actual FS or pg IO)?

BTW, it would seem Useful to measure all of raw HD IO, FS HD IO,
and pg HD IO as this would give us an idea of just how much overhead
each layer is imposing on the process.

We may be able to get better IO than we currently are for things like
sorts by the simple expedient of making sure we read enough data per
seek.

For instance, a HD with a 12ms average access time and a ASTR of
50MBps should always read _at least_ 600KB/access or it is impossible
for it to achieve it's rated ASTR.

This number will vary according to the average access time and the
ASTR of your physical IO subsystem, but the concept is valid for _any_
physical IO subsystem.
 

-----Original Message-----
From: "Jeffrey W. Baker" <jwbaker@acm.org>
Sent: Oct 3, 2005 4:42 PM
To: josh@agliodbs.com
Cc: 
Subject: Re: [HACKERS] [PERFORM] A Better External Sort?

On Mon, 2005-10-03 at 13:34 -0700, Josh Berkus wrote:
> Michael,
> 
> > >Realistically, you can't do better than about 25MB/s on a
> > > single-threaded I/O on current Linux machines,
> >
> > What on earth gives you that idea? Did you drop a zero?
> 
> Nope, LOTS of testing, at OSDL, GreenPlum and Sun.   For comparison, A 
> Big-Name Proprietary Database doesn't get much more than that either.

I find this claim very suspicious.  I get single-threaded reads in
excess of 1GB/sec with XFS and > 250MB/sec with ext3.  

-jwb

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faq


From pgsql-performance-owner@postgresql.org  Mon Oct  3 18:28:49 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 6BA56D9AF1;
	Mon,  3 Oct 2005 18:28:38 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 38967-08; Mon,  3 Oct 2005 21:28:33 +0000 (GMT)
Received: from mail.Mi8.com (d01gw01.mi8.com [63.240.6.47])
	by svr1.postgresql.org (Postfix) with ESMTP id 9F2E4D9A9F;
	Mon,  3 Oct 2005 18:28:31 -0300 (ADT)
Received: from 172.16.1.118 by mail.Mi8.com with ESMTP (- Welcome to Mi8
	Corporation www.Mi8.com (D1)); Mon, 03 Oct 2005 17:28:12 -0400
X-Server-Uuid: 241911D6-425B-44B9-A073-E3FE0F8FC774
Received: from MI8NYCMAIL06.Mi8.com ([172.16.1.175]) by
	d01smtp03.Mi8.com with Microsoft SMTPSVC(6.0.3790.1830); Mon, 3 Oct
	2005 17:28:12 -0400
Received: from 67.103.45.218 ([67.103.45.218]) by MI8NYCMAIL06.Mi8.com (
	[172.16.1.219]) via Exchange Front-End Server mi8owa.mi8.com (
	[172.16.1.104]) with Microsoft Exchange Server HTTP-DAV ; Mon, 3 Oct
	2005 17:28:12 -0500
User-Agent: Microsoft-Entourage/11.2.0.050811
Date: Mon, 03 Oct 2005 14:28:12 -0700
Subject: Re: [HACKERS] A Better External Sort?
From: "Luke Lonergan" <llonergan@greenplum.com>
To: "Josh Berkus" <josh@agliodbs.com>,
	"Jeffrey W. Baker" <jwbaker@acm.org>
Cc: pgsql-hackers@postgresql.org, "Michael Stone" <mstone+postgres@mathom.us>,
	pgsql-performance@postgresql.org
Message-ID: <BF66F07C.10892%llonergan@greenplum.com>
Thread-Topic: [HACKERS] [PERFORM] A Better External Sort?
Thread-Index: AcXIYVtamc5sWDRUEdq40gANk63kWA==
In-Reply-To: <200510031416.15620.josh@agliodbs.com>
MIME-Version: 1.0
X-OriginalArrivalTime: 03 Oct 2005 21:28:12.0590 (UTC)
	FILETIME=[5BB504E0:01C5C861]
X-WSS-ID: 6F5F7DE64JK160780-01-01
Content-Type: text/plain;
 charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=1.574 required=5 tests=[AWL=-0.007,
	FORGED_RCVD_HELO=0.05, RCVD_NUMERIC_HELO=1.531]
X-Spam-Level: *
X-Archive-Number: 200510/29
X-Sequence-Number: 14797

Jeff, Josh,

On 10/3/05 2:16 PM, "Josh Berkus" <josh@agliodbs.com> wrote:

> Jeff,
> 
>>> Nope, LOTS of testing, at OSDL, GreenPlum and Sun.   For comparison, A
>>> Big-Name Proprietary Database doesn't get much more than that either.
>> 
>> I find this claim very suspicious.  I get single-threaded reads in
>> excess of 1GB/sec with XFS and > 250MB/sec with ext3.
> 
> Database reads?  Or raw FS reads?  It's not the same thing.
> 
> Also, we're talking *write speed* here, not read speed.

I think you are both talking past each other here.  I'll state what I
*think* each of you are saying:

Josh: single threaded DB writes are limited to 25MB/s

My opinion: Not if they're done better than they are now in PostgreSQL.
PostgreSQL COPY is still CPU limited at 12MB/s on a super fast Opteron.  The
combination of WAL and head writes while this is the case is about 50MB/s,
which is far from the limit of the filesystems we test on that routinely
perform at 250MB/s on ext2 writing in sequential 8k blocks.

There is no reason that we couldn't do triple the current COPY speed by
reducing the CPU overhead in parsing and attribute conversion.  We've talked
this to death, and implemented much of the code to fix it, but there's much
more to do.

Jeff: Plenty of FS bandwidth to be had on Linux, observed 250MB/s on ext3
and 1,000MB/s on XFS.

Wow - can you provide a link or the results from the XFS test?  Is this 8k
blocksize sequential I/O?  How many spindles and what controller are you
using?  Inquiring minds want to know...

- Luke 



From pgsql-performance-owner@postgresql.org  Mon Oct  3 18:32:41 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 70494D9ED2;
	Mon,  3 Oct 2005 18:32:38 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 42938-04; Mon,  3 Oct 2005 21:32:30 +0000 (GMT)
Received: from gghcwest.com (adsl-71-128-90-172.dsl.pltn13.pacbell.net
	[71.128.90.172])
	by svr1.postgresql.org (Postfix) with ESMTP id 96D45D9ED1;
	Mon,  3 Oct 2005 18:32:30 -0300 (ADT)
Received: from toonses.gghcwest.com (toonses.gghcwest.com [192.168.168.115])
	by gghcwest.com (8.12.10/8.12.9) with ESMTP id j93LWOmd013894;
	Mon, 3 Oct 2005 14:32:25 -0700
Received: from jwb by toonses.gghcwest.com with local (Exim 4.52)
	id 1EMXv8-0007Zr-Rm; Mon, 03 Oct 2005 14:32:26 -0700
Subject: Re: [HACKERS] A Better External Sort?
From: "Jeffrey W. Baker" <jwbaker@acm.org>
To: Josh Berkus <josh@agliodbs.com>
Cc: pgsql-hackers@postgresql.org, Michael Stone <mstone+postgres@mathom.us>,
	pgsql-performance@postgresql.org
In-Reply-To: <200510031416.15620.josh@agliodbs.com>
References: 
 <31833713.1128111650174.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
	<200510031334.02030.josh@agliodbs.com>
	<1128372151.28509.1.camel@toonses.gghcwest.com>
	<200510031416.15620.josh@agliodbs.com>
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Date: Mon, 03 Oct 2005 14:32:26 -0700
Message-Id: <1128375146.29080.9.camel@toonses.gghcwest.com>
Mime-Version: 1.0
X-Mailer: Evolution 2.4.0 
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=-0.361 required=5 tests=[AWL=-0.411,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/30
X-Sequence-Number: 14798

On Mon, 2005-10-03 at 14:16 -0700, Josh Berkus wrote:
> Jeff,
> 
> > > Nope, LOTS of testing, at OSDL, GreenPlum and Sun.   For comparison, A
> > > Big-Name Proprietary Database doesn't get much more than that either.
> >
> > I find this claim very suspicious.  I get single-threaded reads in
> > excess of 1GB/sec with XFS and > 250MB/sec with ext3.
> 
> Database reads?  Or raw FS reads?  It's not the same thing.

Just reading files off the filesystem.  These are input rates I get with
a specialized sort implementation.  1GB/sec is not even especially
wonderful, I can get that on two controllers with 24-disk stripe set.

I guess database reads are different, but I remain unconvinced that they
are *fundamentally* different.  After all, a tab-delimited file (my sort
workload) is a kind of database.

> Also, we're talking *write speed* here, not read speed.

Ok, I did not realize.  Still you should see 250-300MB/sec
single-threaded sequential output on ext3, assuming the storage can
provide that rate.

> I also find *your* claim suspicious, since there's no way XFS is 300% faster 
> than ext3 for the *general* case.

On a single disk you wouldn't notice, but XFS scales much better when
you throw disks at it.  I get a 50MB/sec boost from the 24th disk,
whereas ext3 stops scaling after 16 disks.  For writes both XFS and ext3
top out around 8 disks, but in this case XFS tops out at 500MB/sec while
ext3 can't break 350MB/sec.

I'm hopeful that in the future the work being done at ClusterFS will
make ext3 on-par with XFS.

-jwb

From pgsql-performance-owner@postgresql.org  Wed Oct  5 02:28:57 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 3A148D9EB3;
	Mon,  3 Oct 2005 18:43:37 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 43127-10; Mon,  3 Oct 2005 21:43:31 +0000 (GMT)
Received: from mail.skype.net (mail.skype.net [195.215.8.149])
	by svr1.postgresql.org (Postfix) with ESMTP id EA63CD9EB0;
	Mon,  3 Oct 2005 18:43:32 -0300 (ADT)
Received: from localhost (localhost.localdomain [127.0.0.1])
	by mail.skype.net (Postfix) with ESMTP id 6E5894DD6A;
	Mon,  3 Oct 2005 23:43:34 +0200 (CEST)
Received: from [192.168.1.2] (217-159-136-226-dsl.kt.estpak.ee
	[217.159.136.226])
	by mail.skype.net (Postfix) with ESMTP id 79F984DE27;
	Mon,  3 Oct 2005 23:43:33 +0200 (CEST)
Subject: Re: [HACKERS] A Better External Sort?
From: Hannu Krosing <hannu@skype.net>
To: Josh Berkus <josh@agliodbs.com>
Cc: "Jeffrey W. Baker" <jwbaker@acm.org>, pgsql-hackers@postgresql.org,
	Michael Stone <mstone+postgres@mathom.us>, pgsql-performance@postgresql.org
In-Reply-To: <200510031416.15620.josh@agliodbs.com>
References: 
 <31833713.1128111650174.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
	<200510031334.02030.josh@agliodbs.com>
	<1128372151.28509.1.camel@toonses.gghcwest.com>
	<200510031416.15620.josh@agliodbs.com>
Content-Type: text/plain
Date: Tue, 04 Oct 2005 00:43:10 +0300
Message-Id: <1128375790.5882.18.camel@fuji.krosing.net>
Mime-Version: 1.0
X-Mailer: Evolution 2.0.4 (2.0.4-6) 
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0 required=5 tests=[none]
X-Spam-Level: 
X-Archive-Number: 200510/70
X-Sequence-Number: 14838

On E, 2005-10-03 at 14:16 -0700, Josh Berkus wrote:
> Jeff,
> 
> > > Nope, LOTS of testing, at OSDL, GreenPlum and Sun.   For comparison, A
> > > Big-Name Proprietary Database doesn't get much more than that either.
> >
> > I find this claim very suspicious.  I get single-threaded reads in
> > excess of 1GB/sec with XFS and > 250MB/sec with ext3.
> 
> Database reads?  Or raw FS reads?  It's not the same thing.

Just FYI, I run a count(*) on a 15.6GB table on a lightly loaded db and
it run in 163 sec. (Dual opteron 2.6GHz, 6GB RAM, 6 x 74GB 15k  disks in
RAID10, reiserfs). A little less than 100MB sec.

After this I ran count(*) over a 2.4GB file from another tablespace on
another device (4x142GB 10k disks in RAID10) and it run 22.5 sec on
first run and 12.5 on second.

db=# show shared_buffers ;
 shared_buffers
----------------
 196608
(1 row)

db=# select version();
                                          version
--------------------------------------------------------------------------------------------
 PostgreSQL 8.0.3 on x86_64-pc-linux-gnu, compiled by GCC cc (GCC) 3.3.6
(Debian 1:3.3.6-7)
(1 row)


-- 
Hannu Krosing <hannu@skype.net>


From pgsql-general-owner@postgresql.org  Mon Oct  3 18:46:57 2005
X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id AF850D9EC2;
	Mon,  3 Oct 2005 18:46:46 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 46776-04; Mon,  3 Oct 2005 21:46:41 +0000 (GMT)
Received: from smtp.nildram.co.uk (smtp.nildram.co.uk [195.112.4.54])
	by svr1.postgresql.org (Postfix) with ESMTP id 1FA65D7E1D;
	Mon,  3 Oct 2005 18:46:42 -0300 (ADT)
Received: from 192.168.0.3 (unknown [84.12.188.233])
	by smtp.nildram.co.uk (Postfix) with ESMTP
	id 62266250AA5; Mon,  3 Oct 2005 22:46:41 +0100 (BST)
Subject: Re: [PERFORM] database bloat, but vacuums are done, and fsm seems
From: Simon Riggs <simon@2ndquadrant.com>
To: hubert depesz lubaczewski <depesz@gmail.com>
Cc: PostgreSQL General <pgsql-general@postgresql.org>,
	pgsqlperform <pgsql-performance@postgresql.org>
In-Reply-To: <9e4684ce05092800075d37d0cc@mail.gmail.com>
References: <9e4684ce05092800075d37d0cc@mail.gmail.com>
Content-Type: text/plain
Organization: 2nd Quadrant
Date: Mon, 03 Oct 2005 22:47:02 +0100
Message-Id: <1128376022.8603.137.camel@localhost.localdomain>
Mime-Version: 1.0
X-Mailer: Evolution 2.0.2 (2.0.2-3) 
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.068 required=5 tests=[AWL=0.018,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/81
X-Sequence-Number: 84310

On Wed, 2005-09-28 at 09:07 +0200, hubert depesz lubaczewski wrote:
> database has quite huge load of updates, but i thought that vacum will
> guard me from database bloat, but from what i observed it means that
> vacuuming of b-tree indices is somewhat faulty.

No, thats perfectly normal.

Indices are packed tighter when they are first created and they spread
out a bit as you update the database. Blocks start at 90% full and end
up at 50% full for non-monotonic indexes (e.g. SERIAL) or 67% for
monotonic.

It's a long debated design feature on any DBMS that uses b-trees.

REINDEX or dump/restore should be identical.

Best Regards, Simon Riggs


From pgsql-hackers-owner@postgresql.org  Mon Oct  3 18:51:17 2005
X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 0D13FD9E27
	for <pgsql-hackers-postgresql.org@localhost.postgresql.org>;
	Mon,  3 Oct 2005 18:51:15 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 45371-10
	for <pgsql-hackers-postgresql.org@localhost.postgresql.org>;
	Mon,  3 Oct 2005 21:51:12 +0000 (GMT)
Received: from smtp.nildram.co.uk (smtp.nildram.co.uk [195.112.4.54])
	by svr1.postgresql.org (Postfix) with ESMTP id 75E48D9E0E
	for <pgsql-hackers@postgresql.org>;
	Mon,  3 Oct 2005 18:51:13 -0300 (ADT)
Received: from 192.168.0.3 (unknown [84.12.188.233])
	by smtp.nildram.co.uk (Postfix) with ESMTP
	id C0E4D250DD5; Mon,  3 Oct 2005 22:51:11 +0100 (BST)
Subject: Re: [PERFORM] A Better External Sort?
From: Simon Riggs <simon@2ndquadrant.com>
To: Martijn van Oosterhout <kleptog@svana.org>
Cc: Tom Lane <tgl@sss.pgh.pa.us>,
	Ron Peacetree <rjpeace@earthlink.net>, pgsql-hackers@postgresql.org
In-Reply-To: <20051002193835.GJ30492@svana.org>
References: 
 <18329659.1128188552696.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
	<20051001215602.GG13830@svana.org> <29837.1128223567@sss.pgh.pa.us>
	<20051002123240.GA30492@svana.org> <20051002193835.GJ30492@svana.org>
Content-Type: text/plain
Organization: 2nd Quadrant
Date: Mon, 03 Oct 2005 22:51:32 +0100
Message-Id: <1128376292.8603.142.camel@localhost.localdomain>
Mime-Version: 1.0
X-Mailer: Evolution 2.0.2 (2.0.2-3) 
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.066 required=5 tests=[AWL=0.016,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/124
X-Sequence-Number: 73983

On Sun, 2005-10-02 at 21:38 +0200, Martijn van Oosterhout wrote:
> Ok, I tried two optimisations:
> 

> 2. By specifying: -Winline -finline-limit-1500 (only on tuplesort.c).
> This causes inlineApplySortFunction() to be inlined, like the code
> obviously expects it to be.
> 
> default build (baseline)                    235 seconds
> -finline only                               217 seconds (7% better)
> comparetup_index_fastbyval4 only            221 seconds (6% better)
> comparetup_index_fastbyval4 and -finline    203 seconds (13.5% better)
> 
> This is indexing the integer sequence column on a 2.7 million row
> table. The times are as given by gprof and so exclude system call time.
> 
> Basically, I recommend adding "-Winline -finline-limit-1500" to the
> default build while we discuss other options.

I add -Winline but get no warnings. Why would I use -finline-limit-1500?

I'm interested, but uncertain as to what difference this makes. Surely
using -O3 works fine?

Best Regards, Simon Riggs


From pgsql-performance-owner@postgresql.org  Mon Oct  3 18:58:39 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 0305ED94F8;
	Mon,  3 Oct 2005 18:52:37 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 47710-03; Mon,  3 Oct 2005 21:52:33 +0000 (GMT)
Received: from mail.Mi8.com (d01gw01.mi8.com [63.240.6.47])
	by svr1.postgresql.org (Postfix) with ESMTP id 9CF35D9ED1;
	Mon,  3 Oct 2005 18:52:32 -0300 (ADT)
Received: from 172.16.1.110 by mail.Mi8.com with ESMTP (- Welcome to Mi8
	Corporation www.Mi8.com (D1)); Mon, 03 Oct 2005 17:52:28 -0400
X-Server-Uuid: 241911D6-425B-44B9-A073-E3FE0F8FC774
Received: from MI8NYCMAIL06.Mi8.com ([172.16.1.175]) by
	D01SMTP01.Mi8.com with Microsoft SMTPSVC(6.0.3790.211); Mon, 3 Oct 2005
	17:52:27 -0400
Received: from 67.103.45.218 ([67.103.45.218]) by MI8NYCMAIL06.Mi8.com (
	[172.16.1.219]) via Exchange Front-End Server mi8owa.mi8.com (
	[172.16.1.104]) with Microsoft Exchange Server HTTP-DAV ; Mon, 3 Oct
	2005 17:52:27 -0500
User-Agent: Microsoft-Entourage/11.2.0.050811
Date: Mon, 03 Oct 2005 14:52:27 -0700
Subject: Re: [HACKERS] A Better External Sort?
From: "Luke Lonergan" <llonergan@greenplum.com>
To: "Hannu Krosing" <hannu@skype.net>,
	"Josh Berkus" <josh@agliodbs.com>
Cc: "Jeffrey W. Baker" <jwbaker@acm.org>, pgsql-hackers@postgresql.org,
	"Michael Stone" <mstone+postgres@mathom.us>,
	pgsql-performance@postgresql.org
Message-ID: <BF66F62B.108A0%llonergan@greenplum.com>
Thread-Topic: [HACKERS] [PERFORM] A Better External Sort?
Thread-Index: AcXIZL6a/Q9jgTRXEdq40gANk63kWA==
In-Reply-To: <1128375790.5882.18.camel@fuji.krosing.net>
MIME-Version: 1.0
X-OriginalArrivalTime: 03 Oct 2005 21:52:27.0957 (UTC)
	FILETIME=[BF2C6650:01C5C864]
X-WSS-ID: 6F5F77964JK176011-01-01
Content-Type: text/plain;
 charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=1.574 required=5 tests=[AWL=-0.007,
	FORGED_RCVD_HELO=0.05, RCVD_NUMERIC_HELO=1.531]
X-Spam-Level: *
X-Archive-Number: 200510/33
X-Sequence-Number: 14801

Hannu,

On 10/3/05 2:43 PM, "Hannu Krosing" <hannu@skype.net> wrote:

> Just FYI, I run a count(*) on a 15.6GB table on a lightly loaded db and
> it run in 163 sec. (Dual opteron 2.6GHz, 6GB RAM, 6 x 74GB 15k  disks in
> RAID10, reiserfs). A little less than 100MB sec.

This confirms our findings - sequential scan is CPU limited at about 120MB/s
per single threaded executor.  This is too slow for fast file systems like
we're discussing here.

Bizgres MPP gets 250MB/s by running multiple scanners, but we still chew up
unnecessary amounts of CPU.
  
> After this I ran count(*) over a 2.4GB file from another tablespace on
> another device (4x142GB 10k disks in RAID10) and it run 22.5 sec on
> first run and 12.5 on second.

You're getting caching effects here.

- Luke



From pgsql-performance-owner@postgresql.org  Mon Oct  3 19:03:20 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id C4780D9E0E;
	Mon,  3 Oct 2005 18:53:43 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 48503-02; Mon,  3 Oct 2005 21:53:40 +0000 (GMT)
Received: from vms040pub.verizon.net (vms040pub.verizon.net [206.46.252.40])
	by svr1.postgresql.org (Postfix) with ESMTP id A4825D9AC5;
	Mon,  3 Oct 2005 18:53:40 -0300 (ADT)
Received: from osgiliath.mathom.us ([70.108.61.78])
	by vms040.mailsrvcs.net (Sun Java System Messaging Server 6.2 HotFix
	0.04 (built Dec 24 2004)) with ESMTPA id
	<0INT00M7W0T9QHE0@vms040.mailsrvcs.net>;
	Mon, 03 Oct 2005 16:53:33 -0500 (CDT)
Received: from localhost (localhost [127.0.0.1])
	by osgiliath.mathom.us (Postfix) with ESMTP id CDDFD6003B9; Mon,
	03 Oct 2005 17:53:32 -0400 (EDT)
Received: from osgiliath.mathom.us ([127.0.0.1])
	by localhost (osgiliath [127.0.0.1]) (amavisd-new, port 10024)
	with LMTP id 21539-03-5; Mon, 03 Oct 2005 17:53:32 -0400 (EDT)
Received: by osgiliath.mathom.us (Postfix, from userid 1000)
	id B06146000E9; Mon, 03 Oct 2005 17:53:32 -0400 (EDT)
Date: Mon, 03 Oct 2005 17:53:32 -0400
From: Michael Stone <mstone+postgres@mathom.us>
Subject: Re: [HACKERS] A Better External Sort?
In-reply-to: <200510031334.02030.josh@agliodbs.com>
To: Josh Berkus <josh@agliodbs.com>
Cc: pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org
Mail-Followup-To: Josh Berkus <josh@agliodbs.com>,
	pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org
Message-id: <20051003215332.GS2241@mathom.us>
MIME-version: 1.0
Content-type: text/plain; charset=us-ascii; format=flowed
Content-disposition: inline
X-Pgp-Fingerprint: 53 FF 38 00 E7 DD 0A 9C  84 52 84 C5 EE DF 7C 88
X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at mathom.us
References: 
 <31833713.1128111650174.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
	<200509301341.22795.josh@agliodbs.com>
	<20050930231032.GQ2241@mathom.us>
	<200510031334.02030.josh@agliodbs.com>
User-Agent: Mutt/1.5.10i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.004 required=5 tests=[AWL=0.004]
X-Spam-Level: 
X-Archive-Number: 200510/34
X-Sequence-Number: 14802

On Mon, Oct 03, 2005 at 01:34:01PM -0700, Josh Berkus wrote:
>> >Realistically, you can't do better than about 25MB/s on a
>> > single-threaded I/O on current Linux machines,
>>
>> What on earth gives you that idea? Did you drop a zero?
>
>Nope, LOTS of testing, at OSDL, GreenPlum and Sun.   For comparison, A 
>Big-Name Proprietary Database doesn't get much more than that either.

You seem to be talking about database IO, which isn't what you said.


From pgsql-performance-owner@postgresql.org  Mon Oct  3 18:57:25 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 5306BD9AC5;
	Mon,  3 Oct 2005 18:55:48 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 45032-10; Mon,  3 Oct 2005 21:55:40 +0000 (GMT)
Received: from davinci.ethosmedia.com (server227.ethosmedia.com
	[209.128.84.227])
	by svr1.postgresql.org (Postfix) with ESMTP id A0D1BD7E1D;
	Mon,  3 Oct 2005 18:55:36 -0300 (ADT)
X-EthosMedia-Virus-Scanned: no infections found
Received: from [64.81.245.111] (account josh@agliodbs.com HELO
	temoku.sf.agliodbs.com)
	by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.1.8)
	with ESMTP id 8192646; Mon, 03 Oct 2005 14:58:03 -0700
From: Josh Berkus <josh@agliodbs.com>
Reply-To: josh@agliodbs.com
Organization: Aglio Database Solutions
To: Michael Stone <mstone+postgres@mathom.us>
Subject: Re: [HACKERS] A Better External Sort?
Date: Mon, 3 Oct 2005 14:59:30 -0700
User-Agent: KMail/1.8
Cc: pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org
References: 
 <31833713.1128111650174.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
	<200510031334.02030.josh@agliodbs.com>
	<20051003215332.GS2241@mathom.us>
In-Reply-To: <20051003215332.GS2241@mathom.us>
MIME-Version: 1.0
Content-Type: text/plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Message-Id: <200510031459.30802.josh@agliodbs.com>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.046 required=5 tests=[AWL=-0.004,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/32
X-Sequence-Number: 14800

Michael,

> >Nope, LOTS of testing, at OSDL, GreenPlum and Sun.   For comparison, A
> >Big-Name Proprietary Database doesn't get much more than that either.
>
> You seem to be talking about database IO, which isn't what you said.

Right, well, it was what I meant.   I failed to specify, that's all.

-- 
--Josh

Josh Berkus
Aglio Database Solutions
San Francisco

From pgsql-performance-owner@postgresql.org  Mon Oct  3 19:10:41 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 23252D9E9C;
	Mon,  3 Oct 2005 18:59:22 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 47947-10; Mon,  3 Oct 2005 21:59:17 +0000 (GMT)
Received: from davinci.ethosmedia.com (server227.ethosmedia.com
	[209.128.84.227])
	by svr1.postgresql.org (Postfix) with ESMTP id 6227AD9EE0;
	Mon,  3 Oct 2005 18:59:18 -0300 (ADT)
X-EthosMedia-Virus-Scanned: no infections found
Received: from [64.81.245.111] (account josh@agliodbs.com HELO
	temoku.sf.agliodbs.com)
	by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.1.8)
	with ESMTP id 8192664; Mon, 03 Oct 2005 15:01:44 -0700
From: Josh Berkus <josh@agliodbs.com>
Reply-To: josh@agliodbs.com
Organization: Aglio Database Solutions
To: "Jeffrey W. Baker" <jwbaker@acm.org>
Subject: Re: [HACKERS] A Better External Sort?
Date: Mon, 3 Oct 2005 15:03:11 -0700
User-Agent: KMail/1.8
Cc: pgsql-hackers@postgresql.org, Michael Stone <mstone+postgres@mathom.us>,
	pgsql-performance@postgresql.org
References: 
 <31833713.1128111650174.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
	<200510031416.15620.josh@agliodbs.com>
	<1128375146.29080.9.camel@toonses.gghcwest.com>
In-Reply-To: <1128375146.29080.9.camel@toonses.gghcwest.com>
MIME-Version: 1.0
Content-Type: text/plain;
  charset="utf-8"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Message-Id: <200510031503.12158.josh@agliodbs.com>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.046 required=5 tests=[AWL=-0.004,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/35
X-Sequence-Number: 14803

Jeffrey,

> I guess database reads are different, but I remain unconvinced that they
> are *fundamentally* different.  After all, a tab-delimited file (my sort
> workload) is a kind of database.

Unfortunately, they are ... because of CPU overheads.   I'm basing what's 
"reasonable" for data writes on the rates which other high-end DBs can 
make.   From that, 25mb/s or even 40mb/s for sorts should be achievable 
but doing 120mb/s would require some kind of breakthrough.

> On a single disk you wouldn't notice, but XFS scales much better when
> you throw disks at it.  I get a 50MB/sec boost from the 24th disk,
> whereas ext3 stops scaling after 16 disks.  For writes both XFS and ext3
> top out around 8 disks, but in this case XFS tops out at 500MB/sec while
> ext3 can't break 350MB/sec.

That would explain it.  I seldom get more than 6 disks (and 2 channels) to 
test with.

-- 
--Josh

Josh Berkus
Aglio Database Solutions
San Francisco

From pgsql-performance-owner@postgresql.org  Mon Oct  3 17:05:04 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 15BA1D83DE
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon,  3 Oct 2005 17:04:59 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 11210-04
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon,  3 Oct 2005 20:04:55 +0000 (GMT)
Received: from floppy.pyrenet.fr (news.pyrenet.fr [194.116.145.2])
	by svr1.postgresql.org (Postfix) with ESMTP id 86E97D9EE1
	for <pgsql-performance@postgresql.org>;
	Mon,  3 Oct 2005 17:04:54 -0300 (ADT)
Received: by floppy.pyrenet.fr (Postfix, from userid 106)
	id 0346331F51; Mon,  3 Oct 2005 22:04:55 +0200 (MET DST)
From: "Qingqing Zhou" <zhouqq@cs.toronto.edu>
X-Newsgroups: pgsql.performance
Subject: Re: Query seem to slow if table have more than 200 million rows
Date: Mon, 3 Oct 2005 16:04:50 -0700
Organization: Hub.Org Networking Services
Lines: 56
Message-ID: <dhs2t1$ge0$1@news.hub.org>
References: <dh9ti0$ovs$1@news.hub.org>
	<SVONERLVbNDN4CxpAOA00000061@ki-communication.com>
X-Complaints-To: usenet@news.hub.org
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-RFC2646: Format=Flowed; Original
To: pgsql-performance@postgresql.org
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=1.192 required=5 tests=[AWL=0.007,
	PRIORITY_NO_NAME=1.185]
X-Spam-Level: *
X-Archive-Number: 200510/23
X-Sequence-Number: 14791


""Ahmad Fajar"" <gendowo@konphalindo.or.id> wrote
> Hi Qingqing,
>
> I don't know whether the statistic got is bad or good, this is the
> statistic:

Please do it in this way:

1. Start postmaster with "stats_start_collector=true" and 
"stats_block_level=true".

2. Use psql connect it, do something like this:

test=# select pg_stat_reset();
 pg_stat_reset
---------------
 t
(1 row)

test=# select * from pg_statio_user_indexes ;
 relid | indexrelid | schemaname | relname | indexrelname | idx_blks_read | 
idx_
blks_hit
-------+------------+------------+---------+--------------+---------------+-----
---------
 16385 |      16390 | public     | test    | test_idx     |             0 |
       0
(1 row)

test=# select count(*) from test where a <= 1234;
 count
-------
  7243
(1 row)

test=# select * from pg_statio_user_indexes ;
 relid | indexrelid | schemaname | relname | indexrelname | idx_blks_read | 
idx_
blks_hit
-------+------------+------------+---------+--------------+---------------+-----
---------
 16385 |      16390 | public     | test    | test_idx     |            55 |
       0
(1 row)


This gives us that to get "select count(*) from test where a <= 1234", I 
have to read 55 index blocks (no index block hit since I just restart 
postmaster so the bufferpool is empty).


Regards,
Qingqing



From pgsql-performance-owner@postgresql.org  Mon Oct  3 21:07:14 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 8B5B8D9AA1;
	Mon,  3 Oct 2005 21:07:10 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 92843-07; Tue,  4 Oct 2005 00:07:03 +0000 (GMT)
Received: from pop-altamira.atl.sa.earthlink.net
	(pop-altamira.atl.sa.earthlink.net [207.69.195.62])
	by svr1.postgresql.org (Postfix) with ESMTP id 865B4D9A95;
	Mon,  3 Oct 2005 21:07:04 -0300 (ADT)
Received: from elwamui-polski.atl.sa.earthlink.net ([209.86.224.45])
	by pop-altamira.atl.sa.earthlink.net with esmtp (Exim 3.36 #10)
	id 1EMaKk-0003eV-00; Mon, 03 Oct 2005 20:07:02 -0400
Message-ID: 
 <21602981.1128384422354.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
Date: Mon, 3 Oct 2005 20:07:02 -0400 (EDT)
From: Ron Peacetree <rjpeace@earthlink.net>
Reply-To: Ron Peacetree <rjpeace@earthlink.net>
To: josh@agliodbs.com, pgsql-hackers@postgresql.org,
	pgsql-performance@postgresql.org
Subject: Re: [HACKERS] A Better External Sort?
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: Earthlink Zoo Mail 1.0
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.257 required=5 tests=[AWL=-0.117,
	DNS_FROM_RFC_ABUSE=0.374]
X-Spam-Level: 
X-Archive-Number: 200510/36
X-Sequence-Number: 14804

Let's pretend we get a 24HD HW RAID solution like that J Baker
says he has access to and set it up as a RAID 10.  Assuming
it uses two 64b 133MHz PCI-X busses and has the fastest HDs
available on it,  Jeff says he can hit ~1GBps of XFS FS IO rate
with that set up (12*83.3MBps= 1GBps).

Josh says that pg can't do more than 25MBps of DB level IO
regardless of how fast the physical IO subsystem is because at
25MBps, pg is CPU bound.  

Just how bad is this CPU bound condition?  How powerful a CPU is
needed to attain a DB IO rate of 25MBps?
 
If we replace said CPU with one 2x, 10x, etc faster than that, do we
see any performance increase?

If a modest CPU can drive a DB IO rate of 25MBps, but that rate
does not go up regardless of how much extra CPU we throw at
it...

Ron 

-----Original Message-----
From: Josh Berkus <josh@agliodbs.com>
Sent: Oct 3, 2005 6:03 PM
To: "Jeffrey W. Baker" <jwbaker@acm.org>
Cc: 
Subject: Re: [HACKERS] [PERFORM] A Better External Sort?

Jeffrey,

> I guess database reads are different, but I remain unconvinced that they
> are *fundamentally* different.  After all, a tab-delimited file (my sort
> workload) is a kind of database.

Unfortunately, they are ... because of CPU overheads.   I'm basing what's 
"reasonable" for data writes on the rates which other high-end DBs can 
make.   From that, 25mb/s or even 40mb/s for sorts should be achievable 
but doing 120mb/s would require some kind of breakthrough.

> On a single disk you wouldn't notice, but XFS scales much better when
> you throw disks at it.  I get a 50MB/sec boost from the 24th disk,
> whereas ext3 stops scaling after 16 disks.  For writes both XFS and ext3
> top out around 8 disks, but in this case XFS tops out at 500MB/sec while
> ext3 can't break 350MB/sec.

That would explain it.  I seldom get more than 6 disks (and 2 channels) to 
test with.

-- 
--Josh

Josh Berkus
Aglio Database Solutions
San Francisco

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

               http://archives.postgresql.org


From pgsql-performance-owner@postgresql.org  Wed Oct  5 03:20:41 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 16348D9B19
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon,  3 Oct 2005 21:19:56 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 88867-07
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 00:19:51 +0000 (GMT)
Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.197])
	by svr1.postgresql.org (Postfix) with ESMTP id 6A142D9B18
	for <pgsql-performance@postgresql.org>;
	Mon,  3 Oct 2005 21:19:52 -0300 (ADT)
Received: by xproxy.gmail.com with SMTP id t15so271564wxc
	for <pgsql-performance@postgresql.org>;
	Mon, 03 Oct 2005 17:19:56 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references;
	b=e2YSoltHlF4i0R/RjCoaa5xv1jW6C5kbxM9YMbsC3QjI22N3bAxHsuef9wP1+xWn+Udrp84JPHYdJokNTVoSMHkE3jSf4vdrmHEIY5ToWVJip5aRkF1j6l44J9GrtW0nGChILop311trhQS4J+TEmteGInNhg2j7KeaL2i1jmdw=
Received: by 10.70.109.11 with SMTP id h11mr1963119wxc;
	Mon, 03 Oct 2005 17:19:56 -0700 (PDT)
Received: by 10.70.76.1 with HTTP; Mon, 3 Oct 2005 17:19:56 -0700 (PDT)
Message-ID: <e692861c0510031719p10a59b3je47942077d27cbfe@mail.gmail.com>
Date: Mon, 3 Oct 2005 20:19:56 -0400
From: Gregory Maxwell <gmaxwell@gmail.com>
Reply-To: Gregory Maxwell <gmaxwell@gmail.com>
To: Ron Peacetree <rjpeace@earthlink.net>
Subject: Re: [HACKERS] A Better External Sort?
Cc: josh@agliodbs.com, pgsql-hackers@postgresql.org,
	pgsql-performance@postgresql.org
In-Reply-To: 
 <21602981.1128384422354.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
References: 
 <21602981.1128384422354.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.07 required=5 tests=[AWL=0.046, RCVD_BY_IP=0.024]
X-Spam-Level: 
X-Archive-Number: 200510/71
X-Sequence-Number: 14839

On 10/3/05, Ron Peacetree <rjpeace@earthlink.net> wrote:
[snip]
> Just how bad is this CPU bound condition?  How powerful a CPU is
> needed to attain a DB IO rate of 25MBps?
>
> If we replace said CPU with one 2x, 10x, etc faster than that, do we
> see any performance increase?
>
> If a modest CPU can drive a DB IO rate of 25MBps, but that rate
> does not go up regardless of how much extra CPU we throw at
> it...

Single threaded was mentioned.
Plus even if it's purely cpu bound, it's seldom as trivial as throwing
CPU at it, consider the locking in both the application, in the
filesystem, and elsewhere in the kernel.

From pgsql-performance-owner@postgresql.org  Mon Oct  3 21:32:17 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id B86B8D9B18;
	Mon,  3 Oct 2005 21:32:07 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 93510-05; Tue,  4 Oct 2005 00:31:59 +0000 (GMT)
Received: from pop-altamira.atl.sa.earthlink.net
	(pop-altamira.atl.sa.earthlink.net [207.69.195.62])
	by svr1.postgresql.org (Postfix) with ESMTP id 7B0FED9B57;
	Mon,  3 Oct 2005 21:32:00 -0300 (ADT)
Received: from elwamui-polski.atl.sa.earthlink.net ([209.86.224.45])
	by pop-altamira.atl.sa.earthlink.net with esmtp (Exim 3.36 #10)
	id 1EMaiw-0001WM-00; Mon, 03 Oct 2005 20:32:02 -0400
Message-ID: 
 <15704001.1128385922538.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
Date: Mon, 3 Oct 2005 20:32:02 -0400 (EDT)
From: Ron Peacetree <rjpeace@earthlink.net>
Reply-To: Ron Peacetree <rjpeace@earthlink.net>
To: Gregory Maxwell <gmaxwell@gmail.com>,
	pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org
Subject: Re: [HACKERS] A Better External Sort?
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: Earthlink Zoo Mail 1.0
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.257 required=5 tests=[AWL=-0.117,
	DNS_FROM_RFC_ABUSE=0.374]
X-Spam-Level: 
X-Archive-Number: 200510/37
X-Sequence-Number: 14805

OK, change "performance" to "single thread performance" and we
still have a valid starting point for a discussion.

Ron


-----Original Message-----
From: Gregory Maxwell <gmaxwell@gmail.com>
Sent: Oct 3, 2005 8:19 PM
To: Ron Peacetree <rjpeace@earthlink.net>
Subject: Re: [HACKERS] [PERFORM] A Better External Sort?

On 10/3/05, Ron Peacetree <rjpeace@earthlink.net> wrote:
[snip]
> Just how bad is this CPU bound condition?  How powerful a CPU is
> needed to attain a DB IO rate of 25MBps?
>
> If we replace said CPU with one 2x, 10x, etc faster than that, do we
> see any performance increase?
>
> If a modest CPU can drive a DB IO rate of 25MBps, but that rate
> does not go up regardless of how much extra CPU we throw at
> it...

Single threaded was mentioned.
Plus even if it's purely cpu bound, it's seldom as trivial as throwing
CPU at it, consider the locking in both the application, in the
filesystem, and elsewhere in the kernel.


From pgsql-performance-owner@postgresql.org  Mon Oct  3 23:04:27 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 09A1CD9B2D
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon,  3 Oct 2005 23:04:23 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 19929-07
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 02:04:15 +0000 (GMT)
Received: from cluster1.echolabs.net (mail.atlanticbb.net [216.52.118.222])
	by svr1.postgresql.org (Postfix) with ESMTP id 3ED8CD9B29
	for <pgsql-performance@postgresql.org>;
	Mon,  3 Oct 2005 23:04:16 -0300 (ADT)
X-Scanned-By: RAE MPP/Clamd http://www.messagepartners.com
X-Scanned-By: RAE MPP/Cloudmark http://www.messagepartners.com
Received: from [216.189.176.72] (account jma@atlanticbb.net HELO [127.0.0.1])
	by fe2.cluster1.echolabs.net (CommuniGate Pro SMTP 4.3.7)
	with ESMTPA id 83528382; Mon, 03 Oct 2005 22:04:18 -0400
Message-ID: <4341E328.2060305@freedomcircle.net>
Date: Mon, 03 Oct 2005 22:04:24 -0400
From: Joe <svn@freedomcircle.net>
Organization: Freedom Circle, LLC
User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: PFC <lists@boutiquenumerique.com>
Cc: Gavin Sherry <swm@alcove.com.au>, Magnus Hagander <mha@sollentuna.net>,
	pgsql-performance@postgresql.org
Subject: Re: Comparative performance
References: <6BCB9D8A16AC4241919521715F4D8BCE92E6D6@algol.sollentuna.se>
	<433BDB0B.8010002@freedomcircle.net>
	<Pine.LNX.4.58.0509292230310.26600@linuxworld.com.au>
	<433BE1A0.5000807@freedomcircle.net> <op.sxvguropth1vuj@localhost>
In-Reply-To: <op.sxvguropth1vuj@localhost>
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.071 required=5 tests=[AWL=0.021,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/38
X-Sequence-Number: 14806

PFC wrote:
>     Even though this query isn't that optimized, it's still only 16  
> milliseconds.
>     Why does it take this long for PHP to get the results ?
> 
>     Can you try pg_query'ing this exact same query, FROM PHP, and timing 
> it  with getmicrotime() ?

That query took about 27 msec in actual PHP execution time.  It turns out the 
real culprit is the following query, which interestingly enough retrieves zero 
rows in the case of the Economists page that I've been using for testing, yet it 
uses up about 1370 msec in actual runtime:

SELECT topic_id1, topic_id2, topic_name, categ_id, list_name, t.title, url, 
page_type, rel_type, inverse_id, r.description AS rel_descrip, r.created, r.updated
FROM relationship r, topic t, entry_type e
WHERE ((topic_id1 = topic_id AND topic_id2 = 1252) OR (topic_id2 = topic_id and 
topic_id1 = 1252)) AND rel_type = type_id AND e.class_id = 2
ORDER BY rel_type, list_name;

The EXPLAIN ANALYZE output, after I ran VACUUM ANALYZE on the three tables, is:

  Sort  (cost=4035.55..4035.56 rows=1 width=131) (actual time=2110.000..2110.000 
rows=0 loops=1)
    Sort Key: r.rel_type, t.list_name
    ->  Nested Loop  (cost=36.06..4035.54 rows=1 width=131) (actual 
time=2110.000..2110.000 rows=0 loops=1)
          Join Filter: ((("inner".topic_id1 = "outer".topic_id) AND 
("inner".topic_id2 = 1252)) OR (("inner".topic_id2 = "outer".topic_id) AND 
("inner".topic_id1 = 1252)))
          ->  Seq Scan on topic t  (cost=0.00..38.34 rows=1234 width=90) (actual 
time=0.000..15.000 rows=1234 loops=1)
          ->  Materialize  (cost=36.06..37.13 rows=107 width=45) (actual 
time=0.000..0.509 rows=466 loops=1234)
                ->  Merge Join  (cost=30.31..35.96 rows=107 width=45) (actual 
time=0.000..0.000 rows=466 loops=1)
                      Merge Cond: ("outer".type_id = "inner".rel_type)
                      ->  Index Scan using entry_type_pkey on entry_type e  (cost
=0.00..3.94 rows=16 width=4) (actual time=0.000..0.000 rows=15 loops=1)
                            Filter: (class_id = 2)
                      ->  Sort  (cost=30.31..31.48 rows=466 width=43) (actual 
time=0.000..0.000 rows=466 loops=1)
                            Sort Key: r.rel_type
                            ->  Seq Scan on relationship r  (cost=0.00..9.66 
rows=466 width=43) (actual time=0.000..0.000 rows=466 loops=1)
  Total runtime: 2110.000 ms
(14 rows)

The tables are as follows:

CREATE TABLE entry_type (
   type_id SMALLINT NOT NULL PRIMARY KEY,
   title VARCHAR(32) NOT NULL,
   rel_title VARCHAR(32),
   class_id SMALLINT NOT NULL DEFAULT 1,
   inverse_id SMALLINT,
   updated TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP)
WITHOUT OIDS;

CREATE TABLE topic (
   topic_id serial PRIMARY KEY,
   topic_name VARCHAR(48) NOT NULL UNIQUE,
   categ_id SMALLINT NOT NULL,
   parent_entity INTEGER,
   parent_concept INTEGER,
   crossref_id INTEGER,
   list_name VARCHAR(80) NOT NULL,
   title VARCHAR(80),
   description VARCHAR(255),
   url VARCHAR(64),
   page_type SMALLINT NOT NULL,
   dark_ind BOOLEAN NOT NULL DEFAULT FALSE,
   ad_code INTEGER,
   created DATE NOT NULL DEFAULT CURRENT_DATE,
   updated TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP)
WITHOUT OIDS;

CREATE TABLE relationship (
   topic_id1 INTEGER NOT NULL REFERENCES topic,
   topic_id2 INTEGER NOT NULL REFERENCES topic,
   rel_type INTEGER NOT NULL,
   description VARCHAR(255),
   created DATE NOT NULL DEFAULT CURRENT_DATE,
   updated TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
   PRIMARY KEY (topic_id1, topic_id2, rel_type))
WITHOUT OIDS;

I'm thinking that perhaps I need to set up another index with topic_id2 first 
and topic_id1 second.  In addition, an index on entry_type.class_id may improve 
things.  Another possibility would be to rewrite the query as a UNION.

Of course, this doesn't explain how MySQL manages to execute the query in about 
9 msec.  The only minor differences in the schema are:  entry_type.title and 
rel_title are char(32) in MySQL, entry_type.class_id is a tinyint, and 
topic.categ_id, page_type and dark_ind are also tinyints. MySQL also doesn't 
have the REFERENCES.

A couple of interesting side notes from my testing.  First is that pg_connect() 
took about 39 msec but mysql_connect() took only 4 msec, however, pg_pconnect() 
took 0.14 msec while mysql_pconnect() took 0.99 msec (all tests were repeated 
five times and the quoted results are averages).  Second, is that PostgreSQL's 
performance appears to be much more consistent in certain queries.  For example, 
the query that retrieves the list of subtopics (the names and description of 
economists), took 17 msec in PG, with a low of 15 (three times) and a high of 
21, whereas MySQL took 60 msec on average but had a low of 22 and a high of 102 
msec.

Joe


From pgsql-performance-owner@postgresql.org  Tue Oct  4 05:45:15 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 1985CD9FA6
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 05:45:14 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 23350-09
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 08:45:07 +0000 (GMT)
Received: from boutiquenumerique.com (boutiquenumerique.com [82.67.9.10])
	by svr1.postgresql.org (Postfix) with ESMTP id 08422D72AA
	for <pgsql-performance@postgresql.org>;
	Tue,  4 Oct 2005 05:45:07 -0300 (ADT)
Received: (qmail 32426 invoked from network); 4 Oct 2005 10:46:02 +0200
Received: from unknown (HELO localhost) (boutiquenumerique-lists@192.168.0.4)
	by boutiquenumerique.com with SMTP; 4 Oct 2005 10:46:02 +0200
Date: Tue, 04 Oct 2005 10:45:06 +0200
To: Joe <svn@freedomcircle.net>
Subject: Re: Comparative performance
Cc: pgsql-performance@postgresql.org
References: <6BCB9D8A16AC4241919521715F4D8BCE92E6D6@algol.sollentuna.se>
	<433BDB0B.8010002@freedomcircle.net>
	<Pine.LNX.4.58.0509292230310.26600@linuxworld.com.au>
	<433BE1A0.5000807@freedomcircle.net> <op.sxvguropth1vuj@localhost>
	<4341E328.2060305@freedomcircle.net>
From: PFC <lists@boutiquenumerique.com>
Organization: =?utf-8?Q?La_Boutique_Num=C3=A9rique?=
Content-Type: text/plain; format=flowed; delsp=yes; charset=utf-8
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Message-ID: <op.sx349gxcth1vuj@localhost>
In-Reply-To: <4341E328.2060305@freedomcircle.net>
User-Agent: Opera M2/8.0 (Linux, build 1095)
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/39
X-Sequence-Number: 14807


It's more understandable if the table names are in front of the column  
names :

SELECT relationship.topic_id1, relationship.topic_id2, topic.topic_name,  
topic.categ_id, topic.list_name, topic.title,
topic.url, topic.page_type, relationship.rel_type, entry_type.inverse_id,  
relationship.description AS rel_descrip,
relationship.created, relationship.updated
 FROM relationship, topic, entry_type
WHERE
	((relationship.topic_id1 = topic.topic_id AND relationship.topic_id2 =  
1252)
	OR (relationship.topic_id2 =  topic.topic_id and relationship.topic_id1 =  
1252))
	AND	relationship.rel_type = entry_type.type_id
	AND	entry_type.class_id = 2
	ORDER BY rel_type, list_name;

I see a few problems in your schema.
- topic_id1 and topic_id2 play the same role, there is no constraint to  
determine which is which, hence it is possible to define the same relation  
twice.
- as you search on two columns with OR, you need UNION to use indexes.
- lack of indexes
- I don't understand why the planner doesn't pick up hash joins...
- if you use a version before 8, type mismatch will prevent use of the  
indexes.

I'd suggest rewriting the query like this :
SELECT topic.*, foo.* FROM
topic,
(SELECT topic_id2 as fetch_id, topic_id1, topic_id2, rel_type, description  
as rel_descrip, created, updated
	FROM relationship
	WHERE
		rel_type IN (SELECT type_id FROM entry_type WHERE class_id = 2)
	AND	topic_id1 = 1252
UNION
SELECT topic_id1 as fetch_id, topic_id1, topic_id2, rel_type, description  
as rel_descrip, created, updated
	FROM relationship
	WHERE
		rel_type IN (SELECT type_id FROM entry_type WHERE class_id = 2)
	AND	topic_id2 = 1252)
AS foo
WHERE topic.topic_id = foo.fetch_id


CREATE INDEX'es ON
entry_type( class_id )

relationship( topic_id1, rel_type, topic_id2 )	which becomes your new  
PRIMARY KEY
relationship( topic_id2, rel_type, topic_id1 )

> Of course, this doesn't explain how MySQL manages to execute the query  
> in about 9 msec.  The only minor differences in the schema are:   
> entry_type.title and rel_title are char(32) in MySQL,  
> entry_type.class_id is a tinyint, and topic.categ_id, page_type and  
> dark_ind are also tinyints. MySQL also doesn't have the REFERENCES.

Can you post the result from MySQL EXPLAIN ?

You might be interested in the following code. Just replace mysql_ by pg_,  
it's quite useful.

$global_queries_log = array();

function _getmicrotime()	{	list($u,$s) = explode(' ',microtime());	return  
$u+$s;	}

/*	Formats query, with given arguments, escaping all strings as needed.
	db_quote_query( 'UPDATE junk SET a=%s WHERE b=%s', array( 1,"po'po" ) )
	=>	UPDATE junk SET a='1 WHERE b='po\'po'
*/
function db_quote_query( $sql, $params=false )
{
	// if no params, send query raw
	if( !$params )
		return $sql;

	// quote params
	foreach( $params as $key => $val )
	{
		if( is_array( $val ))
			$val = implode( ',', $val );
		$params[$key] = "'".mysql_real_escape_string( $val )."'";
	}
	return vsprintf( $sql, $params );
}

/*	Formats query, with given arguments, escaping all strings as needed.
	Runs query, logging its execution time.
	Returns the query, or dies with error.
*/
function db_query( $sql, $params=false )
{
	// it's already a query
	if( is_resource( $sql ))
		return $sql;

	$sql = db_quote_query( $sql, $params );

	$t = _getmicrotime();
	$r = mysql_query( $sql );
	if( !$r )
	{
		echo "<div class=bigerror><b>Erreur MySQL  
:</b><br>".mysql_error()."<br><br><b>Requ􏻪te</b>  
:<br>".$sql."<br><br><b>Traceback </b>:<pre>";
		foreach( debug_backtrace() as $t ) xdump( $t );
		echo "</pre></div>";
		die();
	}
	global $global_queries_log;
	$global_queries_log[] = array( _getmicrotime()-$t, $sql );
	return $r;
}

At the end of your page, display the contents of $global_queries_log.




From pgsql-hackers-owner@postgresql.org  Tue Oct  4 07:05:15 2005
X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 6075AD9EB0
	for <pgsql-hackers-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 07:05:14 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 41821-09
	for <pgsql-hackers-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 10:05:09 +0000 (GMT)
Received: from svr2.postgresql.org (svr2.postgresql.org [65.19.161.25])
	by svr1.postgresql.org (Postfix) with ESMTP id 18CD8D9BFD
	for <pgsql-hackers@postgresql.org>;
	Tue,  4 Oct 2005 07:05:11 -0300 (ADT)
Received: from svana.org (svana.org [203.20.62.76])
	by svr2.postgresql.org (Postfix) with ESMTP id 7681BF0C9E
	for <pgsql-hackers@postgresql.org>;
	Tue,  4 Oct 2005 11:00:24 +0100 (BST)
Received: from kleptog by svana.org with local (Exim 3.35 #1 (Debian))
	id 1EMjfM-00050x-00; Tue, 04 Oct 2005 20:04:56 +1000
Date: Tue, 4 Oct 2005 12:04:56 +0200
From: Martijn van Oosterhout <kleptog@svana.org>
To: Simon Riggs <simon@2ndquadrant.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>,
	Ron Peacetree <rjpeace@earthlink.net>, pgsql-hackers@postgresql.org
Subject: Re: [PERFORM] A Better External Sort?
Message-ID: <20051004100441.GC17589@svana.org>
Reply-To: Martijn van Oosterhout <kleptog@svana.org>
References: 
 <18329659.1128188552696.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
	<20051001215602.GG13830@svana.org> <29837.1128223567@sss.pgh.pa.us>
	<20051002123240.GA30492@svana.org>
	<20051002193835.GJ30492@svana.org>
	<1128376292.8603.142.camel@localhost.localdomain>
Mime-Version: 1.0
Content-Type: multipart/signed; micalg=pgp-sha1;
	protocol="application/pgp-signature"; boundary="oJ71EGRlYNjSvfq7"
Content-Disposition: inline
In-Reply-To: <1128376292.8603.142.camel@localhost.localdomain>
User-Agent: Mutt/1.3.28i
X-PGP-Key-ID: Length=1024; ID=0x0DC67BE6
X-PGP-Key-Fingerprint: 295F A899 A81A 156D B522  48A7 6394 F08A 0DC6 7BE6
X-PGP-Key-URL: <http://svana.org/kleptog/0DC67BE6.pgp.asc>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.008 required=5 tests=[AWL=0.008]
X-Spam-Level: 
X-Archive-Number: 200510/161
X-Sequence-Number: 74020


--oJ71EGRlYNjSvfq7
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Mon, Oct 03, 2005 at 10:51:32PM +0100, Simon Riggs wrote:
> > Basically, I recommend adding "-Winline -finline-limit-1500" to the
> > default build while we discuss other options.
>=20
> I add -Winline but get no warnings. Why would I use -finline-limit-1500?
>=20
> I'm interested, but uncertain as to what difference this makes. Surely
> using -O3 works fine?

Different versions of gcc have different ideas of when a function can
be inlined. From my reading of the documentation, this decision is
independant of optimisation level. Maybe your gcc version has a limit
higher than 1500 by default.
--=20
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

--oJ71EGRlYNjSvfq7
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQFDQlO4IB7bNG8LQkwRAi4sAJ9vNeAbCjfuFfVxd49c6pwLDy4eSACeL023
HDxAYHDb4vP8PFsJtwGrgXQ=
=ybxt
-----END PGP SIGNATURE-----

--oJ71EGRlYNjSvfq7--

From pgsql-performance-owner@postgresql.org  Wed Oct  5 03:26:01 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 05414D9FD8
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 07:10:40 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 47276-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 10:10:35 +0000 (GMT)
Received: from floppy.pyrenet.fr (news.pyrenet.fr [194.116.145.2])
	by svr1.postgresql.org (Postfix) with ESMTP id 9D7C0D9FEF
	for <pgsql-performance@postgresql.org>;
	Tue,  4 Oct 2005 07:10:32 -0300 (ADT)
Received: by floppy.pyrenet.fr (Postfix, from userid 106)
	id 928A531059; Tue,  4 Oct 2005 12:10:35 +0200 (MET DST)
From: "Jan Aerts" <jan.aerts@gmail.com>
X-Newsgroups: pgsql.performance
Subject: Re: index on custom function; explain
Date: 4 Oct 2005 03:10:28 -0700
Organization: http://groups.google.com
Lines: 10
Message-ID: <1128420628.326795.158780@g47g2000cwa.googlegroups.com>
References: <1128352451.312090.37640@g44g2000cwa.googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
X-Complaints-To: groups-abuse@google.com
In-Reply-To: <1128352451.312090.37640@g44g2000cwa.googlegroups.com>
User-Agent: G2/0.2
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB;
	rv:1.7.8) Gecko/20050511 Firefox/1.0.4,gzip(gfe),gzip(gfe)
X-HTTP-Via: 1.1 arcl11.cc.bbsrc.ac.uk:8080 (squid/2.5.STABLE9)
Complaints-To: groups-abuse@google.com
Injection-Info: g47g2000cwa.googlegroups.com; posting-host=149.155.96.6;
	posting-account=Qght7Q0AAACFr4FK4UX3lLicX5ApbR8D
To: pgsql-performance@postgresql.org
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0 required=5 tests=[none]
X-Spam-Level: 
X-Archive-Number: 200510/72
X-Sequence-Number: 14840

Some additional thoughts: what appears to take the most time (i.e.
account for the highest cost in the explain), is _not_ running the
function itself (cost=0.00..0.01), but comparing the result from that
function with the name1 column in the mappings table
(cost=0.00..35935.05). Am I right? (See EXPLAIN in previous post.) If
so: that's pretty strange, because the name1-column in the mappings
table is indexed...

jan.


From pgsql-performance-owner@postgresql.org  Tue Oct  4 07:33:57 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id C61EBD9FF7
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 07:33:56 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 52491-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 10:33:49 +0000 (GMT)
Received: from viefep18-int.chello.at (unknown [213.46.255.21])
	by svr1.postgresql.org (Postfix) with ESMTP id 99401D9FF3
	for <pgsql-performance@postgresql.org>;
	Tue,  4 Oct 2005 07:33:48 -0300 (ADT)
Received: from [213.47.56.254] by viefep18-int.chello.at
	(InterMail vM.6.01.04.04 201-2131-118-104-20050224) with ESMTP
	id <20051004103350.ZNIM4453.viefep18-int.chello.at@[213.47.56.254]>
	for <pgsql-performance@postgresql.org>;
	Tue, 4 Oct 2005 12:33:50 +0200
Message-ID: <43425A0E.2050305@foo.at>
Date: Tue, 04 Oct 2005 12:31:42 +0200
From: Stefan Weiss <spaceman@foo.at>
Organization: Foo Orbital Operations
User-Agent: Mozilla Thunderbird 1.0.7 (X11/20050923)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: pgsql-performance@postgresql.org
Subject: Re: Is There Any Way ....
References: <EKEMKEFLOMKDDLIALABIMECFCDAA.lvaningen@esncc.com>
In-Reply-To: <EKEMKEFLOMKDDLIALABIMECFCDAA.lvaningen@esncc.com>
Content-Type: text/plain; charset=ISO-8859-15
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.01 required=5 tests=[AWL=0.010]
X-Spam-Level: 
X-Archive-Number: 200510/40
X-Sequence-Number: 14808

On 2005-09-30 01:21, Lane Van Ingen wrote:
>   (3) Assure that a disk-based table is always in memory (outside of keeping
> it in
>       memory buffers as a result of frequent activity which would prevent
> LRU
>       operations from taking it out) ?

I was wondering about this too. IMO it would be useful to have a way to tell
PG that some tables were needed frequently, and should be cached if
possible. This would allow application developers to consider joins with
these tables as "cheap", even when querying on columns that are not indexed.
I'm thinking about smallish tables like users, groups, *types, etc which
would be needed every 2-3 queries, but might be swept out of RAM by one
large query in between. Keeping a table like "users" on a RAM fs would not
be an option, because the information is not volatile.


cheers,
stefan

From pgsql-hackers-owner@postgresql.org  Tue Oct  4 08:24:39 2005
X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 7FE46D9FF8
	for <pgsql-hackers-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 08:24:38 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 99502-02
	for <pgsql-hackers-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 11:24:34 +0000 (GMT)
Received: from smtp.nildram.co.uk (smtp.nildram.co.uk [195.112.4.54])
	by svr1.postgresql.org (Postfix) with ESMTP id 52D0FD9FF7
	for <pgsql-hackers@postgresql.org>;
	Tue,  4 Oct 2005 08:24:36 -0300 (ADT)
Received: from 192.168.0.3 (unknown [84.12.188.233])
	by smtp.nildram.co.uk (Postfix) with ESMTP
	id 48DC724D4B1; Tue,  4 Oct 2005 12:24:37 +0100 (BST)
Subject: Re: [PERFORM] A Better External Sort?
From: Simon Riggs <simon@2ndquadrant.com>
To: Martijn van Oosterhout <kleptog@svana.org>
Cc: Tom Lane <tgl@sss.pgh.pa.us>,
	Ron Peacetree <rjpeace@earthlink.net>, pgsql-hackers@postgresql.org
In-Reply-To: <20051004100441.GC17589@svana.org>
References: 
 <18329659.1128188552696.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
	<20051001215602.GG13830@svana.org> <29837.1128223567@sss.pgh.pa.us>
	<20051002123240.GA30492@svana.org> <20051002193835.GJ30492@svana.org>
	<1128376292.8603.142.camel@localhost.localdomain>
	<20051004100441.GC17589@svana.org>
Content-Type: text/plain
Organization: 2nd Quadrant
Date: Tue, 04 Oct 2005 12:24:54 +0100
Message-Id: <1128425094.8603.296.camel@localhost.localdomain>
Mime-Version: 1.0
X-Mailer: Evolution 2.0.2 (2.0.2-3) 
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.054 required=5 tests=[AWL=0.004,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/167
X-Sequence-Number: 74026

On Tue, 2005-10-04 at 12:04 +0200, Martijn van Oosterhout wrote:
> On Mon, Oct 03, 2005 at 10:51:32PM +0100, Simon Riggs wrote:
> > > Basically, I recommend adding "-Winline -finline-limit-1500" to the
> > > default build while we discuss other options.
> > 
> > I add -Winline but get no warnings. Why would I use -finline-limit-1500?
> > 
> > I'm interested, but uncertain as to what difference this makes. Surely
> > using -O3 works fine?

How did you determine the 1500 figure? Can you give some more info to
surround that recommendation to allow everybody to evaluate it?

Best Regards, Simon Riggs


From pgsql-hackers-owner@postgresql.org  Tue Oct  4 09:26:12 2005
X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 93E88D9F4B
	for <pgsql-hackers-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 09:26:02 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 13864-09
	for <pgsql-hackers-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 12:24:58 +0000 (GMT)
Received: from svana.org (svana.org [203.20.62.76])
	by svr1.postgresql.org (Postfix) with ESMTP id 9F856D72AA
	for <pgsql-hackers@postgresql.org>;
	Tue,  4 Oct 2005 09:25:00 -0300 (ADT)
Received: from kleptog by svana.org with local (Exim 3.35 #1 (Debian))
	id 1EMlqh-0005fr-00; Tue, 04 Oct 2005 22:24:47 +1000
Date: Tue, 4 Oct 2005 14:24:46 +0200
From: Martijn van Oosterhout <kleptog@svana.org>
To: Simon Riggs <simon@2ndquadrant.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>,
	Ron Peacetree <rjpeace@earthlink.net>, pgsql-hackers@postgresql.org
Subject: Re: [PERFORM] A Better External Sort?
Message-ID: <20051004122443.GF17589@svana.org>
Reply-To: Martijn van Oosterhout <kleptog@svana.org>
References: 
 <18329659.1128188552696.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
	<20051001215602.GG13830@svana.org> <29837.1128223567@sss.pgh.pa.us>
	<20051002123240.GA30492@svana.org>
	<20051002193835.GJ30492@svana.org>
	<1128376292.8603.142.camel@localhost.localdomain>
	<20051004100441.GC17589@svana.org>
	<1128425094.8603.296.camel@localhost.localdomain>
Mime-Version: 1.0
Content-Type: multipart/signed; micalg=pgp-sha1;
	protocol="application/pgp-signature"; boundary="6v9BRtpmy+umdQlo"
Content-Disposition: inline
In-Reply-To: <1128425094.8603.296.camel@localhost.localdomain>
User-Agent: Mutt/1.3.28i
X-PGP-Key-ID: Length=1024; ID=0x0DC67BE6
X-PGP-Key-Fingerprint: 295F A899 A81A 156D B522  48A7 6394 F08A 0DC6 7BE6
X-PGP-Key-URL: <http://svana.org/kleptog/0DC67BE6.pgp.asc>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.008 required=5 tests=[AWL=0.008]
X-Spam-Level: 
X-Archive-Number: 200510/169
X-Sequence-Number: 74028


--6v9BRtpmy+umdQlo
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Tue, Oct 04, 2005 at 12:24:54PM +0100, Simon Riggs wrote:
> How did you determine the 1500 figure? Can you give some more info to
> surround that recommendation to allow everybody to evaluate it?

kleptog@vali:~/dl/cvs/pgsql-local/src/backend/utils/sort$ gcc -finline-limi=
t-1000 -Winline -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wendif-labe=
ls -fno-strict-aliasing -g -I../../../../src/include -D_GNU_SOURCE   -c -o =
tuplesort.o tuplesort.c
tuplesort.c: In function 'applySortFunction':
tuplesort.c:1833: warning: inlining failed in call to 'inlineApplySortFunct=
ion'
tuplesort.c:1906: warning: called from here
tuplesort.c: In function 'comparetup_heap':
tuplesort.c:1833: warning: inlining failed in call to 'inlineApplySortFunct=
ion'
tuplesort.c:1937: warning: called from here
tuplesort.c: In function 'comparetup_index':
tuplesort.c:1833: warning: inlining failed in call to 'inlineApplySortFunct=
ion'
tuplesort.c:2048: warning: called from here
tuplesort.c: In function 'comparetup_datum':
tuplesort.c:1833: warning: inlining failed in call to 'inlineApplySortFunct=
ion'
tuplesort.c:2167: warning: called from here
kleptog@vali:~/dl/cvs/pgsql-local/src/backend/utils/sort$ gcc -finline-limi=
t-1500 -Winline -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wendif-labe=
ls -fno-strict-aliasing -g -I../../../../src/include -D_GNU_SOURCE   -c -o =
tuplesort.o tuplesort.c
<no warnings>

A quick binary search puts the cutoff between 1200 and 1300. Given
version variation I picked a nice round number, 1500.

Ugh, that's for -O2, for -O3 and above it needs to be 4100 to work.
Maybe we should go for 5000 or so.

I'm using: gcc (GCC) 3.3.5 (Debian 1:3.3.5-13)

Have a nice day,
--=20
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

--6v9BRtpmy+umdQlo
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQFDQnSKIB7bNG8LQkwRAgpdAJ4u+KmNpMaHY/WknCkvep4N5YGL3QCfS2qR
OU90plt1mOZZ9UjVH/9oTeI=
=Axn9
-----END PGP SIGNATURE-----

--6v9BRtpmy+umdQlo--

From pgsql-hackers-owner@postgresql.org  Tue Oct  4 11:44:17 2005
X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id B2469D9A8D
	for <pgsql-hackers-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 11:06:24 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 32300-10
	for <pgsql-hackers-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 14:06:20 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id 65077DA001
	for <pgsql-hackers@postgresql.org>;
	Tue,  4 Oct 2005 11:06:22 -0300 (ADT)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j94E6OP3007789;
	Tue, 4 Oct 2005 10:06:24 -0400 (EDT)
To: Martijn van Oosterhout <kleptog@svana.org>
Cc: Simon Riggs <simon@2ndquadrant.com>,
	Ron Peacetree <rjpeace@earthlink.net>, pgsql-hackers@postgresql.org
Subject: Re: [PERFORM] A Better External Sort? 
In-reply-to: <20051004122443.GF17589@svana.org> 
References: 
 <18329659.1128188552696.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
	<20051001215602.GG13830@svana.org> <29837.1128223567@sss.pgh.pa.us>
	<20051002123240.GA30492@svana.org>
	<20051002193835.GJ30492@svana.org>
	<1128376292.8603.142.camel@localhost.localdomain>
	<20051004100441.GC17589@svana.org>
	<1128425094.8603.296.camel@localhost.localdomain>
	<20051004122443.GF17589@svana.org>
Comments: In-reply-to Martijn van Oosterhout <kleptog@svana.org>
	message dated "Tue, 04 Oct 2005 14:24:46 +0200"
Date: Tue, 04 Oct 2005 10:06:24 -0400
Message-ID: <7788.1128434784@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/175
X-Sequence-Number: 74034

Martijn van Oosterhout <kleptog@svana.org> writes:
> A quick binary search puts the cutoff between 1200 and 1300. Given
> version variation I picked a nice round number, 1500.

> Ugh, that's for -O2, for -O3 and above it needs to be 4100 to work.
> Maybe we should go for 5000 or so.

> I'm using: gcc (GCC) 3.3.5 (Debian 1:3.3.5-13)

I don't know what the units of this number are, but it's apparently far
too gcc-version-dependent to consider putting into our build scripts.
Using gcc version 4.0.1 20050727 (current Fedora Core 4 compiler) on
i386, and compiling tuplesort.c as you did, I find:
	-O2: warning goes away between 800 and 900
	-O3: warning is always there (tried values up to 10000000)
(the latter behavior may indicate a bug, not sure).

What's even more interesting is that the warning does not appear in
either case if I omit -finline-limit --- so the default value is plenty.

At least on this particular compiler, the proposed switch would be
counterproductive.

			regards, tom lane

From pgsql-hackers-owner@postgresql.org  Tue Oct  4 12:22:29 2005
X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 0E328DA02B
	for <pgsql-hackers-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 11:31:09 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 39717-03
	for <pgsql-hackers-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 14:31:00 +0000 (GMT)
Received: from svana.org (svana.org [203.20.62.76])
	by svr1.postgresql.org (Postfix) with ESMTP id 8A49ED9FE4
	for <pgsql-hackers@postgresql.org>;
	Tue,  4 Oct 2005 11:31:00 -0300 (ADT)
Received: from kleptog by svana.org with local (Exim 3.35 #1 (Debian))
	id 1EMnoZ-0006GX-00; Wed, 05 Oct 2005 00:30:43 +1000
Date: Tue, 4 Oct 2005 16:30:42 +0200
From: Martijn van Oosterhout <kleptog@svana.org>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Simon Riggs <simon@2ndquadrant.com>,
	Ron Peacetree <rjpeace@earthlink.net>, pgsql-hackers@postgresql.org
Subject: Re: [PERFORM] A Better External Sort?
Message-ID: <20051004143041.GH17589@svana.org>
Reply-To: Martijn van Oosterhout <kleptog@svana.org>
References: 
 <18329659.1128188552696.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
	<20051001215602.GG13830@svana.org> <29837.1128223567@sss.pgh.pa.us>
	<20051002123240.GA30492@svana.org>
	<20051002193835.GJ30492@svana.org>
	<1128376292.8603.142.camel@localhost.localdomain>
	<20051004100441.GC17589@svana.org>
	<1128425094.8603.296.camel@localhost.localdomain>
	<20051004122443.GF17589@svana.org> <7788.1128434784@sss.pgh.pa.us>
Mime-Version: 1.0
Content-Type: multipart/signed; micalg=pgp-sha1;
	protocol="application/pgp-signature"; boundary="82evfD9Ogz2JrdWZ"
Content-Disposition: inline
In-Reply-To: <7788.1128434784@sss.pgh.pa.us>
User-Agent: Mutt/1.3.28i
X-PGP-Key-ID: Length=1024; ID=0x0DC67BE6
X-PGP-Key-Fingerprint: 295F A899 A81A 156D B522  48A7 6394 F08A 0DC6 7BE6
X-PGP-Key-URL: <http://svana.org/kleptog/0DC67BE6.pgp.asc>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.008 required=5 tests=[AWL=0.008]
X-Spam-Level: 
X-Archive-Number: 200510/182
X-Sequence-Number: 74041


--82evfD9Ogz2JrdWZ
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Tue, Oct 04, 2005 at 10:06:24AM -0400, Tom Lane wrote:
> Martijn van Oosterhout <kleptog@svana.org> writes:
> > I'm using: gcc (GCC) 3.3.5 (Debian 1:3.3.5-13)
>=20
> I don't know what the units of this number are, but it's apparently far
> too gcc-version-dependent to consider putting into our build scripts.
> Using gcc version 4.0.1 20050727 (current Fedora Core 4 compiler) on
> i386, and compiling tuplesort.c as you did, I find:
> 	-O2: warning goes away between 800 and 900
> 	-O3: warning is always there (tried values up to 10000000)
> (the latter behavior may indicate a bug, not sure).

Facsinating. The fact that the warning goes away if you don't specify
-finline-limit seems to indicate they've gotten smarter. Or a bug.
We'd have to check the asm code to see if it's actually inlined or
not.

Two options:
1. Add -Winline so we can at least be aware of when it's (not) happening.
2. If we can't get gcc to reliably inline, maybe we need to consider
other options?

In particular, move the isNull test statements out since they are ones
the optimiser can use to best effect.

Add if we put in -Winline, it would be visible to users while
compiling so they can tweak their own build options (if they care).
--=20
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

--82evfD9Ogz2JrdWZ
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQFDQpIQIB7bNG8LQkwRAiz/AJ9uTse88BNBE1Tpx2BO++JWu1dAGQCfah2X
P3fB56iJZap07zm0pfC7EZ4=
=KEhp
-----END PGP SIGNATURE-----

--82evfD9Ogz2JrdWZ--

From pgsql-performance-owner@postgresql.org  Tue Oct  4 12:01:27 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 5F478D9FAD
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 11:42:17 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 40266-06
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 14:42:09 +0000 (GMT)
Received: from TWMAIL.ESNCC.COM (static-66-173-159-28.t1.cavtel.net
	[66.173.159.28])
	by svr1.postgresql.org (Postfix) with ESMTP id B0FDAD9A8D
	for <pgsql-performance@postgresql.org>;
	Tue,  4 Oct 2005 11:42:10 -0300 (ADT)
Received: from spawar2i8uvlb9 ([150.125.117.63]) by TWMAIL.ESNCC.COM with
	Microsoft SMTPSVC(5.0.2195.6713); Tue, 4 Oct 2005 10:42:14 -0400
From: "Lane Van Ingen" <lvaningen@esncc.com>
To: "Stefan Weiss" <spaceman@foo.at>,
	<pgsql-performance@postgresql.org>
Subject: Re: Is There Any Way ....
Date: Tue, 4 Oct 2005 10:45:48 -0400
Message-ID: <EKEMKEFLOMKDDLIALABIOEEICDAA.lvaningen@esncc.com>
MIME-Version: 1.0
Content-Type: text/plain;
	charset="ISO-8859-15"
Content-Transfer-Encoding: 7bit
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0)
In-Reply-To: <43425A0E.2050305@foo.at>
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.181
Importance: Normal
X-OriginalArrivalTime: 04 Oct 2005 14:42:14.0851 (UTC)
	FILETIME=[CFC6C130:01C5C8F1]
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.058 required=5 tests=[AWL=0.008,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/41
X-Sequence-Number: 14809

Yes, Stefan, the kind of usage you are mentioning is exactly why I was
asking.

-----Original Message-----
From: pgsql-performance-owner@postgresql.org
[mailto:pgsql-performance-owner@postgresql.org]On Behalf Of Stefan Weiss
Sent: Tuesday, October 04, 2005 6:32 AM
To: pgsql-performance@postgresql.org
Subject: Re: [PERFORM] Is There Any Way ....


On 2005-09-30 01:21, Lane Van Ingen wrote:
>   (3) Assure that a disk-based table is always in memory (outside of
keeping
> it in
>       memory buffers as a result of frequent activity which would prevent
> LRU
>       operations from taking it out) ?

I was wondering about this too. IMO it would be useful to have a way to tell
PG that some tables were needed frequently, and should be cached if
possible. This would allow application developers to consider joins with
these tables as "cheap", even when querying on columns that are not indexed.
I'm thinking about smallish tables like users, groups, *types, etc which
would be needed every 2-3 queries, but might be swept out of RAM by one
large query in between. Keeping a table like "users" on a RAM fs would not
be an option, because the information is not volatile.


cheers,
stefan

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings



From pgsql-hackers-owner@postgresql.org  Tue Oct  4 12:06:42 2005
X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id C0C74D9FE5
	for <pgsql-hackers-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 11:56:38 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 44087-10
	for <pgsql-hackers-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 14:56:33 +0000 (GMT)
Received: from smtp.nildram.co.uk (smtp.nildram.co.uk [195.112.4.54])
	by svr1.postgresql.org (Postfix) with ESMTP id A4BCFD9F99
	for <pgsql-hackers@postgresql.org>;
	Tue,  4 Oct 2005 11:56:34 -0300 (ADT)
Received: from 192.168.0.3 (unknown [84.12.188.233])
	by smtp.nildram.co.uk (Postfix) with ESMTP
	id 8C3CB251928; Tue,  4 Oct 2005 15:56:36 +0100 (BST)
Subject: Re: [PERFORM] A Better External Sort?
From: Simon Riggs <simon@2ndquadrant.com>
To: Martijn van Oosterhout <kleptog@svana.org>
Cc: Tom Lane <tgl@sss.pgh.pa.us>,
	Ron Peacetree <rjpeace@earthlink.net>, pgsql-hackers@postgresql.org
In-Reply-To: <20051004143041.GH17589@svana.org>
References: 
 <18329659.1128188552696.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
	<20051001215602.GG13830@svana.org> <29837.1128223567@sss.pgh.pa.us>
	<20051002123240.GA30492@svana.org> <20051002193835.GJ30492@svana.org>
	<1128376292.8603.142.camel@localhost.localdomain>
	<20051004100441.GC17589@svana.org>
	<1128425094.8603.296.camel@localhost.localdomain>
	<20051004122443.GF17589@svana.org> <7788.1128434784@sss.pgh.pa.us>
	<20051004143041.GH17589@svana.org>
Content-Type: text/plain
Organization: 2nd Quadrant
Date: Tue, 04 Oct 2005 15:56:53 +0100
Message-Id: <1128437813.8603.305.camel@localhost.localdomain>
Mime-Version: 1.0
X-Mailer: Evolution 2.0.2 (2.0.2-3) 
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.053 required=5 tests=[AWL=0.003,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/177
X-Sequence-Number: 74036

On Tue, 2005-10-04 at 16:30 +0200, Martijn van Oosterhout wrote:
> On Tue, Oct 04, 2005 at 10:06:24AM -0400, Tom Lane wrote:
> > Martijn van Oosterhout <kleptog@svana.org> writes:
> > > I'm using: gcc (GCC) 3.3.5 (Debian 1:3.3.5-13)
> > 
> > I don't know what the units of this number are, but it's apparently far
> > too gcc-version-dependent to consider putting into our build scripts.
> > Using gcc version 4.0.1 20050727 (current Fedora Core 4 compiler) on
> > i386, and compiling tuplesort.c as you did, I find:
> > 	-O2: warning goes away between 800 and 900
> > 	-O3: warning is always there (tried values up to 10000000)
> > (the latter behavior may indicate a bug, not sure).
>
> Facsinating. The fact that the warning goes away if you don't specify
> -finline-limit seems to indicate they've gotten smarter. Or a bug.
> We'd have to check the asm code to see if it's actually inlined or
> not.

I've been using gcc 3.4 and saw no warning when using either "-Winline"
or "-O3 -Winline".

Martijn, at the moment it sounds like this is a feature that we no
longer need to support - even if we should have done for previous
releases.

Best Regards, Simon Riggs


From pgsql-hackers-owner@postgresql.org  Tue Oct  4 12:07:15 2005
X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 7E5D9D9B4D
	for <pgsql-hackers-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 12:02:09 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 47321-01
	for <pgsql-hackers-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 15:02:04 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id B1519D9FE3
	for <pgsql-hackers@postgresql.org>;
	Tue,  4 Oct 2005 12:02:03 -0300 (ADT)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j94F20qI008304;
	Tue, 4 Oct 2005 11:02:00 -0400 (EDT)
To: Martijn van Oosterhout <kleptog@svana.org>
Cc: Simon Riggs <simon@2ndquadrant.com>,
	Ron Peacetree <rjpeace@earthlink.net>, pgsql-hackers@postgresql.org
Subject: Re: [PERFORM] A Better External Sort? 
In-reply-to: <20051004143041.GH17589@svana.org> 
References: 
 <18329659.1128188552696.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
	<20051001215602.GG13830@svana.org> <29837.1128223567@sss.pgh.pa.us>
	<20051002123240.GA30492@svana.org>
	<20051002193835.GJ30492@svana.org>
	<1128376292.8603.142.camel@localhost.localdomain>
	<20051004100441.GC17589@svana.org>
	<1128425094.8603.296.camel@localhost.localdomain>
	<20051004122443.GF17589@svana.org> <7788.1128434784@sss.pgh.pa.us>
	<20051004143041.GH17589@svana.org>
Comments: In-reply-to Martijn van Oosterhout <kleptog@svana.org>
	message dated "Tue, 04 Oct 2005 16:30:42 +0200"
Date: Tue, 04 Oct 2005 11:01:59 -0400
Message-ID: <8303.1128438119@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/178
X-Sequence-Number: 74037

Martijn van Oosterhout <kleptog@svana.org> writes:
> 1. Add -Winline so we can at least be aware of when it's (not) happening.

Yeah, I agree with that part, just not with adding a fixed -finline-limit
value.

While on the subject of gcc warnings ... if I touch that code, I want to
remove -Wold-style-definition from the default flags, too.  It's causing
much more clutter than it's worth, because all the flex files generate
several such warnings.

			regards, tom lane

From pgsql-hackers-owner@postgresql.org  Tue Oct  4 12:31:00 2005
X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 0A99BD9EA8
	for <pgsql-hackers-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 12:23:58 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 49204-07
	for <pgsql-hackers-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 15:23:54 +0000 (GMT)
Received: from svana.org (svana.org [203.20.62.76])
	by svr1.postgresql.org (Postfix) with ESMTP id 69128D99E3
	for <pgsql-hackers@postgresql.org>;
	Tue,  4 Oct 2005 12:23:53 -0300 (ADT)
Received: from kleptog by svana.org with local (Exim 3.35 #1 (Debian))
	id 1EModp-0006UD-00; Wed, 05 Oct 2005 01:23:41 +1000
Date: Tue, 4 Oct 2005 17:23:41 +0200
From: Martijn van Oosterhout <kleptog@svana.org>
To: Simon Riggs <simon@2ndquadrant.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>,
	Ron Peacetree <rjpeace@earthlink.net>, pgsql-hackers@postgresql.org
Subject: Re: [PERFORM] A Better External Sort?
Message-ID: <20051004152336.GI17589@svana.org>
Reply-To: Martijn van Oosterhout <kleptog@svana.org>
References: <29837.1128223567@sss.pgh.pa.us>
 <20051002123240.GA30492@svana.org>
	<20051002193835.GJ30492@svana.org>
	<1128376292.8603.142.camel@localhost.localdomain>
	<20051004100441.GC17589@svana.org>
	<1128425094.8603.296.camel@localhost.localdomain>
	<20051004122443.GF17589@svana.org> <7788.1128434784@sss.pgh.pa.us>
	<20051004143041.GH17589@svana.org>
	<1128437813.8603.305.camel@localhost.localdomain>
Mime-Version: 1.0
Content-Type: multipart/signed; micalg=pgp-sha1;
	protocol="application/pgp-signature"; boundary="nO3oAMapP4dBpMZi"
Content-Disposition: inline
In-Reply-To: <1128437813.8603.305.camel@localhost.localdomain>
User-Agent: Mutt/1.3.28i
X-PGP-Key-ID: Length=1024; ID=0x0DC67BE6
X-PGP-Key-Fingerprint: 295F A899 A81A 156D B522  48A7 6394 F08A 0DC6 7BE6
X-PGP-Key-URL: <http://svana.org/kleptog/0DC67BE6.pgp.asc>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.008 required=5 tests=[AWL=0.008]
X-Spam-Level: 
X-Archive-Number: 200510/185
X-Sequence-Number: 74044


--nO3oAMapP4dBpMZi
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Tue, Oct 04, 2005 at 03:56:53PM +0100, Simon Riggs wrote:
> I've been using gcc 3.4 and saw no warning when using either "-Winline"
> or "-O3 -Winline".

Ok, I've just installed 3.4 and verified that. I examined the asm code
and gcc is inlining it. I concede, at this point just throw in -Winline
and monitor the situation.

As an aside, the *_getattr calls end up a bit suboptimal though. It's
producing code like:

  cmp attlen, 4
  je $elsewhere1
  cmp attlen, 2
  je $elsewhere2
  ld byte
here:

--- much later ---
elsewhere1:
  ld integer
  jmp $here
elsewhere2:
  ld short
  jmp $here

No idea whether we want to go down the path of hinting to gcc which
size will be the most common.

Have a nice day,
--=20
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

--nO3oAMapP4dBpMZi
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQFDQp53IB7bNG8LQkwRAvUxAJsEYOuGCnim4f9KH+ti0GpGFJUGFQCfXoYM
FKbEjhs0YGM0sNH0xmmtVEc=
=ueRj
-----END PGP SIGNATURE-----

--nO3oAMapP4dBpMZi--

From pgsql-hackers-owner@postgresql.org  Tue Oct  4 14:16:32 2005
X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id A20F6DA028
	for <pgsql-hackers-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 14:16:30 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 75860-03
	for <pgsql-hackers-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 17:16:24 +0000 (GMT)
Received: from mail.envyfinancial.com (unknown [206.248.142.186])
	by svr1.postgresql.org (Postfix) with ESMTP id 85C12DA039
	for <pgsql-hackers@postgresql.org>;
	Tue,  4 Oct 2005 14:16:23 -0300 (ADT)
Received: from localhost (localhost.localdomain [127.0.0.1])
	by mail.envyfinancial.com (Postfix) with ESMTP id DC62A234AF;
	Tue,  4 Oct 2005 13:02:53 -0400 (EDT)
Received: from mail.envyfinancial.com ([127.0.0.1])
	by localhost (mark.mielke.cc [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 26456-02; Tue,  4 Oct 2005 13:02:53 -0400 (EDT)
Received: by mail.envyfinancial.com (Postfix, from userid 500)
	id 9A1F3234A9; Tue,  4 Oct 2005 13:02:53 -0400 (EDT)
Date: Tue, 4 Oct 2005 13:02:53 -0400
From: mark@mark.mielke.cc
To: Martijn van Oosterhout <kleptog@svana.org>
Cc: Simon Riggs <simon@2ndquadrant.com>,
	Tom Lane <tgl@sss.pgh.pa.us>, Ron Peacetree <rjpeace@earthlink.net>,
	pgsql-hackers@postgresql.org
Subject: Re: [PERFORM] A Better External Sort?
Message-ID: <20051004170253.GA26380@mark.mielke.cc>
References: <20051002123240.GA30492@svana.org>
	<20051002193835.GJ30492@svana.org>
	<1128376292.8603.142.camel@localhost.localdomain>
	<20051004100441.GC17589@svana.org>
	<1128425094.8603.296.camel@localhost.localdomain>
	<20051004122443.GF17589@svana.org> <7788.1128434784@sss.pgh.pa.us>
	<20051004143041.GH17589@svana.org>
	<1128437813.8603.305.camel@localhost.localdomain>
	<20051004152336.GI17589@svana.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20051004152336.GI17589@svana.org>
User-Agent: Mutt/1.4.2.1i
X-Virus-Scanned: amavisd-new at mail.envyfinancial.com
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.193 required=5 tests=[AWL=0.015, NO_REAL_NAME=0.178]
X-Spam-Level: 
X-Archive-Number: 200510/191
X-Sequence-Number: 74050

On Tue, Oct 04, 2005 at 05:23:41PM +0200, Martijn van Oosterhout wrote:
> On Tue, Oct 04, 2005 at 03:56:53PM +0100, Simon Riggs wrote:
> > I've been using gcc 3.4 and saw no warning when using either "-Winline"
> > or "-O3 -Winline".
> Ok, I've just installed 3.4 and verified that. I examined the asm code
> and gcc is inlining it. I concede, at this point just throw in -Winline
> and monitor the situation.
> As an aside, the *_getattr calls end up a bit suboptimal though. It's
> producing code like:
>   cmp attlen, 4
>   je $elsewhere1
>   cmp attlen, 2
>   je $elsewhere2
>   ld byte
> here:
> --- much later ---
> elsewhere1:
>   ld integer
>   jmp $here
> elsewhere2:
>   ld short
>   jmp $here
> No idea whether we want to go down the path of hinting to gcc which
> size will be the most common.

If it will very frequently be one value, and not the other values, I
don't see why we wouldn't want to hint? #ifdef it to a expand to just
the expression if not using GCC. It's important that we know that the
value would be almost always a certain value, however, as GCC will try
to make the path for the expected value as fast as possible, at the
cost of an unexpected value being slower.

  __builtin_expect (long EXP, long C)

     You may use `__builtin_expect' to provide the compiler with branch
     prediction information.  In general, you should prefer to use
     actual profile feedback for this (`-fprofile-arcs'), as
     programmers are notoriously bad at predicting how their programs
     actually perform.  However, there are applications in which this
     data is hard to collect.

     The return value is the value of EXP, which should be an integral
     expression.  The value of C must be a compile-time constant.  The
     semantics of the built-in are that it is expected that EXP == C.
     For example:

          if (__builtin_expect (x, 0))
            foo ();

     would indicate that we do not expect to call `foo', since we
     expect `x' to be zero.  Since you are limited to integral
     expressions for EXP, you should use constructions such as

          if (__builtin_expect (ptr != NULL, 1))
            error ();

     when testing pointer or floating-point values.

Cheers,
mark

-- 
mark@mielke.cc / markm@ncf.ca / markm@nortel.com     __________________________
.  .  _  ._  . .   .__    .  . ._. .__ .   . . .__  | Neighbourhood Coder
|\/| |_| |_| |/    |_     |\/|  |  |_  |   |/  |_   | 
|  | | | | \ | \   |__ .  |  | .|. |__ |__ | \ |__  | Ottawa, Ontario, Canada

  One ring to rule them all, one ring to find them, one ring to bring them all
                       and in the darkness bind them...

                           http://mark.mielke.cc/


From pgsql-performance-owner@postgresql.org  Tue Oct  4 15:55:23 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id AF7BDD9FAD
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 15:55:20 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 22913-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 18:55:16 +0000 (GMT)
Received: from flake.decibel.org (flake.decibel.org [67.100.216.10])
	by svr1.postgresql.org (Postfix) with ESMTP id 564A1D6F63
	for <pgsql-performance@postgresql.org>;
	Tue,  4 Oct 2005 15:55:12 -0300 (ADT)
Received: by flake.decibel.org (Postfix, from userid 1001)
	id 7CB7D15257; Tue,  4 Oct 2005 13:55:13 -0500 (CDT)
Date: Tue, 4 Oct 2005 13:55:13 -0500
From: "Jim C. Nasby" <jnasby@pervasive.com>
To: Rajesh Kumar Mallah <mallah.rajesh@gmail.com>
Cc: Gavin Sherry <swm@alcove.com.au>,
	pgsql-performance@postgresql.org
Subject: Re: Slow concurrent update of same row in a given table
Message-ID: <20051004185513.GS40138@pervasive.com>
References: <a97c770305092805271ff5e83f@mail.gmail.com>
	<Pine.LNX.4.58.0509282245040.19538@linuxworld.com.au>
	<a97c7703050928104421786201@mail.gmail.com>
	<Pine.LNX.4.58.0509290757220.22312@linuxworld.com.au>
	<a97c77030509281929ca316a1@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <a97c77030509281929ca316a1@mail.gmail.com>
X-Operating-System: FreeBSD 4.11-RELEASE-p10 i386
X-Distributed: Join the Effort!  http://www.distributed.net
User-Agent: Mutt/1.5.9i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.008 required=5 tests=[AWL=0.008]
X-Spam-Level: 
X-Archive-Number: 200510/42
X-Sequence-Number: 14810

On Thu, Sep 29, 2005 at 07:59:34AM +0530, Rajesh Kumar Mallah wrote:
> > I see. These problems regularly come up in database design. The best thing
> > you can do is modify your database design/application such that instead of
> > incrementing a count in a single row, you insert a row into a table,
> > recording the 'dispatch_id'. Counting the number of rows for a given
> > dispatch id will give you your count.
> >
> 
> sorry i will be accumulating huge amount of rows in seperate table
> with no extra info when i really want just the count. Do you have
> a better database design in mind?
> 
> Also i encounter same problem in implementing read count of
> articles in sites and in counting banner impressions where same
> row get updated by multiple processes frequently.

Databases like to work on *sets* of data, not individual rows. Something
like this would probably perform much better than what you've got now,
and would prevent having a huge table laying around:

INSERT INTO holding_table ... -- Done for every incomming
connection/what-have-you

CREATE OR REPLACE FUNCTION summarize() RETURNS void AS $$
DECLARE
    v_rows int;
BEGIN
    DELETE FROM holding_table;
    GET DIAGNOSTICS v_rows = ROW_COUNT;
    UPDATE count_table
        SET count = count + v_rows
    ;
END;
$$ LANGUAGE plpgsql;

Periodically (say, once a minute):
SELECT summarize()
VACUUM holding_table;
VACUUM count_table;
-- 
Jim C. Nasby, Sr. Engineering Consultant      jnasby@pervasive.com
Pervasive Software      http://pervasive.com    work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf       cell: 512-569-9461

From pgsql-performance-owner@postgresql.org  Tue Oct  4 17:19:41 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id C230CDA0AA
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 17:19:38 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 67750-03
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 20:19:32 +0000 (GMT)
Received: from flake.decibel.org (flake.decibel.org [67.100.216.10])
	by svr1.postgresql.org (Postfix) with ESMTP id F3E4CDA08B
	for <pgsql-performance@postgresql.org>;
	Tue,  4 Oct 2005 17:19:32 -0300 (ADT)
Received: by flake.decibel.org (Postfix, from userid 1001)
	id DE5E515257; Tue,  4 Oct 2005 15:19:33 -0500 (CDT)
Date: Tue, 4 Oct 2005 15:19:33 -0500
From: "Jim C. Nasby" <jnasby@pervasive.com>
To: Ron Peacetree <rjpeace@earthlink.net>
Cc: Matthew Nuzum <mattnuzum@gmail.com>, newz@bearfruit.org,
	Postgresql Performance list <pgsql-performance@postgresql.org>
Subject: Re: Logarithmic change (decrease) in performance
Message-ID: <20051004201933.GT40138@pervasive.com>
References: 
 <12381712.1127944983296.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: 
 <12381712.1127944983296.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
X-Operating-System: FreeBSD 4.11-RELEASE-p10 i386
X-Distributed: Join the Effort!  http://www.distributed.net
User-Agent: Mutt/1.5.9i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.008 required=5 tests=[AWL=0.008]
X-Spam-Level: 
X-Archive-Number: 200510/43
X-Sequence-Number: 14811

On Wed, Sep 28, 2005 at 06:03:03PM -0400, Ron Peacetree wrote:
> 1= keep more of the data set in RAM
> 2= increase the size of your HD IO buffers
> 3= make your RAID sets wider (more parallel vs sequential IO)
> 4= reduce the atomic latency of your RAID sets
> (time for Fibre Channel 15Krpm HD's vs 7.2Krpm SATA ones?)
> 5= make sure your data is as unfragmented as possible
> 6= change you DB schema to minimize the problem
> a= overall good schema design
> b= partitioning the data so that the system only has to manipulate a
> reasonable chunk of it at a time.

Note that 6 can easily swamp the rest of these tweaks. A poor schema
design will absolutely kill any system. Also of great importance is how
you're using the database. IE: are you doing any row-by-row operations?

> In many cases, there's a number of ways to accomplish the above.
> Unfortunately, most of them require CapEx.
> 
> Also, ITRW world such systems tend to have this as a chronic
> problem.  This is not a "fix it once and it goes away forever".  This
> is a part of the regular maintenance and upgrade plan(s). 

And why DBA's typically make more money that other IT folks. :)
-- 
Jim C. Nasby, Sr. Engineering Consultant      jnasby@pervasive.com
Pervasive Software      http://pervasive.com    work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf       cell: 512-569-9461

From pgsql-performance-owner@postgresql.org  Tue Oct  4 17:31:15 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id BADFEDA08F
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 17:31:03 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 72136-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 20:31:00 +0000 (GMT)
Received: from flake.decibel.org (flake.decibel.org [67.100.216.10])
	by svr1.postgresql.org (Postfix) with ESMTP id 52B36DA0B7
	for <pgsql-performance@postgresql.org>;
	Tue,  4 Oct 2005 17:31:01 -0300 (ADT)
Received: by flake.decibel.org (Postfix, from userid 1001)
	id 6A92F15255; Tue,  4 Oct 2005 15:31:02 -0500 (CDT)
Date: Tue, 4 Oct 2005 15:31:02 -0500
From: "Jim C. Nasby" <jnasby@pervasive.com>
To: Joe <svn@freedomcircle.net>
Cc: Gavin Sherry <swm@alcove.com.au>, Magnus Hagander <mha@sollentuna.net>,
	pgsql-performance@postgresql.org
Subject: Re: Comparative performance
Message-ID: <20051004203102.GU40138@pervasive.com>
References: <6BCB9D8A16AC4241919521715F4D8BCE92E6D6@algol.sollentuna.se>
	<433BDB0B.8010002@freedomcircle.net>
	<Pine.LNX.4.58.0509292230310.26600@linuxworld.com.au>
	<433BE1A0.5000807@freedomcircle.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <433BE1A0.5000807@freedomcircle.net>
X-Operating-System: FreeBSD 4.11-RELEASE-p10 i386
X-Distributed: Join the Effort!  http://www.distributed.net
User-Agent: Mutt/1.5.9i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.008 required=5 tests=[AWL=0.008]
X-Spam-Level: 
X-Archive-Number: 200510/44
X-Sequence-Number: 14812

On Thu, Sep 29, 2005 at 08:44:16AM -0400, Joe wrote:
> CREATE TABLE entry (
>   entry_id serial PRIMARY KEY,
>   title VARCHAR(128) NOT NULL,
>   subtitle VARCHAR(128),
>   subject_type SMALLINT,
>   subject_id INTEGER REFERENCES topic,
>   actor_type SMALLINT,
>   actor_id INTEGER REFERENCES topic,
>   actor VARCHAR(64),
>   actor_role VARCHAR(64),
>   rel_entry_id INTEGER,
>   rel_entry VARCHAR(64),
>   description VARCHAR(255),
>   quote text,
>   url VARCHAR(255),
>   entry_date CHAR(10),
>   created DATE NOT NULL DEFAULT CURRENT_DATE,
>   updated TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP)
> WITHOUT OIDS;
> CREATE INDEX entry_actor_id ON entry (actor_id);
> CREATE INDEX entry_subject_id ON entry (subject_id);

A few tips...

Fields in PostgreSQL have alignment requirements, so the smallints
aren't saving you anything right now. If you put both of them together
though, you'll save 4 bytes on most hardware.

You'll also get some minor gains from putting all the variable-length
fields at the end, as well as nullable fields. If you search the
archives for 'field order' you should be able to find some useful info.

Make sure these indexes exist if you'll be updating or inserting into
entry:

CREATE INDEX topic__subject_id ON topic(subject_id);
CREATE INDEX topic__actor_id ON topic(actor_id);

Also, the fact that subject and actor both point to topic along with
subject_type and actor_type make me suspect that your design is
de-normalized. Of course there's no way to know without more info.

FWIW, I usually use timestamptz for both created and updated fields.
-- 
Jim C. Nasby, Sr. Engineering Consultant      jnasby@pervasive.com
Pervasive Software      http://pervasive.com    work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf       cell: 512-569-9461

From pgsql-performance-owner@postgresql.org  Tue Oct  4 18:05:11 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 2ADB8DA08B
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 17:41:27 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 74520-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 20:41:21 +0000 (GMT)
Received: from flake.decibel.org (flake.decibel.org [67.100.216.10])
	by svr1.postgresql.org (Postfix) with ESMTP id 8B648D9FD1
	for <pgsql-performance@postgresql.org>;
	Tue,  4 Oct 2005 17:41:21 -0300 (ADT)
Received: by flake.decibel.org (Postfix, from userid 1001)
	id CB2B61525C; Tue,  4 Oct 2005 15:41:22 -0500 (CDT)
Date: Tue, 4 Oct 2005 15:41:22 -0500
From: "Jim C. Nasby" <jnasby@pervasive.com>
To: Joe <svn@freedomcircle.net>
Cc: Andreas Pflug <pgadmin@pse-consulting.de>,
 pgsql-performance@postgresql.org
Subject: Re: Comparative performance
Message-ID: <20051004204122.GV40138@pervasive.com>
References: <433B4AA4.9080008@freedomcircle.net> <op.sxu1g5bnth1vuj@localhost>
	<433BDFF3.3090402@freedomcircle.net>
	<433BEA7B.1050405@pse-consulting.de>
	<433C5108.6070202@freedomcircle.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <433C5108.6070202@freedomcircle.net>
X-Operating-System: FreeBSD 4.11-RELEASE-p10 i386
X-Distributed: Join the Effort!  http://www.distributed.net
User-Agent: Mutt/1.5.9i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.008 required=5 tests=[AWL=0.008]
X-Spam-Level: 
X-Archive-Number: 200510/46
X-Sequence-Number: 14814

On Thu, Sep 29, 2005 at 04:39:36PM -0400, Joe wrote:
> Andreas Pflug wrote:
> >Hm, if you only have 4 tables, why do you need 12 queries?
> >To reduce queries, join them in the query; no need to merge them 
> >physically. If you have only two main tables, I'd bet you only need 1-2 
> >queries for the whole page.
> 
> There are more than four tables and the queries are not functionally 
> overlapping.  As an example, allow me to refer to the page 
> www.freedomcircle.com/topic.php/Economists.
> 
> The top row of navigation buttons (Life, Liberty, etc.) is created from a 
> query of the 'topic' table.  It could've been hard-coded as a PHP array, 
> but with less flexibility.  The alphabetical links are from a SELECT 
> DISTINCT substring from topic.  It could've been generated by a PHP for 
> loop (originally implemented that way) but again with less flexibility.  
> The listing of economists is another SELECT from topic.  The subheadings 
> (Articles, Books) come from a SELECT of an entry_type table --which 
> currently has 70 rows-- and is read into a PHP array since we don't know 
> what headings will be used in a given page.  The detail of the entries 

I suspect this might be something better done in a join.

> comes from that query that I posted earlier, but there are three additional 
> queries that are used for specialized entry types (relationships between 
> topics --e.g., Prof. Williams teaches at George Mason, events, and 
> multi-author or multi-subject articles and books).  And there's yet another 

Likewise...

> table for the specific book information.  Once the data is retrieved it's 
> sorted internally with PHP, at the heading level, before display.

It's often better to let the database sort and/or aggregate data.

> Maybe there is some way to merge all the queries (some already fairly 
> complex) that fetch the data for the entries box but I believe it would be 
> a monstrosity with over 100 lines of SQL.

Also, just because no one else has mentioned it, remember that it's very
easy to get MySQL into a mode where you have no data integrity. If
that's the case it's going to be faster than PostgreSQL (though I'm not
sure how much that affects the performance of SELECTs).
-- 
Jim C. Nasby, Sr. Engineering Consultant      jnasby@pervasive.com
Pervasive Software      http://pervasive.com    work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf       cell: 512-569-9461

From pgsql-performance-owner@postgresql.org  Tue Oct  4 17:45:13 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 14D04DA0B6;
	Tue,  4 Oct 2005 17:43:44 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 77902-04; Tue,  4 Oct 2005 20:43:41 +0000 (GMT)
Received: from flake.decibel.org (flake.decibel.org [67.100.216.10])
	by svr1.postgresql.org (Postfix) with ESMTP id 04951DA090;
	Tue,  4 Oct 2005 17:43:41 -0300 (ADT)
Received: by flake.decibel.org (Postfix, from userid 1001)
	id 7A1EB15255; Tue,  4 Oct 2005 15:43:43 -0500 (CDT)
Date: Tue, 4 Oct 2005 15:43:43 -0500
From: "Jim C. Nasby" <jnasby@pervasive.com>
To: Roger Hand <RHand@kailea.com>
Cc: Christopher Kings-Lynne <chriskl@familyhealth.com.au>,
	"R, Rajesh (STSD)" <rajesh.r2@hp.com>, pgsql-hackers@postgresql.org,
	pgsql-performance@postgresql.org
Subject: Re: [HACKERS] Query in SQL statement
Message-ID: <20051004204343.GW40138@pervasive.com>
References: 
 <DB28E9B548192448A4E8C8A3C1B1E475611D35@sj1-exch-01.us.corp.kailea.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: 
 <DB28E9B548192448A4E8C8A3C1B1E475611D35@sj1-exch-01.us.corp.kailea.com>
X-Operating-System: FreeBSD 4.11-RELEASE-p10 i386
X-Distributed: Join the Effort!  http://www.distributed.net
User-Agent: Mutt/1.5.9i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.008 required=5 tests=[AWL=0.008]
X-Spam-Level: 
X-Archive-Number: 200510/45
X-Sequence-Number: 14813

On Sat, Oct 01, 2005 at 12:51:08PM -0700, Roger Hand wrote:
> > -----Original Message-----
> > From: pgsql-performance-owner@postgresql.org
> > [mailto:pgsql-performance-owner@postgresql.org]On Behalf Of Jim C. Nasby
> > Sent: Friday, September 30, 2005 4:49 PM
> > Subject: Re: [PERFORM] [HACKERS] Query in SQL statement
>  
> > I suggest ditching the CamelCase and going with underline_seperators.
> > I'd also not use the bareword id, instead using bad_user_id. And I'd
> > name the table bad_user. But that's just me. :)
> 
> I converted a db from MS SQL, where tables and fields were CamelCase, and 
> just lowercased the ddl to create the tables.
> 
> So table and fields names were all created in lowercase, but I didn't have to change
> any of the application code: the SELECT statements worked fine with mixed case.
> 
> -- sample DDL
> CREATE TABLE testtable
> (
>   fieldone int4
> ) 
> insert into TestTable (fieldone) values (11);

That will usually work (see Tom's reply), but fieldone is a heck of a
lot harder to read than field_one. But like I said, this is the coding
conventions I've found work well; YMMV.
-- 
Jim C. Nasby, Sr. Engineering Consultant      jnasby@pervasive.com
Pervasive Software      http://pervasive.com    work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf       cell: 512-569-9461

From pgsql-performance-owner@postgresql.org  Tue Oct  4 18:28:16 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 3DDE9DA0AA
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 17:52:26 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 77880-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 20:52:23 +0000 (GMT)
Received: from flake.decibel.org (flake.decibel.org [67.100.216.10])
	by svr1.postgresql.org (Postfix) with ESMTP id 4D5C3DA0B2
	for <pgsql-performance@postgresql.org>;
	Tue,  4 Oct 2005 17:52:24 -0300 (ADT)
Received: by flake.decibel.org (Postfix, from userid 1001)
	id 153B115255; Tue,  4 Oct 2005 15:52:25 -0500 (CDT)
Date: Tue, 4 Oct 2005 15:52:25 -0500
From: "Jim C. Nasby" <jnasby@pervasive.com>
To: adnandursun@asrinbilisim.com.tr
Cc: pgsql-performance@postgresql.org
Subject: Re: SQL Function performance
Message-ID: <20051004205225.GX40138@pervasive.com>
References: <web-145786064@mail3.doruk.net.tr>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <web-145786064@mail3.doruk.net.tr>
X-Operating-System: FreeBSD 4.11-RELEASE-p10 i386
X-Distributed: Join the Effort!  http://www.distributed.net
User-Agent: Mutt/1.5.9i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.111 required=5 tests=[AWL=-0.096,
	UPPERCASE_25_50=0.207]
X-Spam-Level: 
X-Archive-Number: 200510/52
X-Sequence-Number: 14820

On Thu, Sep 29, 2005 at 10:54:58PM +0300, adnandursun@asrinbilisim.com.tr wrote:
> Hi All,
>  
>         I have a SQL function like :
>  
> CREATE OR REPLACE FUNCTION
> fn_get_yetkili_inisyer_listesi(int4, int4)
>   RETURNS SETOF kod_adi_liste_type AS
> $BODY$
>  SELECT Y.KOD,Y.ADI
>    FROM T_YER Y
>   WHERE EXISTS (SELECT 1
>     FROM T_GUZER G
>           WHERE (G.BIN_YER_KOD = $1 OR COALESCE($1,0)=0)
>      AND FN_FIRMA_ISVISIBLE(G.FIRMA_NO,$2) = 1
>      AND G.IN_YER_KOD = Y.KOD)
>     AND Y.IPTAL = 'H';
> $BODY$
>   LANGUAGE 'sql' VOLATILE;
> 
>     When i use like "SELECT * FROM
> fn_get_yetkili_inisyer_listesi(1, 3474)" and 
> planner result is  "Function Scan on
> fn_get_yetkili_inisyer_listesi  (cost=0.00..12.50 rows=1000
> width=36) (1 row) " and it runs very slow.
>  
>     But when i use like 
> 
>     "SELECT Y.KOD,Y.ADI
>          FROM T_YER Y
>        WHERE EXISTS (SELECT 1
>                                         FROM T_GUZER G
>                                       WHERE (G.BIN_YER_KOD
> = 1 OR COALESCE(1,0)=0)
>      AND FN_FIRMA_ISVISIBLE(G.FIRMA_NO,3474) = 1
>      AND G.IN_YER_KOD = Y.KOD)
>      AND Y.IPTAL = 'H';" 
> 
> planner result :
> 
> " 
>                                                  QUERY PLAN
>  
> --------------------------------------------------------------------------------
> -----------------------------
>  Seq Scan on t_yer y  (cost=0.00..3307.79 rows=58 width=14)
>    Filter: (((iptal)::text = 'H'::text) AND (subplan))
>    SubPlan
>      ->  Index Scan using
> t_guzer_ucret_giris_performans_idx on t_guzer g  (cost
> =0.00..28.73 rows=1 width=0)
>            Index Cond: ((bin_yer_kod = 1) AND (in_yer_kod =
> $0))
>            Filter: (fn_firma_isvisible(firma_no, 3474) = 1)
> (6 rows)
> "
>   and it runs very fast.
> 
> Any idea ?

Need EXPLAIN ANALYZE.

I suspect this is due to a cached query plan. PostgreSQL will cache a
query plan for the SELECT the first time you run the function and that
plan will be re-used. Depending on what data you call the function with,
you could get a very different plan.

Also, you might do better with a JOIN instead of using EXISTS.  You can
also make this function STABLE instead of VOLATILE. Likewise, if
FN_FIRMA_ISVISIBLE can't change any data, you can also make it STABLE
which would likely improve the performance of the query. But neither of
these ideas would account for the difference between function
performance and raw query performance.

On a side note, if OR $1 IS NULL works that will be more readable (and
probably faster) than the OR COALESCE($1,0)=0.
-- 
Jim C. Nasby, Sr. Engineering Consultant      jnasby@pervasive.com
Pervasive Software      http://pervasive.com    work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf       cell: 512-569-9461

From pgsql-performance-owner@postgresql.org  Tue Oct  4 18:23:58 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 95751DA08B
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 17:57:14 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 79778-03
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 20:57:10 +0000 (GMT)
Received: from cluster1.echolabs.net (mail.atlanticbb.net [216.52.118.222])
	by svr1.postgresql.org (Postfix) with ESMTP id 1E2E4DA071
	for <pgsql-performance@postgresql.org>;
	Tue,  4 Oct 2005 17:57:10 -0300 (ADT)
X-Scanned-By: RAE MPP/Clamd http://www.messagepartners.com
X-Scanned-By: RAE MPP/Cloudmark http://www.messagepartners.com
Received: from [216.189.176.72] (account jma@atlanticbb.net HELO [127.0.0.1])
	by fe2.cluster1.echolabs.net (CommuniGate Pro SMTP 4.3.7)
	with ESMTPA id 83719658; Tue, 04 Oct 2005 16:57:11 -0400
Message-ID: <4342ECAF.9020903@freedomcircle.net>
Date: Tue, 04 Oct 2005 16:57:19 -0400
From: Joe <svn@freedomcircle.net>
Organization: Freedom Circle, LLC
User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: PFC <lists@boutiquenumerique.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Comparative performance
References: <6BCB9D8A16AC4241919521715F4D8BCE92E6D6@algol.sollentuna.se>
	<433BDB0B.8010002@freedomcircle.net>
	<Pine.LNX.4.58.0509292230310.26600@linuxworld.com.au>
	<433BE1A0.5000807@freedomcircle.net> <op.sxvguropth1vuj@localhost>
	<4341E328.2060305@freedomcircle.net> <op.sx349gxcth1vuj@localhost>
In-Reply-To: <op.sx349gxcth1vuj@localhost>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.07 required=5 tests=[AWL=0.020,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/51
X-Sequence-Number: 14819

PFC wrote:
> - if you use a version before 8, type mismatch will prevent use of the  
> indexes.

I'm using 8.0.3, but the type mismatch between relationship.rel_type and 
entry_type.type_id was unintended.  The current databases use SMALLINT for both. 
  The PostgreSQL schema was derived from an export script stored in Subversion, 
apparently before the column datatypes were changed.

> CREATE INDEX'es ON
> entry_type( class_id )
> 
> relationship( topic_id1, rel_type, topic_id2 )    which becomes your 
> new  PRIMARY KEY
> relationship( topic_id2, rel_type, topic_id1 )

Creating the second relationship index was sufficient to modify the query plan 
to cut down runtime to zero:

  Sort  (cost=75.94..75.95 rows=2 width=381) (actual time=0.000..0.000 rows=0 
loops=1)
    Sort Key: r.rel_type, t.list_name
    ->  Nested Loop  (cost=16.00..75.93 rows=2 width=381) (actual 
time=0.000..0.000 rows=0 loops=1)
          Join Filter: ((("outer".topic_id1 = "inner".topic_id) AND 
("outer".topic_id2 = 1252)) OR (("outer".topic_id2 = "inner".topic_id) AND 
("outer".topic_id1 = 1252)))
          ->  Nested Loop  (cost=16.00..35.11 rows=1 width=169) (actual 
time=0.000..0.000 rows=0 loops=1)
                Join Filter: ("inner".rel_type = "outer".type_id)
                ->  Seq Scan on entry_type e  (cost=0.00..18.75 rows=4 width=4) 
(actual time=0.000..0.000 rows=15 loops=1)
                      Filter: (class_id = 2)
                ->  Materialize  (cost=16.00..16.04 rows=4 width=167) (actual 
time=0.000..0.000 rows=0 loops=15)
                      ->  Seq Scan on relationship r  (cost=0.00..16.00 rows=4 
width=167) (actual time=0.000..0.000 rows=0 loops=1)
                            Filter: ((topic_id2 = 1252) OR (topic_id1 = 1252))
          ->  Seq Scan on topic t  (cost=0.00..30.94 rows=494 width=216) (never 
executed)
  Total runtime: 0.000 ms
(13 rows)

The overall execution time for the Economists page for PostgreSQL is within 4% 
of the MySQL time, so for the time being I'll leave the query in its current form.

Thanks for your help.

Joe


From pgsql-performance-owner@postgresql.org  Tue Oct  4 18:23:20 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id B012AD6F63
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 17:57:22 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 77938-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 20:57:17 +0000 (GMT)
Received: from flake.decibel.org (flake.decibel.org [67.100.216.10])
	by svr1.postgresql.org (Postfix) with ESMTP id 6B94EDA094
	for <pgsql-performance@postgresql.org>;
	Tue,  4 Oct 2005 17:57:18 -0300 (ADT)
Received: by flake.decibel.org (Postfix, from userid 1001)
	id 5F85E1525C; Tue,  4 Oct 2005 15:57:20 -0500 (CDT)
Date: Tue, 4 Oct 2005 15:57:20 -0500
From: "Jim C. Nasby" <jnasby@pervasive.com>
To: Stefan Weiss <spaceman@foo.at>
Cc: pgsql-performance@postgresql.org
Subject: Re: Is There Any Way ....
Message-ID: <20051004205719.GY40138@pervasive.com>
References: <EKEMKEFLOMKDDLIALABIMECFCDAA.lvaningen@esncc.com>
	<43425A0E.2050305@foo.at>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <43425A0E.2050305@foo.at>
X-Operating-System: FreeBSD 4.11-RELEASE-p10 i386
X-Distributed: Join the Effort!  http://www.distributed.net
User-Agent: Mutt/1.5.9i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.008 required=5 tests=[AWL=0.008]
X-Spam-Level: 
X-Archive-Number: 200510/50
X-Sequence-Number: 14818

On Tue, Oct 04, 2005 at 12:31:42PM +0200, Stefan Weiss wrote:
> On 2005-09-30 01:21, Lane Van Ingen wrote:
> >   (3) Assure that a disk-based table is always in memory (outside of keeping
> > it in
> >       memory buffers as a result of frequent activity which would prevent
> > LRU
> >       operations from taking it out) ?
> 
> I was wondering about this too. IMO it would be useful to have a way to tell
> PG that some tables were needed frequently, and should be cached if
> possible. This would allow application developers to consider joins with
> these tables as "cheap", even when querying on columns that are not indexed.
> I'm thinking about smallish tables like users, groups, *types, etc which
> would be needed every 2-3 queries, but might be swept out of RAM by one
> large query in between. Keeping a table like "users" on a RAM fs would not
> be an option, because the information is not volatile.

Why do you think you'll know better than the database how frequently
something is used? At best, your guess will be correct and PostgreSQL
(or the kernel) will keep the table in memory. Or, your guess is wrong
and you end up wasting memory that could have been used for something
else.

It would probably be better if you describe why you want to force this
table (or tables) into memory, so we can point you at more appropriate
solutions.
-- 
Jim C. Nasby, Sr. Engineering Consultant      jnasby@pervasive.com
Pervasive Software      http://pervasive.com    work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf       cell: 512-569-9461

From pgsql-performance-owner@postgresql.org  Tue Oct  4 18:14:26 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id BD0E9DA0A9
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 18:01:38 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 80279-03
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 21:01:35 +0000 (GMT)
Received: from flake.decibel.org (flake.decibel.org [67.100.216.10])
	by svr1.postgresql.org (Postfix) with ESMTP id A8C71DA0B0
	for <pgsql-performance@postgresql.org>;
	Tue,  4 Oct 2005 18:01:36 -0300 (ADT)
Received: by flake.decibel.org (Postfix, from userid 1001)
	id 14D091527C; Tue,  4 Oct 2005 16:01:38 -0500 (CDT)
Date: Tue, 4 Oct 2005 16:01:37 -0500
From: "Jim C. Nasby" <jnasby@pervasive.com>
To: Richard Huxton <dev@archonet.com>
Cc: xchris <lyralyra@fastmail.fm>, pgsql-performance@postgresql.org
Subject: Re: Lists or external TABLE?
Message-ID: <20051004210137.GZ40138@pervasive.com>
References: <1128071781.8112.32.camel@lyra> <433D06AB.3020409@archonet.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <433D06AB.3020409@archonet.com>
X-Operating-System: FreeBSD 4.11-RELEASE-p10 i386
X-Distributed: Join the Effort!  http://www.distributed.net
User-Agent: Mutt/1.5.9i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.008 required=5 tests=[AWL=0.008]
X-Spam-Level: 
X-Archive-Number: 200510/48
X-Sequence-Number: 14816

On Fri, Sep 30, 2005 at 10:34:35AM +0100, Richard Huxton wrote:
> xchris wrote:
> >
> >Let's suppose i need to add an info about addresses (which includes
> >country,city,cap....etc etc).
> >Addresses can vary from 1 to 20 entries..
> >
> >Talking about performance is it better to include a list of addresses in
> >TABLE A or is it better to create an external TABLE B?
> 
> Don't optimise before you have to.
> 
> Do the addresses belong in "A"? If so, put them there. On the other 
> hand, if you want items in "A" to have more than one address, or to 
> share addresses then clearly you will want a separate address table. 
> It's difficult to say more without a clear example of your requirements.
> 
> Even if you choose to alter your design for performance reasons, you 
> should make sure you run tests with realistic workloads and hardware. 
> But first, trust PG to do its job and design your database according to 
> the problem requirements.

On top of what Richard said, 5000 rows is pretty tiny. Even if each row
was 1K wide, that's still only 5MB.

Also, if from a data-model standpoint it doesn't matter which way you
go, I suggest looking at what it will take to write queries against both
versions before deciding. I tend to stay away from arrays because
they tend to be harder to query against.
-- 
Jim C. Nasby, Sr. Engineering Consultant      jnasby@pervasive.com
Pervasive Software      http://pervasive.com    work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf       cell: 512-569-9461

From pgsql-performance-owner@postgresql.org  Tue Oct  4 18:12:24 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id E81E5DA098
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 18:02:25 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 79252-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 21:02:20 +0000 (GMT)
Received: from flake.decibel.org (flake.decibel.org [67.100.216.10])
	by svr1.postgresql.org (Postfix) with ESMTP id 87556DA081
	for <pgsql-performance@postgresql.org>;
	Tue,  4 Oct 2005 18:02:21 -0300 (ADT)
Received: by flake.decibel.org (Postfix, from userid 1001)
	id E47E71527C; Tue,  4 Oct 2005 16:02:23 -0500 (CDT)
Date: Tue, 4 Oct 2005 16:02:23 -0500
From: "Jim C. Nasby" <jnasby@pervasive.com>
To: pgsql-performance@postgresql.org
Subject: Re: Ultra-cheap NVRAM device
Message-ID: <20051004210223.GA40138@pervasive.com>
References: <20051003110226.GA26883@uio.no>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20051003110226.GA26883@uio.no>
X-Operating-System: FreeBSD 4.11-RELEASE-p10 i386
X-Distributed: Join the Effort!  http://www.distributed.net
User-Agent: Mutt/1.5.9i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.008 required=5 tests=[AWL=0.008]
X-Spam-Level: 
X-Archive-Number: 200510/47
X-Sequence-Number: 14815

There was a discussion about this about 2 months ago. See the archives.

On Mon, Oct 03, 2005 at 01:02:26PM +0200, Steinar H. Gunderson wrote:
> I thought this might be interesting, not the least due to the extremely low
> price ($150 + the price of regular DIMMs):
> 
>   http://www.tomshardware.com/storage/20050907/index.html
> 
> Anybody know a good reason why you can't put a WAL on this, and enjoy a hefty
> speed boost for a fraction of the price of a traditional SSD? (Yes, it's
> SATA, not PCI, so the throughput is not all that impressive -- but still,
> it's got close to zero seek time.)
> 
> /* Steinar */
> -- 
> Homepage: http://www.sesse.net/
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
> 
>                http://www.postgresql.org/docs/faq
> 

-- 
Jim C. Nasby, Sr. Engineering Consultant      jnasby@pervasive.com
Pervasive Software      http://pervasive.com    work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf       cell: 512-569-9461

From pgsql-performance-owner@postgresql.org  Tue Oct  4 18:16:08 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 72CA4DA0BF
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 18:11:15 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 79602-07
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 21:11:09 +0000 (GMT)
Received: from cluster1.echolabs.net (smtp-out.echolabs.net [216.52.118.200])
	by svr1.postgresql.org (Postfix) with ESMTP id 4B340DA0AF
	for <pgsql-performance@postgresql.org>;
	Tue,  4 Oct 2005 18:11:08 -0300 (ADT)
X-Scanned-By: RAE MPP/Clamd http://www.messagepartners.com
X-Scanned-By: RAE MPP/Cloudmark http://www.messagepartners.com
Received: from [216.189.176.72] (account jma@atlanticbb.net HELO [127.0.0.1])
	by fe3.cluster1.echolabs.net (CommuniGate Pro SMTP 4.3.7)
	with ESMTPA id 2756355; Tue, 04 Oct 2005 17:05:25 -0400
Message-ID: <4342EFF7.5010405@freedomcircle.net>
Date: Tue, 04 Oct 2005 17:11:19 -0400
From: Joe <svn@freedomcircle.net>
Organization: Freedom Circle, LLC
User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: "Jim C. Nasby" <jnasby@pervasive.com>
Cc: Andreas Pflug <pgadmin@pse-consulting.de>,
 pgsql-performance@postgresql.org
Subject: Re: Comparative performance
References: <433B4AA4.9080008@freedomcircle.net> <op.sxu1g5bnth1vuj@localhost>
	<433BDFF3.3090402@freedomcircle.net>
	<433BEA7B.1050405@pse-consulting.de>
	<433C5108.6070202@freedomcircle.net>
	<20051004204122.GV40138@pervasive.com>
In-Reply-To: <20051004204122.GV40138@pervasive.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.045 required=5 tests=[AWL=0.045]
X-Spam-Level: 
X-Archive-Number: 200510/49
X-Sequence-Number: 14817

Hi Jim,

Jim C. Nasby wrote:
> Also, just because no one else has mentioned it, remember that it's very
> easy to get MySQL into a mode where you have no data integrity. If
> that's the case it's going to be faster than PostgreSQL (though I'm not
> sure how much that affects the performance of SELECTs).

Yes indeed.  When I added the REFERENCES to the schema and reran the conversion 
scripts, aside from having to reorder the table creation and loading (they used 
to be in alphabetical order), I also found a few referential integrity errors in 
the MySQL data.

Joe


From pgsql-performance-owner@postgresql.org  Tue Oct  4 18:32:28 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 4DB1EDA04E
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 18:15:43 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 84132-07
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 21:15:39 +0000 (GMT)
Received: from flake.decibel.org (flake.decibel.org [67.100.216.10])
	by svr1.postgresql.org (Postfix) with ESMTP id 16477D9C38
	for <pgsql-performance@postgresql.org>;
	Tue,  4 Oct 2005 18:15:40 -0300 (ADT)
Received: by flake.decibel.org (Postfix, from userid 1001)
	id 1ACCA1529A; Tue,  4 Oct 2005 16:15:42 -0500 (CDT)
Date: Tue, 4 Oct 2005 16:15:41 -0500
From: "Jim C. Nasby" <jnasby@pervasive.com>
To: K C Lau <kclau60@netvigator.com>
Cc: Simon Riggs <simon@2ndquadrant.com>,
	pgsql-performance@postgresql.org
Subject: Re: SELECT LIMIT 1 VIEW Performance Issue
Message-ID: <20051004211541.GB40138@pervasive.com>
References: <6.2.1.2.0.20050615100524.04f9d6a8@localhost>
	<6.2.1.2.0.20050922102035.07bcf2e0@localhost>
	<1127378456.4145.76.camel@localhost.localdomain>
	<6.2.1.2.0.20050922181009.02c36ca8@localhost>
	<1127474141.19345.10.camel@localhost.localdomain>
	<6.2.1.2.0.20050923195457.02c4fd30@localhost>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <6.2.1.2.0.20050923195457.02c4fd30@localhost>
X-Operating-System: FreeBSD 4.11-RELEASE-p10 i386
X-Distributed: Join the Effort!  http://www.distributed.net
User-Agent: Mutt/1.5.9i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.008 required=5 tests=[AWL=0.008]
X-Spam-Level: 
X-Archive-Number: 200510/53
X-Sequence-Number: 14821

On Fri, Sep 23, 2005 at 08:17:03PM +0800, K C Lau wrote:
> esdt=> create or replace function player_max_atdate (varchar(32)) returns 
> varchar(32) as $$
> esdt$>  select distinct on (PlayerID) AtDate from player where PlayerID= $1 
> order by PlayerID desc, AtDate desc limit 1;
> esdt$> $$ language sql immutable;
> CREATE FUNCTION

That function is not immutable, it should be defined as stable.

> esdt=> create or replace view VCurPlayer3 as select * from Player where 
> AtDate = player_max_atdate(PlayerID);
> CREATE VIEW
> esdt=> explain analyze select PlayerID,AtDate from VCurPlayer3 where 
> PlayerID='22220';
> 
>  Index Scan using pk_player on player  (cost=0.00..1331.83 rows=9 
> width=23) (actual time=76.660..76.664 rows=1 loops=1)
>    Index Cond: ((playerid)::text = '22220'::text)
>    Filter: ((atdate)::text = (player_max_atdate(playerid))::text)
>  Total runtime: 76.716 ms
> 
> Why wouldn't the function get the row as quickly as the direct sql does?

PostgreSQL doesn't pre-compile functions, at least not until 8.1 (and
I'm not sure how much those are pre-compiled, though they are
syntax-checked at creation). Do you get the same result time when you
run it a second time? What time do you get from running just the
function versus the SQL in the function?

Also, remember that every layer you add to the cake means more work for
the database. If speed is that highly critical you'll probably want to
not wrap things in functions, and possibly not use views either.

Also, keep in mind that getting below 1ms doesn't automatically mean
you'll be able to scale to 1000TPS. Things will definately change when
you load the system down, so if performance is that critical you should
start testing with the system under load if you're not already.
-- 
Jim C. Nasby, Sr. Engineering Consultant      jnasby@pervasive.com
Pervasive Software      http://pervasive.com    work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf       cell: 512-569-9461

From pgsql-performance-owner@postgresql.org  Tue Oct  4 18:35:36 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id CF6EBD946C
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 18:31:55 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 91225-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 21:31:52 +0000 (GMT)
Received: from flake.decibel.org (flake.decibel.org [67.100.216.10])
	by svr1.postgresql.org (Postfix) with ESMTP id 79856DA0B3
	for <pgsql-performance@postgresql.org>;
	Tue,  4 Oct 2005 18:31:52 -0300 (ADT)
Received: by flake.decibel.org (Postfix, from userid 1001)
	id 0ED7F1524F; Tue,  4 Oct 2005 16:31:54 -0500 (CDT)
Date: Tue, 4 Oct 2005 16:31:54 -0500
From: "Jim C. Nasby" <jnasby@pervasive.com>
To: K C Lau <kclau60@netvigator.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: SELECT LIMIT 1 VIEW Performance Issue
Message-ID: <20051004213154.GC40138@pervasive.com>
References: <6EE64EF3AB31D5448D0007DD34EEB3417DD406@Herge.rcsinc.local>
	<6.2.1.2.0.20050923155952.05889a50@localhost>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <6.2.1.2.0.20050923155952.05889a50@localhost>
X-Operating-System: FreeBSD 4.11-RELEASE-p10 i386
X-Distributed: Join the Effort!  http://www.distributed.net
User-Agent: Mutt/1.5.9i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.008 required=5 tests=[AWL=0.008]
X-Spam-Level: 
X-Archive-Number: 200510/54
X-Sequence-Number: 14822

On Fri, Sep 23, 2005 at 04:53:55PM +0800, K C Lau wrote:
> Thank you all for your suggestions. I' tried, with some variations too, but 
> still no success. The times given are the best of a few repeated tries on 
> an 8.1 beta 2 db freshly migrated from 8.0.3 on Windows.
> 
> For reference, only the following gets the record quickly:
> 
> esdt=> explain analyze select PlayerID,AtDate from Player a
>  where PlayerID='22220' and AtDate = (select b.AtDate from Player b
>  where b.PlayerID = '22220' order by b.PlayerID desc, b.AtDate desc LIMIT 
>  1);
> 
>  Index Scan using pk_player on player a  (cost=0.75..4.26 rows=1 width=23) 
> (actual time=0.054..0.057 rows=1 loops=1)
>    Index Cond: (((playerid)::text = '22220'::text) AND ((atdate)::text = 
> ($0)::text))
>    InitPlan
>      ->  Limit  (cost=0.00..0.75 rows=1 width=23) (actual 
> time=0.027..0.028 rows=1 loops=1)
>            ->  Index Scan Backward using pk_player on player 
> b  (cost=0.00..1323.05 rows=1756 width=23) (actual time=0.023..0.023 rows=1 
> loops=1)
>                  Index Cond: ((playerid)::text = '22220'::text)
>  Total runtime: 0.132 ms

If you're doing that, you should try something like the following:
decibel=# explain analyze select  * from t where ctid=(select ctid from rrs order by rrs_id desc limit 1);
                                                                 QUERY PLAN                                                                  
---------------------------------------------------------------------------------------------------------------------------------------------
 Tid Scan on t  (cost=0.44..4.45 rows=1 width=42) (actual time=0.750..0.754 rows=1 loops=1)
   Filter: (ctid = $0)
   InitPlan
     ->  Limit  (cost=0.00..0.44 rows=1 width=10) (actual time=0.548..0.549 rows=1 loops=1)
           ->  Index Scan Backward using rrs_rrs__rrs_id on rrs  (cost=0.00..3.08 rows=7 width=10) (actual time=0.541..0.541 rows=1 loops=1)
 Total runtime: 1.061 ms
(6 rows)

decibel=# select count(*) from t; count  
--------
 458752

Note that that's on my nice slow laptop to boot (the count took like 10
seconds).

Just remember that ctid *is not safe outside of a transaction*!! So you can't
do something like

SELECT ctid FROM ...
store that in some variable...
SELECT * FROM table WHERE ctid = variable
-- 
Jim C. Nasby, Sr. Engineering Consultant      jnasby@pervasive.com
Pervasive Software      http://pervasive.com    work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf       cell: 512-569-9461

From pgsql-performance-owner@postgresql.org  Tue Oct  4 18:37:26 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id EAC59DA093
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 18:37:22 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 91630-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 21:37:17 +0000 (GMT)
Received: from cluster1.echolabs.net (mail.atlanticbb.net [216.52.118.222])
	by svr1.postgresql.org (Postfix) with ESMTP id B6D45DA054
	for <pgsql-performance@postgresql.org>;
	Tue,  4 Oct 2005 18:37:18 -0300 (ADT)
X-Scanned-By: RAE MPP/Clamd http://www.messagepartners.com
X-Scanned-By: RAE MPP/Cloudmark http://www.messagepartners.com
Received: from [216.189.176.72] (account jma@atlanticbb.net HELO [127.0.0.1])
	by fe2.cluster1.echolabs.net (CommuniGate Pro SMTP 4.3.7)
	with ESMTPA id 83727318; Tue, 04 Oct 2005 17:37:20 -0400
Message-ID: <4342F61A.1010903@freedomcircle.net>
Date: Tue, 04 Oct 2005 17:37:30 -0400
From: Joe <svn@freedomcircle.net>
Organization: Freedom Circle, LLC
User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: "Jim C. Nasby" <jnasby@pervasive.com>
Cc: Gavin Sherry <swm@alcove.com.au>, Magnus Hagander <mha@sollentuna.net>,
	pgsql-performance@postgresql.org
Subject: Re: Comparative performance
References: <6BCB9D8A16AC4241919521715F4D8BCE92E6D6@algol.sollentuna.se>
	<433BDB0B.8010002@freedomcircle.net>
	<Pine.LNX.4.58.0509292230310.26600@linuxworld.com.au>
	<433BE1A0.5000807@freedomcircle.net>
	<20051004203102.GU40138@pervasive.com>
In-Reply-To: <20051004203102.GU40138@pervasive.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.068 required=5 tests=[AWL=0.018,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/55
X-Sequence-Number: 14823

Jim C. Nasby wrote:
> Make sure these indexes exist if you'll be updating or inserting into
> entry:
> 
> CREATE INDEX topic__subject_id ON topic(subject_id);
> CREATE INDEX topic__actor_id ON topic(actor_id);

Actually, topic's primary key is topic_id.

> Also, the fact that subject and actor both point to topic along with
> subject_type and actor_type make me suspect that your design is
> de-normalized. Of course there's no way to know without more info.

Yes, the design is denormalized.  The reason is that a book or article is 
usually by a single author (an "actor" topic) and it will be listed under one 
main topic (a "subject" topic).  There's a topic_entry table where additional 
actors and subjects can be added.

It's somewhat ironic because I used to teach and/or preach normalization and the 
"goodness" of a 3NF+ design (also about having the database do aggregation and 
sorting as you mentioned in your other email).

> FWIW, I usually use timestamptz for both created and updated fields.

IIRC 'created' ended up as a DATE because MySQL 4 has a restriction about a 
single TIMESTAMP column per table taking the default value of current_timestamp.

Joe


From pgsql-performance-owner@postgresql.org  Tue Oct  4 19:16:44 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id B36CDDA08F
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 19:16:40 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 96875-06
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 22:16:36 +0000 (GMT)
Received: from flake.decibel.org (flake.decibel.org [67.100.216.10])
	by svr1.postgresql.org (Postfix) with ESMTP id DA696DA094
	for <pgsql-performance@postgresql.org>;
	Tue,  4 Oct 2005 19:16:37 -0300 (ADT)
Received: by flake.decibel.org (Postfix, from userid 1001)
	id 9D23F1529A; Tue,  4 Oct 2005 17:16:40 -0500 (CDT)
Date: Tue, 4 Oct 2005 17:16:40 -0500
From: "Jim C. Nasby" <jnasby@pervasive.com>
To: Joe <svn@freedomcircle.net>
Cc: Andreas Pflug <pgadmin@pse-consulting.de>,
 pgsql-performance@postgresql.org
Subject: Re: Comparative performance
Message-ID: <20051004221640.GI40138@pervasive.com>
References: <433B4AA4.9080008@freedomcircle.net> <op.sxu1g5bnth1vuj@localhost>
	<433BDFF3.3090402@freedomcircle.net>
	<433BEA7B.1050405@pse-consulting.de>
	<433C5108.6070202@freedomcircle.net>
	<20051004204122.GV40138@pervasive.com>
	<4342EFF7.5010405@freedomcircle.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <4342EFF7.5010405@freedomcircle.net>
X-Operating-System: FreeBSD 4.11-RELEASE-p10 i386
X-Distributed: Join the Effort!  http://www.distributed.net
User-Agent: Mutt/1.5.9i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.008 required=5 tests=[AWL=0.008]
X-Spam-Level: 
X-Archive-Number: 200510/56
X-Sequence-Number: 14824

On Tue, Oct 04, 2005 at 05:11:19PM -0400, Joe wrote:
> Hi Jim,
> 
> Jim C. Nasby wrote:
> >Also, just because no one else has mentioned it, remember that it's very
> >easy to get MySQL into a mode where you have no data integrity. If
> >that's the case it's going to be faster than PostgreSQL (though I'm not
> >sure how much that affects the performance of SELECTs).
> 
> Yes indeed.  When I added the REFERENCES to the schema and reran the 
> conversion scripts, aside from having to reorder the table creation and 
> loading (they used to be in alphabetical order), I also found a few 
> referential integrity errors in the MySQL data.

Data integrity != refferential integrity. :) It's very easy to
accidentally get MyISAM tables in MySQL, which means you are nowhere
near ACID which also means you can't get anything close to an apples to
apples comparison to PostgreSQL.
-- 
Jim C. Nasby, Sr. Engineering Consultant      jnasby@pervasive.com
Pervasive Software      http://pervasive.com    work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf       cell: 512-569-9461

From pgsql-performance-owner@postgresql.org  Tue Oct  4 19:19:28 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 945A9DA0EB
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 19:19:11 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 99539-07
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 22:19:08 +0000 (GMT)
Received: from flake.decibel.org (flake.decibel.org [67.100.216.10])
	by svr1.postgresql.org (Postfix) with ESMTP id C583BDA0E1
	for <pgsql-performance@postgresql.org>;
	Tue,  4 Oct 2005 19:19:09 -0300 (ADT)
Received: by flake.decibel.org (Postfix, from userid 1001)
	id 2E7BF1527C; Tue,  4 Oct 2005 17:19:12 -0500 (CDT)
Date: Tue, 4 Oct 2005 17:19:12 -0500
From: "Jim C. Nasby" <jnasby@pervasive.com>
To: K C Lau <kclau60@netvigator.com>
Cc: Simon Riggs <simon@2ndquadrant.com>,
	pgsql-performance@postgresql.org
Subject: Re: SELECT LIMIT 1 VIEW Performance Issue
Message-ID: <20051004221911.GJ40138@pervasive.com>
References: <6.2.1.2.0.20050615100524.04f9d6a8@localhost>
	<6.2.1.2.0.20050922102035.07bcf2e0@localhost>
	<1127378456.4145.76.camel@localhost.localdomain>
	<6.2.1.2.0.20050922181009.02c36ca8@localhost>
	<1127474141.19345.10.camel@localhost.localdomain>
	<6.2.1.2.0.20050923195457.02c4fd30@localhost>
	<20051004211541.GB40138@pervasive.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20051004211541.GB40138@pervasive.com>
X-Operating-System: FreeBSD 4.11-RELEASE-p10 i386
X-Distributed: Join the Effort!  http://www.distributed.net
User-Agent: Mutt/1.5.9i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.008 required=5 tests=[AWL=0.008]
X-Spam-Level: 
X-Archive-Number: 200510/57
X-Sequence-Number: 14825

On Tue, Oct 04, 2005 at 04:15:41PM -0500, Jim C. Nasby wrote:
> >    Index Cond: ((playerid)::text = '22220'::text)

Also, why is playerid a text field? Comparing ints will certainly be
faster...
-- 
Jim C. Nasby, Sr. Engineering Consultant      jnasby@pervasive.com
Pervasive Software      http://pervasive.com    work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf       cell: 512-569-9461

From pgsql-performance-owner@postgresql.org  Tue Oct  4 19:24:28 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id F38EBDA08F
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 19:23:56 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 01490-04
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 22:23:52 +0000 (GMT)
Received: from mir3-fs.mir3.com (mail.mir3.com [65.208.188.100])
	by svr1.postgresql.org (Postfix) with ESMTP id B301CDA107
	for <pgsql-performance@postgresql.org>;
	Tue,  4 Oct 2005 19:23:52 -0300 (ADT)
Received: from archimedes ([172.16.2.68]) by mir3-fs.mir3.com with Microsoft
	SMTPSVC(5.0.2195.6713); Tue, 4 Oct 2005 15:27:08 -0700
Subject: Re: Is There Any Way ....
From: Mark Lewis <mark.lewis@mir3.com>
To: Lane Van Ingen <lvaningen@esncc.com>
Cc: Stefan Weiss <spaceman@foo.at>, pgsql-performance@postgresql.org
In-Reply-To: <EKEMKEFLOMKDDLIALABIOEEICDAA.lvaningen@esncc.com>
References: <EKEMKEFLOMKDDLIALABIOEEICDAA.lvaningen@esncc.com>
Content-Type: text/plain
Organization: MIR3, Inc.
Date: Tue, 04 Oct 2005 15:23:52 -0700
Message-Id: <1128464633.19824.25.camel@archimedes>
Mime-Version: 1.0
X-Mailer: Evolution 2.0.2 (2.0.2-16.3) 
Content-Transfer-Encoding: 7bit
X-OriginalArrivalTime: 04 Oct 2005 22:27:08.0648 (UTC)
	FILETIME=[C1C66680:01C5C932]
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.047 required=5 tests=[AWL=0.047]
X-Spam-Level: 
X-Archive-Number: 200510/58
X-Sequence-Number: 14826

Which version of PG are you using?  One of the new features for 8.0 was
an improved caching algorithm that was smart enough to avoid letting a
single big query sweep everything else out of cache.

-- Mark Lewis


On Tue, 2005-10-04 at 10:45 -0400, Lane Van Ingen wrote:
> Yes, Stefan, the kind of usage you are mentioning is exactly why I was
> asking.
> 
> -----Original Message-----
> From: pgsql-performance-owner@postgresql.org
> [mailto:pgsql-performance-owner@postgresql.org]On Behalf Of Stefan Weiss
> Sent: Tuesday, October 04, 2005 6:32 AM
> To: pgsql-performance@postgresql.org
> Subject: Re: [PERFORM] Is There Any Way ....
> 
> 
> On 2005-09-30 01:21, Lane Van Ingen wrote:
> >   (3) Assure that a disk-based table is always in memory (outside of
> keeping
> > it in
> >       memory buffers as a result of frequent activity which would prevent
> > LRU
> >       operations from taking it out) ?
> 
> I was wondering about this too. IMO it would be useful to have a way to tell
> PG that some tables were needed frequently, and should be cached if
> possible. This would allow application developers to consider joins with
> these tables as "cheap", even when querying on columns that are not indexed.
> I'm thinking about smallish tables like users, groups, *types, etc which
> would be needed every 2-3 queries, but might be swept out of RAM by one
> large query in between. Keeping a table like "users" on a RAM fs would not
> be an option, because the information is not volatile.
> 
> 
> cheers,
> stefan
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 5: don't forget to increase your free space map settings
> 
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 6: explain analyze is your friend


From pgsql-performance-owner@postgresql.org  Tue Oct  4 20:20:22 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id B727BDA112
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 20:20:10 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 16820-07
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 23:20:03 +0000 (GMT)
Received: from netbox.unitech.com.ar (unknown [200.32.92.34])
	by svr1.postgresql.org (Postfix) with ESMTP id 7BE2FDA0AB
	for <pgsql-performance@postgresql.org>;
	Tue,  4 Oct 2005 20:20:02 -0300 (ADT)
Received: from dariop (dariop.unitech.com.ar [192.168.1.237])
	by netbox.unitech.com.ar (8.11.6/8.11.6) with ESMTP id j950I5p15847;
	Tue, 4 Oct 2005 21:18:05 -0300
Received: from 127.0.0.1 (AVG SMTP 7.0.344 [267.11.9]);
	Tue, 04 Oct 2005 20:19:15 -0300
From: "Dario" <dario_d_s@unitech.com.ar>
To: "Joe" <svn@freedomcircle.net>,
	"Jim C. Nasby" <jnasby@pervasive.com>
Cc: "Andreas Pflug" <pgadmin@pse-consulting.de>,
	<pgsql-performance@postgresql.org>
Subject: Re: Comparative performance
Date: Tue, 4 Oct 2005 20:19:14 -0300
Message-ID: <MHEDJHCKDNOEHJKHIOCJIECICIAA.dario_d_s@unitech.com.ar>
MIME-Version: 1.0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0)
In-Reply-To: <4342EFF7.5010405@freedomcircle.net>
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506
Importance: Normal
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.044 required=5 tests=[AWL=0.044]
X-Spam-Level: 
X-Archive-Number: 200510/59
X-Sequence-Number: 14827

Postgresql uses MVCC to ensure data integrity. Server must choose the right
version of tuple, according to transaction ID of statement. Even for a
select (ACID features of postgresql, I think C and I apply here), it must
accomplish some extra work.

-----Mensaje original-----
De: pgsql-performance-owner@postgresql.org
[mailto:pgsql-performance-owner@postgresql.org]En nombre de Joe
Enviado el: martes, 04 de octubre de 2005 18:11
Para: Jim C. Nasby
CC: Andreas Pflug; pgsql-performance@postgresql.org
Asunto: Re: [PERFORM] Comparative performance


Hi Jim,

Jim C. Nasby wrote:
> Also, just because no one else has mentioned it, remember that it's very
> easy to get MySQL into a mode where you have no data integrity. If
> that's the case it's going to be faster than PostgreSQL (though I'm not
> sure how much that affects the performance of SELECTs).

Yes indeed.  When I added the REFERENCES to the schema and reran the
conversion
scripts, aside from having to reorder the table creation and loading (they
used
to be in alphabetical order), I also found a few referential integrity
errors in
the MySQL data.

Joe


---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster


From pgsql-performance-owner@postgresql.org  Tue Oct  4 20:38:05 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id E57F7DA0ED
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 20:35:20 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 23369-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 23:35:15 +0000 (GMT)
Received: from pop-cowbird.atl.sa.earthlink.net
	(pop-cowbird.atl.sa.earthlink.net [207.69.195.68])
	by svr1.postgresql.org (Postfix) with ESMTP id C354ED6F63
	for <pgsql-performance@postgresql.org>;
	Tue,  4 Oct 2005 20:35:13 -0300 (ADT)
Received: from elwamui-polski.atl.sa.earthlink.net ([209.86.224.45])
	by pop-cowbird.atl.sa.earthlink.net with esmtp (Exim 3.36 #10)
	id 1EMwI7-0002Gy-00; Tue, 04 Oct 2005 19:33:47 -0400
Message-ID: 
 <32713495.1128468827337.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
Date: Tue, 4 Oct 2005 19:33:47 -0400 (EDT)
From: Ron Peacetree <rjpeace@earthlink.net>
Reply-To: Ron Peacetree <rjpeace@earthlink.net>
To: "Jim C. Nasby" <jnasby@pervasive.com>,
	pgsql-performance@postgresql.org
Subject: Re: Is There Any Way ....
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: EarthLink Zoo Mail 1.0
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.257 required=5 tests=[AWL=-0.117,
	DNS_FROM_RFC_ABUSE=0.374]
X-Spam-Level: 
X-Archive-Number: 200510/60
X-Sequence-Number: 14828

pg is _very_ stupid about caching.  Almost all of the caching is left
to the OS, and it's that way by design (as post after post by TL has
pointed out).

That means pg has almost no ability to take application domain
specific knowledge into account when deciding what to cache.
There's plenty of papers on caching out there that show that
context dependent knowledge leads to more effective caching
algorithms than context independent ones are capable of.

(Which means said design choice is a Mistake, but unfortunately
one with too much inertia behind it currentyl to change easily.)

Under these circumstances, it is quite possible that an expert class
human could optimize memory usage better than the OS + pg.
   
If one is _sure_ they know what they are doing, I'd suggest using
tmpfs or the equivalent for critical read-only tables.  For "hot"
tables that are rarely written to and where data loss would not be
a disaster, "tmpfs" can be combined with an asyncronous writer
process push updates to HD.  Just remember that a power hit
means that 

The (much) more expensive alternative is to buy SSD(s) and put
the critical tables on it at load time.

Ron
 

-----Original Message-----
From: "Jim C. Nasby" <jnasby@pervasive.com>
Sent: Oct 4, 2005 4:57 PM
To: Stefan Weiss <spaceman@foo.at>
Cc: pgsql-performance@postgresql.org
Subject: Re: [PERFORM] Is There Any Way ....

On Tue, Oct 04, 2005 at 12:31:42PM +0200, Stefan Weiss wrote:
> On 2005-09-30 01:21, Lane Van Ingen wrote:
> >   (3) Assure that a disk-based table is always in memory (outside of keeping
> > it in
> >       memory buffers as a result of frequent activity which would prevent
> > LRU
> >       operations from taking it out) ?
> 
> I was wondering about this too. IMO it would be useful to have a way to tell
> PG that some tables were needed frequently, and should be cached if
> possible. This would allow application developers to consider joins with
> these tables as "cheap", even when querying on columns that are not indexed.
> I'm thinking about smallish tables like users, groups, *types, etc which
> would be needed every 2-3 queries, but might be swept out of RAM by one
> large query in between. Keeping a table like "users" on a RAM fs would not
> be an option, because the information is not volatile.

Why do you think you'll know better than the database how frequently
something is used? At best, your guess will be correct and PostgreSQL
(or the kernel) will keep the table in memory. Or, your guess is wrong
and you end up wasting memory that could have been used for something
else.

It would probably be better if you describe why you want to force this
table (or tables) into memory, so we can point you at more appropriate
solutions.

From pgsql-performance-owner@postgresql.org  Tue Oct  4 21:01:11 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 44E86D9F39
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 21:01:09 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 27311-10
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 00:01:04 +0000 (GMT)
Received: from flake.decibel.org (flake.decibel.org [67.100.216.10])
	by svr1.postgresql.org (Postfix) with ESMTP id C901ED9B31
	for <pgsql-performance@postgresql.org>;
	Tue,  4 Oct 2005 21:01:01 -0300 (ADT)
Received: by flake.decibel.org (Postfix, from userid 1001)
	id 6E0481529A; Tue,  4 Oct 2005 19:01:04 -0500 (CDT)
Date: Tue, 4 Oct 2005 19:01:04 -0500
From: "Jim C. Nasby" <jnasby@pervasive.com>
To: Ron Peacetree <rjpeace@earthlink.net>
Cc: pgsql-performance@postgresql.org
Subject: Re: Is There Any Way ....
Message-ID: <20051005000104.GO40138@pervasive.com>
References: 
 <32713495.1128468827337.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: 
 <32713495.1128468827337.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
X-Operating-System: FreeBSD 4.11-RELEASE-p10 i386
X-Distributed: Join the Effort!  http://www.distributed.net
User-Agent: Mutt/1.5.9i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.008 required=5 tests=[AWL=0.008]
X-Spam-Level: 
X-Archive-Number: 200510/61
X-Sequence-Number: 14829

On Tue, Oct 04, 2005 at 07:33:47PM -0400, Ron Peacetree wrote:
> pg is _very_ stupid about caching.  Almost all of the caching is left
> to the OS, and it's that way by design (as post after post by TL has
> pointed out).
> 
> That means pg has almost no ability to take application domain
> specific knowledge into account when deciding what to cache.
> There's plenty of papers on caching out there that show that
> context dependent knowledge leads to more effective caching
> algorithms than context independent ones are capable of.
> 
> (Which means said design choice is a Mistake, but unfortunately
> one with too much inertia behind it currentyl to change easily.)
> 
> Under these circumstances, it is quite possible that an expert class
> human could optimize memory usage better than the OS + pg.

Do you have any examples where this has actually happened? Especially
with 8.x, which isn't all that 'stupid' about how it handles buffers?
-- 
Jim C. Nasby, Sr. Engineering Consultant      jnasby@pervasive.com
Pervasive Software      http://pervasive.com    work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf       cell: 512-569-9461

From pgsql-performance-owner@postgresql.org  Tue Oct  4 21:44:50 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id F379BDA0E1
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 21:44:41 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 42785-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 00:44:34 +0000 (GMT)
Received: from outbound0.sv.meer.net (outbound0.sv.meer.net [205.217.152.13])
	by svr1.postgresql.org (Postfix) with ESMTP id 754F0DA0F0
	for <pgsql-performance@postgresql.org>;
	Tue,  4 Oct 2005 21:44:35 -0300 (ADT)
Received: from mail.meer.net (mail.meer.net [209.157.152.14])
	by outbound0.sv.meer.net (8.12.10/8.12.6) with ESMTP id j950ffsm015975
	for <pgsql-performance@postgresql.org>;
	Tue, 4 Oct 2005 17:41:48 -0700 (PDT)
	(envelope-from trainor@transborder.net)
Received: from [192.168.1.46] (pool-151-197-28-186.phil.east.verizon.net
	[151.197.28.186])
	by mail.meer.net (8.13.3/8.13.3/meer) with ESMTP id j950erDY086499
	for <pgsql-performance@postgresql.org>;
	Tue, 4 Oct 2005 17:40:54 -0700 (PDT)
	(envelope-from trainor@transborder.net)
Mime-Version: 1.0 (Apple Message framework v623)
In-Reply-To: 
 <32713495.1128468827337.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
References: 
 <32713495.1128468827337.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
Content-Type: text/plain; charset=US-ASCII; format=flowed
Message-Id: <8bafaa62907deae2460ba2ecbb022741@transborder.net>
Content-Transfer-Encoding: 7bit
From: "Douglas J. Trainor" <trainor@transborder.net>
Subject: Re: Is There Any Way ....
Date: Tue, 4 Oct 2005 20:40:54 -0400
To: pgsql-performance@postgresql.org
X-Mailer: Apple Mail (2.623)
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0 required=5 tests=[none]
X-Spam-Level: 
X-Archive-Number: 200510/62
X-Sequence-Number: 14830


Ron Peacetree sounds like someone talking out of his _AZZ_.
He can save his unreferenced flapdoodle for his SQL Server
clients.  Maybe he will post references so that we may all
learn at the feet of Master Peacetree.  :-)

     douglas

On Oct 4, 2005, at 7:33 PM, Ron Peacetree wrote:

> pg is _very_ stupid about caching.  Almost all of the caching is left
> to the OS, and it's that way by design (as post after post by TL has
> pointed out).
>
> That means pg has almost no ability to take application domain
> specific knowledge into account when deciding what to cache.
> There's plenty of papers on caching out there that show that
> context dependent knowledge leads to more effective caching
> algorithms than context independent ones are capable of.
>
> (Which means said design choice is a Mistake, but unfortunately
> one with too much inertia behind it currentyl to change easily.)
>
> Under these circumstances, it is quite possible that an expert class
> human could optimize memory usage better than the OS + pg.
>
> If one is _sure_ they know what they are doing, I'd suggest using
> tmpfs or the equivalent for critical read-only tables.  For "hot"
> tables that are rarely written to and where data loss would not be
> a disaster, "tmpfs" can be combined with an asyncronous writer
> process push updates to HD.  Just remember that a power hit
> means that
>
> The (much) more expensive alternative is to buy SSD(s) and put
> the critical tables on it at load time.
>
> Ron
>
>
> -----Original Message-----
> From: "Jim C. Nasby" <jnasby@pervasive.com>
> Sent: Oct 4, 2005 4:57 PM
> To: Stefan Weiss <spaceman@foo.at>
> Cc: pgsql-performance@postgresql.org
> Subject: Re: [PERFORM] Is There Any Way ....
>
> On Tue, Oct 04, 2005 at 12:31:42PM +0200, Stefan Weiss wrote:
>> On 2005-09-30 01:21, Lane Van Ingen wrote:
>>>   (3) Assure that a disk-based table is always in memory (outside of 
>>> keeping
>>> it in
>>>       memory buffers as a result of frequent activity which would 
>>> prevent
>>> LRU
>>>       operations from taking it out) ?
>>
>> I was wondering about this too. IMO it would be useful to have a way 
>> to tell
>> PG that some tables were needed frequently, and should be cached if
>> possible. This would allow application developers to consider joins 
>> with
>> these tables as "cheap", even when querying on columns that are not 
>> indexed.
>> I'm thinking about smallish tables like users, groups, *types, etc 
>> which
>> would be needed every 2-3 queries, but might be swept out of RAM by 
>> one
>> large query in between. Keeping a table like "users" on a RAM fs 
>> would not
>> be an option, because the information is not volatile.
>
> Why do you think you'll know better than the database how frequently
> something is used? At best, your guess will be correct and PostgreSQL
> (or the kernel) will keep the table in memory. Or, your guess is wrong
> and you end up wasting memory that could have been used for something
> else.
>
> It would probably be better if you describe why you want to force this
> table (or tables) into memory, so we can point you at more appropriate
> solutions.


From pgsql-performance-owner@postgresql.org  Tue Oct  4 22:09:12 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 83331DA0F0
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 22:09:06 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 49087-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 01:09:02 +0000 (GMT)
Received: from mail.baymountain.com (mail.baymountain.com [8.7.96.19])
	by svr1.postgresql.org (Postfix) with SMTP id 2E462DA0AB
	for <pgsql-performance@postgresql.org>;
	Tue,  4 Oct 2005 22:09:03 -0300 (ADT)
Received: (qmail 30517 invoked by uid 504); 5 Oct 2005 01:09:06 -0000
Received: from emil@baymountain.com by mail.baymountain.com by uid 501 with
	qmail-scanner-1.16 (spamassassin: 2.53.  Clear:SA:0(0.0/7.0):.
	Processed in 0.266532 secs); 05 Oct 2005 01:09:06 -0000
Received: from unknown (HELO briggspack.com)
	(emil@briggspack.com@24.211.148.77)
	by mail.baymountain.com with SMTP; 5 Oct 2005 01:09:06 -0000
From: Emil Briggs <emil@baymountain.com>
Reply-To: emil@baymountain.com
Organization: Baymountain, Inc.
To: pgsql-performance@postgresql.org
Subject: Indexes on ramdisk
Date: Tue, 4 Oct 2005 21:09:01 -0400
User-Agent: KMail/1.7.1
MIME-Version: 1.0
Content-Type: text/plain;
  charset="us-ascii"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Message-Id: <200510042109.01849.emil@baymountain.com>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.037 required=5 tests=[AWL=-0.013,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/63
X-Sequence-Number: 14831


I have an application that has a table that is both read and write intensive. 
Data from iostat indicates that the write speed of the system is the factor 
that is limiting performance. The table has around 20 columns and most of the 
columns are indexed. The data and the indices for the table are distributed 
over several mirrored disk partitions and pg_xlog is on another. I'm looking 
at ways to improve performance and besides the obvious one of getting an SSD 
I thought about putting the indices on a ramdisk. That means that after a 
power failure or shutdown I would have to recreate them but that is 
acceptable for this application. What I am wondering though is whether or not 
I would see much performance benefit and if there would be any startup 
problems after a power down event due to the indices not being present. Any 
insight would be appreciated.

Emil

From pgsql-performance-owner@postgresql.org  Tue Oct  4 22:30:02 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id AD739DA0F0
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  4 Oct 2005 22:29:57 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 71000-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 01:29:49 +0000 (GMT)
Received: from hosting.commandprompt.com (128.commandprompt.com
	[207.173.200.128])
	by svr1.postgresql.org (Postfix) with ESMTP id 4C414DA0AB
	for <pgsql-performance@postgresql.org>;
	Tue,  4 Oct 2005 22:29:50 -0300 (ADT)
Received: from [192.168.1.100] (clbb-248.saw.net [64.146.135.248])
	(authenticated bits=0)
	by hosting.commandprompt.com (8.13.4/8.13.4) with ESMTP id
	j951RHkQ024368; Tue, 4 Oct 2005 18:27:20 -0700
Message-ID: <43432D22.6090109@commandprompt.com>
Date: Tue, 04 Oct 2005 18:32:18 -0700
From: "Joshua D. Drake" <jd@commandprompt.com>
User-Agent: Mozilla Thunderbird 1.0.6 (X11/20050912)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: "Douglas J. Trainor" <trainor@transborder.net>
Cc: pgsql-performance@postgresql.org
Subject: Re: Is There Any Way ....
References: 
 <32713495.1128468827337.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
	<8bafaa62907deae2460ba2ecbb022741@transborder.net>
In-Reply-To: <8bafaa62907deae2460ba2ecbb022741@transborder.net>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.021 required=5 tests=[AWL=0.021]
X-Spam-Level: 
X-Archive-Number: 200510/64
X-Sequence-Number: 14832

Douglas J. Trainor wrote:

>
> Ron Peacetree sounds like someone talking out of his _AZZ_.
> He can save his unreferenced flapdoodle for his SQL Server
> clients.  Maybe he will post references so that we may all
> learn at the feet of Master Peacetree.  :-)

Although I agree that I would definitely like to see some test cases
for what Ron is talking about, I don't think that resorting to insults
is going to help the situation.

Ron, if you would please -- provide some test cases for what you are
describing I am sure that anyone would love to see them. We are all
for improving PostgreSQL.

Sincerely,

Joshua D. Drake

-- 
Your PostgreSQL solutions company - Command Prompt, Inc. 1.800.492.2240
PostgreSQL Replication, Consulting, Custom Programming, 24x7 support
Managed Services, Shared and Dedicated Hosting
Co-Authors: plPHP, plPerlNG - http://www.commandprompt.com/


From pgsql-performance-owner@postgresql.org  Wed Oct  5 00:07:06 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 61DDDDA101
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 00:07:04 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 83964-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 03:07:02 +0000 (GMT)
Received: from pop-cowbird.atl.sa.earthlink.net
	(pop-cowbird.atl.sa.earthlink.net [207.69.195.68])
	by svr1.postgresql.org (Postfix) with ESMTP id 6453DDA0F9
	for <pgsql-performance@postgresql.org>;
	Wed,  5 Oct 2005 00:07:01 -0300 (ADT)
Received: from elwamui-polski.atl.sa.earthlink.net ([209.86.224.45])
	by pop-cowbird.atl.sa.earthlink.net with esmtp (Exim 3.36 #10)
	id 1EMzcM-0004F8-00; Tue, 04 Oct 2005 23:06:54 -0400
Message-ID: 
 <17434238.1128481614269.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
Date: Tue, 4 Oct 2005 23:06:54 -0400 (EDT)
From: Ron Peacetree <rjpeace@earthlink.net>
Reply-To: Ron Peacetree <rjpeace@earthlink.net>
To: "Joshua D. Drake" <jd@commandprompt.com>, pgsql-performance@postgresql.org
Subject: Re: Is There Any Way ....
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: EarthLink Zoo Mail 1.0
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.257 required=5 tests=[AWL=-0.117,
	DNS_FROM_RFC_ABUSE=0.374]
X-Spam-Level: 
X-Archive-Number: 200510/65
X-Sequence-Number: 14833

Unfortunately, no matter what I say or do, I'm not going to please
or convince anyone who has already have made their minds up
to the extent that they post comments like Mr Trainor's below.
His response style pretty much proves my earlier point that this
is presently a religious issue within the pg community.

The absolute best proof would be to build a version of pg that does
what Oracle and DB2 have done and implement it's own DB
specific memory manager and then compare the performance
between the two versions on the same HW, OS, and schema.

The second best proof would be to set up either DB2 or Oracle so
that they _don't_ use their memory managers and compare their
performance to a set up that _does_ use said memory managers
on the same HW, OS, and schema.

I don't currently have the resources for either experiment.

Some might even argue that IBM (where Codd and Date worked)
and Oracle just _might_ have had justification for the huge effort
they put into developing such infrastructure. 

Then there's the large library of research on caching strategies
in just about every HW and SW domain, including DB theory,
that points put that the more context dependent, ie application
or domain specific awareness, caching strategies are the better
they are.

Maybe after we do all we can about physical IO and sorting
performance I'll take on the religious fanatics on this one.

One problem set at a time.
Ron   
 

-----Original Message-----
From: "Joshua D. Drake" <jd@commandprompt.com>
Sent: Oct 4, 2005 9:32 PM
To: "Douglas J. Trainor" <trainor@transborder.net>
Cc: pgsql-performance@postgresql.org
Subject: Re: [PERFORM] Is There Any Way ....

Douglas J. Trainor wrote:

>
> Ron Peacetree sounds like someone talking out of his _AZZ_.
> He can save his unreferenced flapdoodle for his SQL Server
> clients.  Maybe he will post references so that we may all
> learn at the feet of Master Peacetree.  :-)

Although I agree that I would definitely like to see some test cases
for what Ron is talking about, I don't think that resorting to insults
is going to help the situation.

Ron, if you would please -- provide some test cases for what you are
describing I am sure that anyone would love to see them. We are all
for improving PostgreSQL.

Sincerely,

Joshua D. Drake

-- 
Your PostgreSQL solutions company - Command Prompt, Inc. 1.800.492.2240
PostgreSQL Replication, Consulting, Custom Programming, 24x7 support
Managed Services, Shared and Dedicated Hosting
Co-Authors: plPHP, plPerlNG - http://www.commandprompt.com/


---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend


From pgsql-performance-owner@postgresql.org  Wed Oct  5 00:23:25 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 4491DD7DBE
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 00:23:23 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 98262-09
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 03:23:19 +0000 (GMT)
Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.203])
	by svr1.postgresql.org (Postfix) with ESMTP id 5AAFDDA0C7
	for <pgsql-performance@postgresql.org>;
	Wed,  5 Oct 2005 00:23:18 -0300 (ADT)
Received: by wproxy.gmail.com with SMTP id 71so31516wra
	for <pgsql-performance@postgresql.org>;
	Tue, 04 Oct 2005 20:23:17 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:references;
	b=EXNNqjNnrjOZER0lvH+V27qmj3sC7Z1IRrk4+A1JYdE0F1ZF0pS6NxXutrMLeTwHSNB2T5Gx3uLlxx259l2CS0mIG0cLHonqWkyTYtgeamZ0YQ2o2cv9SC8iqmDRdcrRNNcRdJC5dBUtG+/zy5PxuCkyVz8wuaNY0URxXzuNjKw=
Received: by 10.54.72.8 with SMTP id u8mr182463wra;
	Tue, 04 Oct 2005 20:23:17 -0700 (PDT)
Received: by 10.54.84.8 with HTTP; Tue, 4 Oct 2005 20:23:17 -0700 (PDT)
Message-ID: <33c6269f0510042023t24175e33vf84d9af609a8ccd7@mail.gmail.com>
Date: Tue, 4 Oct 2005 23:23:17 -0400
From: Alex Turner <armtuk@gmail.com>
Reply-To: Alex Turner <armtuk@gmail.com>
To: emil@baymountain.com
Subject: Re: Indexes on ramdisk
Cc: pgsql-performance@postgresql.org
In-Reply-To: <200510042109.01849.emil@baymountain.com>
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="----=_Part_14912_24637405.1128482597905"
References: <200510042109.01849.emil@baymountain.com>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.251 required=5 tests=[AWL=-0.069, HTML_10_20=0.295,
	HTML_MESSAGE=0.001, RCVD_BY_IP=0.024]
X-Spam-Level: 
X-Archive-Number: 200510/66
X-Sequence-Number: 14834

------=_Part_14912_24637405.1128482597905
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Talk about your IO system a bit. There might be obvious ways to improve.

What System/Motherboard are you using?
What Controller Cards are you using?
What kind of Disks do you have (SATA, SCSI 7.6k 10k 15k)
What denominations (9, 18, 36, 72, 143, 80, 160, 200 240Gig)?
What kind of RAIDs do you have setup (How many drives what stripe sizes, ho=
w
many used for what).
What levels of RAID are you using (0,1,10,5,50)?

With good setup, a dual PCI-X bus motherboard can hit 2GB/sec and thousands
of transactions to disk if you have a controller/disks that can keep up.
That is typicaly enough for most people without resorting to SSD.

Alex Turner
NetEconomist

On 10/4/05, Emil Briggs <emil@baymountain.com> wrote:
>
>
> I have an application that has a table that is both read and write
> intensive.
> Data from iostat indicates that the write speed of the system is the
> factor
> that is limiting performance. The table has around 20 columns and most of
> the
> columns are indexed. The data and the indices for the table are
> distributed
> over several mirrored disk partitions and pg_xlog is on another. I'm
> looking
> at ways to improve performance and besides the obvious one of getting an
> SSD
> I thought about putting the indices on a ramdisk. That means that after a
> power failure or shutdown I would have to recreate them but that is
> acceptable for this application. What I am wondering though is whether or
> not
> I would see much performance benefit and if there would be any startup
> problems after a power down event due to the indices not being present.
> Any
> insight would be appreciated.
>
> Emil
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: don't forget to increase your free space map settings
>

------=_Part_14912_24637405.1128482597905
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Talk about your IO system a bit.&nbsp; There might be obvious ways to impro=
ve.<br>
<br>
What System/Motherboard are you using?<br>
What Controller Cards are you using?<br>
What kind of Disks do you have (SATA, SCSI 7.6k 10k 15k)<br>
What denominations (9, 18, 36, 72, 143, 80, 160, 200 240Gig)?<br>
What kind of RAIDs do you have setup (How many drives what stripe sizes, ho=
w many used for what).<br>
What levels of RAID are you using (0,1,10,5,50)?<br>
<br>
With good setup, a dual PCI-X bus motherboard can hit 2GB/sec and
thousands of transactions&nbsp; to disk if you have a controller/disks
that can keep up.&nbsp; That is typicaly enough for most people without
resorting to SSD.<br>
<br>
Alex Turner<br>
NetEconomist<br><br><div><span class=3D"gmail_quote">On 10/4/05, <b class=
=3D"gmail_sendername">Emil Briggs</b> &lt;<a href=3D"mailto:emil@baymountai=
n.com">emil@baymountain.com</a>&gt; wrote:</span><blockquote class=3D"gmail=
_quote" style=3D"border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt=
 0pt 0.8ex; padding-left: 1ex;">
<br>I have an application that has a table that is both read and write inte=
nsive.<br>Data from iostat indicates that the write speed of the system is =
the factor<br>that is limiting performance. The table has around 20 columns=
 and most of the
<br>columns are indexed. The data and the indices for the table are distrib=
uted<br>over several mirrored disk partitions and pg_xlog is on another. I'=
m looking<br>at ways to improve performance and besides the obvious one of =
getting an SSD
<br>I thought about putting the indices on a ramdisk. That means that after=
 a<br>power failure or shutdown I would have to recreate them but that is<b=
r>acceptable for this application. What I am wondering though is whether or=
 not
<br>I would see much performance benefit and if there would be any startup<=
br>problems after a power down event due to the indices not being present. =
Any<br>insight would be appreciated.<br><br>Emil<br><br>-------------------=
--------(end of broadcast)---------------------------
<br>TIP 5: don't forget to increase your free space map settings<br></block=
quote></div><br>

------=_Part_14912_24637405.1128482597905--

From pgsql-performance-owner@postgresql.org  Wed Oct  5 00:41:35 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 89734D9477
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 00:41:33 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 34930-04
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 03:41:30 +0000 (GMT)
Received: from mail.baymountain.com (mail.baymountain.com [8.7.96.19])
	by svr1.postgresql.org (Postfix) with SMTP id D0BDCD93DA
	for <pgsql-performance@postgresql.org>;
	Wed,  5 Oct 2005 00:41:29 -0300 (ADT)
Received: (qmail 3520 invoked by uid 504); 5 Oct 2005 03:41:28 -0000
Received: from emil@baymountain.com by mail.baymountain.com by uid 501 with
	qmail-scanner-1.16 (spamassassin: 2.53.  Clear:SA:0(0.0/7.0):.
	Processed in 0.270083 secs); 05 Oct 2005 03:41:28 -0000
Received: from unknown (HELO briggspack.com)
	(emil@briggspack.com@24.211.148.77)
	by mail.baymountain.com with SMTP; 5 Oct 2005 03:41:27 -0000
From: Emil Briggs <emil@baymountain.com>
Reply-To: emil@baymountain.com
Organization: Baymountain, Inc.
To: pgsql-performance@postgresql.org
Subject: Re: Indexes on ramdisk
Date: Tue, 4 Oct 2005 23:41:23 -0400
User-Agent: KMail/1.7.1
References: <200510042109.01849.emil@baymountain.com>
	<33c6269f0510042023t24175e33vf84d9af609a8ccd7@mail.gmail.com>
In-Reply-To: <33c6269f0510042023t24175e33vf84d9af609a8ccd7@mail.gmail.com>
MIME-Version: 1.0
Content-Type: text/plain;
  charset="utf-8"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Message-Id: <200510042341.23264.emil@baymountain.com>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.038 required=5 tests=[AWL=-0.013,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/67
X-Sequence-Number: 14835

> Talk about your IO system a bit. There might be obvious ways to improve.
>
> What System/Motherboard are you using?
> What Controller Cards are you using?
> What kind of Disks do you have (SATA, SCSI 7.6k 10k 15k)
> What denominations (9, 18, 36, 72, 143, 80, 160, 200 240Gig)?
> What kind of RAIDs do you have setup (How many drives what stripe sizes,
> how many used for what).
> What levels of RAID are you using (0,1,10,5,50)?
>

It's a quad opteron system. RAID controller is a 4 channel LSILogic Megaraid  
320 connected to 10 15k 36.7G SCSI disks. The disks are configured in 5 
mirrored partitions. The pg_xlog is on one mirror and the data and indexes 
are spread over the other 4 using tablespaces. These numbers from 
pg_stat_user_tables are from about 2 hours earlier today on this one table.


idx_scan           20578690
idx_tup_fetch  35866104841
n_tup_ins        1940081
n_tup_upd       1604041
n_tup_del        1880424



From pgsql-performance-owner@postgresql.org  Wed Oct  5 00:52:55 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 263ADD9BDC
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 00:52:49 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 38746-06
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 03:52:47 +0000 (GMT)
Received: from gp.word-to-the-wise.com (gp.word-to-the-wise.com
 [64.71.176.18])
	by svr1.postgresql.org (Postfix) with ESMTP id 97245D9B4E
	for <pgsql-performance@postgresql.org>;
	Wed,  5 Oct 2005 00:52:46 -0300 (ADT)
Received: by gp.word-to-the-wise.com (Postfix, from userid 500)
	id 1C6D68FC07D; Tue,  4 Oct 2005 20:50:13 -0700 (PDT)
Date: Tue, 4 Oct 2005 20:50:13 -0700
From: Steve Atkins <steve@blighty.com>
To: pgsql-performance@postgresql.org
Subject: Re: Is There Any Way ....
Message-ID: <20051005035012.GA21033@gp.word-to-the-wise.com>
References: 
 <17434238.1128481614269.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: 
 <17434238.1128481614269.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
User-Agent: Mutt/1.4.1i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.889 required=5 tests=[AWL=-0.487,
	DNS_FROM_RFC_POST=1.376]
X-Spam-Level: 
X-Archive-Number: 200510/68
X-Sequence-Number: 14836

On Tue, Oct 04, 2005 at 11:06:54PM -0400, Ron Peacetree wrote:

> Some might even argue that IBM (where Codd and Date worked)
> and Oracle just _might_ have had justification for the huge effort
> they put into developing such infrastructure. 

The OS and FS world is very, very different now than it was when
the Oracle and DB2 architectures were being crafted. What may have
been an excellent development effort then may not provide such good
ROI now.

> Then there's the large library of research on caching strategies
> in just about every HW and SW domain, including DB theory,
> that points put that the more context dependent, ie application
> or domain specific awareness, caching strategies are the better
> they are.
> 
> Maybe after we do all we can about physical IO and sorting
> performance I'll take on the religious fanatics on this one.

Actually, the main "religious fanatic" I've seen recently is yourself.
While I have a gut feel that some of the issues you raise could
certainly do with further investigation, I'm not seeing that much from
you other than statements that muchof what postgresql does is wrong
(not "wrong for your Ron's use case", but "wrong in every respect").

A little less arrogance and a little more "here are some possibilities
for improvement", "here is an estimate of the amount of effort that
might be needed" and "here are some rough benchmarks showing the
potential return on that investment" would, at the very least, make
the threads far less grating to read.

Cheers,
  Steve

From pgsql-performance-owner@postgresql.org  Wed Oct  5 01:05:27 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id D40D2D7FE7
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 01:05:25 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 82344-07
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 04:05:12 +0000 (GMT)
Received: from mail.envyfinancial.com (unknown [206.248.142.186])
	by svr1.postgresql.org (Postfix) with ESMTP id A6736D9C84
	for <pgsql-performance@postgresql.org>;
	Wed,  5 Oct 2005 01:05:11 -0300 (ADT)
Received: from localhost (localhost.localdomain [127.0.0.1])
	by mail.envyfinancial.com (Postfix) with ESMTP id A997F234B2;
	Tue,  4 Oct 2005 23:50:24 -0400 (EDT)
Received: from mail.envyfinancial.com ([127.0.0.1])
	by localhost (mark.mielke.cc [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 02774-01; Tue,  4 Oct 2005 23:50:24 -0400 (EDT)
Received: by mail.envyfinancial.com (Postfix, from userid 500)
	id 6AAEF234B1; Tue,  4 Oct 2005 23:50:24 -0400 (EDT)
Date: Tue, 4 Oct 2005 23:50:24 -0400
From: mark@mark.mielke.cc
To: Ron Peacetree <rjpeace@earthlink.net>
Cc: "Joshua D. Drake" <jd@commandprompt.com>, pgsql-performance@postgresql.org
Subject: Re: Is There Any Way ....
Message-ID: <20051005035024.GA2529@mark.mielke.cc>
References: 
 <17434238.1128481614269.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: 
 <17434238.1128481614269.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
User-Agent: Mutt/1.4.2.1i
X-Virus-Scanned: amavisd-new at mail.envyfinancial.com
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.192 required=5 tests=[AWL=0.014, NO_REAL_NAME=0.178]
X-Spam-Level: 
X-Archive-Number: 200510/69
X-Sequence-Number: 14837

On Tue, Oct 04, 2005 at 11:06:54PM -0400, Ron Peacetree wrote:
> Unfortunately, no matter what I say or do, I'm not going to please
> or convince anyone who has already have made their minds up
> to the extent that they post comments like Mr Trainor's below.
> His response style pretty much proves my earlier point that this
> is presently a religious issue within the pg community.

Religious for some. Conservative for others.

Sometimes people need to see the way, before they are willing to
accept it merely on the say so of another person. In some circles, it
is called the scientific method... :-)

Also, there is a cost to complicated specific optimizations. They can
be a real maintenance and portability head-ache. What is the value ratio
of performance to maintenance or portability?

> The absolute best proof would be to build a version of pg that does
> what Oracle and DB2 have done and implement it's own DB
> specific memory manager and then compare the performance
> between the two versions on the same HW, OS, and schema.

Not necessarily. Even if a version of PostgreSQL were to be written to
function in this new model, there would be no guarantee that it was
written in the most efficient manner possible. Performance could show
PostgreSQL using its own caching, and disk space management
implementation, and performing poorly. The only true, and accurate way
would be to implement, and then invest time by those most competent to
test, and optimize the implementation. At this point, it would become
a moving target, as those who believe otherwise, would be free to
pursue using more efficient file systems, or modifications to the
operating system to better co-operate with PostgreSQL.

I don't think there can be a true answer to this one. The more
innovative, and clever people, will always be able to make their
solution work better. If the difference in performance was really so
obvious, there wouldn't be doubters on either side. It would be clear
to all. The fact is, there is reason to doubt. Perhaps not doubt that
the final solution would be more efficient, but rather, the reason
to doubt that the difference in efficiency would be significant.

> The second best proof would be to set up either DB2 or Oracle so
> that they _don't_ use their memory managers and compare their
> performance to a set up that _does_ use said memory managers
> on the same HW, OS, and schema.

Same as above. If Oracle was designed to work with the functionality,
then disabling the functionality, wouldn't prove that an efficient
design would perform equally poorly, or even, poorly at all. I think
it would be obvious that Oracle would have invested most of their
dollars into the common execution paths, with the expected
functionality present.

> I don't currently have the resources for either experiment.

This is the real problem. :-)

> Some might even argue that IBM (where Codd and Date worked)
> and Oracle just _might_ have had justification for the huge effort
> they put into developing such infrastructure. 

Or, not. They might just have more money to throw at the problem,
and be entrenched into their solution to the point that they need
to innovate to ensure that their solution appears to be the best.

> Then there's the large library of research on caching strategies
> in just about every HW and SW domain, including DB theory,
> that points put that the more context dependent, ie application
> or domain specific awareness, caching strategies are the better
> they are.

A lot of this is theory. It may be good theory, but there is no
guarantee that the variables listed in these theories match, or
properly estimate the issues that would be found in a real
implementation.

> Maybe after we do all we can about physical IO and sorting
> performance I'll take on the religious fanatics on this one.
> One problem set at a time.

In any case, I'm on your side - in theory. Intuitively, I don't
understand how anybody could claim that a general solution could ever
be faster than a specific solution. Anybody who claimed this, would
go down in my books as a fool. It should be obvious to these people
that, as an extreme, the entire operating system caching layer, and
the entire file system layer could be inlined into PostgreSQL,
avoiding many of the expenses involved in switching back and forth
between user space and system space, leaving a more efficient,
although significantly more complicated solution.

Whether by luck, or by experience of those involved, I haven't seen
any senior PostgreSQL developers actually stating that it couldn't be
faster. Instead, I've seen it claimed that the PostgreSQL developers
don't have the resources to attack this problem, as there are other
far more pressing features, product defects, and more obviously
beneficial optimization opportunities to work on. Memory management,
or disk management, is "good enough" as provided by decent operating
systems, and the itch just isn't bad enough to scratch yet. They
remain unconvinced that the gain in performance, would be worth the
cost of maintaining this extra complexity in the code base.

If you believe the case can be made, it is up to you to make it.

Cheers!
mark

-- 
mark@mielke.cc / markm@ncf.ca / markm@nortel.com     __________________________
.  .  _  ._  . .   .__    .  . ._. .__ .   . . .__  | Neighbourhood Coder
|\/| |_| |_| |/    |_     |\/|  |  |_  |   |/  |_   | 
|  | | | | \ | \   |__ .  |  | .|. |__ |__ | \ |__  | Ottawa, Ontario, Canada

  One ring to rule them all, one ring to find them, one ring to bring them all
                       and in the darkness bind them...

                           http://mark.mielke.cc/


From pgsql-performance-owner@postgresql.org  Wed Oct  5 03:36:12 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id E9B64D6F63
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 03:16:39 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 06022-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 06:16:33 +0000 (GMT)
Received: from gwmta.wicourts.gov (gwmta.wicourts.gov [165.219.244.91])
	by svr1.postgresql.org (Postfix) with ESMTP id 59B7EDA1D4
	for <pgsql-performance@postgresql.org>;
	Wed,  5 Oct 2005 03:16:32 -0300 (ADT)
Received: from Courts-MTA by gwmta.wicourts.gov
	with Novell_GroupWise; Wed, 05 Oct 2005 01:16:32 -0500
Message-Id: <s3432970.018@gwmta.wicourts.gov>
X-Mailer: Novell GroupWise Internet Agent 6.5.4 
Date: Wed, 05 Oct 2005 01:16:23 -0500
From: "Kevin Grittner" <Kevin.Grittner@wicourts.gov>
To: <jd@commandprompt.com>, <rjpeace@earthlink.net>,
	<pgsql-performance@postgresql.org>
Subject: Re: Is There Any Way ....
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.003 required=5 tests=[AWL=0.003]
X-Spam-Level: 
X-Archive-Number: 200510/75
X-Sequence-Number: 14843

First off, Mr. Trainor's response proves nothing about anyone or
anything except Mr. Trainor.
=20
I'm going to offer an opinion on the caching topic.  I don't have
any benchmarks; I'm offering a general sense of the issue based on
decades of experience, so I'll give a short summary of that.
=20
I've been earning my living by working with computers since 1972,
and am the architect and primary author of a little-known
database product (developed in 1984) which saw tens of thousands
of installations in various vertical markets.  (Last I checked, a
couple years ago, it was still being used statewide by one state
government after a multi-million dollar attempt to replace it with a
popular commercial database product failed.)  I've installed and
tuned many other database products over the years.  I'm just getting
to know PostgreSQL, and am pretty excited about it.
=20
Now on to the meat of it.
=20
My experience is that a DBMS can improve performance by caching
certain types of data.  In the product I developed, we had a fairly
small cache which used a weighting algorithm for what to keep
(rather than simply relying on LRU).  Index pages got higher weight
than data pages; the higher in the index, the higher the weight.
Recent access got higher weight than older access, although it took
quite a while for the older access to age out entirely. This
improved performance quite a bit over a generalized caching
product alone.
=20
However, there was a point of diminishing return.  My sense is that
every 10% you add to a "smart" cache yields less benefit at a
higher cost, so beyond a certain point, taking RAM from the general
cache to expand the smart cache degrades performance.  Clever
programming techniques can shift the break-even point, but I very
much doubt it can be eliminated entirely, unless the ratio of
performance between CPU+RAM and persistent storage is much
more extreme than I've ever seen.
=20
There is another issue, which has been raised from time to time in
these lists, but not enunciated clearly enough in my view.  These
discussions about caching generally address maximum throughput,
while there are times when it is important that certain tables can
be queried very quickly, even if it hurts overall throughput.  As an
example, there can be tables which are accessed as a user types in
a window and tabs around from one GUI control to another.  The
user perception of the application performance is going to depend
PRIMARILY on how quickly the GUI renders the results of these
queries; if the run time for a large report goes up by 10%, they
will probably not notice.  This is a situation where removing RAM
from a generalized cache, or one based on database internals, to
create an "application specific" cache can yield big rewards.
=20
One client has addressed this in a commercial product by defining
a named cache large enough to hold these tables, and binding those
tables to the cache.  One side benefit is that such caches can be
defined as "relaxed LRU" -- meaning that they eliminate the
overhead of tracking accesses, since they can assume that data will
rarely, if ever, be discarded from the cache.
=20
It seems to me that in the PostgreSQL world, this would currently
be addressed by binding the tables to a tablespace where the file
system, controller, or drive(s) would cache the data, although this
is somewhat less flexible than the "named cache" approach -- unless
there is a file system that can layer a cache on top of a reference to
some other file system's space.  (And let's not forget the many OS
environments in which people use PostgreSQL.)  So I do see that
there would be benefit to adding a feature to PostgreSQL to define
caches and bind tables or indexes to them.
=20
So I do think that it is SMART of PostgreSQL to rely on the
increasingly sophisticated file systems to provide the MAIN cache.
I suspect that a couple types of smaller "smart" caches in front of
this could boost performance, and it might be a significant boost.
I'm not sure what the current shared memory is used for; perhaps
this is already caching specific types of structures for the DBMS.
I'm pretty sure that programmers of GUI apps would appreciate the
named cache feature, so they could tune the database for snappy
GUI response, even under heavy load.
=20
I realize this is short on specifics -- I'm shooting for perspective.
For the record, I don't consider myself particularly religious on the
topic, but I do pull back a little at arguments which sound strictly
academic -- I've found that most of what I've drawn from those
circles has needed adjustment in solving real-world problems.
(Particularly when algorithms optimize for best worst-case
performance.  I've found users are much happier with best typical
case performance as long as the product of worst case performance
and worst case frequency is low.)
=20
Like many others who have posted on the topic, I am quite
prepared to alter my views in the face of relavent evidence.
=20
Feel free to laugh at the old fart who decided to sip his Bushmill's
while reading through this thread and try to run with the young lions.
As someone else recently requested, though, please don't point while
you laugh -- that's just rude.   :-)
=20
-Kevin
=20
=20
>>> Ron Peacetree <rjpeace@earthlink.net> 10/04/05 10:06 PM >>>
Unfortunately, no matter what I say or do, I'm not going to please
or convince anyone who has already have made their minds up
to the extent that they post comments like Mr Trainor's below.
His response style pretty much proves my earlier point that this
is presently a religious issue within the pg community.


From pgsql-performance-owner@postgresql.org  Wed Oct  5 05:57:11 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id A3F50DA17A;
	Wed,  5 Oct 2005 05:57:05 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 94444-08; Wed,  5 Oct 2005 08:57:02 +0000 (GMT)
Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75])
	by svr1.postgresql.org (Postfix) with ESMTP id 62192DA166;
	Wed,  5 Oct 2005 05:57:03 -0300 (ADT)
Received: from mainbox.archonet.com
	(84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99])
	by smtp.metronet.co.uk (MetroNet Mail) with ESMTP
	id D8BF8414283; Wed,  5 Oct 2005 09:55:24 +0100 (BST)
Received: from localhost (localhost.localdomain [127.0.0.1])
	by mainbox.archonet.com (Postfix) with ESMTP id 5452C15EDA;
	Wed,  5 Oct 2005 09:54:16 +0100 (BST)
Received: from mainbox.archonet.com ([127.0.0.1])
	by localhost (mainbox [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 12230-04; Wed, 5 Oct 2005 09:54:12 +0100 (BST)
Received: from [192.168.1.17] (client17.office.archonet.com [192.168.1.17])
	by mainbox.archonet.com (Postfix) with ESMTP id E768615ED5;
	Wed,  5 Oct 2005 09:54:11 +0100 (BST)
Message-ID: <434394B3.4070009@archonet.com>
Date: Wed, 05 Oct 2005 09:54:11 +0100
From: Richard Huxton <dev@archonet.com>
User-Agent: Mozilla Thunderbird 1.0.6 (X11/20050912)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: "R, Rajesh (STSD)" <rajesh.r2@hp.com>
Cc: pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org
Subject: Re: Query in SQL statement
References: 
 <5CBFB210D9870F40B9E5A0FBD31F3A770283AC48@bgeexc01.asiapacific.cpqcorp.net>
In-Reply-To: 
 <5CBFB210D9870F40B9E5A0FBD31F3A770283AC48@bgeexc01.asiapacific.cpqcorp.net>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.057 required=5 tests=[AWL=0.007,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/91
X-Sequence-Number: 14859

R, Rajesh (STSD) wrote:
>  
> Am trying to port a mysql statement to postgres.
> 
> Please help me in finding the error in this,

Can I recommend the reference section of the manuals for this sort of 
thing? There is an excellent section detailing the valid SQL for the 
CREATE TABLE command.

Also - the pgsql-hackers list is for discussion of database development, 
and the performance list is for performance problems. This would be 
better posted on pgsql-general or -sql or -novice.

> CREATE SEQUENCE ai_id;

This line is causing the first error:
 > ERROR:  relation "ai_id" already exists

That's because you've already successfully created the sequence, so it 
already exists. Either drop it and recreate it, or stop trying to 
recreate it.

> CREATE TABLE badusers (
>   id int DEFAULT nextval('ai_id') NOT NULL,
>   UserName varchar(30),
>   Date  datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,

Well, "Date" is a type-name, "datetime" isn't and even if it was 
"0000-00-00" isn't a valid date is it?

>   Reason varchar(200),
>   Admin varchar(30) DEFAULT '-',
>   PRIMARY KEY (id),
>   KEY UserName (UserName),
>   KEY Date (Date)

The word "KEY" isn't valid here either - are you trying to define an 
index? If so, see the "CREATE INDEX" section of the SQL reference.

http://www.postgresql.org/docs/8.0/static/sql-commands.html

If you reply to this message, please remove the pgsql-hackers CC:
--
   Richard Huxton
   Archonet Ltd

From pgsql-performance-owner@postgresql.org  Wed Oct  5 05:57:05 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 2859EDA15F
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 05:57:03 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 91881-06
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 08:57:00 +0000 (GMT)
Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75])
	by svr1.postgresql.org (Postfix) with ESMTP id A126ADA157
	for <pgsql-performance@postgresql.org>;
	Wed,  5 Oct 2005 05:57:01 -0300 (ADT)
Received: from mainbox.archonet.com
	(84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99])
	by smtp.metronet.co.uk (MetroNet Mail) with ESMTP
	id BC37B402A8B; Wed,  5 Oct 2005 09:55:24 +0100 (BST)
Received: from localhost (localhost.localdomain [127.0.0.1])
	by mainbox.archonet.com (Postfix) with ESMTP id 8324115EDB;
	Wed,  5 Oct 2005 09:55:01 +0100 (BST)
Received: from mainbox.archonet.com ([127.0.0.1])
	by localhost (mainbox [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 12240-02; Wed, 5 Oct 2005 09:54:59 +0100 (BST)
Received: from [192.168.1.17] (client17.office.archonet.com [192.168.1.17])
	by mainbox.archonet.com (Postfix) with ESMTP id 04E8E15ED5;
	Wed,  5 Oct 2005 09:54:58 +0100 (BST)
Message-ID: <434394E2.4030508@archonet.com>
Date: Wed, 05 Oct 2005 09:54:58 +0100
From: Richard Huxton <dev@archonet.com>
User-Agent: Mozilla Thunderbird 1.0.6 (X11/20050912)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: =?ISO-8859-15?Q?AL=DD_=C7EL=DDK?= <ali@verus.com.tr>
Cc: pgsql-performance@postgresql.org
Subject: Re: Which one FreeBSD or Linux
References: <dhmqc3$19rf$1@news.hub.org>
In-Reply-To: <dhmqc3$19rf$1@news.hub.org>
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: quoted-printable
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.057 required=5 tests=[AWL=0.007,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/90
X-Sequence-Number: 14858

AL=DD =C7EL=DDK wrote:
> FreeBSD or Linux , which system has better performance for PostgreSQL=20

Depends on the underlying hardware and your experience. I'd recommend=20
going with whichever you are more familiar, so long as it will support=20
the hardware you need to buy.

--=20
   Richard Huxton
   Archonet Ltd


From pgsql-hackers-owner@postgresql.org  Wed Oct  5 06:20:54 2005
X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 1DC73DA161;
	Wed,  5 Oct 2005 06:04:06 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 18190-08; Wed,  5 Oct 2005 09:03:58 +0000 (GMT)
Received: from bgerelbas02.asiapac.hp.net (bgerelbas02.asiapac.hp.net
	[15.219.201.135])
	by svr1.postgresql.org (Postfix) with ESMTP id 76969DA15F;
	Wed,  5 Oct 2005 06:03:58 -0300 (ADT)
Received: from bgeexg11.asiapacific.cpqcorp.net
	(bgeexg11.asiapacific.cpqcorp.net [16.150.33.26])
	by bgerelbas02.asiapac.hp.net (Postfix) with ESMTP id 8B4F732F74;
	Wed,  5 Oct 2005 14:33:32 +0530 (IST)
Received: from bgeexc01.asiapacific.cpqcorp.net ([16.150.33.37]) by
	bgeexg11.asiapacific.cpqcorp.net with Microsoft
	SMTPSVC(6.0.3790.211); Wed, 5 Oct 2005 14:33:16 +0530
X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0
Content-class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Subject: Re: [PERFORM] Query in SQL statement
Date: Wed, 5 Oct 2005 14:33:15 +0530
Message-ID: 
 <5CBFB210D9870F40B9E5A0FBD31F3A77028FD2A8@bgeexc01.asiapacific.cpqcorp.net>
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
Thread-Topic: [PERFORM] Query in SQL statement
Thread-Index: AcXJisxSgANhQecUStKP7+Bepx6Z3gAAK0yA
From: "R, Rajesh (STSD)" <rajesh.r2@hp.com>
To: "Richard Huxton" <dev@archonet.com>
Cc: <pgsql-hackers@postgresql.org>,
	<pgsql-performance@postgresql.org>
X-OriginalArrivalTime: 05 Oct 2005 09:03:16.0439 (UTC)
	FILETIME=[9F8D1E70:01C5C98B]
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.069 required=5 tests=[AWL=0.069]
X-Spam-Level: 
X-Archive-Number: 200510/205
X-Sequence-Number: 74064


Thanks.=20
I've already understood that=20
I need to post it in another list.

Sorry for wasting your precious time.=20

--
Rajesh R

-----Original Message-----
From: Richard Huxton [mailto:dev@archonet.com]=20
Sent: Wednesday, October 05, 2005 2:24 PM
To: R, Rajesh (STSD)
Cc: pgsql-hackers@postgresql.org; pgsql-performance@postgresql.org
Subject: Re: [PERFORM] Query in SQL statement

R, Rajesh (STSD) wrote:
> =20
> Am trying to port a mysql statement to postgres.
>=20
> Please help me in finding the error in this,

Can I recommend the reference section of the manuals for this sort of
thing? There is an excellent section detailing the valid SQL for the
CREATE TABLE command.

Also - the pgsql-hackers list is for discussion of database development,
and the performance list is for performance problems. This would be
better posted on pgsql-general or -sql or -novice.

> CREATE SEQUENCE ai_id;

This line is causing the first error:
 > ERROR:  relation "ai_id" already exists

That's because you've already successfully created the sequence, so it
already exists. Either drop it and recreate it, or stop trying to
recreate it.

> CREATE TABLE badusers (
>   id int DEFAULT nextval('ai_id') NOT NULL,
>   UserName varchar(30),
>   Date  datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,

Well, "Date" is a type-name, "datetime" isn't and even if it was
"0000-00-00" isn't a valid date is it?

>   Reason varchar(200),
>   Admin varchar(30) DEFAULT '-',
>   PRIMARY KEY (id),
>   KEY UserName (UserName),
>   KEY Date (Date)

The word "KEY" isn't valid here either - are you trying to define an
index? If so, see the "CREATE INDEX" section of the SQL reference.

http://www.postgresql.org/docs/8.0/static/sql-commands.html

If you reply to this message, please remove the pgsql-hackers CC:
--
   Richard Huxton
   Archonet Ltd

From pgsql-performance-owner@postgresql.org  Wed Oct  5 06:19:43 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 44E6AD9179
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 06:10:44 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 43528-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 09:10:41 +0000 (GMT)
Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75])
	by svr1.postgresql.org (Postfix) with ESMTP id 6FE5ED8F54
	for <pgsql-performance@postgresql.org>;
	Wed,  5 Oct 2005 06:10:41 -0300 (ADT)
Received: from mainbox.archonet.com
	(84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99])
	by smtp.metronet.co.uk (MetroNet Mail) with ESMTP
	id D1448418309; Wed,  5 Oct 2005 10:10:37 +0100 (BST)
Received: from localhost (localhost.localdomain [127.0.0.1])
	by mainbox.archonet.com (Postfix) with ESMTP id 5425915EDB;
	Wed,  5 Oct 2005 10:09:23 +0100 (BST)
Received: from mainbox.archonet.com ([127.0.0.1])
	by localhost (mainbox [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 12570-02; Wed, 5 Oct 2005 10:09:20 +0100 (BST)
Received: from [192.168.1.17] (client17.office.archonet.com [192.168.1.17])
	by mainbox.archonet.com (Postfix) with ESMTP id 8C50715ED5;
	Wed,  5 Oct 2005 10:09:20 +0100 (BST)
Message-ID: <43439840.7010803@archonet.com>
Date: Wed, 05 Oct 2005 10:09:20 +0100
From: Richard Huxton <dev@archonet.com>
User-Agent: Mozilla Thunderbird 1.0.6 (X11/20050912)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: "R, Rajesh (STSD)" <rajesh.r2@hp.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Query in SQL statement
References: 
 <5CBFB210D9870F40B9E5A0FBD31F3A77028FD2A8@bgeexc01.asiapacific.cpqcorp.net>
In-Reply-To: 
 <5CBFB210D9870F40B9E5A0FBD31F3A77028FD2A8@bgeexc01.asiapacific.cpqcorp.net>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.057 required=5 tests=[AWL=0.007,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/92
X-Sequence-Number: 14860

R, Rajesh (STSD) wrote:
> Thanks. 
> I've already understood that 
> I need to post it in another list.
> 
> Sorry for wasting your precious time. 

No time wasted. It was a perfectly reasonable question, just to the 
wrong lists.

--
   Richard Huxton
   Archonet Ltd

From pgsql-performance-owner@postgresql.org  Wed Oct  5 06:41:29 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 08B93D7FE7;
	Wed,  5 Oct 2005 06:41:28 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 67500-09; Wed,  5 Oct 2005 09:41:23 +0000 (GMT)
Received: from vms042pub.verizon.net (vms042pub.verizon.net [206.46.252.42])
	by svr1.postgresql.org (Postfix) with ESMTP id 43669D6F63;
	Wed,  5 Oct 2005 06:41:24 -0300 (ADT)
Received: from osgiliath.mathom.us ([70.108.61.78])
	by vms042.mailsrvcs.net (Sun Java System Messaging Server 6.2 HotFix
	0.04 (built Dec 24 2004)) with ESMTPA id
	<0INV005W0S92ASA6@vms042.mailsrvcs.net>;
	Wed, 05 Oct 2005 04:41:26 -0500 (CDT)
Received: from localhost (localhost [127.0.0.1])
	by osgiliath.mathom.us (Postfix) with ESMTP id B86D060849A; Wed,
	05 Oct 2005 05:41:25 -0400 (EDT)
Received: from osgiliath.mathom.us ([127.0.0.1])
	by localhost (osgiliath [127.0.0.1]) (amavisd-new, port 10024)
	with LMTP id 01195-04-3; Wed, 05 Oct 2005 05:41:25 -0400 (EDT)
Received: by osgiliath.mathom.us (Postfix, from userid 1000)
	id 9C4D3608468; Wed, 05 Oct 2005 05:41:25 -0400 (EDT)
Date: Wed, 05 Oct 2005 05:41:25 -0400
From: Michael Stone <mstone+postgres@mathom.us>
Subject: Re: [HACKERS] A Better External Sort?
In-reply-to: <20051001161936.GE13830@svana.org>
To: Martijn van Oosterhout <kleptog@svana.org>
Cc: pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org
Mail-Followup-To: Martijn van Oosterhout <kleptog@svana.org>,
	pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org
Message-id: <20051005094125.GW2241@mathom.us>
MIME-version: 1.0
Content-type: text/plain; charset=us-ascii; format=flowed
Content-disposition: inline
X-Pgp-Fingerprint: 53 FF 38 00 E7 DD 0A 9C  84 52 84 C5 EE DF 7C 88
X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at mathom.us
References: 
 <25552174.1128176560482.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
	<20051001161936.GE13830@svana.org>
User-Agent: Mutt/1.5.10i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.004 required=5 tests=[AWL=0.004]
X-Spam-Level: 
X-Archive-Number: 200510/93
X-Sequence-Number: 14861

On Sat, Oct 01, 2005 at 06:19:41PM +0200, Martijn van Oosterhout wrote:
>COPY TO /dev/null WITH binary
>13MB/s    55% user 45% system  (ergo, CPU bound)
[snip]
>the most expensive. But it does point out that the whole process is
>probably CPU bound more than anything else.

Note that 45% of that cpu usage is system--which is where IO overhead
would end up being counted. Until you profile where you system time is
going it's premature to say it isn't an IO problem.

Mike Stone


From pgsql-performance-owner@postgresql.org  Wed Oct  5 06:43:42 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 9A4FEDA1A1;
	Wed,  5 Oct 2005 06:43:40 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 15001-02; Wed,  5 Oct 2005 09:43:35 +0000 (GMT)
Received: from vms040pub.verizon.net (vms040pub.verizon.net [206.46.252.40])
	by svr1.postgresql.org (Postfix) with ESMTP id A31CDDA180;
	Wed,  5 Oct 2005 06:43:35 -0300 (ADT)
Received: from osgiliath.mathom.us ([70.108.61.78])
	by vms040.mailsrvcs.net (Sun Java System Messaging Server 6.2 HotFix
	0.04 (built Dec 24 2004)) with ESMTPA id
	<0INV0042CSC46OR4@vms040.mailsrvcs.net>;
	Wed, 05 Oct 2005 04:43:16 -0500 (CDT)
Received: from localhost (localhost [127.0.0.1])
	by osgiliath.mathom.us (Postfix) with ESMTP id 1D28460849A; Wed,
	05 Oct 2005 05:43:16 -0400 (EDT)
Received: from osgiliath.mathom.us ([127.0.0.1])
	by localhost (osgiliath [127.0.0.1]) (amavisd-new, port 10024)
	with LMTP id 01195-04-8; Wed, 05 Oct 2005 05:43:15 -0400 (EDT)
Received: by osgiliath.mathom.us (Postfix, from userid 1000)
	id E4AD5608468; Wed, 05 Oct 2005 05:43:15 -0400 (EDT)
Date: Wed, 05 Oct 2005 05:43:15 -0400
From: Michael Stone <mstone+postgres@mathom.us>
Subject: Re: [HACKERS] A Better External Sort?
In-reply-to: <1128375790.5882.18.camel@fuji.krosing.net>
To: Hannu Krosing <hannu@skype.net>
Cc: pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org
Mail-Followup-To: Hannu Krosing <hannu@skype.net>,
	pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org
Message-id: <20051005094315.GX2241@mathom.us>
MIME-version: 1.0
Content-type: text/plain; charset=us-ascii; format=flowed
Content-disposition: inline
X-Pgp-Fingerprint: 53 FF 38 00 E7 DD 0A 9C  84 52 84 C5 EE DF 7C 88
X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at mathom.us
References: 
 <31833713.1128111650174.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
	<200510031334.02030.josh@agliodbs.com>
	<1128372151.28509.1.camel@toonses.gghcwest.com>
	<200510031416.15620.josh@agliodbs.com>
	<1128375790.5882.18.camel@fuji.krosing.net>
User-Agent: Mutt/1.5.10i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.003 required=5 tests=[AWL=0.003]
X-Spam-Level: 
X-Archive-Number: 200510/94
X-Sequence-Number: 14862

On Tue, Oct 04, 2005 at 12:43:10AM +0300, Hannu Krosing wrote:
>Just FYI, I run a count(*) on a 15.6GB table on a lightly loaded db and
>it run in 163 sec. (Dual opteron 2.6GHz, 6GB RAM, 6 x 74GB 15k  disks in
>RAID10, reiserfs). A little less than 100MB sec.

And none of that 15G table is in the 6G RAM?

Mike Stone

From pgsql-hackers-owner@postgresql.org  Wed Oct  5 07:33:15 2005
X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id EF345D9E78;
	Wed,  5 Oct 2005 07:33:13 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 33240-03; Wed,  5 Oct 2005 10:33:06 +0000 (GMT)
Received: from mail.skype.net (mail.skype.net [195.215.8.149])
	by svr1.postgresql.org (Postfix) with ESMTP id 95AEFD9072;
	Wed,  5 Oct 2005 07:33:06 -0300 (ADT)
Received: from localhost (localhost.localdomain [127.0.0.1])
	by mail.skype.net (Postfix) with ESMTP id 784464DD89;
	Wed,  5 Oct 2005 12:33:08 +0200 (CEST)
Received: from [192.168.0.41] (joltid-gw.joltid.org [195.50.194.24])
	by mail.skype.net (Postfix) with ESMTP id 0A1594DE60;
	Wed,  5 Oct 2005 12:32:53 +0200 (CEST)
Subject: Re: [PERFORM] A Better External Sort?
From: Hannu Krosing <hannu@skype.net>
To: Michael Stone <mstone+postgres@mathom.us>
Cc: pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org
In-Reply-To: <20051005094315.GX2241@mathom.us>
References: 
 <31833713.1128111650174.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
	<200510031334.02030.josh@agliodbs.com>
	<1128372151.28509.1.camel@toonses.gghcwest.com>
	<200510031416.15620.josh@agliodbs.com>
	<1128375790.5882.18.camel@fuji.krosing.net>
	<20051005094315.GX2241@mathom.us>
Content-Type: text/plain
Date: Wed, 05 Oct 2005 13:32:52 +0300
Message-Id: <1128508373.8561.28.camel@fuji.krosing.net>
Mime-Version: 1.0
X-Mailer: Evolution 2.0.4 (2.0.4-6) 
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.008 required=5 tests=[AWL=0.008]
X-Spam-Level: 
X-Archive-Number: 200510/206
X-Sequence-Number: 74065

On K, 2005-10-05 at 05:43 -0400, Michael Stone wrote:
> On Tue, Oct 04, 2005 at 12:43:10AM +0300, Hannu Krosing wrote:
> >Just FYI, I run a count(*) on a 15.6GB table on a lightly loaded db and
> >it run in 163 sec. (Dual opteron 2.6GHz, 6GB RAM, 6 x 74GB 15k  disks in
> >RAID10, reiserfs). A little less than 100MB sec.
> 
> And none of that 15G table is in the 6G RAM?

I believe so, as there had been another query running for some time,
doing a select form a 50GB table.

-- 
Hannu Krosing <hannu@skype.net>


From pgsql-hackers-owner@postgresql.org  Wed Oct  5 07:49:17 2005
X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 290A5D829A
	for <pgsql-hackers-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 07:49:17 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 64141-03
	for <pgsql-hackers-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 10:49:13 +0000 (GMT)
Received: from svana.org (svana.org [203.20.62.76])
	by svr1.postgresql.org (Postfix) with ESMTP id 707D5D6F63
	for <pgsql-hackers@postgresql.org>;
	Wed,  5 Oct 2005 07:49:14 -0300 (ADT)
Received: from kleptog by svana.org with local (Exim 3.35 #1 (Debian))
	id 1EN6pp-0003sv-00; Wed, 05 Oct 2005 20:49:17 +1000
Date: Wed, 5 Oct 2005 12:49:17 +0200
From: Martijn van Oosterhout <kleptog@svana.org>
To: pgsql-hackers@postgresql.org
Subject: Re: [PERFORM] A Better External Sort?
Message-ID: <20051005104916.GC12206@svana.org>
Reply-To: Martijn van Oosterhout <kleptog@svana.org>
References: 
 <25552174.1128176560482.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
	<20051001161936.GE13830@svana.org>
	<20051005094125.GW2241@mathom.us>
Mime-Version: 1.0
Content-Type: multipart/signed; micalg=pgp-sha1;
	protocol="application/pgp-signature"; boundary="MnLPg7ZWsaic7Fhd"
Content-Disposition: inline
In-Reply-To: <20051005094125.GW2241@mathom.us>
User-Agent: Mutt/1.3.28i
X-PGP-Key-ID: Length=1024; ID=0x0DC67BE6
X-PGP-Key-Fingerprint: 295F A899 A81A 156D B522  48A7 6394 F08A 0DC6 7BE6
X-PGP-Key-URL: <http://svana.org/kleptog/0DC67BE6.pgp.asc>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.008 required=5 tests=[AWL=0.008]
X-Spam-Level: 
X-Archive-Number: 200510/207
X-Sequence-Number: 74066


--MnLPg7ZWsaic7Fhd
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Wed, Oct 05, 2005 at 05:41:25AM -0400, Michael Stone wrote:
> On Sat, Oct 01, 2005 at 06:19:41PM +0200, Martijn van Oosterhout wrote:
> >COPY TO /dev/null WITH binary
> >13MB/s    55% user 45% system  (ergo, CPU bound)
> [snip]
> >the most expensive. But it does point out that the whole process is
> >probably CPU bound more than anything else.
>=20
> Note that 45% of that cpu usage is system--which is where IO overhead
> would end up being counted. Until you profile where you system time is
> going it's premature to say it isn't an IO problem.

It's a dual CPU system, so 50% is the limit for a single process. Since
system usage < user, PostgreSQL is the limiter. Sure, the system is
taking a lot of time, but PostgreSQL is still the limiting factor.

Anyway, the later measurements using gprof exclude system time
altogether and it still shows CPU being the limiting factor. Fact is,
extracting tuples from pages is expensive.
--=20
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

--MnLPg7ZWsaic7Fhd
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQFDQ6+rIB7bNG8LQkwRAtX6AKCNa7sgu1nH5L01TE02lcH2rdk2/wCfaeP1
i2wioGSUf1rEbRJjZLtuTL0=
=zdXF
-----END PGP SIGNATURE-----

--MnLPg7ZWsaic7Fhd--

From pgsql-performance-owner@postgresql.org  Wed Oct  5 08:04:41 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 72594DA1A8
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 08:04:40 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 19759-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 11:04:34 +0000 (GMT)
Received: from outbound0.sv.meer.net (outbound0.sv.meer.net [205.217.152.13])
	by svr1.postgresql.org (Postfix) with ESMTP id 0CF4ADA010
	for <pgsql-performance@postgresql.org>;
	Wed,  5 Oct 2005 08:04:34 -0300 (ADT)
Received: from mail.meer.net (mail.meer.net [209.157.152.14])
	by outbound0.sv.meer.net (8.12.10/8.12.6) with ESMTP id j95B1DtW022603
	for <pgsql-performance@postgresql.org>;
	Wed, 5 Oct 2005 04:01:44 -0700 (PDT)
	(envelope-from trainor@transborder.net)
Received: from [192.168.1.46] (pool-151-197-28-186.phil.east.verizon.net
	[151.197.28.186])
	by mail.meer.net (8.13.3/8.13.3/meer) with ESMTP id j95B0Wge068180
	for <pgsql-performance@postgresql.org>;
	Wed, 5 Oct 2005 04:00:32 -0700 (PDT)
	(envelope-from trainor@transborder.net)
Mime-Version: 1.0 (Apple Message framework v623)
In-Reply-To: 
 <17434238.1128481614269.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
References: 
 <17434238.1128481614269.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
Content-Type: text/plain; charset=US-ASCII; format=flowed
Message-Id: <13cfaebb14df6b16470084ba8fea81c8@transborder.net>
Content-Transfer-Encoding: 7bit
From: "Douglas J. Trainor" <trainor@transborder.net>
Subject: Re: Is There Any Way ....
Date: Wed, 5 Oct 2005 07:00:32 -0400
To: pgsql-performance@postgresql.org
X-Mailer: Apple Mail (2.623)
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0 required=5 tests=[none]
X-Spam-Level: 
X-Archive-Number: 200510/95
X-Sequence-Number: 14863


Hey, you can say what you want about my style, but you
still haven't pointed to even one article from the vast literature
that you claim supports your argument.  And I did include a
smiley.  Your original email that PostgreSQL is wrong and
that you are right led me to believe that you, like others making
such statements, would not post your references.  You remind
me of Ted Nelson, who wanted the computing center at
the University of Illinois at Chicago to change their systems
just for him.  BTW, I'm a scientist -- I haven't made my mind
up about anything.  I really am interested in what you say,
if there is any real work backing up your claims such that
it would impact average cases.

Any app designer can conceive of many ways to game the
server to their app's advantage -- I'm not interested in that
potboiler.

     douglas

On Oct 4, 2005, at 11:06 PM, Ron Peacetree wrote:

> Unfortunately, no matter what I say or do, I'm not going to please
> or convince anyone who has already have made their minds up
> to the extent that they post comments like Mr Trainor's below.
> His response style pretty much proves my earlier point that this
> is presently a religious issue within the pg community.
>
> The absolute best proof would be to build a version of pg that does
> what Oracle and DB2 have done and implement it's own DB
> specific memory manager and then compare the performance
> between the two versions on the same HW, OS, and schema.
>
> The second best proof would be to set up either DB2 or Oracle so
> that they _don't_ use their memory managers and compare their
> performance to a set up that _does_ use said memory managers
> on the same HW, OS, and schema.
>
> I don't currently have the resources for either experiment.
>
> Some might even argue that IBM (where Codd and Date worked)
> and Oracle just _might_ have had justification for the huge effort
> they put into developing such infrastructure.
>
> Then there's the large library of research on caching strategies
> in just about every HW and SW domain, including DB theory,
> that points put that the more context dependent, ie application
> or domain specific awareness, caching strategies are the better
> they are.
>
> Maybe after we do all we can about physical IO and sorting
> performance I'll take on the religious fanatics on this one.
>
> One problem set at a time.
> Ron


From pgsql-performance-owner@postgresql.org  Wed Oct  5 08:16:28 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 878DAD86A4
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 08:16:27 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 31302-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 11:16:23 +0000 (GMT)
Received: from netbox.unitech.com.ar (unknown [200.32.92.34])
	by svr1.postgresql.org (Postfix) with ESMTP id 45C43D7FE7
	for <pgsql-performance@postgresql.org>;
	Wed,  5 Oct 2005 08:16:20 -0300 (ADT)
Received: from dariop (dariop.unitech.com.ar [192.168.1.237])
	by netbox.unitech.com.ar (8.11.6/8.11.6) with ESMTP id j95CFYp20703
	for <pgsql-performance@postgresql.org>; Wed, 5 Oct 2005 09:15:34 -0300
Received: from 127.0.0.1 (AVG SMTP 7.0.344 [267.11.10]);
	Wed, 05 Oct 2005 08:16:46 -0300
From: "Dario" <dario_d_s@unitech.com.ar>
To: <pgsql-performance@postgresql.org>
Subject: Re: Is There Any Way ....
Date: Wed, 5 Oct 2005 08:16:46 -0300
Message-ID: <MHEDJHCKDNOEHJKHIOCJCEDACIAA.dario_d_s@unitech.com.ar>
MIME-Version: 1.0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Priority: 5 (Lowest)
X-MSMail-Priority: Low
X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0)
In-Reply-To: <43432D22.6090109@commandprompt.com>
Importance: Low
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.041 required=5 tests=[AWL=0.041]
X-Spam-Level: 
X-Archive-Number: 200510/96
X-Sequence-Number: 14864

I'm sure there will be cases when some human assisted caching algorithm will
perform better than an mathetical statistical based design, but it will also
depend on the "human". And it probably will make thing worse when workload
changes and human doesn't realize. It must be considered that, today,
hardware cost is not the %90 of budget that it used to be. Throwing hardware
at the system can be as much expensive as throwing certified "it stuff".
(just think in coffee budget! :-) )

If you need to improve "user perception", you can do others things. Like
caching a table in your client  (with a trigger for any change on table X
updating a table called "timestamp_table_change" and a small select to this
table, you can easily know when you must update your client). If it is a
application server, serving http request, then "user perception" will be
sticked to bandwidth AND application server (some of them have cache for
request).

FYI, I don't recall a mechanism in MSSQL to cache a table in buffers. Oracle
has some structures to allow that. (you know) It uses his own buffer. Since
version 9i, you can set three different data buffers, one (recycled cache)
for low usage tables (I mean tables with blocks which don't have too much
chance to be queried again, like a very large historical table) , one for
high usage tables (keep cache), and the regular one (difference is in
algorithm). And you must also set a buffer cache size for tablespaces with
different block size. But there is no such thing as "create table x keep
entirenly in buffer". And above all things, oracle doc always states "first,
tune design, then tune queries, then start tunning engine".

greetings.




From pgsql-performance-owner@postgresql.org  Wed Oct  5 10:23:34 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id A916ED8CC7
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 10:22:51 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 02856-09
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 13:22:46 +0000 (GMT)
Received: from Herge.rcsinc.local (unknown [70.89.208.142])
	by svr1.postgresql.org (Postfix) with ESMTP id 3AB28D6F63
	for <pgsql-performance@postgresql.org>;
	Wed,  5 Oct 2005 10:22:47 -0300 (ADT)
Content-class: urn:content-classes:message
Subject: Re: SELECT LIMIT 1 VIEW Performance Issue
MIME-Version: 1.0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Date: Wed, 5 Oct 2005 09:22:48 -0400
Message-ID: <6EE64EF3AB31D5448D0007DD34EEB3417DD50B@Herge.rcsinc.local>
X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
Thread-Topic: [PERFORM] SELECT LIMIT 1 VIEW Performance Issue
Thread-Index: AcXJK7nppw3fjpUbSK66Xzcu+0dGMgAgSDQg
From: "Merlin Moncure" <merlin.moncure@rcsonline.com>
To: "Jim C. Nasby" <jnasby@pervasive.com>
Cc: <pgsql-performance@postgresql.org>,
	"K C Lau" <kclau60@netvigator.com>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.039 required=5 tests=[AWL=-0.011,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/97
X-Sequence-Number: 14865

[to K C:] sorry, was out on vactation all last week.  I was visualizing
the problem incorrectly anyways...

Jim wrote:
> That function is not immutable, it should be defined as stable.

That is 100% correct: however now and then I declare stable functions as
immutable in some cases because the planner treats them differently with
no side effects...this is a hack of course...see my earlier suggestion
to try both immutable and stable versions.  I can give a pretty good
example of when this can make a big difference.
=20
> PostgreSQL doesn't pre-compile functions, at least not until 8.1 (and
> I'm not sure how much those are pre-compiled, though they are
> syntax-checked at creation). Do you get the same result time when you
> run it a second time? What time do you get from running just the
> function versus the SQL in the function?

plpgsql functions are at least partially compiled (sql functions afaik
are not), in that a internal state is generated following the first
execution.  This is the cause of all those infernal 'invalid table oid'
errors.
=20
> Also, remember that every layer you add to the cake means more work
for
> the database. If speed is that highly critical you'll probably want to
> not wrap things in functions, and possibly not use views either.

The overhead of the function/view is totally inconsequential next to the
planner choosing a suboptimal plan.  The purpose of the function is to
coerce the planner into choosing the correct plan.

> Also, keep in mind that getting below 1ms doesn't automatically mean
> you'll be able to scale to 1000TPS. Things will definately change when
> you load the system down, so if performance is that critical you
should
> start testing with the system under load if you're not already.


From pgsql-performance-owner@postgresql.org  Wed Oct  5 10:24:16 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id F283EDA1F8
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 10:23:45 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 27932-06
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 13:23:41 +0000 (GMT)
Received: from mailhost.intellivid.com (mailhost.intellivid.com
 [64.32.200.11])
	by svr1.postgresql.org (Postfix) with ESMTP id 0821BDA1F5
	for <pgsql-performance@postgresql.org>;
	Wed,  5 Oct 2005 10:23:40 -0300 (ADT)
Received: from [192.168.2.68] (spectre.intellivid.com [192.168.2.68])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(Client did not present a certificate)
	by newmail.intellivid.com (Postfix) with ESMTP id 325D0F18107
	for <pgsql-performance@postgresql.org>;
	Wed,  5 Oct 2005 09:23:45 -0400 (EDT)
Subject: wal_buffers
From: Ian Westmacott <ianw@intellivid.com>
To: pgsql-performance@postgresql.org
Content-Type: text/plain
Organization: Intellivid Corp.
Message-Id: <1128518624.15795.28.camel@spectre.intellivid.com>
Mime-Version: 1.0
X-Mailer: Ximian Evolution 1.4.6 
Date: Wed, 05 Oct 2005 09:23:45 -0400
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0 required=5 tests=[none]
X-Spam-Level: 
X-Archive-Number: 200510/98
X-Sequence-Number: 14866

Can anyone tell me what precisely a WAL buffer contains,
so that I can compute an appropriate setting for
wal_buffers (in 8.0.3)?

I know the documentation suggests there is little
evidence that supports increasing wal_buffers, but we
are inserting a large amount of data that, I believe,
easily exceeds the default 64K in a single transaction.
We are also very sensitive to write latency.

As background, we are doing a sustained insert of 2.2
billion rows in 1.3 million transactions per day.  Thats
about 1700 rows per transaction, at (roughly) 50 bytes
per row.


From pgsql-performance-owner@postgresql.org  Wed Oct  5 10:51:53 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 88BE5DA180
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 10:51:50 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 71169-10
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 13:51:46 +0000 (GMT)
Received: from gwmta.wicourts.gov (gwmta.wicourts.gov [165.219.244.91])
	by svr1.postgresql.org (Postfix) with ESMTP id 150F9DA17A
	for <pgsql-performance@postgresql.org>;
	Wed,  5 Oct 2005 10:51:47 -0300 (ADT)
Received: from Courts-MTA by gwmta.wicourts.gov
	with Novell_GroupWise; Wed, 05 Oct 2005 08:51:47 -0500
Message-Id: <s3439423.035@gwmta.wicourts.gov>
X-Mailer: Novell GroupWise Internet Agent 6.5.4 
Date: Wed, 05 Oct 2005 08:51:43 -0500
From: "Kevin Grittner" <Kevin.Grittner@wicourts.gov>
To: <pgsql-performance@postgresql.org>, <dario_d_s@unitech.com.ar>
Subject: Re: Is There Any Way ....
Mime-Version: 1.0
x-priority: 5
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.003 required=5 tests=[AWL=0.003]
X-Spam-Level: 
X-Archive-Number: 200510/99
X-Sequence-Number: 14867

** Low Priority **

Human feedback from testers and users has proven pretty effective
at catching errors in the "human assisted" cache configuration.  When
people setting up the servers have missed the named cache configuration,
and all they had was the single general purpose cache, it has been caught
because of user complaints on performance.
=20
There was an attempt made to simulate database queries -- hitting a
client side cache on some of the roughly100 tables (out of 300 in the well
normalized schema) which fit this pattern of usage.  It didn't prove very
cost effective.  It just makes more sense to allow the DBAs to tweek
database performance through database configuration changes than to
jump through that many hoops in application code to try to achieve it
where it becomes an issue.
=20
As far as I know, you can't use this technique in Microsoft SQL Server or
Oracle.  They are using Sybase Adaptive Server Enterprise (ASE).  I
believe named caches were added in version 12.0, long after Microsoft
split off with their separate code stream based on the Sybase effort.
=20
-Kevin
=20
=20
>>> "Dario" <dario_d_s@unitech.com.ar> 10/05/05 6:16 AM >>>
I'm sure there will be cases when some human assisted caching algorithm =
will
perform better than an mathetical statistical based design, but it will =
also
depend on the "human". And it probably will make thing worse when workload
changes and human doesn't realize. It must be considered that, today,
hardware cost is not the %90 of budget that it used to be. Throwing =
hardware
at the system can be as much expensive as throwing certified "it stuff".
(just think in coffee budget! :-) )

If you need to improve "user perception", you can do others things. Like
caching a table in your client  (with a trigger for any change on table X
updating a table called "timestamp_table_change" and a small select to =
this
table, you can easily know when you must update your client). If it is a
application server, serving http request, then "user perception" will be
sticked to bandwidth AND application server (some of them have cache for
request).

FYI, I don't recall a mechanism in MSSQL to cache a table in buffers. =
Oracle
has some structures to allow that. (you know) It uses his own buffer. =
Since
version 9i, you can set three different data buffers, one (recycled cache)
for low usage tables (I mean tables with blocks which don't have too much
chance to be queried again, like a very large historical table) , one for
high usage tables (keep cache), and the regular one (difference is in
algorithm). And you must also set a buffer cache size for tablespaces with
different block size. But there is no such thing as "create table x keep
entirenly in buffer". And above all things, oracle doc always states =
"first,
tune design, then tune queries, then start tunning engine".

greetings.




---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
       subscribe-nomail command to majordomo@postgresql.org so that your
       message can get through to the mailing list cleanly


From pgsql-performance-owner@postgresql.org  Wed Oct  5 11:57:00 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 509E5DA16E
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 11:55:39 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 87493-06
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 14:55:31 +0000 (GMT)
Received: from Herge.rcsinc.local (mail.rcsonline.com [70.89.208.142])
	by svr1.postgresql.org (Postfix) with ESMTP id 7C8EFDA127
	for <pgsql-performance@postgresql.org>;
	Wed,  5 Oct 2005 11:55:32 -0300 (ADT)
Content-class: urn:content-classes:message
MIME-Version: 1.0
Subject: Re: Indexes on ramdisk
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Date: Wed, 5 Oct 2005 10:55:36 -0400
Message-ID: <6EE64EF3AB31D5448D0007DD34EEB3417DD50F@Herge.rcsinc.local>
X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
Thread-Topic: [PERFORM] Indexes on ramdisk
Thread-Index: AcXJX3XGcAD6diqcQyGozZfh0I9WtwAXQ+8Q
From: "Merlin Moncure" <merlin.moncure@rcsonline.com>
To: <emil@baymountain.com>
Cc: <pgsql-performance@postgresql.org>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.039 required=5 tests=[AWL=-0.011,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/100
X-Sequence-Number: 14868

> It's a quad opteron system. RAID controller is a 4 channel LSILogic
> Megaraid
> 320 connected to 10 15k 36.7G SCSI disks. The disks are configured in
5
> mirrored partitions. The pg_xlog is on one mirror and the data and
indexes
> are spread over the other 4 using tablespaces. These numbers from
> pg_stat_user_tables are from about 2 hours earlier today on this one
> table.
>=20
>=20
> idx_scan           20578690
> idx_tup_fetch  35866104841
> n_tup_ins        1940081
> n_tup_upd       1604041
> n_tup_del        1880424

Is your raid controller configured to buffer your writes?  How much RAM
are you packing?  Are you running 64 bit?

Merlin

From pgsql-performance-owner@postgresql.org  Wed Oct  5 12:03:50 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 714DBD80C2
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 12:03:07 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 32061-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 15:03:05 +0000 (GMT)
Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.206])
	by svr1.postgresql.org (Postfix) with ESMTP id C0CFAD6F47
	for <pgsql-performance@postgresql.org>;
	Wed,  5 Oct 2005 12:03:03 -0300 (ADT)
Received: by wproxy.gmail.com with SMTP id 71so74654wra
	for <pgsql-performance@postgresql.org>;
	Wed, 05 Oct 2005 08:03:03 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:references;
	b=ZpP4rzqWpFjSc4389daL63oJcuPc3QMfBvt1OfU/E7iOWvk2lUSAQF00vCSGpPuws6fdc4YRQmXouc/Ul1MqyzYthww5qCzLhe4f1Lhapsy3gr8xpKn3s4DZbwpgcskxMYxNZ/NV96Yr2L67NgVhKkDM/j1YcGF1D2aPvzGInxQ=
Received: by 10.54.69.8 with SMTP id r8mr407693wra;
	Wed, 05 Oct 2005 08:03:03 -0700 (PDT)
Received: by 10.54.84.8 with HTTP; Wed, 5 Oct 2005 08:03:03 -0700 (PDT)
Message-ID: <33c6269f0510050803w72097bb5v526a0126af876af4@mail.gmail.com>
Date: Wed, 5 Oct 2005 11:03:03 -0400
From: Alex Turner <armtuk@gmail.com>
Reply-To: Alex Turner <armtuk@gmail.com>
To: emil@baymountain.com
Subject: Re: Indexes on ramdisk
Cc: pgsql-performance@postgresql.org
In-Reply-To: <200510042341.23264.emil@baymountain.com>
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="----=_Part_4616_25671259.1128524583287"
References: <200510042109.01849.emil@baymountain.com>
	<33c6269f0510042023t24175e33vf84d9af609a8ccd7@mail.gmail.com>
	<200510042341.23264.emil@baymountain.com>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.355 required=5 tests=[AWL=-0.174, HTML_20_30=0.504,
	HTML_MESSAGE=0.001, RCVD_BY_IP=0.024]
X-Spam-Level: 
X-Archive-Number: 200510/101
X-Sequence-Number: 14869

------=_Part_4616_25671259.1128524583287
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

What kind of order of improvement do you need to see?

What period are these number for? Were they collected over 1 hour, 1 day, 1
month?

How much Cache do you have on the controller?

You can certainly get more speed by adding more disk and possibly by adding
more controller RAM/a second controller. 10 disks isn't really that many fo=
r
a totally kick-ass DB server. You can acheive more block writes with RAID
10s than with RAID 1s. Wether it's cost effective is dependant on lots of
factors like your chassis and drive enclosures etc. vs SSD. SSD will be
faster, but last I heard was expensive, and I checked a few websites but
couldn't get much price info. Normaly when you can't get price info, thats =
a
bad sign ;). If you are doing large chunks of writes to a small number of
tables, then you might be better off with a single large RAID 10 for your
tablespace than with seperate RAID 1s. If you are writing 5 to 1 more table
data than index data, you are hurting yourself by seperating on to multiple
RAID 1s instead of a single RAID 10 which could write at 2-3x for the 5, an=
d
2-3x for the 1 and only suffer a single seek penalty but get data onto disk
twice to three times as fast (depending how many RAID 1s you join). Try
unseperating RAID 1s, and combine to a RAID 10. for indexes and tablespaces=
.
The controller will re-sequence your writes/reads to help with effeciency,
and dbwriter is there to make things go easier.

You can at least get some idea by doing an iostat and see how many IOs and
how much throughput is happening. That will rappidly help determine if you
are bound by IOs or by MB/sec.

Worst case I'm wrong, but IMHO it's worth a try.

Alex Turner
NetEconomist

On 10/4/05, Emil Briggs <emil@baymountain.com> wrote:
>
> > Talk about your IO system a bit. There might be obvious ways to improve=
.
> >
> > What System/Motherboard are you using?
> > What Controller Cards are you using?
> > What kind of Disks do you have (SATA, SCSI 7.6k 10k 15k)
> > What denominations (9, 18, 36, 72, 143, 80, 160, 200 240Gig)?
> > What kind of RAIDs do you have setup (How many drives what stripe sizes=
,
> > how many used for what).
> > What levels of RAID are you using (0,1,10,5,50)?
> >
>
> It's a quad opteron system. RAID controller is a 4 channel LSILogic
> Megaraid
> 320 connected to 10 15k 36.7G SCSI disks. The disks are configured in 5
> mirrored partitions. The pg_xlog is on one mirror and the data and indexe=
s
> are spread over the other 4 using tablespaces. These numbers from
> pg_stat_user_tables are from about 2 hours earlier today on this one
> table.
>
>
> idx_scan 20578690
> idx_tup_fetch 35866104841
> n_tup_ins 1940081
> n_tup_upd 1604041
> n_tup_del 1880424
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
>
> http://archives.postgresql.org
>

------=_Part_4616_25671259.1128524583287
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

What kind of order of improvement do you need to see?<br>
<br>
What period are these number for?&nbsp; Were they collected over 1 hour, 1 =
day, 1 month?<br>
<br>
How much Cache do you have on the controller?<br>
<br>
You can certainly get more speed by adding more disk and possibly by
adding more controller RAM/a second controller.&nbsp; 10 disks isn't
really that many for a totally kick-ass DB server.&nbsp; You can
acheive more block writes with RAID 10s than with RAID 1s.&nbsp; Wether
it's cost effective is dependant on lots of factors like your chassis
and drive enclosures etc. vs SSD.&nbsp; SSD will be faster, but last I
heard was expensive, and I checked a few websites but couldn't get much
price info.&nbsp; Normaly when you can't get price info, thats a bad
sign ;).&nbsp; If you are doing large chunks of writes to a small
number of tables, then you might be better off with a single large RAID
10 for your tablespace than with seperate RAID 1s.&nbsp; If you are
writing 5 to 1 more table data than index data, you are hurting
yourself by seperating on to multiple RAID 1s instead of a single RAID
10 which could write at 2-3x for the 5, and 2-3x for the 1 and only
suffer a single seek penalty but get data onto disk twice to three
times as fast (depending how many RAID 1s you join).&nbsp; Try
unseperating RAID 1s, and combine to a RAID 10. for indexes and
tablespaces.&nbsp; The controller will re-sequence your writes/reads to
help with effeciency, and dbwriter is there to make things go easier.<br>
<br>
You can at least get some idea by doing an iostat and see how many IOs
and how much throughput is happening. That will rappidly help determine
if you are bound by IOs or by MB/sec.<br>
<br>
Worst case I'm wrong, but IMHO it's worth a try.<br>
<br>
Alex Turner<br>
NetEconomist<br><br><div><span class=3D"gmail_quote">On 10/4/05, <b class=
=3D"gmail_sendername">Emil Briggs</b> &lt;<a href=3D"mailto:emil@baymountai=
n.com">emil@baymountain.com</a>&gt; wrote:</span><blockquote class=3D"gmail=
_quote" style=3D"border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt=
 0pt 0.8ex; padding-left: 1ex;">
&gt; Talk about your IO system a bit. There might be obvious ways to improv=
e.<br>&gt;<br>&gt; What System/Motherboard are you using?<br>&gt; What Cont=
roller Cards are you using?<br>&gt; What kind of Disks do you have (SATA, S=
CSI=20
7.6k 10k 15k)<br>&gt; What denominations (9, 18, 36, 72, 143, 80, 160, 200 =
240Gig)?<br>&gt; What kind of RAIDs do you have setup (How many drives what=
 stripe sizes,<br>&gt; how many used for what).<br>&gt; What levels of RAID=
 are you using (0,1,10,5,50)?
<br>&gt;<br><br>It's a quad opteron system. RAID controller is a 4 channel =
LSILogic Megaraid<br>320 connected to 10 15k 36.7G SCSI disks. The disks ar=
e configured in 5<br>mirrored partitions. The pg_xlog is on one mirror and =
the data and indexes
<br>are spread over the other 4 using tablespaces. These numbers from<br>pg=
_stat_user_tables are from about 2 hours earlier today on this one table.<b=
r><br><br>idx_scan&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp; 20578690<br>idx_tup_fetch&nbsp;&nbsp;35866104841<br>
n_tup_ins&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1940081<br>n_tup_u=
pd&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1604041<br>n_tup_del&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1880424<br><br><br><br>--------------------=
-------(end of broadcast)---------------------------<br>TIP 4: Have you sea=
rched our list archives?<br><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp; <a href=3D"http://archives.postgresql.org">http://archives.postgr=
esql.org</a><br></blockquote></div><br>

------=_Part_4616_25671259.1128524583287--

From pgsql-performance-owner@postgresql.org  Wed Oct  5 12:35:28 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 383E8DA1AE
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 12:04:18 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 18660-06
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 15:04:13 +0000 (GMT)
Received: from frank.wiles.org (frank.wiles.org [24.124.39.75])
	by svr1.postgresql.org (Postfix) with ESMTP id DE60ADA16D
	for <pgsql-performance@postgresql.org>;
	Wed,  5 Oct 2005 12:04:11 -0300 (ADT)
Received: from kungfu (frank.wiles.org [127.0.0.1])
	by frank.wiles.org (8.13.1/8.13.1) with SMTP id j95F472Z012793;
	Wed, 5 Oct 2005 10:04:07 -0500
Date: Wed, 5 Oct 2005 10:05:43 -0500
From: Frank Wiles <frank@wiles.org>
To: Ron Peacetree <rjpeace@earthlink.net>
Cc: jd@commandprompt.com, pgsql-performance@postgresql.org
Subject: Re: Is There Any Way ....
Message-Id: <20051005100543.4b19d4fe.frank@wiles.org>
In-Reply-To: 
 <17434238.1128481614269.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
References: 
 <17434238.1128481614269.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
X-Mailer: Sylpheed version 2.0.1 (GTK+ 2.6.10; i686-pc-linux-gnu)
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.017 required=5 tests=[AWL=0.017]
X-Spam-Level: 
X-Archive-Number: 200510/103
X-Sequence-Number: 14871

On Tue, 4 Oct 2005 23:06:54 -0400 (EDT)
Ron Peacetree <rjpeace@earthlink.net> wrote:

> Then there's the large library of research on caching strategies
> in just about every HW and SW domain, including DB theory,
> that points put that the more context dependent, ie application
> or domain specific awareness, caching strategies are the better
> they are.

  Isn't this also a very strong argument for putting your caching
  into your application and not at the database level? 
 
  As you say the more "application or domain specific" it is the better.
  I don't see how PostgreSQL is going to magically determine what
  is perfect for everyone's differing needs and implement it for you. 

  Even rudimentary controls such "always keep this
  table/index/whatever in RAM" aren't as fine grained or specific
  enough to get full benefit. 

  My suggestion is to use something like memcached to store your
  data in, based on the particular needs of your application.  This
  puts all of the control in the hands of the programmer where, in
  my opinion, it belongs. 

  Just to clarify, I'm not entirely against the idea, but I certainly
  think there are other areas of PostgreSQL we should be focusing our
  efforts. 

 ---------------------------------
   Frank Wiles <frank@wiles.org>
   http://www.wiles.org
 ---------------------------------


From pgsql-performance-owner@postgresql.org  Wed Oct  5 12:34:02 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 2FEB8DA215;
	Wed,  5 Oct 2005 12:25:41 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 63496-09; Wed,  5 Oct 2005 15:25:38 +0000 (GMT)
Received: from mail.Mi8.com (d01gw01.mi8.com [63.240.6.47])
	by svr1.postgresql.org (Postfix) with ESMTP id D17F0DA214;
	Wed,  5 Oct 2005 12:25:36 -0300 (ADT)
Received: from 172.16.1.118 by mail.Mi8.com with ESMTP (- Welcome to Mi8
	Corporation www.Mi8.com (D1)); Wed, 05 Oct 2005 11:24:14 -0400
X-Server-Uuid: 241911D6-425B-44B9-A073-E3FE0F8FC774
Received: from MI8NYCMAIL06.Mi8.com ([172.16.1.175]) by
	d01smtp03.Mi8.com with Microsoft SMTPSVC(6.0.3790.1830); Wed, 5 Oct
	2005 11:24:08 -0400
X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0
Content-class: urn:content-classes:message
MIME-Version: 1.0
Subject: Re: [HACKERS] A Better External Sort?
Date: Wed, 5 Oct 2005 11:24:07 -0400
Message-ID: <3E37B936B592014B978C4415F90D662DE11B55@MI8NYCMAIL06.Mi8.com>
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
Thread-Topic: [HACKERS] [PERFORM] A Better External Sort?
Thread-Index: AcXJtOWLCrqmITV4TlejGIA++6wZXgAC+4ca
From: "Luke Lonergan" <LLonergan@greenplum.com>
To: "Michael Stone" <mstone+postgres@mathom.us>,
	"Martijn van Oosterhout" <kleptog@svana.org>
Cc: pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org
X-OriginalArrivalTime: 05 Oct 2005 15:24:08.0380 (UTC)
	FILETIME=[D45E97C0:01C5C9C0]
X-WSS-ID: 6F5D2F9739081364-02-01
Content-Type: text/plain;
 charset=us-ascii
Content-Transfer-Encoding: quoted-printable
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0 required=5 tests=[none]
X-Spam-Level: 
X-Archive-Number: 200510/102
X-Sequence-Number: 14870

Nope - it would be disk wait.

COPY is CPU bound on I/O subsystems faster that 50 MB/s on COPY (in) and =
about 15 MB/s (out).

- Luke

 -----Original Message-----
From: 	Michael Stone [mailto:mstone+postgres@mathom.us]
Sent:	Wed Oct 05 09:58:41 2005
To:	Martijn van Oosterhout
Cc:	pgsql-hackers@postgresql.org; pgsql-performance@postgresql.org
Subject:	Re: [HACKERS] [PERFORM] A Better External Sort?

On Sat, Oct 01, 2005 at 06:19:41PM +0200, Martijn van Oosterhout wrote:
>COPY TO /dev/null WITH binary
>13MB/s    55% user 45% system  (ergo, CPU bound)
[snip]
>the most expensive. But it does point out that the whole process is
>probably CPU bound more than anything else.

Note that 45% of that cpu usage is system--which is where IO overhead
would end up being counted. Until you profile where you system time is
going it's premature to say it isn't an IO problem.

Mike Stone


---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster



From pgsql-performance-owner@postgresql.org  Wed Oct  5 12:59:43 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id A3DB5DA207;
	Wed,  5 Oct 2005 12:33:57 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 03022-05; Wed,  5 Oct 2005 15:33:54 +0000 (GMT)
Received: from vms044pub.verizon.net (vms044pub.verizon.net [206.46.252.44])
	by svr1.postgresql.org (Postfix) with ESMTP id 6293BDA214;
	Wed,  5 Oct 2005 12:33:51 -0300 (ADT)
Received: from osgiliath.mathom.us ([70.108.61.78])
	by vms044.mailsrvcs.net (Sun Java System Messaging Server 6.2 HotFix
	0.04 (built Dec 24 2004)) with ESMTPA id
	<0INW002Q98KD7NSD@vms044.mailsrvcs.net>;
	Wed, 05 Oct 2005 10:33:50 -0500 (CDT)
Received: from localhost (localhost [127.0.0.1])
	by osgiliath.mathom.us (Postfix) with ESMTP id 927056002D3; Wed,
	05 Oct 2005 11:33:49 -0400 (EDT)
Received: from osgiliath.mathom.us ([127.0.0.1])
	by localhost (osgiliath [127.0.0.1]) (amavisd-new, port 10024)
	with LMTP id 11298-01-5; Wed, 05 Oct 2005 11:33:49 -0400 (EDT)
Received: by osgiliath.mathom.us (Postfix, from userid 1000)
	id 64F0F6002C9; Wed, 05 Oct 2005 11:33:49 -0400 (EDT)
Date: Wed, 05 Oct 2005 11:33:49 -0400
From: Michael Stone <mstone+postgres@mathom.us>
Subject: Re: [HACKERS] A Better External Sort?
In-reply-to: <3E37B936B592014B978C4415F90D662DE11B55@MI8NYCMAIL06.Mi8.com>
To: Luke Lonergan <LLonergan@greenplum.com>
Cc: pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org
Mail-Followup-To: Luke Lonergan <LLonergan@greenplum.com>,
	pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org
Message-id: <20051005153349.GZ2241@mathom.us>
MIME-version: 1.0
Content-type: text/plain; charset=us-ascii; format=flowed
Content-disposition: inline
X-Pgp-Fingerprint: 53 FF 38 00 E7 DD 0A 9C  84 52 84 C5 EE DF 7C 88
X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at mathom.us
References: <3E37B936B592014B978C4415F90D662DE11B55@MI8NYCMAIL06.Mi8.com>
User-Agent: Mutt/1.5.10i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.003 required=5 tests=[AWL=0.003]
X-Spam-Level: 
X-Archive-Number: 200510/104
X-Sequence-Number: 14872

On Wed, Oct 05, 2005 at 11:24:07AM -0400, Luke Lonergan wrote:
>Nope - it would be disk wait.

I said I/O overhead; i.e., it could be the overhead of calling the
kernel for I/O's. E.g., the following process is having I/O problems:

time dd if=/dev/sdc of=/dev/null bs=1 count=10000000                                                                       
10000000+0 records in                                                                                                      
10000000+0 records out                                                                                                     
10000000 bytes transferred in 8.887845 seconds (1125132 bytes/sec)                                                         
                                                                                                                           
real    0m8.889s                                                                                                           
user    0m0.877s                                                                                                           
sys     0m8.010s                                                                                                           

it's not in disk wait state (in fact the whole read was cached) but it's
only getting 1MB/s. 

Mike Stone

From pgsql-performance-owner@postgresql.org  Wed Oct  5 13:40:21 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 5A52DDA16D;
	Wed,  5 Oct 2005 13:14:45 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 80909-02; Wed,  5 Oct 2005 16:14:38 +0000 (GMT)
Received: from pop-satin.atl.sa.earthlink.net (pop-satin.atl.sa.earthlink.net
	[207.69.195.63])
	by svr1.postgresql.org (Postfix) with ESMTP id DB9BFD7FE7;
	Wed,  5 Oct 2005 13:14:34 -0300 (ADT)
Received: from elwamui-chisos.atl.sa.earthlink.net ([209.86.224.31])
	by pop-satin.atl.sa.earthlink.net with esmtp (Exim 3.36 #10)
	id 1ENBuP-0004kZ-00; Wed, 05 Oct 2005 12:14:21 -0400
Message-ID: 
 <4579585.1128528861232.JavaMail.root@elwamui-chisos.atl.sa.earthlink.net>
Date: Wed, 5 Oct 2005 12:14:21 -0400 (EDT)
From: Ron Peacetree <rjpeace@earthlink.net>
Reply-To: Ron Peacetree <rjpeace@earthlink.net>
To: Luke Lonergan <LLonergan@greenplum.com>,
	pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org
Subject: Re: [HACKERS] A Better External Sort?
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: EarthLink Zoo Mail 1.0
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.258 required=5 tests=[AWL=-0.116,
	DNS_FROM_RFC_ABUSE=0.374]
X-Spam-Level: 
X-Archive-Number: 200510/105
X-Sequence-Number: 14873

I've now gotten verification from multiple working DBA's that DB2, Oracle, and
SQL Server can achieve ~250MBps ASTR (with as much as ~500MBps ASTR in
setups akin to Oracle RAC) when attached to a decent (not outrageous, but
decent) HD subsystem...

I've not yet had any RW DBA verify Jeff Baker's supposition that ~1GBps ASTR is
attainable.  Cache based bursts that high, yes.  ASTR, no.

The DBA's in question run RW installations that include Solaris, M$, and Linux OS's
for companies that just about everyone on these lists are likely to recognize.

Also, the implication of these pg IO limits is that money spent on even moderately
priced 300MBps SATA II based RAID HW is wasted $'s.

In total, this situation is a recipe for driving potential pg users to other DBMS. 
  
25MBps in and 15MBps out is =BAD=.

Have we instrumented the code in enough detail that we can tell _exactly_ where
the performance drainage is?

We have to fix this.
Ron  


-----Original Message-----
From: Luke Lonergan <LLonergan@greenplum.com>
Sent: Oct 5, 2005 11:24 AM
To: Michael Stone <mstone+postgres@mathom.us>, Martijn van Oosterhout <kleptog@svana.org>
Cc: pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org
Subject: Re: [HACKERS] [PERFORM] A Better External Sort?

Nope - it would be disk wait.

COPY is CPU bound on I/O subsystems faster that 50 MB/s on COPY (in) and about 15 MB/s (out).

- Luke

 -----Original Message-----
From: 	Michael Stone [mailto:mstone+postgres@mathom.us]
Sent:	Wed Oct 05 09:58:41 2005
To:	Martijn van Oosterhout
Cc:	pgsql-hackers@postgresql.org; pgsql-performance@postgresql.org
Subject:	Re: [HACKERS] [PERFORM] A Better External Sort?

On Sat, Oct 01, 2005 at 06:19:41PM +0200, Martijn van Oosterhout wrote:
>COPY TO /dev/null WITH binary
>13MB/s    55% user 45% system  (ergo, CPU bound)
[snip]
>the most expensive. But it does point out that the whole process is
>probably CPU bound more than anything else.

Note that 45% of that cpu usage is system--which is where IO overhead
would end up being counted. Until you profile where you system time is
going it's premature to say it isn't an IO problem.

Mike Stone


---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster



---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend


From pgsql-performance-owner@postgresql.org  Wed Oct  5 14:16:40 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 18DDDDA23E
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 14:04:23 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 87188-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 17:04:18 +0000 (GMT)
Received: from news.hub.org (news.hub.org [200.46.204.72])
	by svr1.postgresql.org (Postfix) with ESMTP id 62283DA216
	for <pgsql-performance@postgresql.org>;
	Wed,  5 Oct 2005 14:04:19 -0300 (ADT)
Received: from news.hub.org (news.hub.org [200.46.204.72])
	by news.hub.org (8.13.1/8.13.1) with ESMTP id j95H4If2001843
	for <pgsql-performance@postgresql.org>; Wed, 5 Oct 2005 17:04:18 GMT
	(envelope-from news@news.hub.org)
Received: (from news@localhost)
	by news.hub.org (8.13.1/8.13.1/Submit) id j95H41NX001466
	for pgsql-performance@postgresql.org; Wed, 5 Oct 2005 17:04:01 GMT
	(envelope-from news)
From: Chris Browne <cbbrowne@acm.org>
X-Newsgroups: pgsql.performance
Subject: Re: Ultra-cheap NVRAM device
Date: Wed, 05 Oct 2005 13:01:04 -0400
Organization: cbbrowne Computing Inc
Lines: 24
Message-ID: <60achnnbjj.fsf@dba2.int.libertyrms.com>
References: <20051003110226.GA26883@uio.no>
	<08A56EA3-94AD-4F44-88B3-FF8A7EC56B2B@drivefaster.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
X-Complaints-To: usenet@news.hub.org
User-Agent: Gnus/5.1007 (Gnus v5.10.7) XEmacs/21.4.17 (Jumbo Shrimp, linux)
Cancel-Lock: sha1:dOoFIUhJtbg8pHVzMotDFiSptbE=
To: pgsql-performance@postgresql.org
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=-2.483 required=5 tests=[ALL_TRUSTED=-2.82, AWL=0.337]
X-Spam-Level: 
X-Archive-Number: 200510/108
X-Sequence-Number: 14876

fbsd@drivefaster.net (Dan Harris) writes:
> On Oct 3, 2005, at 5:02 AM, Steinar H. Gunderson wrote:
>
>> I thought this might be interesting, not the least due to the
>> extremely low
>> price ($150 + the price of regular DIMMs):
>
> Replying before my other post came through.. It looks like their
> benchmarks are markedly improved since the last article I read on
> this.  There may be more interest now..

It still needs a few more generations worth of improvement.

1.  It's still limited to SATA speed
2.  It's not ECC smart

What I'd love to see would be something that much smarter, or, at
least, that pushes the limits of SATA speed, and which has both a
battery on board and enough CF storage to cope with outages.
-- 
output = reverse("gro.mca" "@" "enworbbc")
http://www.ntlug.org/~cbbrowne/linuxxian.html
We  all live in  a yellow  subroutine, a  yellow subroutine,  a yellow
subroutine...

From pgsql-performance-owner@postgresql.org  Wed Oct  5 14:12:32 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 6C8D5DA16E
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 14:08:42 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 00854-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 17:08:37 +0000 (GMT)
Received: from pop-satin.atl.sa.earthlink.net (pop-satin.atl.sa.earthlink.net
	[207.69.195.63])
	by svr1.postgresql.org (Postfix) with ESMTP id 3FE2FD6F47
	for <pgsql-performance@postgresql.org>;
	Wed,  5 Oct 2005 14:08:37 -0300 (ADT)
Received: from elwamui-chisos.atl.sa.earthlink.net ([209.86.224.31])
	by pop-satin.atl.sa.earthlink.net with esmtp (Exim 3.36 #10)
	id 1ENCkt-0002WZ-00; Wed, 05 Oct 2005 13:08:35 -0400
Message-ID: 
 <25743727.1128532115286.JavaMail.root@elwamui-chisos.atl.sa.earthlink.net>
Date: Wed, 5 Oct 2005 13:08:35 -0400 (EDT)
From: Ron Peacetree <rjpeace@earthlink.net>
Reply-To: Ron Peacetree <rjpeace@earthlink.net>
To: Kevin Grittner <Kevin.Grittner@wicourts.gov>,
	pgsql-performance@postgresql.org
Subject: Re: Is There Any Way ....
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: EarthLink Zoo Mail 1.0
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.258 required=5 tests=[AWL=-0.116,
	DNS_FROM_RFC_ABUSE=0.374]
X-Spam-Level: 
X-Archive-Number: 200510/107
X-Sequence-Number: 14875

From: Kevin Grittner <Kevin.Grittner@wicourts.gov>
Sent: Oct 5, 2005 2:16 AM
Subject: Re: [PERFORM] Is There Any Way ....

>First off, Mr. Trainor's response proves nothing about anyone or
>anything except Mr. Trainor.
>
Fair Enough.  I apologize for the inappropriately general statement.

 
>I'm going to offer an opinion on the caching topic.  I don't have
>any benchmarks; I'm offering a general sense of the issue based on
>decades of experience, so I'll give a short summary of that.
> 
>I've been earning my living by working with computers since 1972,
>
~1978 for me.  So to many on this list, I also would be an "old fart".


<description of qualifications snipped>
>
I've pretty much spent my entire career thinking about and making
advances in RW distributed computing and parallel processing as
first a programmer and then a systems architect. 
 

>Now on to the meat of it. 
<excellent and fair handed overall analysis snipped>
>
I agree with your comments just about across the board.


I also agree with the poster(s) who noted that the "TLC factor" and the
2x every 18months pace of increasing HW performance and RAM capacity
make this stuff a moving target.

OTOH, there are some fundamentals that don't seem to change no
matter how far or fast the computing field evolves.

As usual, the proper answers involve finding a sometimes nontrivial
balance between building on known precedent and not being trapped
by doctrine.

Ron

From pgsql-performance-owner@postgresql.org  Wed Oct  5 14:07:58 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 3F9E5DA240;
	Wed,  5 Oct 2005 14:07:15 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 65246-10; Wed,  5 Oct 2005 17:07:12 +0000 (GMT)
Received: from hosting.commandprompt.com (128.commandprompt.com
	[207.173.200.128])
	by svr1.postgresql.org (Postfix) with ESMTP id 67356DA238;
	Wed,  5 Oct 2005 14:07:09 -0300 (ADT)
Received: from [192.168.1.55] (fc1smp [66.93.38.87]) (authenticated bits=0)
	by hosting.commandprompt.com (8.13.4/8.13.4) with ESMTP id
	j95H4QDb015257; Wed, 5 Oct 2005 10:04:26 -0700
Subject: Re: [HACKERS] A Better External Sort?
From: "Joshua D. Drake" <jd@commandprompt.com>
Reply-To: jd@commandprompt.com
To: Ron Peacetree <rjpeace@earthlink.net>
Cc: Luke Lonergan <LLonergan@greenplum.com>,
	pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org
In-Reply-To: 
 <4579585.1128528861232.JavaMail.root@elwamui-chisos.atl.sa.earthlink.net>
References: 
 <4579585.1128528861232.JavaMail.root@elwamui-chisos.atl.sa.earthlink.net>
Content-Type: text/plain
Organization: Command Prompt, Inc.
Date: Wed, 05 Oct 2005 10:18:25 -0700
Message-Id: <1128532705.2336.1.camel@jd.commandprompt.com>
Mime-Version: 1.0
X-Mailer: Evolution 2.4.0 (2.4.0-3.1.fc4.nr) 
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.012 required=5 tests=[AWL=0.012]
X-Spam-Level: 
X-Archive-Number: 200510/106
X-Sequence-Number: 14874


> We have to fix this.
> Ron  
> 


The source is freely available for your perusal. Please feel free to
point us in specific directions in the code where you may see some
benefit. I am positive all of us that can, would put resources into
fixing the issue had we a specific direction to attack.

Sincerely,

Joshua D. Drake


-- 
Your PostgreSQL solutions company - Command Prompt, Inc. 1.800.492.2240
PostgreSQL Replication, Consulting, Custom Programming, 24x7 support
Managed Services, Shared and Dedicated Hosting
Co-Authors: plPHP, plPerlNG - http://www.commandprompt.com/



From pgsql-performance-owner@postgresql.org  Wed Oct  5 14:41:10 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id F2510DA22D;
	Wed,  5 Oct 2005 14:21:08 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 29680-01; Wed,  5 Oct 2005 17:21:04 +0000 (GMT)
Received: from pop-satin.atl.sa.earthlink.net (pop-satin.atl.sa.earthlink.net
	[207.69.195.63])
	by svr1.postgresql.org (Postfix) with ESMTP id 29229DA16E;
	Wed,  5 Oct 2005 14:21:05 -0300 (ADT)
Received: from elwamui-chisos.atl.sa.earthlink.net ([209.86.224.31])
	by pop-satin.atl.sa.earthlink.net with esmtp (Exim 3.36 #10)
	id 1ENCwy-0005W0-00; Wed, 05 Oct 2005 13:21:04 -0400
Message-ID: 
 <25154967.1128532864650.JavaMail.root@elwamui-chisos.atl.sa.earthlink.net>
Date: Wed, 5 Oct 2005 13:21:04 -0400 (EDT)
From: Ron Peacetree <rjpeace@earthlink.net>
Reply-To: Ron Peacetree <rjpeace@earthlink.net>
To: jd@commandprompt.com, pgsql-hackers@postgresql.org,
	pgsql-performance@postgresql.org
Subject: Re: [HACKERS] A Better External Sort?
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: EarthLink Zoo Mail 1.0
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.258 required=5 tests=[AWL=-0.116,
	DNS_FROM_RFC_ABUSE=0.374]
X-Spam-Level: 
X-Archive-Number: 200510/109
X-Sequence-Number: 14877

First I wanted to verify that pg's IO rates were inferior to The Competition.
Now there's at least an indication that someone else has solved similar
problems.  Existence proofs make some things easier ;-)

Is there any detailed programmer level architectual doc set for pg?  I know
"the best doc is the code", but the code in isolation is often the Slow Path to
understanding with systems as complex as a DBMS IO layer.

Ron
 

-----Original Message-----
From: "Joshua D. Drake" <jd@commandprompt.com>
Sent: Oct 5, 2005 1:18 PM
Subject: Re: [HACKERS] [PERFORM] A Better External Sort?


The source is freely available for your perusal. Please feel free to
point us in specific directions in the code where you may see some
benefit. I am positive all of us that can, would put resources into
fixing the issue had we a specific direction to attack.

Sincerely,

Joshua D. Drake

From pgsql-general-owner@postgresql.org  Wed Oct  5 15:24:05 2005
X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 50B73DA257;
	Wed,  5 Oct 2005 15:24:02 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 26004-09; Wed,  5 Oct 2005 18:23:52 +0000 (GMT)
Received: from mail.clickdiario.com (mail.clickdiario.com [70.85.167.114])
	by svr1.postgresql.org (Postfix) with ESMTP id 3104FDA1A5;
	Wed,  5 Oct 2005 15:23:52 -0300 (ADT)
Received: from localhost (localhost [127.0.0.1])
	by mail.clickdiario.com (Postfix) with ESMTP id B0EE510674;
	Wed,  5 Oct 2005 13:28:04 -0500 (CDT)
Received: from mail.clickdiario.com ([127.0.0.1])
	by localhost (mail.clickdiario.com [127.0.0.1]) (amavisd-new,
	port 10024)
	with ESMTP id 30611-05; Wed, 5 Oct 2005 13:28:04 -0500 (CDT)
Received: from cristian1 (unknown [216.230.158.50])
	by mail.clickdiario.com (Postfix) with ESMTP id 0E6B0100E5;
	Wed,  5 Oct 2005 13:28:03 -0500 (CDT)
From: "Cristian Prieto" <cristian@clickdiario.com>
To: <pgsql-general@postgresql.org>,
	<pgsql-performance@postgresql.org>
Subject: Text/Varchar performance...
Date: Wed, 5 Oct 2005 12:21:35 -0600
MIME-Version: 1.0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit
X-Mailer: Microsoft Office Outlook, Build 11.0.5510
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
Thread-Index: AcXJ2Z4us8IFwjmGTVOiJdhYl6kVMA==
Message-Id: <20051005182803.0E6B0100E5@mail.clickdiario.com>
X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at example.com
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.015 required=5 tests=[AWL=0.015]
X-Spam-Level: 
X-Archive-Number: 200510/203
X-Sequence-Number: 84432

Hello, just a little question, It's preferable to use Text Fields or
varchar(255) fields in a table? Are there any performance differences in the
use of any of them?

Thanks a lot for your answer!


From pgsql-performance-owner@postgresql.org  Wed Oct  5 15:30:45 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id A8AF0DA215;
	Wed,  5 Oct 2005 15:30:41 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 43691-10; Wed,  5 Oct 2005 18:30:33 +0000 (GMT)
Received: from gghcwest.com (adsl-71-128-90-172.dsl.pltn13.pacbell.net
	[71.128.90.172])
	by svr1.postgresql.org (Postfix) with ESMTP id 93CEFDA283;
	Wed,  5 Oct 2005 15:30:31 -0300 (ADT)
Received: from toonses.gghcwest.com (toonses.gghcwest.com [192.168.168.115])
	by gghcwest.com (8.12.10/8.12.9) with ESMTP id j95IUKmd027940;
	Wed, 5 Oct 2005 11:30:21 -0700
Received: from jwb by toonses.gghcwest.com with local (Exim 4.52)
	id 1ENE21-00018H-Hs; Wed, 05 Oct 2005 11:30:21 -0700
Subject: Re: [HACKERS] A Better External Sort?
From: "Jeffrey W. Baker" <jwbaker@acm.org>
To: Ron Peacetree <rjpeace@earthlink.net>
Cc: Luke Lonergan <LLonergan@greenplum.com>,
	pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org
In-Reply-To: 
 <4579585.1128528861232.JavaMail.root@elwamui-chisos.atl.sa.earthlink.net>
References: 
 <4579585.1128528861232.JavaMail.root@elwamui-chisos.atl.sa.earthlink.net>
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Date: Wed, 05 Oct 2005 11:30:21 -0700
Message-Id: <1128537021.3963.1.camel@toonses.gghcwest.com>
Mime-Version: 1.0
X-Mailer: Evolution 2.4.1 
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=-0.319 required=5 tests=[AWL=-0.369,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/111
X-Sequence-Number: 14879

On Wed, 2005-10-05 at 12:14 -0400, Ron Peacetree wrote:
> I've now gotten verification from multiple working DBA's that DB2, Oracle, and
> SQL Server can achieve ~250MBps ASTR (with as much as ~500MBps ASTR in
> setups akin to Oracle RAC) when attached to a decent (not outrageous, but
> decent) HD subsystem...
> 
> I've not yet had any RW DBA verify Jeff Baker's supposition that ~1GBps ASTR is
> attainable.  Cache based bursts that high, yes.  ASTR, no.

I find your tone annoying.  That you do not have access to this level of
hardware proves nothing, other than pointing out that your repeated
emails on this list are based on supposition.

If you want 1GB/sec STR you need:

1) 1 or more Itanium CPUs
2) 24 or more disks
3) 2 or more SATA controllers
4) Linux

Have fun.

-jwb

From pgsql-performance-owner@postgresql.org  Wed Oct  5 15:35:03 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 4B0B1D91B4
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 15:35:00 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 48895-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 18:34:51 +0000 (GMT)
Received: from cassarossa.samfundet.no (cassarossa.samfundet.no
	[129.241.93.19])
	by svr1.postgresql.org (Postfix) with ESMTP id E8F85DA283
	for <pgsql-performance@postgresql.org>;
	Wed,  5 Oct 2005 15:34:47 -0300 (ADT)
Received: from trofast.ipv6.sesse.net ([2001:700:300:dc03:20e:cff:fe36:a766]
	helo=trofast.sesse.net)
	by cassarossa.samfundet.no with esmtp (Exim 4.50) id 1ENE6E-000460-W7
	for pgsql-performance@postgresql.org; Wed, 05 Oct 2005 20:34:44 +0200
Received: from sesse by trofast.sesse.net with local (Exim 3.36 #1 (Debian))
	id 1ENE6D-0008Ut-00
	for <pgsql-performance@postgresql.org>; Wed, 05 Oct 2005 20:34:41 +0200
Date: Wed, 5 Oct 2005 20:34:41 +0200
From: "Steinar H. Gunderson" <sgunderson@bigfoot.com>
To: pgsql-performance@postgresql.org
Subject: Re: Text/Varchar performance...
Message-ID: <20051005183441.GA32451@uio.no>
Mail-Followup-To: pgsql-performance@postgresql.org
References: <20051005182803.0E6B0100E5@mail.clickdiario.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
In-Reply-To: <20051005182803.0E6B0100E5@mail.clickdiario.com>
X-Operating-System: Linux 2.6.11.8 on a i686
X-Message-Flag: Outlook? --> http://www.mozilla.org/products/thunderbird/
User-Agent: Mutt/1.5.10i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.013 required=5 tests=[AWL=0.013]
X-Spam-Level: 
X-Archive-Number: 200510/112
X-Sequence-Number: 14880

On Wed, Oct 05, 2005 at 12:21:35PM -0600, Cristian Prieto wrote:
> Hello, just a little question, It's preferable to use Text Fields or
> varchar(255) fields in a table? Are there any performance differences in the
> use of any of them?

They are essentially the same. Note that you can have varchar without length
(well, up to about a gigabyte or so after compression), and you can have
varchar with a length well above 255 (say, 100000).

/* Steinar */
-- 
Homepage: http://www.sesse.net/

From pgsql-performance-owner@postgresql.org  Wed Oct  5 15:35:45 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 0F497DA21A
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 15:35:43 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 49747-06
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 18:35:39 +0000 (GMT)
Received: from Herge.rcsinc.local (mail.rcsonline.com [70.89.208.142])
	by svr1.postgresql.org (Postfix) with ESMTP id 7692BD91B4
	for <pgsql-performance@postgresql.org>;
	Wed,  5 Oct 2005 15:35:38 -0300 (ADT)
Content-class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Subject: Re: Ultra-cheap NVRAM device
Date: Wed, 5 Oct 2005 14:35:37 -0400
X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0
Message-ID: <6EE64EF3AB31D5448D0007DD34EEB3417DD518@Herge.rcsinc.local>
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
Thread-Topic: [PERFORM] Ultra-cheap NVRAM device
Thread-Index: AcXJ0QQNr88FzLd5Sdi4CjvSugc8QQACP9Ow
From: "Merlin Moncure" <merlin.moncure@rcsonline.com>
To: "Chris Browne" <cbbrowne@acm.org>
Cc: <pgsql-performance@postgresql.org>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.039 required=5 tests=[AWL=-0.011,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/113
X-Sequence-Number: 14881

Chris wrote:
> fbsd@drivefaster.net (Dan Harris) writes:
> > On Oct 3, 2005, at 5:02 AM, Steinar H. Gunderson wrote:
> >
> >> I thought this might be interesting, not the least due to the
> >> extremely low
> >> price ($150 + the price of regular DIMMs):
> >
> > Replying before my other post came through.. It looks like their
> > benchmarks are markedly improved since the last article I read on
> > this.  There may be more interest now..
>=20
> It still needs a few more generations worth of improvement.
>=20
> 1.  It's still limited to SATA speed
> 2.  It's not ECC smart

3. Another zero (or two) on the price tag :).  While it looks like a fun
toy to play with, for it to replace hard drives in server environments
they need to provide more emphasis and effort in assuring people their
drive is reliable.

If they really wanted it to be adopted in server environments, it would
have been packaged in a 3.5" drive, not a pci card, since that's what we
all hot swap (especially since it already uses SATA interface).  They
would also have allowed use of 2 and 4gb DIMS, and put in a small hard
drive that the memory paged to when powered off, and completely isolated
the power supply...hard to pack all that in 60$.

That said, we are in the last days of the hard disk.  I think it is only
a matter of months before we see a sub 1000$ part which have zero
latency in the 20-40 GB range.  Once that happens economies of scale
will kick in and hard drives will become basically a backup device.

Merlin

From pgsql-general-owner@postgresql.org  Wed Oct  5 15:57:03 2005
X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id CE480DA283;
	Wed,  5 Oct 2005 15:56:59 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 09817-05; Wed,  5 Oct 2005 18:56:56 +0000 (GMT)
Received: from davinci.ethosmedia.com (server227.ethosmedia.com
	[209.128.84.227])
	by svr1.postgresql.org (Postfix) with ESMTP id 3C310DA282;
	Wed,  5 Oct 2005 15:56:56 -0300 (ADT)
X-EthosMedia-Virus-Scanned: no infections found
Received: from [64.81.245.111] (account josh@agliodbs.com HELO
	temoku.sf.agliodbs.com)
	by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.1.8)
	with ESMTP id 8206200; Wed, 05 Oct 2005 11:59:21 -0700
From: Josh Berkus <josh@agliodbs.com>
Reply-To: josh@agliodbs.com
Organization: Aglio Database Solutions
To: pgsql-performance@postgresql.org
Subject: Re: [PERFORM] Text/Varchar performance...
Date: Wed, 5 Oct 2005 12:00:48 -0700
User-Agent: KMail/1.8
Cc: "Cristian Prieto" <cristian@clickdiario.com>, pgsql-general@postgresql.org
References: <20051005182803.0E6B0100E5@mail.clickdiario.com>
In-Reply-To: <20051005182803.0E6B0100E5@mail.clickdiario.com>
MIME-Version: 1.0
Content-Type: text/plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Message-Id: <200510051200.48515.josh@agliodbs.com>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.046 required=5 tests=[AWL=-0.004,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/205
X-Sequence-Number: 84434

Cristian,

> Hello, just a little question, It's preferable to use Text Fields or
> varchar(255) fields in a table? Are there any performance differences in
> the use of any of them?

TEXT, VARCHAR, and CHAR use the same underlying storage mechanism.   This 
means that TEXT is actually the "fastest" since it doesn't check length or 
space-pad.  However, that's unlikely to affect you unless you've millions 
of records; you should use the type which makes sense given your 
application.

For "large text fields" I always use TEXT.  BTW, in PostgreSQL VARCHAR is 
not limited to 255; I think we support up to 1GB of text or something 
preposterous.

-- 
--Josh

Josh Berkus
Aglio Database Solutions
San Francisco

From pgsql-hackers-owner@postgresql.org  Wed Oct  5 16:44:01 2005
X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 7DBAEDA261
	for <pgsql-hackers-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 16:43:58 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 61823-07
	for <pgsql-hackers-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 19:43:54 +0000 (GMT)
Received: from zproxy.gmail.com (zproxy.gmail.com [64.233.162.207])
	by svr1.postgresql.org (Postfix) with ESMTP id 18BCFDA257
	for <pgsql-hackers@postgresql.org>;
	Wed,  5 Oct 2005 16:43:52 -0300 (ADT)
Received: by zproxy.gmail.com with SMTP id z31so85685nzd
	for <pgsql-hackers@postgresql.org>;
	Wed, 05 Oct 2005 12:43:54 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:reply-to:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references;
	b=l3fCysXH+V87Eod3R3y+m9upm3u9hi2AAChqwy2totmH47ZSjUMJCjplXMh+yoSwkDa+pS+YJXWgCGkKqXbom1GKEgWf5KteAqMoZfJs9Pp0Sga3Tth1knD9IT25T55IID0M0+3YY59ZMuX4elI+opYNsaaN7Kl2Ktjq+3kwh7A=
Received: by 10.36.60.9 with SMTP id i9mr821566nza;
	Wed, 05 Oct 2005 12:43:54 -0700 (PDT)
Received: by 10.36.23.13 with HTTP; Wed, 5 Oct 2005 12:43:54 -0700 (PDT)
Message-ID: <b35603930510051243v60b97d0fu800fb9de2f080cb1@mail.gmail.com>
Date: Thu, 6 Oct 2005 08:43:54 +1300
From: Andrej Ricnik-Bay <andrej.groups@gmail.com>
Reply-To: Andrej Ricnik-Bay <andrej.groups@gmail.com>
To: pgsql-hackers@postgresql.org
Subject: Re: [PERFORM] A Better External Sort?
In-Reply-To: <20051005153349.GZ2241@mathom.us>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
References: <3E37B936B592014B978C4415F90D662DE11B55@MI8NYCMAIL06.Mi8.com>
	<20051005153349.GZ2241@mathom.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.061 required=5 tests=[AWL=0.037, RCVD_BY_IP=0.024]
X-Spam-Level: 
X-Archive-Number: 200510/238
X-Sequence-Number: 74097

On 10/6/05, Michael Stone <mstone+postgres@mathom.us> wrote:
> On Wed, Oct 05, 2005 at 11:24:07AM -0400, Luke Lonergan wrote:
> >Nope - it would be disk wait.
>
> I said I/O overhead; i.e., it could be the overhead of calling the
> kernel for I/O's. E.g., the following process is having I/O problems:
>
> time dd if=3D/dev/sdc of=3D/dev/null bs=3D1 count=3D10000000
> 10000000+0 records in
> 10000000+0 records out
> 10000000 bytes transferred in 8.887845 seconds (1125132 bytes/sec)
>
> real    0m8.889s
> user    0m0.877s
> sys     0m8.010s
>
> it's not in disk wait state (in fact the whole read was cached) but it's
> only getting 1MB/s.
>
> Mike Stone
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: don't forget to increase your free space map settings
>
I think you only proved that dd isn't the smartest tool out there... or
that using it with a blocksize of 1 byte doesn't make too much sense.


[andrej@diggn:~]$ time dd if=3D/dev/sr0 of=3D/dev/null bs=3D2048 count=3D48=
83
4883+0 records in
4883+0 records out

real    0m6.824s
user    0m0.010s
sys     0m0.060s
[andrej@diggn:~]$ time dd if=3D/dev/sr0 of=3D/dev/null bs=3D1 count=3D10000=
000
10000000+0 records in
10000000+0 records out

real    0m18.523s
user    0m7.410s
sys     0m10.310s
[andrej@diggn:~]$ time dd if=3D/dev/sr0 of=3D/dev/null bs=3D8192 count=3D12=
20
1220+0 records in
1220+0 records out

real    0m6.796s
user    0m0.000s
sys     0m0.070s

That's with caching, and all.  Or did I miss the point of your post
completely?  Interestingly, the CPU usage with the bs=3D1 goes up
to 97%, it stays at a mellow 3% with the 8192 and 2048.


Cheers,
Andrej

From pgsql-performance-owner@postgresql.org  Wed Oct  5 17:01:51 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id A20FED9EA5
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 17:01:28 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 88258-09
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 20:01:20 +0000 (GMT)
Received: from outbound0.sv.meer.net (outbound0.sv.meer.net [205.217.152.13])
	by svr1.postgresql.org (Postfix) with ESMTP id C1483DA29A
	for <pgsql-performance@postgresql.org>;
	Wed,  5 Oct 2005 17:01:19 -0300 (ADT)
Received: from mail.meer.net (mail.meer.net [209.157.152.14])
	by outbound0.sv.meer.net (8.12.10/8.12.6) with ESMTP id j95JqMsi028240
	for <pgsql-performance@postgresql.org>;
	Wed, 5 Oct 2005 12:52:22 -0700 (PDT)
	(envelope-from trainor@transborder.net)
Received: from [192.168.1.46] (pool-151-197-28-186.phil.east.verizon.net
	[151.197.28.186])
	by mail.meer.net (8.13.3/8.13.3/meer) with ESMTP id j95JqGD4030526
	for <pgsql-performance@postgresql.org>;
	Wed, 5 Oct 2005 12:52:16 -0700 (PDT)
	(envelope-from trainor@transborder.net)
Mime-Version: 1.0 (Apple Message framework v623)
In-Reply-To: 
 <17434238.1128481614269.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
References: 
 <17434238.1128481614269.JavaMail.root@elwamui-polski.atl.sa.earthlink.net>
Content-Type: multipart/alternative; boundary=Apple-Mail-1--89115678
Message-Id: <aaa8d7ac7b4f938fd6f613930acd5d6e@transborder.net>
From: "Douglas J. Trainor" <trainor@transborder.net>
Subject: Re: Is There Any Way ....
Date: Wed, 5 Oct 2005 15:52:19 -0400
To: pgsql-performance@postgresql.org
X-Mailer: Apple Mail (2.623)
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0 required=5 tests=[none]
X-Spam-Level: 
X-Archive-Number: 200510/115
X-Sequence-Number: 14883


--Apple-Mail-1--89115678
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	format=flowed

A blast from the past is forwarded below.

     douglas

Begin forwarded message:

> From: Tom Lane <tgl@sss.pgh.pa.us>
> Date: August 23, 2005 3:23:43 PM EDT
> To: Donald Courtney <Donald.Courtney@sun.com>
> Cc: pgsql-performance@postgresql.org, Frank Wiles <frank@wiles.org>, 
> gokulnathbabu manoharan <gokulnathbabu@yahoo.com>
> Subject: Re: [PERFORM] Caching by Postgres
>
> Donald Courtney <Donald.Courtney@Sun.COM> writes:
>> I am not alone in having the *expectation* that a database should have
>> some cache size parameter and the option to skip the file system.  If
>> I use oracle, sybase, mysql and maxdb they all have the ability to
>> size a data cache and move to 64 bits.
>
> And you're not alone in holding that opinion despite having no shred
> of evidence that it's worthwhile expanding the cache that far.
>
> However, since we've gotten tired of hearing this FUD over and over,
> 8.1 will have the ability to set shared_buffers as high as you want.
> I expect next we'll be hearing from people complaining that they
> set shared_buffers to use all of RAM and performance went into the
> tank ...
>
> 			regards, tom lane


On Oct 4, 2005, at 11:06 PM, Ron Peacetree wrote:

> Unfortunately, no matter what I say or do, I'm not going to please
> or convince anyone who has already have made their minds up
> to the extent that they post comments like Mr Trainor's below.
> His response style pretty much proves my earlier point that this
> is presently a religious issue within the pg community.
>
> The absolute best proof would be to build a version of pg that does
> what Oracle and DB2 have done and implement it's own DB
> specific memory manager and then compare the performance
> between the two versions on the same HW, OS, and schema.
>
> The second best proof would be to set up either DB2 or Oracle so
> that they _don't_ use their memory managers and compare their
> performance to a set up that _does_ use said memory managers
> on the same HW, OS, and schema.
>
> I don't currently have the resources for either experiment.
>
> Some might even argue that IBM (where Codd and Date worked)
> and Oracle just _might_ have had justification for the huge effort
> they put into developing such infrastructure.
>
> Then there's the large library of research on caching strategies
> in just about every HW and SW domain, including DB theory,
> that points put that the more context dependent, ie application
> or domain specific awareness, caching strategies are the better
> they are.
>
> Maybe after we do all we can about physical IO and sorting
> performance I'll take on the religious fanatics on this one.
>
> One problem set at a time.
> Ron

--Apple-Mail-1--89115678
Content-Transfer-Encoding: 7bit
Content-Type: text/enriched;
	charset=US-ASCII

A blast from the past is forwarded below.


    douglas


Begin forwarded message:


<excerpt><bold><color><param>0000,0000,0000</param>From:
</color></bold>Tom Lane <<tgl@sss.pgh.pa.us>

<bold><color><param>0000,0000,0000</param>Date: </color></bold>August
23, 2005 3:23:43 PM EDT

<bold><color><param>0000,0000,0000</param>To: </color></bold>Donald
Courtney <<Donald.Courtney@sun.com>

<bold><color><param>0000,0000,0000</param>Cc:
</color></bold>pgsql-performance@postgresql.org, Frank Wiles
<<frank@wiles.org>, gokulnathbabu manoharan <<gokulnathbabu@yahoo.com>

<bold><color><param>0000,0000,0000</param>Subject: </color>Re:
[PERFORM] Caching by Postgres 

</bold>

Donald Courtney <<Donald.Courtney@Sun.COM> writes:

<excerpt>I am not alone in having the *expectation* that a database
should have

some cache size parameter and the option to skip the file system.  If

I use oracle, sybase, mysql and maxdb they all have the ability to

size a data cache and move to 64 bits.

</excerpt>

And you're not alone in holding that opinion despite having no shred

of evidence that it's worthwhile expanding the cache that far.


However, since we've gotten tired of hearing this FUD over and over,

8.1 will have the ability to set shared_buffers as high as you want.

I expect next we'll be hearing from people complaining that they

set shared_buffers to use all of RAM and performance went into the

tank ...


			regards, tom lane

</excerpt>


On Oct 4, 2005, at 11:06 PM, Ron Peacetree wrote:


<excerpt>Unfortunately, no matter what I say or do, I'm not going to
please

or convince anyone who has already have made their minds up

to the extent that they post comments like Mr Trainor's below.

His response style pretty much proves my earlier point that this

is presently a religious issue within the pg community.


The absolute best proof would be to build a version of pg that does

what Oracle and DB2 have done and implement it's own DB

specific memory manager and then compare the performance

between the two versions on the same HW, OS, and schema.


The second best proof would be to set up either DB2 or Oracle so

that they _don't_ use their memory managers and compare their

performance to a set up that _does_ use said memory managers

on the same HW, OS, and schema.


I don't currently have the resources for either experiment.


Some might even argue that IBM (where Codd and Date worked)

and Oracle just _might_ have had justification for the huge effort

they put into developing such infrastructure. 


Then there's the large library of research on caching strategies

in just about every HW and SW domain, including DB theory,

that points put that the more context dependent, ie application

or domain specific awareness, caching strategies are the better

they are.


Maybe after we do all we can about physical IO and sorting

performance I'll take on the religious fanatics on this one.


One problem set at a time.

Ron   

</excerpt>
--Apple-Mail-1--89115678--


From pgsql-hackers-owner@postgresql.org  Wed Oct  5 16:55:11 2005
X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 49CCFDA294
	for <pgsql-hackers-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 16:54:48 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 93239-06
	for <pgsql-hackers-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 19:54:43 +0000 (GMT)
Received: from rproxy.gmail.com (rproxy.gmail.com [64.233.170.206])
	by svr1.postgresql.org (Postfix) with ESMTP id C6ACDDA2AB
	for <pgsql-hackers@postgresql.org>;
	Wed,  5 Oct 2005 16:54:41 -0300 (ADT)
Received: by rproxy.gmail.com with SMTP id 34so9589rns
	for <pgsql-hackers@postgresql.org>;
	Wed, 05 Oct 2005 12:54:42 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references;
	b=WM7PFPf1dqTBf2+255gFh3ckvmNWaYid4ONSPUzCYTakBwOn78KoiAcHvHlfrXopYeFZg133+jGWzXCunNMfCjL+fIRaNwU7e7wj4vgruUAXUv7FJykT82qa71BV3gssVO7i3TG12bqKqbiKOuOFHMcw6IiJCMHZKIQkmI/cY3s=
Received: by 10.11.119.14 with SMTP id r14mr9334cwc;
	Wed, 05 Oct 2005 12:54:42 -0700 (PDT)
Received: by 10.11.119.38 with HTTP; Wed, 5 Oct 2005 12:54:42 -0700 (PDT)
Message-ID: <36e682920510051254v794908a0o@mail.gmail.com>
Date: Wed, 5 Oct 2005 15:54:42 -0400
From: "Jonah H. Harris" <jonah.harris@gmail.com>
Reply-To: "Jonah H. Harris" <jonah.harris@gmail.com>
To: Ron Peacetree <rjpeace@earthlink.net>
Subject: Re: [PERFORM] A Better External Sort?
Cc: jd@commandprompt.com, pgsql-hackers@postgresql.org,
	pgsql-performance@postgresql.org
In-Reply-To: 
 <25154967.1128532864650.JavaMail.root@elwamui-chisos.atl.sa.earthlink.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
References: 
 <25154967.1128532864650.JavaMail.root@elwamui-chisos.atl.sa.earthlink.net>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.196 required=5 tests=[AWL=0.172, RCVD_BY_IP=0.024]
X-Spam-Level: 
X-Archive-Number: 200510/240
X-Sequence-Number: 74099

Ron,

This thread is getting on my nerves.  Your tone in some of the other
posts (as-well-as this one) is getting very annoying.  Yes,
PostgreSQL's storage manager (like all other open source databases),
lacks many of the characteristics and enhancements of the commercial
databases.  Unlike Oracle, Microsoft, etc., the PostgreSQL Global
Development Group doesn't have the tens of millions of dollars
required to pay hundreds of developers around the world for
round-the-clock development and R&D.  Making sure that every little
tweak, on every system, is taken advantage of is expensive (in terms
of time) for an open source project where little ROI is gained.=20
Before you make a statement like, "I wanted to verify that pg's IO
rates were inferior to The Competition", think about how you'd write
your own RDBMS from scratch (in reality, not in theory).

As for your question regarding developer docs for the storage manager
and related components, read the READMEs and the code... just like
everyone else.

Rather than posting more assumptions and theory, please read through
the code and come back with actual suggestions.

-Jonah

2005/10/5, Ron Peacetree <rjpeace@earthlink.net>:
> First I wanted to verify that pg's IO rates were inferior to The Competit=
ion.
> Now there's at least an indication that someone else has solved similar
> problems.  Existence proofs make some things easier ;-)
>
> Is there any detailed programmer level architectual doc set for pg?  I kn=
ow
> "the best doc is the code", but the code in isolation is often the Slow P=
ath to
> understanding with systems as complex as a DBMS IO layer.
>
> Ron
>
>
> -----Original Message-----
> From: "Joshua D. Drake" <jd@commandprompt.com>
> Sent: Oct 5, 2005 1:18 PM
> Subject: Re: [HACKERS] [PERFORM] A Better External Sort?
>
>
> The source is freely available for your perusal. Please feel free to
> point us in specific directions in the code where you may see some
> benefit. I am positive all of us that can, would put resources into
> fixing the issue had we a specific direction to attack.
>
> Sincerely,
>
> Joshua D. Drake
>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: In versions below 8.0, the planner will ignore your desire to
>        choose an index scan if your joining column's datatypes do not
>        match
>


--
Respectfully,

Jonah H. Harris, Database Internals Architect
EnterpriseDB Corporation
http://www.enterprisedb.com/

From pgsql-performance-owner@postgresql.org  Wed Oct  5 20:46:45 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id EDD8CDA231
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 20:46:31 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 58874-10
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 23:46:28 +0000 (GMT)
Received: from mail.baymountain.com (mail.baymountain.com [8.7.96.19])
	by svr1.postgresql.org (Postfix) with SMTP id 781D9D9EA5
	for <pgsql-performance@postgresql.org>;
	Wed,  5 Oct 2005 20:46:26 -0300 (ADT)
Received: (qmail 21450 invoked by uid 504); 5 Oct 2005 23:46:29 -0000
Received: from emil@baymountain.com by mail.baymountain.com by uid 501 with
	qmail-scanner-1.16 (spamassassin: 2.53.  Clear:SA:0(0.0/7.0):.
	Processed in 0.269184 secs); 05 Oct 2005 23:46:29 -0000
Received: from unknown (HELO briggspack.com)
	(emil@briggspack.com@24.211.148.77)
	by mail.baymountain.com with SMTP; 5 Oct 2005 23:46:28 -0000
From: Emil Briggs <emil@baymountain.com>
Reply-To: emil@baymountain.com
Organization: Baymountain, Inc.
To: pgsql-performance@postgresql.org
Subject: Re: Indexes on ramdisk
Date: Wed, 5 Oct 2005 19:46:24 -0400
User-Agent: KMail/1.7.1
References: <200510042109.01849.emil@baymountain.com>
	<200510042341.23264.emil@baymountain.com>
	<33c6269f0510050803w72097bb5v526a0126af876af4@mail.gmail.com>
In-Reply-To: <33c6269f0510050803w72097bb5v526a0126af876af4@mail.gmail.com>
MIME-Version: 1.0
Content-Type: text/plain;
  charset="utf-8"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Message-Id: <200510051946.24326.emil@baymountain.com>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.038 required=5 tests=[AWL=-0.013,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/116
X-Sequence-Number: 14884

> What kind of order of improvement do you need to see?
>

A lot since the load on the system is expected to increase by up to 100% over 
the next 6 months.

> What period are these number for? Were they collected over 1 hour, 1 day, 1
> month?
>

I thought I mentioned that in the earlier post but it was from a 2 hour 
period. It's a busy system.

> How much Cache do you have on the controller?
>

64Mbytes but I don't think that's an issue. As I mentioned in the first post 
the table that is the bottleneck has indexes on 15 columns and is seeing a 
lot of inserts, deletes and updates. The indexes are spread out over the 5 
mirrors but it's still a couple of writes per mirror for each operation. I'm 
going to order an SSD which should give us a lot more headroom than trying to 
rearrange the RAID setup.


From pgsql-performance-owner@postgresql.org  Wed Oct  5 20:54:25 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 699AEDA285;
	Wed,  5 Oct 2005 20:54:21 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 36914-10; Wed,  5 Oct 2005 23:54:16 +0000 (GMT)
Received: from pop-sarus.atl.sa.earthlink.net (pop-sarus.atl.sa.earthlink.net
	[207.69.195.72])
	by svr1.postgresql.org (Postfix) with ESMTP id 20719D9EA5;
	Wed,  5 Oct 2005 20:54:17 -0300 (ADT)
Received: from elwamui-milano.atl.sa.earthlink.net ([209.86.224.40])
	by pop-sarus.atl.sa.earthlink.net with esmtp (Exim 3.36 #10)
	id 1ENJ5T-00048q-00; Wed, 05 Oct 2005 19:54:15 -0400
Message-ID: 
 <138872.1128556455518.JavaMail.root@elwamui-milano.atl.sa.earthlink.net>
Date: Wed, 5 Oct 2005 19:54:15 -0400 (EDT)
From: Ron Peacetree <rjpeace@earthlink.net>
Reply-To: Ron Peacetree <rjpeace@earthlink.net>
To: "Jonah H. Harris" <jonah.harris@gmail.com>,
	pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org
Subject: Re: [HACKERS] A Better External Sort?
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: EarthLink Zoo Mail 1.0
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.258 required=5 tests=[AWL=-0.116,
	DNS_FROM_RFC_ABUSE=0.374]
X-Spam-Level: 
X-Archive-Number: 200510/117
X-Sequence-Number: 14885

I'm putting in as much time as I can afford thinking about pg related
performance issues.  I'm doing it because of a sincere desire to help
understand and solve them, not to annoy people.

If I didn't believe in pg, I would't be posting thoughts about how to
make it better.  

It's probably worth some review (suggestions marked with a "+":

+I came to the table with a possibly better way to deal with external
sorts (that now has branched into 2 efforts: short term improvements
to the existing code, and the original from-the-ground-up idea).  That
suggestion was based on a great deal of prior thought and research,
despite what some others might think.

Then we were told that our IO limit was lower than I thought.

+I suggested that as a "Quick Fix" we try making sure we do IO
transfers in large enough chunks based in the average access time
of the physical device in question so as to achieve the device's
ASTR (ie at least 600KB per access for a 50MBps ASTR device with
a 12ms average access time.) whenever circumstances allowed us.
As far as I know, this experiment hasn't been tried yet.

I asked some questions about physical layout and format translation
overhead being possibly suboptimal that seemed to be agreed to, but
specifics as to where we are taking the hit don't seem to have been
made explicit yet.

+I made the "from left field" suggestion that perhaps a pg native fs
format would be worth consideration.  This is a major project, so
the suggestion was to at least some extent tongue-in-cheek.

+I then made some suggestions about better code instrumentation
so that we can more accurately characterize were the bottlenecks are. 

We were also told that evidently we are CPU bound far before one
would naively expect to be based on the performance specifications
of the components involved.

Double checking among the pg developer community led to some
differing opinions as to what the actual figures were and under what
circumstances they were achieved.  Further discussion seems to have
converged on both accurate values and a better understanding as to
the HW and SW  needed; _and_ we've gotten some RW confirmation
as to what current reasonable expectations are within this problem
domain from outside the pg community.

+Others have made some good suggestions in this thread as well.
Since I seem to need to defend my tone here, I'm not detailing them
here.  That should not be construed as a lack of appreciation of them.

Now I've asked for the quickest path to detailed understanding of the
pg IO subsystem.  The goal being to get more up to speed on its
coding details.  Certainly not to annoy you or anyone else.

At least from my perspective, this for the most part seems to have
been an useful and reasonable engineering discussion that has
exposed a number of important things.
  
Regards,
Ron

From pgsql-performance-owner@postgresql.org  Wed Oct  5 20:58:37 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 02F86DA206;
	Wed,  5 Oct 2005 20:55:59 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 59628-10; Wed,  5 Oct 2005 23:55:54 +0000 (GMT)
Received: from mail.mi8.com (d01gw02.mi8.com [63.240.6.46])
	by svr1.postgresql.org (Postfix) with ESMTP id D6138DA207;
	Wed,  5 Oct 2005 20:55:54 -0300 (ADT)
Received: from 172.16.1.118 by mail.mi8.com with ESMTP (- Welcome to Mi8
	Corporation www.Mi8.com (D2)); Wed, 05 Oct 2005 19:55:53 -0400
X-Server-Uuid: 7829E76E-BB9E-4995-8473-3C0929DF7DD1
Received: from MI8NYCMAIL06.Mi8.com ([172.16.1.175]) by
	d01smtp03.Mi8.com with Microsoft SMTPSVC(6.0.3790.1830); Wed, 5 Oct
	2005 19:55:53 -0400
Received: from 67.103.45.218 ([67.103.45.218]) by MI8NYCMAIL06.Mi8.com (
	[172.16.1.219]) via Exchange Front-End Server mi8owa.mi8.com (
	[172.16.1.104]) with Microsoft Exchange Server HTTP-DAV ; Wed, 5 Oct
	2005 19:55:53 -0500
User-Agent: Microsoft-Entourage/11.2.0.050811
Date: Wed, 05 Oct 2005 16:55:51 -0700
Subject: Re: [HACKERS] A Better External Sort?
From: "Luke Lonergan" <llonergan@greenplum.com>
To: "Michael Stone" <mstone+postgres@mathom.us>
Cc: pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org
Message-ID: <BF69B617.10B72%llonergan@greenplum.com>
Thread-Topic: [HACKERS] [PERFORM] A Better External Sort?
Thread-Index: AcXKCFCOjxWPyjX7EdqbagANk63kWA==
In-Reply-To: <20051005153349.GZ2241@mathom.us>
MIME-Version: 1.0
X-OriginalArrivalTime: 05 Oct 2005 23:55:53.0721 (UTC)
	FILETIME=[522DCE90:01C5CA08]
X-WSS-ID: 6F5AB7834P81223849-01-01
Content-Type: text/plain;
 charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=1.573 required=5 tests=[AWL=-0.008,
	FORGED_RCVD_HELO=0.05, RCVD_NUMERIC_HELO=1.531]
X-Spam-Level: *
X-Archive-Number: 200510/118
X-Sequence-Number: 14886

Michael,

On 10/5/05 8:33 AM, "Michael Stone" <mstone+postgres@mathom.us> wrote:

> real    0m8.889s 
> user    0m0.877s 
> sys     0m8.010s 
> 
> it's not in disk wait state (in fact the whole read was cached) but it's
> only getting 1MB/s.

You've proven my point completely.  This process is bottlenecked in the CPU.
The only way to improve it would be to optimize the system (libc) functions
like "fread" where it is spending most of it's time.

In COPY, we found lots of libc functions like strlen() being called
ridiculous numbers of times, in one case it was called on every
timestamp/date attribute to get the length of TZ, which is constant.  That
one function call was in the system category, and was responsible for
several percent of the time.

By the way, system routines like fgetc/getc/strlen/atoi etc, don't appear in
gprof profiles of dynamic linked objects, nor by default in oprofile
results.

If the bottleneck is in I/O, you will see the time spent in disk wait, not
in system.

- Luke



From pgsql-performance-owner@postgresql.org  Wed Oct  5 21:12:48 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 82D67DA286
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed,  5 Oct 2005 21:12:46 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 69201-07
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu,  6 Oct 2005 00:12:39 +0000 (GMT)
Received: from cassarossa.samfundet.no (cassarossa.samfundet.no
	[129.241.93.19])
	by svr1.postgresql.org (Postfix) with ESMTP id EAFE9DA272
	for <pgsql-performance@postgresql.org>;
	Wed,  5 Oct 2005 21:12:39 -0300 (ADT)
Received: from trofast.sesse.net ([129.241.93.32])
	by cassarossa.samfundet.no with esmtp (Exim 4.50) id 1ENJNJ-0007L9-Aw
	for pgsql-performance@postgresql.org; Thu, 06 Oct 2005 02:12:42 +0200
Received: from sesse by trofast.sesse.net with local (Exim 3.36 #1 (Debian))
	id 1ENJNH-0002ja-00
	for <pgsql-performance@postgresql.org>; Thu, 06 Oct 2005 02:12:39 +0200
Date: Thu, 6 Oct 2005 02:12:39 +0200
From: "Steinar H. Gunderson" <sgunderson@bigfoot.com>
To: pgsql-performance@postgresql.org
Subject: Re: [HACKERS] A Better External Sort?
Message-ID: <20051006001239.GB7856@uio.no>
Mail-Followup-To: pgsql-performance@postgresql.org
References: <20051005153349.GZ2241@mathom.us>
	<BF69B617.10B72%llonergan@greenplum.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
In-Reply-To: <BF69B617.10B72%llonergan@greenplum.com>
X-Operating-System: Linux 2.6.11.8 on a i686
X-Message-Flag: Outlook? --> http://www.mozilla.org/products/thunderbird/
User-Agent: Mutt/1.5.10i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.013 required=5 tests=[AWL=0.013]
X-Spam-Level: 
X-Archive-Number: 200510/119
X-Sequence-Number: 14887

On Wed, Oct 05, 2005 at 04:55:51PM -0700, Luke Lonergan wrote:
> In COPY, we found lots of libc functions like strlen() being called
> ridiculous numbers of times, in one case it was called on every
> timestamp/date attribute to get the length of TZ, which is constant.  That
> one function call was in the system category, and was responsible for
> several percent of the time.

What? strlen is definitely not in the kernel, and thus won't count as system
time.

/* Steinar */
-- 
Homepage: http://www.sesse.net/

From pgsql-performance-owner@postgresql.org  Thu Oct  6 03:39:32 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 22DC5DA302
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu,  6 Oct 2005 03:39:31 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 15997-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu,  6 Oct 2005 06:39:25 +0000 (GMT)
Received: from window.monsterlabs.com (window.monsterlabs.com
	[216.183.105.176])
	by svr1.postgresql.org (Postfix) with SMTP id B4137DA18B
	for <pgsql-performance@postgresql.org>;
	Thu,  6 Oct 2005 03:39:24 -0300 (ADT)
Received: (qmail 5945 invoked from network); 6 Oct 2005 06:35:28 -0000
Received: from pcp0012204803pcs.blairblvd.tn.nash.comcast.net (HELO
	?192.168.15.103?) (69.245.49.69)
	by 0 with SMTP; 6 Oct 2005 06:35:28 -0000
In-Reply-To: <1128518624.15795.28.camel@spectre.intellivid.com>
References: <1128518624.15795.28.camel@spectre.intellivid.com>
Mime-Version: 1.0 (Apple Message framework v734)
Content-Type: text/plain; charset=WINDOWS-1252; delsp=yes; format=flowed
Message-Id: <C140F925-0D7D-41B4-873A-6C81C0D3D307@sitening.com>
Cc: pgsql-performance@postgresql.org
Content-Transfer-Encoding: quoted-printable
From: "Thomas F. O'Connell" <tfo@sitening.com>
Subject: Re: wal_buffers
Date: Thu, 6 Oct 2005 01:39:20 -0500
To: Ian Westmacott <ianw@intellivid.com>
X-Mailer: Apple Mail (2.734)
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.019 required=5 tests=[AWL=0.019]
X-Spam-Level: 
X-Archive-Number: 200510/120
X-Sequence-Number: 14888


On Oct 5, 2005, at 8:23 AM, Ian Westmacott wrote:

> Can anyone tell me what precisely a WAL buffer contains,
> so that I can compute an appropriate setting for
> wal_buffers (in 8.0.3)?
>
> I know the documentation suggests there is little
> evidence that supports increasing wal_buffers, but we
> are inserting a large amount of data that, I believe,
> easily exceeds the default 64K in a single transaction.
> We are also very sensitive to write latency.
>
> As background, we are doing a sustained insert of 2.2
> billion rows in 1.3 million transactions per day.  Thats
> about 1700 rows per transaction, at (roughly) 50 bytes
> per row.

Ian,

The WAL Configuration chapter (25.2) has a pretty good discussion of =20
how wal_buffers is used:

http://www.postgresql.org/docs/8.0/static/wal-configuration.html

You might also take a look at Josh Berkus' recent testing on this =20
setting:

http://www.powerpostgresql.com/

--
Thomas F. O'Connell
Co-Founder, Information Architect
Sitening, LLC

Strategic Open Source: Open Your i=99

http://www.sitening.com/
110 30th Avenue North, Suite 6
Nashville, TN 37203-6320
615-469-5150
615-469-5151 (fax)

From pgsql-performance-owner@postgresql.org  Thu Oct  6 05:19:28 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 0A589DA345
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu,  6 Oct 2005 05:19:27 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 75845-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu,  6 Oct 2005 08:19:21 +0000 (GMT)
Received: from zoom.spline.inf.fu-berlin.de (unknown [130.133.110.148])
	by svr1.postgresql.org (Postfix) with ESMTP id D31C1D6E83
	for <pgsql-performance@postgresql.org>;
	Thu,  6 Oct 2005 05:19:21 -0300 (ADT)
Received: by zoom.spline.inf.fu-berlin.de (Postfix, from userid 2091)
	id 4D6B654E00; Thu,  6 Oct 2005 10:19:20 +0200 (CEST)
Date: Thu, 6 Oct 2005 10:19:19 +0200
From: Yann Michel <yann-postgresql@spline.de>
To: "jan.aerts@bbsrc.ac.uk" <jan.aerts@gmail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: index on custom function; explain
Message-ID: <20051006081919.GA17081@zoom.spline.inf.fu-berlin.de>
References: <1128352451.312090.37640@g44g2000cwa.googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <1128352451.312090.37640@g44g2000cwa.googlegroups.com>
User-Agent: Mutt/1.5.9i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0 required=5 tests=[none]
X-Spam-Level: 
X-Archive-Number: 200510/121
X-Sequence-Number: 14889

Hi,

On Mon, Oct 03, 2005 at 08:14:11AM -0700, jan.aerts@bbsrc.ac.uk wrote:
> So my questions are:
> * Does anyone have any idea how I can integrate a function that lists
> all aliases for a given name into such a mapping query?

what version are you using?

TIP 9: In versions below 8.0, the planner will ignore your desire to
       choose an index scan if your joining column's datatypes do not
       match

Cheers,
Yann

From pgsql-performance-owner@postgresql.org  Thu Oct  6 06:49:39 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 93842DA272;
	Thu,  6 Oct 2005 06:49:38 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 56477-04; Thu,  6 Oct 2005 09:49:34 +0000 (GMT)
Received: from vms048pub.verizon.net (vms048pub.verizon.net [206.46.252.48])
	by svr1.postgresql.org (Postfix) with ESMTP id B3011D9D29;
	Thu,  6 Oct 2005 06:49:32 -0300 (ADT)
Received: from osgiliath.mathom.us ([70.108.61.78])
	by vms048.mailsrvcs.net (Sun Java System Messaging Server 6.2 HotFix
	0.04 (built Dec 24 2004)) with ESMTPA id
	<0INX00A9DNAMQXZ5@vms048.mailsrvcs.net>;
	Thu, 06 Oct 2005 04:49:35 -0500 (CDT)
Received: from localhost (localhost [127.0.0.1])
	by osgiliath.mathom.us (Postfix) with ESMTP id 5F84A6285C6; Thu,
	06 Oct 2005 05:49:34 -0400 (EDT)
Received: from osgiliath.mathom.us ([127.0.0.1])
	by localhost (osgiliath [127.0.0.1]) (amavisd-new, port 10024)
	with LMTP id 31111-02-4; Thu, 06 Oct 2005 05:49:34 -0400 (EDT)
Received: by osgiliath.mathom.us (Postfix, from userid 1000)
	id 438836000AA; Thu, 06 Oct 2005 05:49:34 -0400 (EDT)
Date: Thu, 06 Oct 2005 05:49:34 -0400
From: Michael Stone <mstone+postgres@mathom.us>
Subject: Re: [HACKERS] A Better External Sort?
In-reply-to: <BF69B617.10B72%llonergan@greenplum.com>
To: Luke Lonergan <llonergan@greenplum.com>
Cc: pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org
Mail-Followup-To: Luke Lonergan <llonergan@greenplum.com>,
	pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org
Message-id: <20051006094934.GB17398@mathom.us>
MIME-version: 1.0
Content-type: text/plain; charset=us-ascii; format=flowed
Content-disposition: inline
X-Pgp-Fingerprint: 53 FF 38 00 E7 DD 0A 9C  84 52 84 C5 EE DF 7C 88
X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at mathom.us
References: <20051005153349.GZ2241@mathom.us>
	<BF69B617.10B72%llonergan@greenplum.com>
User-Agent: Mutt/1.5.11
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.003 required=5 tests=[AWL=0.003]
X-Spam-Level: 
X-Archive-Number: 200510/122
X-Sequence-Number: 14890

On Wed, Oct 05, 2005 at 04:55:51PM -0700, Luke Lonergan wrote:
>You've proven my point completely.  This process is bottlenecked in the CPU.
>The only way to improve it would be to optimize the system (libc) functions
>like "fread" where it is spending most of it's time.

Or to optimize its IO handling to be more efficient. (E.g., use larger
blocks to reduce the number of syscalls.) 

Mike Stone

From pgsql-hackers-owner@postgresql.org  Thu Oct  6 07:37:45 2005
X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id E54D1DA3E4
	for <pgsql-hackers-postgresql.org@localhost.postgresql.org>;
	Thu,  6 Oct 2005 07:37:44 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 14658-02
	for <pgsql-hackers-postgresql.org@localhost.postgresql.org>;
	Thu,  6 Oct 2005 10:37:37 +0000 (GMT)
Received: from mail.skype.net (mail.skype.net [195.215.8.149])
	by svr1.postgresql.org (Postfix) with ESMTP id 8374ADA3A2
	for <pgsql-hackers@postgresql.org>;
	Thu,  6 Oct 2005 07:37:37 -0300 (ADT)
Received: from localhost (localhost.localdomain [127.0.0.1])
	by mail.skype.net (Postfix) with ESMTP id 470984DE7E;
	Thu,  6 Oct 2005 12:37:38 +0200 (CEST)
Received: from [192.168.0.41] (joltid-gw.joltid.org [195.50.194.24])
	by mail.skype.net (Postfix) with ESMTP id AFDE24DE78;
	Thu,  6 Oct 2005 12:37:37 +0200 (CEST)
Subject: Re: [PERFORM] A Better External Sort?
From: Hannu Krosing <hannu@skype.net>
To: Ron Peacetree <rjpeace@earthlink.net>
Cc: pgsql-hackers@postgresql.org
In-Reply-To: 
 <25154967.1128532864650.JavaMail.root@elwamui-chisos.atl.sa.earthlink.net>
References: 
 <25154967.1128532864650.JavaMail.root@elwamui-chisos.atl.sa.earthlink.net>
Content-Type: text/plain
Date: Thu, 06 Oct 2005 13:37:36 +0300
Message-Id: <1128595056.8561.32.camel@fuji.krosing.net>
Mime-Version: 1.0
X-Mailer: Evolution 2.0.4 (2.0.4-6) 
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.008 required=5 tests=[AWL=0.008]
X-Spam-Level: 
X-Archive-Number: 200510/258
X-Sequence-Number: 74117

On K, 2005-10-05 at 13:21 -0400, Ron Peacetree wrote:
> First I wanted to verify that pg's IO rates were inferior to The Competition.
> Now there's at least an indication that someone else has solved similar
> problems.  Existence proofs make some things easier ;-)
> 
> Is there any detailed programmer level architectual doc set for pg?  I know
> "the best doc is the code",

For postgres it is often "best doc's are in the code, in form of
comments."

-- 
Hannu Krosing <hannu@skype.net>


From pgsql-hackers-owner@postgresql.org  Thu Oct  6 07:44:09 2005
X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 53F3DDA372;
	Thu,  6 Oct 2005 07:44:07 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 92636-07; Thu,  6 Oct 2005 10:43:59 +0000 (GMT)
Received: from mail.skype.net (mail.skype.net [195.215.8.149])
	by svr1.postgresql.org (Postfix) with ESMTP id 91866DA36A;
	Thu,  6 Oct 2005 07:44:00 -0300 (ADT)
Received: from localhost (localhost.localdomain [127.0.0.1])
	by mail.skype.net (Postfix) with ESMTP id 3A1A24DE78;
	Thu,  6 Oct 2005 12:44:03 +0200 (CEST)
Received: from [192.168.0.41] (joltid-gw.joltid.org [195.50.194.24])
	by mail.skype.net (Postfix) with ESMTP id 540CE4DE74;
	Thu,  6 Oct 2005 12:44:02 +0200 (CEST)
Subject: Re: [PERFORM] A Better External Sort?
From: Hannu Krosing <hannu@skype.net>
To: Ron Peacetree <rjpeace@earthlink.net>
Cc: "Jonah H. Harris" <jonah.harris@gmail.com>,
	pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org
In-Reply-To: 
 <138872.1128556455518.JavaMail.root@elwamui-milano.atl.sa.earthlink.net>
References: 
 <138872.1128556455518.JavaMail.root@elwamui-milano.atl.sa.earthlink.net>
Content-Type: text/plain
Date: Thu, 06 Oct 2005 13:44:00 +0300
Message-Id: <1128595441.8561.36.camel@fuji.krosing.net>
Mime-Version: 1.0
X-Mailer: Evolution 2.0.4 (2.0.4-6) 
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.008 required=5 tests=[AWL=0.008]
X-Spam-Level: 
X-Archive-Number: 200510/259
X-Sequence-Number: 74118

On K, 2005-10-05 at 19:54 -0400, Ron Peacetree wrote:

> +I made the "from left field" suggestion that perhaps a pg native fs
> format would be worth consideration.  This is a major project, so
> the suggestion was to at least some extent tongue-in-cheek.

This idea is discussed about once a year on hackers. If you are more
interested in this, search the archives :)

-- 
Hannu Krosing <hannu@skype.net>


From pgsql-performance-owner@postgresql.org  Thu Oct  6 09:56:33 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 8EC8CD9D19
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu,  6 Oct 2005 09:56:32 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 04134-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu,  6 Oct 2005 12:56:26 +0000 (GMT)
Received: from mailhost.intellivid.com (mailhost.intellivid.com
 [64.32.200.11])
	by svr1.postgresql.org (Postfix) with ESMTP id 97E2FD6E83
	for <pgsql-performance@postgresql.org>;
	Thu,  6 Oct 2005 09:56:27 -0300 (ADT)
Received: from [192.168.2.68] (spectre.intellivid.com [192.168.2.68])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(Client did not present a certificate)
	by newmail.intellivid.com (Postfix) with ESMTP id 3AC1BF18107;
	Thu,  6 Oct 2005 08:56:31 -0400 (EDT)
Subject: Re: wal_buffers
From: Ian Westmacott <ianw@intellivid.com>
To: "Thomas F. O'Connell" <tfo@sitening.com>
Cc: pgsql-performance@postgresql.org
In-Reply-To: <C140F925-0D7D-41B4-873A-6C81C0D3D307@sitening.com>
References: <1128518624.15795.28.camel@spectre.intellivid.com>
	<C140F925-0D7D-41B4-873A-6C81C0D3D307@sitening.com>
Content-Type: text/plain
Organization: Intellivid Corp.
Message-Id: <1128603390.18319.16.camel@spectre.intellivid.com>
Mime-Version: 1.0
X-Mailer: Ximian Evolution 1.4.6 
Date: Thu, 06 Oct 2005 08:56:31 -0400
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0 required=5 tests=[none]
X-Spam-Level: 
X-Archive-Number: 200510/123
X-Sequence-Number: 14891

On Thu, 2005-10-06 at 02:39, Thomas F. O'Connell wrote:
> The WAL Configuration chapter (25.2) has a pretty good discussion of  
> how wal_buffers is used:
> 
> http://www.postgresql.org/docs/8.0/static/wal-configuration.html
> 
> You might also take a look at Josh Berkus' recent testing on this  
> setting:
> 
> http://www.powerpostgresql.com/

Thanks; I'd seen the documentation, but not Josh Berkus'
testing.

For my part, I don't have a large number of concurrent
connections, only one.  But it is doing large writes,
and XLogInsert is number 2 on the profile (with
LWLockAcquire and LWLockRelease close behind).  I suppose
that is expected, but lead by the documentation I wanted
to make sure XLogInsert always had some buffer space to
play with.

	--Ian



From pgsql-performance-owner@postgresql.org  Thu Oct  6 10:19:13 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 79AD7DA0E2
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu,  6 Oct 2005 10:17:54 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 57206-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu,  6 Oct 2005 13:17:49 +0000 (GMT)
Received: from tbmail.tradebot.com
	(Tradebot-Systems-1096753.cust-rtr.swbell.net [68.90.170.2])
	by svr1.postgresql.org (Postfix) with ESMTP id 86CDBD9D29
	for <pgsql-performance@postgresql.org>;
	Thu,  6 Oct 2005 10:17:50 -0300 (ADT)
Received: from 192.168.200.29 ([192.168.200.29]) by tbmail.tradebot.com
	([192.168.1.50]) with Microsoft Exchange Server HTTP-DAV ;
	Thu,  6 Oct 2005 13:17:54 +0000
Received: from krb06 by TBMAIL; 06 Oct 2005 08:17:54 -0500
Subject: functions and execution plan caching
From: Kelly Burkhart <kelly@tradebotsystems.com>
To: pgsql-performance@postgresql.org
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Date: Thu, 06 Oct 2005 08:17:54 -0500
Message-Id: <1128604674.5421.35.camel@krb06.tradebot.com>
Mime-Version: 1.0
X-Mailer: Evolution 2.2.1 
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.05 required=5 tests=[AWL=-0.000,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/124
X-Sequence-Number: 14892

I am working on a system which will be heavily dependent on functions
(some SQL, some PL/pgSQL).  I am worried about the backend caching query
execution plans for long running connections.

Given:
- Processes which are connected to the database for long periods of time
(transactions are always short).
- These processes will use some functions to query data.
- Lots of data is being inserted into tables that these functions query.
- Vacuums are done frequently.

Am I at risk of degrading performance after some time due to stale
execution plans?

Thanks,

-Kelly

From pgsql-performance-owner@postgresql.org  Thu Oct  6 10:23:50 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 4BFE4DA3A5
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu,  6 Oct 2005 10:23:49 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 95401-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu,  6 Oct 2005 13:23:40 +0000 (GMT)
Received: from mx1.surnet.cl (mx2.surnet.cl [216.155.73.181])
	by svr1.postgresql.org (Postfix) with ESMTP id 4CDB0DA394
	for <pgsql-performance@postgresql.org>;
	Thu,  6 Oct 2005 10:23:41 -0300 (ADT)
Received: from unknown (HELO cluster.surnet.cl) ([216.155.73.165])
	by mx1.surnet.cl with ESMTP; 06 Oct 2005 09:23:17 -0400
Received: from alvh.no-ip.org (200.85.218.5) by cluster.surnet.cl (7.0.043)
	(authenticated as alvherre@surnet.cl)
	id 433A601F001FA325; Thu, 6 Oct 2005 09:23:45 -0400
Received: by alvh.no-ip.org (Postfix, from userid 1000)
	id 7BBD6C2DC18; Thu,  6 Oct 2005 09:23:45 -0400 (CLT)
Date: Thu, 6 Oct 2005 09:23:45 -0400
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
To: Ian Westmacott <ianw@intellivid.com>
Cc: "Thomas F. O'Connell" <tfo@sitening.com>, pgsql-performance@postgresql.org
Subject: Re: wal_buffers
Message-ID: <20051006132345.GI5373@surnet.cl>
Mail-Followup-To: Ian Westmacott <ianw@intellivid.com>,
	"Thomas F. O'Connell" <tfo@sitening.com>,
	pgsql-performance@postgresql.org
References: <1128518624.15795.28.camel@spectre.intellivid.com>
	<C140F925-0D7D-41B4-873A-6C81C0D3D307@sitening.com>
	<1128603390.18319.16.camel@spectre.intellivid.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <1128603390.18319.16.camel@spectre.intellivid.com>
User-Agent: Mutt/1.5.10i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=1.999 required=5 tests=[AWL=-0.827,
	DNS_FROM_RFC_ABUSE=0.374, DNS_FROM_RFC_POST=1.376, FORGED_RCVD_HELO=0.05,
	RCVD_IN_NJABL_PROXY=1.026]
X-Spam-Level: *
X-Archive-Number: 200510/125
X-Sequence-Number: 14893

On Thu, Oct 06, 2005 at 08:56:31AM -0400, Ian Westmacott wrote:
> On Thu, 2005-10-06 at 02:39, Thomas F. O'Connell wrote:
> > The WAL Configuration chapter (25.2) has a pretty good discussion of  
> > how wal_buffers is used:
> > 
> > http://www.postgresql.org/docs/8.0/static/wal-configuration.html
> > 
> > You might also take a look at Josh Berkus' recent testing on this  
> > setting:
> > 
> > http://www.powerpostgresql.com/
> 
> Thanks; I'd seen the documentation, but not Josh Berkus'
> testing.
> 
> For my part, I don't have a large number of concurrent
> connections, only one.  But it is doing large writes,
> and XLogInsert is number 2 on the profile (with
> LWLockAcquire and LWLockRelease close behind).  I suppose
> that is expected, but lead by the documentation I wanted
> to make sure XLogInsert always had some buffer space to
> play with.

If you are using a single connection, you are wasting lots of cycles
just waiting for the disk to spin.  Were you to use multiple
connections, some transactions could be doing some useful work while
others are waiting for their transaction to be committed.

-- 
Alvaro Herrera                  http://www.amazon.com/gp/registry/5ZYLFMCVHXC
"I suspect most samba developers are already technically insane...
Of course, since many of them are Australians, you can't tell." (L. Torvalds)

From pgsql-hackers-owner@postgresql.org  Thu Oct  6 14:01:18 2005
X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 28A1EDA3DC;
	Thu,  6 Oct 2005 13:58:01 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 54149-07; Thu,  6 Oct 2005 16:57:55 +0000 (GMT)
Received: from svana.org (svana.org [203.20.62.76])
	by svr1.postgresql.org (Postfix) with ESMTP id 48F24DA3B1;
	Thu,  6 Oct 2005 13:57:54 -0300 (ADT)
Received: from kleptog by svana.org with local (Exim 3.35 #1 (Debian))
	id 1ENZ3j-0004kx-00; Fri, 07 Oct 2005 02:57:31 +1000
Date: Thu, 6 Oct 2005 18:57:30 +0200
From: Martijn van Oosterhout <kleptog@svana.org>
To: Ron Peacetree <rjpeace@earthlink.net>
Cc: "Jonah H. Harris" <jonah.harris@gmail.com>,
	pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org
Subject: Re: [PERFORM] A Better External Sort?
Message-ID: <20051006165725.GF10127@svana.org>
Reply-To: Martijn van Oosterhout <kleptog@svana.org>
References: 
 <138872.1128556455518.JavaMail.root@elwamui-milano.atl.sa.earthlink.net>
Mime-Version: 1.0
Content-Type: multipart/signed; micalg=pgp-sha1;
	protocol="application/pgp-signature"; boundary="gdTfX7fkYsEEjebm"
Content-Disposition: inline
In-Reply-To: 
 <138872.1128556455518.JavaMail.root@elwamui-milano.atl.sa.earthlink.net>
User-Agent: Mutt/1.3.28i
X-PGP-Key-ID: Length=1024; ID=0x0DC67BE6
X-PGP-Key-Fingerprint: 295F A899 A81A 156D B522  48A7 6394 F08A 0DC6 7BE6
X-PGP-Key-URL: <http://svana.org/kleptog/0DC67BE6.pgp.asc>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.008 required=5 tests=[AWL=0.008]
X-Spam-Level: 
X-Archive-Number: 200510/287
X-Sequence-Number: 74146


--gdTfX7fkYsEEjebm
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Wed, Oct 05, 2005 at 07:54:15PM -0400, Ron Peacetree wrote:
> I asked some questions about physical layout and format translation
> overhead being possibly suboptimal that seemed to be agreed to, but
> specifics as to where we are taking the hit don't seem to have been
> made explicit yet.

This hit is easy to see and terribly hard to do anything about at the
same time. Any single row in a table stores its values but the offsets
arn't constant. If a field is NULL, it is skipped. If a field is
variable length, you have to look at the length before you can jump
over to the next value.

If you have no NULLs and no variable length fields, then you can
optimise access. This is already done and it's hard to see how you
could improve it further. To cut costs, many places use
heap_deform_tuple and similar routines so that the costs are reduced,
but they're still there.

Upping the data transfer rate from disk is a worthy goal, just some
people beleive it is of lower priority than improving CPU usage.

> We were also told that evidently we are CPU bound far before one
> would naively expect to be based on the performance specifications
> of the components involved.

As someone pointed out, calls to the C library are not counted
seperately, making it harder to see if we're overcalling some of them.
Pinpointing the performance bottleneck is hard work.

> Now I've asked for the quickest path to detailed understanding of the
> pg IO subsystem.  The goal being to get more up to speed on its
> coding details.  Certainly not to annoy you or anyone else.

Well, the work is all in storage/smgr and storage/file. It's not
terribly complicated, it just sometimes takes a while to understand
*why* it is done this way.

Indeed, one of the things on my list is to remove all the lseeks in
favour of pread. Halving the number of kernel calls has got to be worth
something right? Portability is an issue ofcourse...

But it's been a productive thread, absolutly. Progress has been made...

Have a nice day,
--=20
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

--gdTfX7fkYsEEjebm
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQFDRVd0IB7bNG8LQkwRApCLAJ0ezBpzEpD8ubpKGjEjhhcPq5Oo6gCdGtZc
q22gs+81mm52zQpPhUScJHA=
=EN7M
-----END PGP SIGNATURE-----

--gdTfX7fkYsEEjebm--

From pgsql-performance-owner@postgresql.org  Thu Oct  6 15:50:16 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 066FED9D29
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu,  6 Oct 2005 15:50:14 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 61325-03
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu,  6 Oct 2005 18:50:07 +0000 (GMT)
Received: from mail1.catalyst.net.nz (godel.catalyst.net.nz [202.78.240.40])
	by svr1.postgresql.org (Postfix) with ESMTP id 08221D99E3
	for <pgsql-performance@postgresql.org>;
	Thu,  6 Oct 2005 15:50:04 -0300 (ADT)
Received: from leibniz.catalyst.net.nz ([202.78.240.7]
	helo=lamb.mcmillan.net.nz) by mail1.catalyst.net.nz with esmtpsa
	(TLS-1.0:DHE_RSA_AES_256_CBC_SHA:32) (Exim 4.50)
	id 1ENaod-0005Mv-2V; Fri, 07 Oct 2005 07:50:03 +1300
Received: from lamb.mcmillan.net.nz (lamb.mcmillan.net.nz [127.0.0.1])
	by lamb.mcmillan.net.nz (Postfix) with ESMTP id 222917A00F7;
	Fri,  7 Oct 2005 07:50:02 +1300 (NZDT)
Subject: Re: index on custom function; explain
From: Andrew McMillan <andrew@catalyst.net.nz>
To: Jan Aerts <jan.aerts@gmail.com>
Cc: pgsql-performance@postgresql.org
In-Reply-To: <1128420628.326795.158780@g47g2000cwa.googlegroups.com>
References: <1128352451.312090.37640@g44g2000cwa.googlegroups.com>
	<1128420628.326795.158780@g47g2000cwa.googlegroups.com>
Content-Type: multipart/signed; micalg=pgp-sha1;
	protocol="application/pgp-signature";
	boundary="=-lEDfzr2pG8VI9y7+7Tey"
Date: Fri, 07 Oct 2005 07:50:01 +1300
Message-Id: <1128624601.17294.86.camel@lamb.mcmillan.net.nz>
Mime-Version: 1.0
X-Mailer: Evolution 2.2.3 
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.05 required=5 tests=[FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/126
X-Sequence-Number: 14894


--=-lEDfzr2pG8VI9y7+7Tey
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable

On Tue, 2005-10-04 at 03:10 -0700, Jan Aerts wrote:
> Some additional thoughts: what appears to take the most time (i.e.
> account for the highest cost in the explain), is _not_ running the
> function itself (cost=3D0.00..0.01), but comparing the result from that
> function with the name1 column in the mappings table
> (cost=3D0.00..35935.05). Am I right? (See EXPLAIN in previous post.) If
> so: that's pretty strange, because the name1-column in the mappings
> table is indexed...

35935.05 is for the loop, 0.01 is for the operation within the loop.

What version of PostgreSQL is this?  Some old versions were not good at
handling the IN ( ... ) clause.

Also, PostgreSQL doesn't always do a wonderful job of considering the
activities of a function into the design of the query plans.  Sometimes
this can be a blessing, but not in this case.

Cheers,
					Andrew.

-------------------------------------------------------------------------
Andrew @ Catalyst .Net .NZ  Ltd,  PO Box 11-053, Manners St,  Wellington
WEB: http://catalyst.net.nz/            PHYS: Level 2, 150-154 Willis St
DDI: +64(4)803-2201      MOB: +64(272)DEBIAN      OFFICE: +64(4)499-2267
It is truth which you cannot contradict; you can without any difficulty
                      contradict Socrates. - Plato

-------------------------------------------------------------------------


--=-lEDfzr2pG8VI9y7+7Tey
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQBDRXHZjJA0f48GgBIRAiALAKCdMFuYfQ7hR0YbJNkH9gJ9KWyG+gCfbB4v
kPiwjm5zqGlu2jiA+pXV3f4=
=jIXL
-----END PGP SIGNATURE-----

--=-lEDfzr2pG8VI9y7+7Tey--


From pgsql-performance-owner@postgresql.org  Thu Oct  6 16:53:37 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id DB8D7D8833
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu,  6 Oct 2005 16:46:19 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 55714-07
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu,  6 Oct 2005 19:46:12 +0000 (GMT)
Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158])
	by svr1.postgresql.org (Postfix) with ESMTP id AEE69DA415
	for <pgsql-performance@postgresql.org>;
	Thu,  6 Oct 2005 16:46:09 -0300 (ADT)
Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1])
	by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id j96Jk8gg076626
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);
	Thu, 6 Oct 2005 13:46:10 -0600 (MDT)
	(envelope-from mfuhr@winnie.fuhr.org)
Received: from winnie.fuhr.org (localhost [127.0.0.1])
	by winnie.fuhr.org (8.13.3/8.13.3) with ESMTP id j96Jk7ZW035332;
	Thu, 6 Oct 2005 13:46:07 -0600 (MDT)
	(envelope-from mfuhr@winnie.fuhr.org)
Received: (from mfuhr@localhost)
	by winnie.fuhr.org (8.13.3/8.13.3/Submit) id j96Jk60I035331;
	Thu, 6 Oct 2005 13:46:06 -0600 (MDT) (envelope-from mfuhr)
Date: Thu, 6 Oct 2005 13:46:06 -0600
From: Michael Fuhr <mike@fuhr.org>
To: Kelly Burkhart <kelly@tradebotsystems.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: functions and execution plan caching
Message-ID: <20051006194606.GA17939@winnie.fuhr.org>
References: <1128604674.5421.35.camel@krb06.tradebot.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <1128604674.5421.35.camel@krb06.tradebot.com>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/127
X-Sequence-Number: 14895

On Thu, Oct 06, 2005 at 08:17:54AM -0500, Kelly Burkhart wrote:
> Given:
> - Processes which are connected to the database for long periods of time
> (transactions are always short).
> - These processes will use some functions to query data.
> - Lots of data is being inserted into tables that these functions query.
> - Vacuums are done frequently.
> 
> Am I at risk of degrading performance after some time due to stale
> execution plans?

Yes, because plans are chosen based on the statistics that were
current when the function was first called.  For example, if a
sequential scan made sense when you first called the function, then
subsequent calls will also use a sequential scan.  You can see this
for yourself with a simple test: create a table, populate it with
a handful of records, and call a function that issues a query that
can (but won't necessarily) use an index.  Then add a lot of records
to the table and call the function again.  You'll probably notice
that the function runs slower than the same query run from outside
the function, and that the function runs fast if you recreate it
or call it in a new session.

If you set debug_print_plan to on and client_min_messages to debug1,
then you'll see the plan that the function chose (but only on the
first call to the function).  If you have statistics enabled, then
you can query pg_stat_user_tables and pg_stat_user_indexes to see
whether subsequent calls use sequential or index scans (this should
be done when nobody else is querying the table so the statistics
represent only what you did).

You can avoid cached plans by using EXECUTE.  You'll have to run
tests to see whether the potential gain is worth the overhead.

-- 
Michael Fuhr

From pgsql-performance-owner@postgresql.org  Thu Oct  6 17:09:46 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 33C02D9743
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu,  6 Oct 2005 16:57:49 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 03629-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu,  6 Oct 2005 19:57:45 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id E3C2EDA41E
	for <pgsql-performance@postgresql.org>;
	Thu,  6 Oct 2005 16:57:45 -0300 (ADT)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j96Jvc0d025131;
	Thu, 6 Oct 2005 15:57:38 -0400 (EDT)
To: Martijn van Oosterhout <kleptog@svana.org>
Cc: Ron Peacetree <rjpeace@earthlink.net>,
	"Jonah H. Harris" <jonah.harris@gmail.com>,
	pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org
Subject: Re: [HACKERS] A Better External Sort? 
In-reply-to: <20051006165725.GF10127@svana.org> 
References: 
 <138872.1128556455518.JavaMail.root@elwamui-milano.atl.sa.earthlink.net>
	<20051006165725.GF10127@svana.org>
Comments: In-reply-to Martijn van Oosterhout <kleptog@svana.org>
	message dated "Thu, 06 Oct 2005 18:57:30 +0200"
Date: Thu, 06 Oct 2005 15:57:38 -0400
Message-ID: <25130.1128628658@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/128
X-Sequence-Number: 14896

Martijn van Oosterhout <kleptog@svana.org> writes:
> Indeed, one of the things on my list is to remove all the lseeks in
> favour of pread. Halving the number of kernel calls has got to be worth
> something right? Portability is an issue ofcourse...

Being sure that it's not a pessimization is another issue.  I note that
glibc will emulate these functions if the kernel doesn't have them;
which means you could be replacing one kernel call with three.

And I don't think autoconf has any way to determine whether a libc
function represents a native kernel call or not ...

			regards, tom lane

From pgsql-hackers-owner@postgresql.org  Thu Oct  6 18:26:50 2005
X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 4529ADA407;
	Thu,  6 Oct 2005 17:14:58 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 46406-07; Thu,  6 Oct 2005 20:14:55 +0000 (GMT)
Received: from svana.org (svana.org [203.20.62.76])
	by svr1.postgresql.org (Postfix) with ESMTP id 03C7DDA41E;
	Thu,  6 Oct 2005 17:14:55 -0300 (ADT)
Received: from kleptog by svana.org with local (Exim 3.35 #1 (Debian))
	id 1ENc8d-0005YC-00; Fri, 07 Oct 2005 06:14:47 +1000
Date: Thu, 6 Oct 2005 22:14:47 +0200
From: Martijn van Oosterhout <kleptog@svana.org>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Ron Peacetree <rjpeace@earthlink.net>,
	"Jonah H. Harris" <jonah.harris@gmail.com>,
	pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org
Subject: Re: [PERFORM] A Better External Sort?
Message-ID: <20051006201447.GG10127@svana.org>
Reply-To: Martijn van Oosterhout <kleptog@svana.org>
References: 
 <138872.1128556455518.JavaMail.root@elwamui-milano.atl.sa.earthlink.net>
	<20051006165725.GF10127@svana.org> <25130.1128628658@sss.pgh.pa.us>
Mime-Version: 1.0
Content-Type: multipart/signed; micalg=pgp-sha1;
	protocol="application/pgp-signature"; boundary="gm5TwAJMO0F2iVRz"
Content-Disposition: inline
In-Reply-To: <25130.1128628658@sss.pgh.pa.us>
User-Agent: Mutt/1.3.28i
X-PGP-Key-ID: Length=1024; ID=0x0DC67BE6
X-PGP-Key-Fingerprint: 295F A899 A81A 156D B522  48A7 6394 F08A 0DC6 7BE6
X-PGP-Key-URL: <http://svana.org/kleptog/0DC67BE6.pgp.asc>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.008 required=5 tests=[AWL=0.008]
X-Spam-Level: 
X-Archive-Number: 200510/300
X-Sequence-Number: 74159


--gm5TwAJMO0F2iVRz
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Thu, Oct 06, 2005 at 03:57:38PM -0400, Tom Lane wrote:
> Martijn van Oosterhout <kleptog@svana.org> writes:
> > Indeed, one of the things on my list is to remove all the lseeks in
> > favour of pread. Halving the number of kernel calls has got to be worth
> > something right? Portability is an issue ofcourse...
>=20
> Being sure that it's not a pessimization is another issue.  I note that
> glibc will emulate these functions if the kernel doesn't have them;
> which means you could be replacing one kernel call with three.

=46rom the linux pread manpage:

HISTORY
       The pread and pwrite system calls were added to Linux in version
       2.1.60; the entries in the i386 system call table were added in
       2.1.69.  The libc support (including emulation on older kernels
       without the system calls) was added in glibc 2.1.

Are we awfully worried about people still using 2.0 kernels? And it
would replace two calls with three in the worst case, we currently
lseek before every read.

I don't know about other OSes.
--=20
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

--gm5TwAJMO0F2iVRz
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQFDRYW2IB7bNG8LQkwRAhq3AJ9nnPQg2JiTBU16YQe00F6lVDeNsQCggoku
kFSCCpIm/4BSwiZCmAHkBNI=
=xrHy
-----END PGP SIGNATURE-----

--gm5TwAJMO0F2iVRz--

From pgsql-performance-owner@postgresql.org  Thu Oct  6 18:23:57 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 85672DA40B;
	Thu,  6 Oct 2005 17:17:26 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 39355-09; Thu,  6 Oct 2005 20:17:20 +0000 (GMT)
Received: from mx1.surnet.cl (mx1.surnet.cl [216.155.73.180])
	by svr1.postgresql.org (Postfix) with ESMTP id 21CB2DA430;
	Thu,  6 Oct 2005 17:17:20 -0300 (ADT)
Received: from unknown (HELO cluster.surnet.cl) ([216.155.73.165])
	by mx1.surnet.cl with ESMTP; 06 Oct 2005 16:18:02 -0400
Received: from alvh.no-ip.org (216.155.86.150) by cluster.surnet.cl (7.0.043)
	(authenticated as alvherre@surnet.cl)
	id 433A601F0020AD5A; Thu, 6 Oct 2005 16:17:21 -0400
Received: by alvh.no-ip.org (Postfix, from userid 1000)
	id BEB74C2DC18; Thu,  6 Oct 2005 16:17:21 -0400 (CLT)
Date: Thu, 6 Oct 2005 16:17:21 -0400
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Martijn van Oosterhout <kleptog@svana.org>,
	Ron Peacetree <rjpeace@earthlink.net>,
	"Jonah H. Harris" <jonah.harris@gmail.com>,
	pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org
Subject: Re: [HACKERS] A Better External Sort?
Message-ID: <20051006201721.GB6513@surnet.cl>
Mail-Followup-To: Tom Lane <tgl@sss.pgh.pa.us>,
	Martijn van Oosterhout <kleptog@svana.org>,
	Ron Peacetree <rjpeace@earthlink.net>,
	"Jonah H. Harris" <jonah.harris@gmail.com>,
	pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org
References: 
 <138872.1128556455518.JavaMail.root@elwamui-milano.atl.sa.earthlink.net>
	<20051006165725.GF10127@svana.org> <25130.1128628658@sss.pgh.pa.us>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
In-Reply-To: <25130.1128628658@sss.pgh.pa.us>
User-Agent: Mutt/1.5.10i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=1.833 required=5 tests=[AWL=0.083,
	DNS_FROM_RFC_ABUSE=0.374, DNS_FROM_RFC_POST=1.376]
X-Spam-Level: *
X-Archive-Number: 200510/130
X-Sequence-Number: 14898

On Thu, Oct 06, 2005 at 03:57:38PM -0400, Tom Lane wrote:
> Martijn van Oosterhout <kleptog@svana.org> writes:
> > Indeed, one of the things on my list is to remove all the lseeks in
> > favour of pread. Halving the number of kernel calls has got to be worth
> > something right? Portability is an issue ofcourse...
> 
> Being sure that it's not a pessimization is another issue.  I note that
> glibc will emulate these functions if the kernel doesn't have them;
> which means you could be replacing one kernel call with three.
> 
> And I don't think autoconf has any way to determine whether a libc
> function represents a native kernel call or not ...

The problem kernels would be Linux 2.0, which I very much doubt is going
to be present in to-be-deployed database servers.

Unless someone runs glibc on top of some other kernel, I guess.  Is this
a common scenario?  I've never seen it.

-- 
Alvaro Herrera                  http://www.amazon.com/gp/registry/DXLWNGRJD34
Oh, oh, las chicas galacianas, lo har�n por las perlas,
�Y las de Arrakis por el agua! Pero si buscas damas
Que se consuman como llamas, �Prueba una hija de Caladan! (Gurney Halleck)

From pgsql-performance-owner@postgresql.org  Thu Oct  6 18:14:29 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 92854DA430
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu,  6 Oct 2005 17:25:26 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 70073-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu,  6 Oct 2005 20:25:23 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id 4DC92DA418
	for <pgsql-performance@postgresql.org>;
	Thu,  6 Oct 2005 17:25:24 -0300 (ADT)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j96KPB9e025401;
	Thu, 6 Oct 2005 16:25:11 -0400 (EDT)
To: Martijn van Oosterhout <kleptog@svana.org>
Cc: Ron Peacetree <rjpeace@earthlink.net>,
	"Jonah H. Harris" <jonah.harris@gmail.com>,
	pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org
Subject: Re: [HACKERS] A Better External Sort? 
In-reply-to: <20051006201447.GG10127@svana.org> 
References: 
 <138872.1128556455518.JavaMail.root@elwamui-milano.atl.sa.earthlink.net>
	<20051006165725.GF10127@svana.org> <25130.1128628658@sss.pgh.pa.us>
	<20051006201447.GG10127@svana.org>
Comments: In-reply-to Martijn van Oosterhout <kleptog@svana.org>
	message dated "Thu, 06 Oct 2005 22:14:47 +0200"
Date: Thu, 06 Oct 2005 16:25:11 -0400
Message-ID: <25400.1128630311@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/129
X-Sequence-Number: 14897

Martijn van Oosterhout <kleptog@svana.org> writes:
> Are we awfully worried about people still using 2.0 kernels? And it
> would replace two calls with three in the worst case, we currently
> lseek before every read.

That's utterly false.

			regards, tom lane

From pgsql-performance-owner@postgresql.org  Thu Oct  6 18:46:51 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 449BADA38F
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu,  6 Oct 2005 18:26:11 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 93112-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu,  6 Oct 2005 21:26:06 +0000 (GMT)
Received: from TWMAIL.ESNCC.COM (static-66-173-159-28.t1.cavtel.net
	[66.173.159.28])
	by svr1.postgresql.org (Postfix) with ESMTP id E8DD2DA068
	for <pgsql-performance@postgresql.org>;
	Thu,  6 Oct 2005 18:26:06 -0300 (ADT)
Received: from spawar2i8uvlb9 ([150.125.117.63]) by TWMAIL.ESNCC.COM with
	Microsoft SMTPSVC(5.0.2195.6713); Thu, 6 Oct 2005 17:26:22 -0400
From: "Lane Van Ingen" <lvaningen@esncc.com>
To: <pgsql-performance@postgresql.org>
Subject: Need Some Suggestions
Date: Thu, 6 Oct 2005 17:29:42 -0400
Message-ID: <EKEMKEFLOMKDDLIALABIMEHACDAA.lvaningen@esncc.com>
MIME-Version: 1.0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0)
Importance: Normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.181
X-OriginalArrivalTime: 06 Oct 2005 21:26:22.0476 (UTC)
	FILETIME=[995034C0:01C5CABC]
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.057 required=5 tests=[AWL=0.007,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/131
X-Sequence-Number: 14899

I have an application that is prone to sudden, unscheduled high bursts of
activity, and
I am finding that the application design permits me to detect the activity
bursts within
an existing function. The bursts only affect 3 tables, but degradation
becomes apparent
after 2,000 updates, and significant after 8,000 updates.

I already know that a plain vacuum (without full, analyze, or free options)
solves my
problem. Since vacuum is classified in the documentation as an SQL command,
I tried to
call it using a trigger function on one the tables (they all have roughly
the same insert
/ update rate). However, I just found out that vacuum cannot be called by a
function.
Vacuums done by a scheduler at 3AM in the morning are adequate to handle my
non-peak
needs otherwise.

autovacuum sounds like it would do the trick, but I am on a WINDOWS 2003
environment, but
I have Googled up messages that it still has various problems (in Windows)
which won't be
resolved until 8.1 is out. But I have a problem NOW, and the application is
deployed
around the world.

QUESTION:
  Is there anyway anyone knows of to permit me to execute an operating
system program
(even vacuumdb) or possibly to add a C function to the library which would
allow me to
do this (I am not a C programmer, but have access to some persons who are)?

Very important to me for performance reasons.

Does anybody have some suggestions on the best path for me to take?



From pgsql-hackers-owner@postgresql.org  Thu Oct  6 18:40:44 2005
X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 581B9DA477;
	Thu,  6 Oct 2005 18:40:35 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 59436-08; Thu,  6 Oct 2005 21:40:27 +0000 (GMT)
Received: from svana.org (svana.org [203.20.62.76])
	by svr1.postgresql.org (Postfix) with ESMTP id 698E5DA47B;
	Thu,  6 Oct 2005 18:40:27 -0300 (ADT)
Received: from kleptog by svana.org with local (Exim 3.35 #1 (Debian))
	id 1ENdTN-0006y9-00; Fri, 07 Oct 2005 07:40:17 +1000
Date: Thu, 6 Oct 2005 23:40:17 +0200
From: Martijn van Oosterhout <kleptog@svana.org>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Ron Peacetree <rjpeace@earthlink.net>,
	"Jonah H. Harris" <jonah.harris@gmail.com>,
	pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org
Subject: Re: [PERFORM] A Better External Sort?
Message-ID: <20051006214017.GH10127@svana.org>
Reply-To: Martijn van Oosterhout <kleptog@svana.org>
References: 
 <138872.1128556455518.JavaMail.root@elwamui-milano.atl.sa.earthlink.net>
	<20051006165725.GF10127@svana.org> <25130.1128628658@sss.pgh.pa.us>
	<20051006201447.GG10127@svana.org> <25400.1128630311@sss.pgh.pa.us>
Mime-Version: 1.0
Content-Type: multipart/signed; micalg=pgp-sha1;
	protocol="application/pgp-signature"; boundary="ik0NlRzMGhMnxrMX"
Content-Disposition: inline
In-Reply-To: <25400.1128630311@sss.pgh.pa.us>
User-Agent: Mutt/1.3.28i
X-PGP-Key-ID: Length=1024; ID=0x0DC67BE6
X-PGP-Key-Fingerprint: 295F A899 A81A 156D B522  48A7 6394 F08A 0DC6 7BE6
X-PGP-Key-URL: <http://svana.org/kleptog/0DC67BE6.pgp.asc>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.008 required=5 tests=[AWL=0.008]
X-Spam-Level: 
X-Archive-Number: 200510/301
X-Sequence-Number: 74160


--ik0NlRzMGhMnxrMX
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Thu, Oct 06, 2005 at 04:25:11PM -0400, Tom Lane wrote:
> Martijn van Oosterhout <kleptog@svana.org> writes:
> > Are we awfully worried about people still using 2.0 kernels? And it
> > would replace two calls with three in the worst case, we currently
> > lseek before every read.
>=20
> That's utterly false.

Oops, you're right. I usually strace during a vacuum or a large query
and my screen fills up with:

lseek()
read()
lseek()
read()
=2E..

So didn't wonder if the straight sequential read was optimised. Still,
I think pread() would be a worthwhile improvement, at least for Linux.

--=20
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

--ik0NlRzMGhMnxrMX
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQFDRZnAIB7bNG8LQkwRAqq2AJ0QYtDrUJT31ViotfhMiVm0Spj1eACeJUGr
ZxQKA/rJTo40yD2rpUd9CU0=
=i1Ai
-----END PGP SIGNATURE-----

--ik0NlRzMGhMnxrMX--

From pgsql-performance-owner@postgresql.org  Thu Oct  6 20:55:33 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id A9CA9DA418
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu,  6 Oct 2005 20:55:31 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 68504-09
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu,  6 Oct 2005 23:55:24 +0000 (GMT)
Received: from smtp105.sbc.mail.mud.yahoo.com (smtp105.sbc.mail.mud.yahoo.com
	[68.142.198.204])
	by svr1.postgresql.org (Postfix) with SMTP id B1B2ED8833
	for <pgsql-performance@postgresql.org>;
	Thu,  6 Oct 2005 20:55:24 -0300 (ADT)
Received: (qmail 41197 invoked from network); 6 Oct 2005 23:55:28 -0000
Received: from unknown (HELO discord.dyndns.org)
	(jeffroe996@sbcglobal.net@71.133.109.188 with plain)
	by smtp105.sbc.mail.mud.yahoo.com with SMTP; 6 Oct 2005 23:55:27 -0000
Received: from localhost (localhost.localdomain [127.0.0.1])
	by discord.dyndns.org (8.13.4/8.13.4) with ESMTP id j96NtREH024871
	for <pgsql-performance@postgresql.org>; Thu, 6 Oct 2005 16:55:27 -0700
Date: Thu, 6 Oct 2005 16:55:27 -0700 (PDT)
From: Jeff Frost <jeff@frostconsultingllc.com>
X-X-Sender: jeff@discord.dyndns.org
To: pgsql-performance@postgresql.org
Subject: Status of Opteron vs Xeon
Message-ID: <Pine.LNX.4.64.0510061654080.21147@discord.dyndns.org>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.04 required=5 tests=[AWL=-0.010,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/132
X-Sequence-Number: 14900

What's the current status of how much faster the Opteron is compared to the 
Xeons?  I know the Opterons used to be close to 2x faster, but is that still 
the case?  I understand much work has been done to reduce the contect 
switching storms on the Xeon architecture, is this correct?

-- 
Jeff Frost, Owner 	<jeff@frostconsultingllc.com>
Frost Consulting, LLC 	http://www.frostconsultingllc.com/
Phone: 650-780-7908	FAX: 650-649-1954

From pgsql-performance-owner@postgresql.org  Fri Oct  7 04:55:47 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 0976CDA494
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri,  7 Oct 2005 04:55:24 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 66583-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri,  7 Oct 2005 07:55:21 +0000 (GMT)
Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75])
	by svr1.postgresql.org (Postfix) with ESMTP id 3F8C4DA44B
	for <pgsql-performance@postgresql.org>;
	Fri,  7 Oct 2005 04:55:21 -0300 (ADT)
Received: from mainbox.archonet.com
	(84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99])
	by smtp.metronet.co.uk (MetroNet Mail) with ESMTP
	id 6A3F6418431; Fri,  7 Oct 2005 08:55:18 +0100 (BST)
Received: from localhost (localhost.localdomain [127.0.0.1])
	by mainbox.archonet.com (Postfix) with ESMTP id 6D1F015EDA;
	Fri,  7 Oct 2005 08:52:49 +0100 (BST)
Received: from mainbox.archonet.com ([127.0.0.1])
	by localhost (mainbox [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 09871-05; Fri, 7 Oct 2005 08:52:47 +0100 (BST)
Received: from [192.168.1.17] (client17.office.archonet.com [192.168.1.17])
	by mainbox.archonet.com (Postfix) with ESMTP id 03F0015ED5;
	Fri,  7 Oct 2005 08:52:47 +0100 (BST)
Message-ID: <4346294E.7080803@archonet.com>
Date: Fri, 07 Oct 2005 08:52:46 +0100
From: Richard Huxton <dev@archonet.com>
User-Agent: Mozilla Thunderbird 1.0.6 (X11/20050912)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: Lane Van Ingen <lvaningen@esncc.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Need Some Suggestions
References: <EKEMKEFLOMKDDLIALABIMEHACDAA.lvaningen@esncc.com>
In-Reply-To: <EKEMKEFLOMKDDLIALABIMEHACDAA.lvaningen@esncc.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.058 required=5 tests=[AWL=0.008,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/133
X-Sequence-Number: 14901

Lane Van Ingen wrote:
> I have an application that is prone to sudden, unscheduled high bursts of
> activity, and
> I am finding that the application design permits me to detect the activity
> bursts within
> an existing function. The bursts only affect 3 tables, but degradation
> becomes apparent
> after 2,000 updates, and significant after 8,000 updates.

Hmm - assuming your free-space settings are large enough, it might be 
adequate to just run a vacuum on the 3 tables every 5 minutes or so. It 
sounds like these are quite small tables with a lot of activity, so if 
there's not much for vacuum to do it won't place too much load on your 
system.

--
   Richard Huxton
   Archonet Ltd

From pgsql-performance-owner@postgresql.org  Fri Oct  7 06:24:19 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 2894CDA48E
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri,  7 Oct 2005 06:24:18 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 86454-07
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri,  7 Oct 2005 09:24:13 +0000 (GMT)
Received: from ns2.dialtelecom.sk (ns2.dialtelecom.sk [217.67.16.3])
	by svr1.postgresql.org (Postfix) with ESMTP id E6289D9001
	for <pgsql-performance@postgresql.org>;
	Fri,  7 Oct 2005 06:24:11 -0300 (ADT)
Received: (qmail 2406 invoked by uid 0); 7 Oct 2005 09:23:48 -0000
Received: from unknown (HELO omikron.sk) (217.67.24.100)
	by ns2.dialtelecom.sk with SMTP; 7 Oct 2005 09:23:45 -0000
Received: (qmail 15740 invoked from network); 7 Oct 2005 09:23:45 -0000
Received: from unknown (HELO stratos) (158.195.31.19)
	by 0 with SMTP; 7 Oct 2005 09:23:45 -0000
Message-ID: <935801c5cb20$dcf93a00$131fc39e@stratos>
From: "Cestmir Hybl" <cestmirl@freeside.sk>
To: <pgsql-performance@postgresql.org>
Subject: count(*) using index scan in "query often, update rarely" environment
Date: Fri, 7 Oct 2005 11:24:05 +0200
Organization: NUSTEP s.r.o.
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="----=_NextPart_000_9355_01C5CB31.A0496DD0"
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 6.00.2900.2527
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.062 required=5 tests=[AWL=-0.034, HTML_50_60=0.095,
	HTML_MESSAGE=0.001]
X-Spam-Level: 
X-Archive-Number: 200510/134
X-Sequence-Number: 14902

This is a multi-part message in MIME format.

------=_NextPart_000_9355_01C5CB31.A0496DD0
Content-Type: text/plain;
	charset="iso-8859-2"
Content-Transfer-Encoding: quoted-printable

Hello all

First of all, I do understand why pgsql with it's MVCC design has to =
examine tuples to evaluate "count(*)" and "count(*) where (...)" queries =
in environment with heavy concurrent updates.

This kind of usage IMHO isn't the average one. There are many =
circumstances with rather "query often, update rarely" character.

Isn't it possible (and reasonable) for these environments to keep track =
of whether there is a transaction in progress with update to given table =
and if not, use an index scan (count(*) where) or cached value =
(count(*)) to perform this kind of query?

(sorry for disturbing if this was already discussed)

Regards,

Cestmir Hybl
------=_NextPart_000_9355_01C5CB31.A0496DD0
Content-Type: text/html;
	charset="iso-8859-2"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-2">
<META content=3D"MSHTML 6.00.2900.2722" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hello all</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>First of all, I do understand why pgsql =
with it's=20
MVCC design has to examine tuples to evaluate "count(*)"&nbsp;and =
"count(*)=20
where (...)" queries in environment with heavy concurrent =
updates.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>This kind of usage IMHO isn't the =
average one.=20
There are many circumstances with rather "query often, update=20
rarely"&nbsp;character.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Isn't it possible (and reasonable) for =
these=20
environments to keep track of whether there is a transaction in progress =
with=20
update to given table and if not, use an index scan (count(*) where) or =
cached=20
value (count(*)) to perform this kind of query?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>(sorry for disturbing if this was =
already=20
discussed)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Regards,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Cestmir Hybl</FONT></DIV></BODY></HTML>

------=_NextPart_000_9355_01C5CB31.A0496DD0--


From pgsql-performance-owner@postgresql.org  Fri Oct  7 06:54:29 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id C012EDA53B
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri,  7 Oct 2005 06:54:28 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 45227-10
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri,  7 Oct 2005 09:54:20 +0000 (GMT)
Received: from qproxy.gmail.com (qproxy.gmail.com [72.14.204.202])
	by svr1.postgresql.org (Postfix) with ESMTP id B4559DA521
	for <pgsql-performance@postgresql.org>;
	Fri,  7 Oct 2005 06:54:20 -0300 (ADT)
Received: by qproxy.gmail.com with SMTP id z1so493320qbc
	for <pgsql-performance@postgresql.org>;
	Fri, 07 Oct 2005 02:54:23 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:references;
	b=f9Ud/9vObec/4Xia9lDNm6b0ruhD6PZs7JD/zlvLtaR5QEOuVC0FL6lPBt7fAfYWtxu0Wzl6QjZCQpqhzoBP0hYmSLDn0XJW+5rAi7u7bXG6aicnh7MXwXiBy4JiFAjSbBLgnE4J0+pSkNCM6Uz+HrcFpYAXYkcf6c5ljaQZEfE=
Received: by 10.64.209.15 with SMTP id h15mr241562qbg;
	Fri, 07 Oct 2005 02:54:23 -0700 (PDT)
Received: by 10.64.195.4 with HTTP; Fri, 7 Oct 2005 02:54:23 -0700 (PDT)
Message-ID: <9e4684ce0510070254v67e08bcfhb725715803a5de25@mail.gmail.com>
Date: Fri, 7 Oct 2005 11:54:23 +0200
From: hubert depesz lubaczewski <depesz@gmail.com>
Reply-To: hubert depesz lubaczewski <depesz@gmail.com>
To: Cestmir Hybl <cestmirl@freeside.sk>
Subject: Re: count(*) using index scan in "query often,
	update rarely" environment
Cc: pgsql-performance@postgresql.org
In-Reply-To: <935801c5cb20$dcf93a00$131fc39e@stratos>
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="----=_Part_10913_26676785.1128678863681"
References: <935801c5cb20$dcf93a00$131fc39e@stratos>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=1.144 required=5 tests=[AWL=1.033, HTML_40_50=0.086,
	HTML_MESSAGE=0.001, RCVD_BY_IP=0.024]
X-Spam-Level: *
X-Archive-Number: 200510/135
X-Sequence-Number: 14903

------=_Part_10913_26676785.1128678863681
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

On 10/7/05, Cestmir Hybl <cestmirl@freeside.sk> wrote:
>
> Isn't it possible (and reasonable) for these environments to keep track o=
f
> whether there is a transaction in progress with update to given table and=
 if
> not, use an index scan (count(*) where) or cached value (count(*)) to
> perform this kind of query?
>

if i understand your problem correctly, then simple usage of triggers will
do the job just fine.

hubert

------=_Part_10913_26676785.1128678863681
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

On 10/7/05, <b class=3D"gmail_sendername">Cestmir Hybl</b> &lt;<a href=3D"m=
ailto:cestmirl@freeside.sk">cestmirl@freeside.sk</a>&gt; wrote:<div><span c=
lass=3D"gmail_quote"></span><blockquote class=3D"gmail_quote" style=3D"bord=
er-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-l=
eft: 1ex;">
<div><font face=3D"Arial" size=3D"2">Isn't it possible (and reasonable) for=
 these=20
environments to keep track of whether there is a transaction in progress wi=
th=20
update to given table and if not, use an index scan (count(*) where) or cac=
hed=20
value (count(*)) to perform this kind of query?</font></div>
<div></div></blockquote></div><br>
if i understand your problem correctly, then simple usage of triggers will =
do the job just fine.<br>
<br>
hubert<br>

------=_Part_10913_26676785.1128678863681--

From pgsql-performance-owner@postgresql.org  Fri Oct  7 07:14:18 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 9A452D9DBF
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri,  7 Oct 2005 07:14:17 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 19807-04
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri,  7 Oct 2005 10:14:12 +0000 (GMT)
Received: from ns2.dialtelecom.sk (ns2.dialtelecom.sk [217.67.16.3])
	by svr1.postgresql.org (Postfix) with ESMTP id A0151DA512
	for <pgsql-performance@postgresql.org>;
	Fri,  7 Oct 2005 07:14:07 -0300 (ADT)
Received: (qmail 4334 invoked by uid 0); 7 Oct 2005 10:14:09 -0000
Received: from unknown (HELO omikron.sk) (217.67.24.100)
	by ns2.dialtelecom.sk with SMTP; 7 Oct 2005 10:14:09 -0000
Received: (qmail 27551 invoked from network); 7 Oct 2005 10:14:09 -0000
Received: from unknown (HELO stratos) (158.195.31.19)
	by 0 with SMTP; 7 Oct 2005 10:14:09 -0000
Message-ID: <9d5b01c5cb27$e7a1c970$131fc39e@stratos>
From: "Cestmir Hybl" <cestmirl@freeside.sk>
To: "hubert depesz lubaczewski" <depesz@gmail.com>
Cc: <pgsql-performance@postgresql.org>
References: <935801c5cb20$dcf93a00$131fc39e@stratos>
	<9e4684ce0510070254v67e08bcfhb725715803a5de25@mail.gmail.com>
Subject: Re: count(*) using index scan in "query often,
	update rarely" environment
Date: Fri, 7 Oct 2005 12:14:29 +0200
Organization: NUSTEP s.r.o.
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="----=_NextPart_000_9D58_01C5CB38.AAF817C0"
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 6.00.2900.2527
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.042 required=5 tests=[AWL=0.014, HTML_60_70=0.027,
	HTML_MESSAGE=0.001]
X-Spam-Level: 
X-Archive-Number: 200510/136
X-Sequence-Number: 14904

This is a multi-part message in MIME format.

------=_NextPart_000_9D58_01C5CB38.AAF817C0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Yes, I can possibly use triggers to maintanin counts of several fixed =
groups of records or total recordcount (but it's unpractical).

No, I can't speed-up evaluation of generic "count(*) where ()" queries =
this way.

My question was rather about general performance of count() queries in =
environment with infrequent updates.

Cestmir
  ----- Original Message -----=20
  From: hubert depesz lubaczewski=20
  To: Cestmir Hybl=20
  Cc: pgsql-performance@postgresql.org=20
  Sent: Friday, October 07, 2005 11:54 AM
  Subject: Re: [PERFORM] count(*) using index scan in "query often, =
update rarely" environment


  On 10/7/05, Cestmir Hybl <cestmirl@freeside.sk> wrote:
    Isn't it possible (and reasonable) for these environments to keep =
track of whether there is a transaction in progress with update to given =
table and if not, use an index scan (count(*) where) or cached value =
(count(*)) to perform this kind of query?

  if i understand your problem correctly, then simple usage of triggers =
will do the job just fine.

  hubert

------=_NextPart_000_9D58_01C5CB38.AAF817C0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2900.2722" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Yes, I can possibly use triggers to =
maintanin=20
counts of several fixed groups of records or total recordcount (but it's =

unpractical).</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>No, I can't speed-up evaluation of =
generic=20
"count(*) where ()" queries this way.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>My question was rather about general =
performance of=20
count() queries in environment with infrequent updates.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Cestmir</FONT></DIV>
<BLOCKQUOTE=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV>
  <DIV=20
  style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
  <A title=3Ddepesz@gmail.com href=3D"mailto:depesz@gmail.com">hubert =
depesz=20
  lubaczewski</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A =
title=3Dcestmirl@freeside.sk=20
  href=3D"mailto:cestmirl@freeside.sk">Cestmir Hybl</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Cc:</B> <A=20
  title=3Dpgsql-performance@postgresql.org=20
  =
href=3D"mailto:pgsql-performance@postgresql.org">pgsql-performance@postgr=
esql.org</A>=20
  </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Friday, October 07, 2005 =
11:54=20
  AM</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> Re: [PERFORM] count(*) =
using=20
  index scan in "query often, update rarely" environment</DIV>
  <DIV><BR></DIV>On 10/7/05, <B class=3Dgmail_sendername>Cestmir =
Hybl</B> &lt;<A=20
  href=3D"mailto:cestmirl@freeside.sk">cestmirl@freeside.sk</A>&gt; =
wrote:
  <DIV><SPAN class=3Dgmail_quote></SPAN>
  <BLOCKQUOTE class=3Dgmail_quote=20
  style=3D"PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: =
rgb(204,204,204) 1px solid">
    <DIV><FONT face=3DArial size=3D2>Isn't it possible (and reasonable) =
for these=20
    environments to keep track of whether there is a transaction in =
progress=20
    with update to given table and if not, use an index scan (count(*) =
where) or=20
    cached value (count(*)) to perform this kind of query?</FONT></DIV>
    <DIV></DIV></BLOCKQUOTE></DIV><BR>if i understand your problem =
correctly, then=20
  simple usage of triggers will do the job just=20
fine.<BR><BR>hubert<BR></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_9D58_01C5CB38.AAF817C0--


From pgsql-performance-owner@postgresql.org  Fri Oct  7 07:48:24 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 9F77DD9AB9
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri,  7 Oct 2005 07:48:23 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 96807-09
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri,  7 Oct 2005 10:48:17 +0000 (GMT)
Received: from cassarossa.samfundet.no (cassarossa.samfundet.no
	[129.241.93.19])
	by svr1.postgresql.org (Postfix) with ESMTP id A7594D9001
	for <pgsql-performance@postgresql.org>;
	Fri,  7 Oct 2005 07:48:17 -0300 (ADT)
Received: from trofast.sesse.net ([129.241.93.32])
	by cassarossa.samfundet.no with esmtp (Exim 4.50) id 1ENply-0004nP-CK
	for pgsql-performance@postgresql.org; Fri, 07 Oct 2005 12:48:19 +0200
Received: from sesse by trofast.sesse.net with local (Exim 3.36 #1 (Debian))
	id 1ENplw-0002QF-00
	for <pgsql-performance@postgresql.org>; Fri, 07 Oct 2005 12:48:16 +0200
Date: Fri, 7 Oct 2005 12:48:16 +0200
From: "Steinar H. Gunderson" <sgunderson@bigfoot.com>
To: pgsql-performance@postgresql.org
Subject: Re: count(*) using index scan in "query often,
	update rarely" environment
Message-ID: <20051007104816.GA8371@uio.no>
Mail-Followup-To: pgsql-performance@postgresql.org
References: <935801c5cb20$dcf93a00$131fc39e@stratos>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
In-Reply-To: <935801c5cb20$dcf93a00$131fc39e@stratos>
X-Operating-System: Linux 2.6.11.8 on a i686
X-Message-Flag: Outlook? --> http://www.mozilla.org/products/thunderbird/
User-Agent: Mutt/1.5.10i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.012 required=5 tests=[AWL=0.012]
X-Spam-Level: 
X-Archive-Number: 200510/137
X-Sequence-Number: 14905

On Fri, Oct 07, 2005 at 11:24:05AM +0200, Cestmir Hybl wrote:
> Isn't it possible (and reasonable) for these environments to keep track of
> whether there is a transaction in progress with update to given table and
> if not, use an index scan (count(*) where) or cached value (count(*)) to
> perform this kind of query?

Even if there is no running update, there might still be dead rows in the
table. In any case, of course, a new update could always be occurring while
your counting query was still running.

/* Steinar */
-- 
Homepage: http://www.sesse.net/

From pgsql-performance-owner@postgresql.org  Fri Oct  7 08:14:06 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 24D6FDA552
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri,  7 Oct 2005 08:14:05 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 07543-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri,  7 Oct 2005 11:13:57 +0000 (GMT)
Received: from ns2.dialtelecom.sk (ns2.dialtelecom.sk [217.67.16.3])
	by svr1.postgresql.org (Postfix) with ESMTP id B8BCADA52C
	for <pgsql-performance@postgresql.org>;
	Fri,  7 Oct 2005 08:13:57 -0300 (ADT)
Received: (qmail 7004 invoked by uid 0); 7 Oct 2005 11:14:00 -0000
Received: from unknown (HELO omikron.sk) (217.67.24.100)
	by ns2.dialtelecom.sk with SMTP; 7 Oct 2005 11:14:00 -0000
Received: (qmail 7604 invoked from network); 7 Oct 2005 11:14:00 -0000
Received: from unknown (HELO stratos) (158.195.31.19)
	by 0 with SMTP; 7 Oct 2005 11:14:00 -0000
Message-ID: <9fbe01c5cb30$4407d580$131fc39e@stratos>
From: "Cestmir Hybl" <cestmirl@freeside.sk>
To: "Steinar H. Gunderson" <sgunderson@bigfoot.com>,
	<pgsql-performance@postgresql.org>
References: <935801c5cb20$dcf93a00$131fc39e@stratos>
	<20051007104816.GA8371@uio.no>
Subject: Re: count(*) using index scan in "query often,
	update rarely" environment
Date: Fri, 7 Oct 2005 13:14:20 +0200
Organization: NUSTEP s.r.o.
MIME-Version: 1.0
Content-Type: text/plain; format=flowed; charset="utf-8"; reply-type=original
Content-Transfer-Encoding: 7bit
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 6.00.2900.2527
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.024 required=5 tests=[AWL=0.024]
X-Spam-Level: 
X-Archive-Number: 200510/138
X-Sequence-Number: 14906

collision: it's possible to either block updating transaction until index 
scan ends or discard index scan imediately and finish query using MVCC 
compliant scan

dead rows: this sounds like more serious counter-argument, I don't know much 
about dead records management and whether it would be  possible/worth to 
make indexes matching live records when there's no transaction in progress 
on that table

----- Original Message ----- 
From: "Steinar H. Gunderson" <sgunderson@bigfoot.com>
To: <pgsql-performance@postgresql.org>
Sent: Friday, October 07, 2005 12:48 PM
Subject: Re: [PERFORM] count(*) using index scan in "query often, update 
rarely" environment


> On Fri, Oct 07, 2005 at 11:24:05AM +0200, Cestmir Hybl wrote:
>> Isn't it possible (and reasonable) for these environments to keep track 
>> of
>> whether there is a transaction in progress with update to given table and
>> if not, use an index scan (count(*) where) or cached value (count(*)) to
>> perform this kind of query?
>
> Even if there is no running update, there might still be dead rows in the
> table. In any case, of course, a new update could always be occurring 
> while
> your counting query was still running.
>
> /* Steinar */
> -- 
> Homepage: http://www.sesse.net/
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: Don't 'kill -9' the postmaster 


From pgsql-performance-owner@postgresql.org  Fri Oct  7 09:27:09 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id C503FDA563
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri,  7 Oct 2005 09:27:08 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 30847-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri,  7 Oct 2005 12:27:03 +0000 (GMT)
Received: from Herge.rcsinc.local (mail.rcsonline.com [70.89.208.142])
	by svr1.postgresql.org (Postfix) with ESMTP id 9FDB8D8833
	for <pgsql-performance@postgresql.org>;
	Fri,  7 Oct 2005 09:27:04 -0300 (ADT)
Content-class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Subject: Re: Status of Opteron vs Xeon
Date: Fri, 7 Oct 2005 08:27:05 -0400
X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0
Message-ID: <6EE64EF3AB31D5448D0007DD34EEB3417DD53E@Herge.rcsinc.local>
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
Thread-Topic: [PERFORM] Status of Opteron vs Xeon
Thread-Index: AcXK0muzQYUTVJcKRE+Y0chgPW3+eAAZmqnw
From: "Merlin Moncure" <merlin.moncure@rcsonline.com>
To: "Jeff Frost" <jeff@frostconsultingllc.com>
Cc: <pgsql-performance@postgresql.org>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.04 required=5 tests=[AWL=-0.010,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/139
X-Sequence-Number: 14907

> What's the current status of how much faster the Opteron is compared
to
> the
> Xeons?  I know the Opterons used to be close to 2x faster, but is that
> still
> the case?  I understand much work has been done to reduce the contect
> switching storms on the Xeon architecture, is this correct?

Up until two days ago (Oct 5) Intel has had no answer for AMD's dual
core offerings...unfortunately this has allowed AMD to charge top dollar
for dual core Opterons.  The Intel dual core solution on the P4 side
hasn't been very impressive particularly with regard to thermals.

My 90nm athlon 3000 at home runs very cool...if I underclock it a bit I
can actually turn off the cooling fan :).

IMO, right now it's AMD all the way, but if you are planning a big
purchase, it might be smart to wait a couple of months for the big price
realignment as Intel's dual xeons hit the retail channel.

Merlin


From pgsql-performance-owner@postgresql.org  Fri Oct  7 10:07:20 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id D654FDA50B
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri,  7 Oct 2005 10:07:18 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 01920-07
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri,  7 Oct 2005 13:07:10 +0000 (GMT)
Received: from mx1.surnet.cl (mx2.surnet.cl [216.155.73.181])
	by svr1.postgresql.org (Postfix) with ESMTP id F07D7DA56C
	for <pgsql-performance@postgresql.org>;
	Fri,  7 Oct 2005 10:07:11 -0300 (ADT)
Received: from unknown (HELO cluster.surnet.cl) ([216.155.73.165])
	by mx1.surnet.cl with ESMTP; 07 Oct 2005 09:06:46 -0400
Received: from alvh.no-ip.org (200.85.218.198) by cluster.surnet.cl (7.0.043)
	(authenticated as alvherre@surnet.cl)
	id 433A601F002215BB; Fri, 7 Oct 2005 09:07:15 -0400
Received: by alvh.no-ip.org (Postfix, from userid 1000)
	id 1D5E0C2DC18; Fri,  7 Oct 2005 09:07:15 -0400 (CLT)
Date: Fri, 7 Oct 2005 09:07:15 -0400
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
To: Cestmir Hybl <cestmirl@freeside.sk>
Cc: "Steinar H. Gunderson" <sgunderson@bigfoot.com>,
	pgsql-performance@postgresql.org
Subject: Re: count(*) using index scan in "query often,
	update rarely" environment
Message-ID: <20051007130714.GB5175@surnet.cl>
Mail-Followup-To: Cestmir Hybl <cestmirl@freeside.sk>,
	"Steinar H. Gunderson" <sgunderson@bigfoot.com>,
	pgsql-performance@postgresql.org
References: <935801c5cb20$dcf93a00$131fc39e@stratos>
	<20051007104816.GA8371@uio.no>
	<9fbe01c5cb30$4407d580$131fc39e@stratos>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <9fbe01c5cb30$4407d580$131fc39e@stratos>
User-Agent: Mutt/1.5.10i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=1.495 required=5 tests=[AWL=-0.305,
	DNS_FROM_RFC_ABUSE=0.374, DNS_FROM_RFC_POST=1.376,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: *
X-Archive-Number: 200510/140
X-Sequence-Number: 14908

On Fri, Oct 07, 2005 at 01:14:20PM +0200, Cestmir Hybl wrote:
> collision: it's possible to either block updating transaction until 
> index scan ends or discard index scan imediately and finish query using 
> MVCC compliant scan

You can't change from one scan method to a different one on the fly.
There's no way to know which tuples have alreaady been returned.

Our index access methods are designed to be very concurrent, and it
works extremely well.  One index scan being able to block an update
would destroy that advantage.

> dead rows: this sounds like more serious counter-argument, I don't know 
> much about dead records management and whether it would be  
> possible/worth to make indexes matching live records when there's no 
> transaction in progress on that table

It's not possible, because a finishing transaction would have to clean
up every index it has used, and also any index it hasn't used but has
been modified by another transaction which couldn't clean up by itself
but didn't do the work because the first one was looking at the index.
It's easy to see that it's possible to create an unbounded number of
transactions, each forcing the other to do some index cleanup.  This is
not acceptable.

Plus, it would be very hard to implement, and a very wide door to bugs.

-- 
Alvaro Herrera                        http://www.advogato.org/person/alvherre
"Et put se mouve" (Galileo Galilei)

From pgsql-performance-owner@postgresql.org  Fri Oct  7 10:37:57 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id B882ED83C7
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri,  7 Oct 2005 10:34:11 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 88732-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri,  7 Oct 2005 13:34:06 +0000 (GMT)
Received: from TWMAIL.ESNCC.COM (static-66-173-159-28.t1.cavtel.net
	[66.173.159.28])
	by svr1.postgresql.org (Postfix) with ESMTP id 7E8B3DA53B
	for <pgsql-performance@postgresql.org>;
	Fri,  7 Oct 2005 10:34:07 -0300 (ADT)
Received: from spawar2i8uvlb9 ([150.125.117.63]) by TWMAIL.ESNCC.COM with
	Microsoft SMTPSVC(5.0.2195.6713); Fri, 7 Oct 2005 09:34:12 -0400
From: "Lane Van Ingen" <lvaningen@esncc.com>
To: "Richard Huxton" <dev@archonet.com>
Cc: <pgsql-performance@postgresql.org>
Subject: Re: Need Some Suggestions
Date: Fri, 7 Oct 2005 09:37:44 -0400
Message-ID: <EKEMKEFLOMKDDLIALABIIEHHCDAA.lvaningen@esncc.com>
MIME-Version: 1.0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0)
In-Reply-To: <4346294E.7080803@archonet.com>
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.181
Importance: Normal
X-OriginalArrivalTime: 07 Oct 2005 13:34:12.0221 (UTC)
	FILETIME=[CD941AD0:01C5CB43]
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.057 required=5 tests=[AWL=0.007,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/141
X-Sequence-Number: 14909

You are correct, in that these tables are not large (50,000 records), but
their effect on performance is noticeable. Plain VACUUM (no freeze, full,
etc)
does the trick well, but I am unable to figure a way to call the 'plain
vanilla
version' of VACUUM via a PostgreSQL trigger function (does not allow it).

Using the Windows scheduler (schtask, somewhat like Unix cron) is an option,
but not a good one, as it takes too much out of the platform to run. My
client
does not use strong platforms, so I have to be concerned about that. VACUUM
is
a minimum impact on performance when running. I believe it would be much
better
to be able to call VACUUM out of a function, the same way in which other SQL
commands are used.

-----Original Message-----
From: Richard Huxton [mailto:dev@archonet.com]
Sent: Friday, October 07, 2005 3:53 AM
To: Lane Van Ingen
Cc: pgsql-performance@postgresql.org
Subject: Re: [PERFORM] Need Some Suggestions

Lane Van Ingen wrote:
> I have an application that is prone to sudden, unscheduled high bursts of
> activity, and I am finding that the application design permits me to
detect
> the activity bursts within an existing function. The bursts only affect 3
> tables, but degradation becomes apparent after 2,000 updates, and quite
> significant after 8,000 updates.

Hmm - assuming your free-space settings are large enough, it might be
adequate to just run a vacuum on the 3 tables every 5 minutes or so. It
sounds like these are quite small tables with a lot of activity, so if
there's not much for vacuum to do it won't place too much load on your
system.

--
   Richard Huxton
   Archonet Ltd



From pgsql-performance-owner@postgresql.org  Fri Oct  7 10:42:32 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 2C734DA508
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri,  7 Oct 2005 10:42:31 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 03717-09
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri,  7 Oct 2005 13:42:27 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id 3127FDA56E
	for <pgsql-performance@postgresql.org>;
	Fri,  7 Oct 2005 10:42:29 -0300 (ADT)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j97DgWXt003255;
	Fri, 7 Oct 2005 09:42:32 -0400 (EDT)
To: "Cestmir Hybl" <cestmirl@freeside.sk>
Cc: pgsql-performance@postgresql.org
Subject: Re: count(*) using index scan in "query often,
	update rarely" environment
In-reply-to: <935801c5cb20$dcf93a00$131fc39e@stratos> 
References: <935801c5cb20$dcf93a00$131fc39e@stratos>
Comments: In-reply-to "Cestmir Hybl" <cestmirl@freeside.sk>
	message dated "Fri, 07 Oct 2005 11:24:05 +0200"
Date: Fri, 07 Oct 2005 09:42:32 -0400
Message-ID: <3254.1128692552@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/142
X-Sequence-Number: 14910

"Cestmir Hybl" <cestmirl@freeside.sk> writes:
> Isn't it possible (and reasonable) for these environments to keep track =
> of whether there is a transaction in progress with update to given table =
> and if not, use an index scan (count(*) where) or cached value =
> (count(*)) to perform this kind of query?

Please read the archives before bringing up such well-discussed issues.

There's a workable-looking design in the archives (pghackers probably)
for maintaining overall table counts in a separate table, with each
transaction adding one row of "delta" information just before it
commits.  I haven't seen anything else that looks remotely attractive.

			regards, tom lane

From pgsql-performance-owner@postgresql.org  Fri Oct  7 10:50:31 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 4413ADA580
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri,  7 Oct 2005 10:50:30 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 54950-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri,  7 Oct 2005 13:50:25 +0000 (GMT)
Received: from Herge.rcsinc.local (mail.rcsonline.com [70.89.208.142])
	by svr1.postgresql.org (Postfix) with ESMTP id 3FF1FDA586
	for <pgsql-performance@postgresql.org>;
	Fri,  7 Oct 2005 10:50:26 -0300 (ADT)
Content-class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Subject: Re: count(*) using index scan in "query often,
	update rarely" environment
Date: Fri, 7 Oct 2005 09:50:30 -0400
X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0
Message-ID: <6EE64EF3AB31D5448D0007DD34EEB3417DD541@Herge.rcsinc.local>
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
Thread-Topic: [PERFORM] count(*) using index scan in "query often,
	update rarely" environment
Thread-Index: AcXLJX6DK1dmqs+BSDmqVVB22ekbRAAHXLuQ
From: "Merlin Moncure" <merlin.moncure@rcsonline.com>
To: "hubert depesz lubaczewski" <depesz@gmail.com>
Cc: <pgsql-performance@postgresql.org>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.04 required=5 tests=[AWL=-0.010,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/143
X-Sequence-Number: 14911

On 10/7/05, Cestmir Hybl <cestmirl@freeside.sk> wrote:
Isn't it possible (and reasonable) for these environments to keep track
of whether there is a transaction in progress with update to given table
and if not, use an index scan (count(*) where) or cached value
(count(*)) to perform this kind of query?
________________________________________

The answer to the first question is subtle.  Basically, the PostgreSQL
engine is designed for high concurrency.  We are definitely on the right
side of the cost/benefit tradeoff here.  SQL server does not have MVCC
(or at least until 2005 appears) so they are on the other side of the
tradeoff.

You can of course serialize the access yourself by materializing the
count in a small table and use triggers or cleverly designed
transactions.  This is trickier than it might look however so check the
archives for a thorough treatment of the topic.

One interesting thing is that making count(*) over large swaths of data
is frequently an indicator of a poorly normalized database.  Is it
possible to optimize the counting by laying out your data in a different
way?

Merlin



From pgsql-performance-owner@postgresql.org  Fri Oct  7 11:32:24 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 8A82FDA57A
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri,  7 Oct 2005 11:15:23 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 52220-03
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri,  7 Oct 2005 14:15:16 +0000 (GMT)
Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75])
	by svr1.postgresql.org (Postfix) with ESMTP id C91E8DA571
	for <pgsql-performance@postgresql.org>;
	Fri,  7 Oct 2005 11:15:18 -0300 (ADT)
Received: from mainbox.archonet.com
	(84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99])
	by smtp.metronet.co.uk (MetroNet Mail) with ESMTP
	id DC0CD416F35; Fri,  7 Oct 2005 15:15:10 +0100 (BST)
Received: from localhost (localhost.localdomain [127.0.0.1])
	by mainbox.archonet.com (Postfix) with ESMTP id 596A615EDA;
	Fri,  7 Oct 2005 15:11:20 +0100 (BST)
Received: from mainbox.archonet.com ([127.0.0.1])
	by localhost (mainbox [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 19964-05; Fri, 7 Oct 2005 15:11:07 +0100 (BST)
Received: from [192.168.1.17] (client17.office.archonet.com [192.168.1.17])
	by mainbox.archonet.com (Postfix) with ESMTP id 2D94915ED5;
	Fri,  7 Oct 2005 15:11:02 +0100 (BST)
Message-ID: <434681F5.6000906@archonet.com>
Date: Fri, 07 Oct 2005 15:11:01 +0100
From: Richard Huxton <dev@archonet.com>
User-Agent: Mozilla Thunderbird 1.0.6 (X11/20050912)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-performance@postgresql.org
Subject: Re: count(*) using index scan in "query often, update rarely"
References: <935801c5cb20$dcf93a00$131fc39e@stratos>
	<3254.1128692552@sss.pgh.pa.us>
In-Reply-To: <3254.1128692552@sss.pgh.pa.us>
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.058 required=5 tests=[AWL=0.008,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/144
X-Sequence-Number: 14912

Tom Lane wrote:
> 
> There's a workable-looking design in the archives (pghackers probably)
> for maintaining overall table counts in a separate table, with each
> transaction adding one row of "delta" information just before it
> commits.  I haven't seen anything else that looks remotely attractive.

It might be useful if there was a way to trap certain queries and 
rewrite/replace them. That way more complex queries could be 
transparently redirected to a summary table etc. I'm guessing that the 
overhead to check every query would quickly destroy any gains though.

--
   Richard Huxton
   Archonet Ltd

From pgsql-performance-owner@postgresql.org  Fri Oct  7 15:04:13 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id B89E7D9AAE
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri,  7 Oct 2005 15:04:11 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 85678-06
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri,  7 Oct 2005 18:04:04 +0000 (GMT)
Received: from floppy.pyrenet.fr (floppy.pyrenet.fr [194.116.145.2])
	by svr1.postgresql.org (Postfix) with ESMTP id 59FEFD982E
	for <pgsql-performance@postgresql.org>;
	Fri,  7 Oct 2005 15:04:03 -0300 (ADT)
Received: by floppy.pyrenet.fr (Postfix, from userid 106)
	id 0FA2A31059; Fri,  7 Oct 2005 20:04:04 +0200 (MET DST)
From: Chris Browne <cbbrowne@acm.org>
X-Newsgroups: pgsql.performance
Subject: Re: Status of Opteron vs Xeon
Date: Fri, 07 Oct 2005 13:33:28 -0400
Organization: cbbrowne Computing Inc
Lines: 22
Message-ID: <60r7axjkpj.fsf@dba2.int.libertyrms.com>
References: <Pine.LNX.4.64.0510061654080.21147@discord.dyndns.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
X-Complaints-To: usenet@news.hub.org
User-Agent: Gnus/5.1007 (Gnus v5.10.7) XEmacs/21.4.17 (Jumbo Shrimp, linux)
Cancel-Lock: sha1:/icvu4IO0q5pUSqSnvFPn8LiBWU=
To: pgsql-performance@postgresql.org
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.088 required=5 tests=[AWL=0.088]
X-Spam-Level: 
X-Archive-Number: 200510/145
X-Sequence-Number: 14913

jeff@frostconsultingllc.com (Jeff Frost) writes:
> What's the current status of how much faster the Opteron is compared
> to the Xeons?  I know the Opterons used to be close to 2x faster,
> but is that still the case?  I understand much work has been done to
> reduce the contect switching storms on the Xeon architecture, is
> this correct?

Work has gone into 8.1 to try to help with the context switch storms;
that doesn't affect previous versions.

Furthermore, it does not do anything to address the consideration that
memory access on Opterons seem to be intrinsically faster than on Xeon
due to differences in the memory bus architecture.  

The only evident ways to address that are:
 a) For Intel to deploy chips with better memory buses;
 b) For Intel to convince people to deploy compilers that 
    optimize badly on AMD to make Intel chips look better...
-- 
(format nil "~S@~S" "cbbrowne" "ntlug.org")
http://cbbrowne.com/info/lsf.html
A mathematician is a machine for converting caffeine into theorems.

From pgsql-performance-owner@postgresql.org  Fri Oct  7 15:44:47 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id AD68FDA509
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri,  7 Oct 2005 15:44:42 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 06094-06
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri,  7 Oct 2005 18:44:38 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id CCC47DA45C
	for <pgsql-performance@postgresql.org>;
	Fri,  7 Oct 2005 15:44:38 -0300 (ADT)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j97IibT7006430;
	Fri, 7 Oct 2005 14:44:37 -0400 (EDT)
To: Chris Browne <cbbrowne@acm.org>
Cc: pgsql-performance@postgresql.org
Subject: Re: Status of Opteron vs Xeon 
In-reply-to: <60r7axjkpj.fsf@dba2.int.libertyrms.com> 
References: <Pine.LNX.4.64.0510061654080.21147@discord.dyndns.org>
	<60r7axjkpj.fsf@dba2.int.libertyrms.com>
Comments: In-reply-to Chris Browne <cbbrowne@acm.org>
	message dated "Fri, 07 Oct 2005 13:33:28 -0400"
Date: Fri, 07 Oct 2005 14:44:37 -0400
Message-ID: <6429.1128710677@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/146
X-Sequence-Number: 14914

Chris Browne <cbbrowne@acm.org> writes:
> jeff@frostconsultingllc.com (Jeff Frost) writes:
>> What's the current status of how much faster the Opteron is compared
>> to the Xeons?  I know the Opterons used to be close to 2x faster,
>> but is that still the case?  I understand much work has been done to
>> reduce the contect switching storms on the Xeon architecture, is
>> this correct?

> Work has gone into 8.1 to try to help with the context switch storms;
> that doesn't affect previous versions.

Also note that we've found that the current coding of the TAS macro
seems to be very bad for at least some Opterons --- they do much better
if the "pre-test" cmpb is removed.  But this is not true for all x86_64
chips.  We still have an open issue about what to do about this.

			regards, tom lane

From pgsql-performance-owner@postgresql.org  Fri Oct  7 15:47:50 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 33CFAD9B4E
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri,  7 Oct 2005 15:47:48 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 25634-04
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri,  7 Oct 2005 18:47:42 +0000 (GMT)
Received: from davinci.ethosmedia.com (server227.ethosmedia.com
	[209.128.84.227])
	by svr1.postgresql.org (Postfix) with ESMTP id 86CC0D8F06
	for <pgsql-performance@postgresql.org>;
	Fri,  7 Oct 2005 15:47:43 -0300 (ADT)
X-EthosMedia-Virus-Scanned: no infections found
Received: from [64.81.245.111] (account josh@agliodbs.com HELO
	temoku.sf.agliodbs.com)
	by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.1.8)
	with ESMTP id 8220689; Fri, 07 Oct 2005 11:50:09 -0700
From: Josh Berkus <josh@agliodbs.com>
Reply-To: josh@agliodbs.com
Organization: Aglio Database Solutions
To: pgsql-performance@postgresql.org
Subject: Re: wal_buffers
Date: Fri, 7 Oct 2005 11:51:36 -0700
User-Agent: KMail/1.8
Cc: Ian Westmacott <ianw@intellivid.com>,
	"Thomas F. O'Connell" <tfo@sitening.com>
References: <1128518624.15795.28.camel@spectre.intellivid.com>
	<C140F925-0D7D-41B4-873A-6C81C0D3D307@sitening.com>
	<1128603390.18319.16.camel@spectre.intellivid.com>
In-Reply-To: <1128603390.18319.16.camel@spectre.intellivid.com>
MIME-Version: 1.0
Content-Type: text/plain;
  charset="utf-8"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Message-Id: <200510071151.36959.josh@agliodbs.com>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.046 required=5 tests=[AWL=-0.004,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/147
X-Sequence-Number: 14915

Ian, Thomas,

> Thanks; I'd seen the documentation, but not Josh Berkus'
> testing.

BTW, that's still an open question for me.  I'm now theorizing that it's 
best to set wal_buffers to the expected maximum number of concurrent write 
connections.   However, I don't have enough test systems to test that 
meaningfully.

Your test results will help.

-- 
--Josh

Josh Berkus
Aglio Database Solutions
San Francisco

From pgsql-performance-owner@postgresql.org  Fri Oct  7 16:05:30 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 99CD5D94BD
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri,  7 Oct 2005 16:03:58 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 84312-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri,  7 Oct 2005 19:03:52 +0000 (GMT)
Received: from mail.baymountain.com (mail.baymountain.com [8.7.96.19])
	by svr1.postgresql.org (Postfix) with SMTP id 11DC3D83C7
	for <pgsql-performance@postgresql.org>;
	Fri,  7 Oct 2005 16:03:52 -0300 (ADT)
Received: (qmail 27613 invoked by uid 504); 7 Oct 2005 19:03:52 -0000
Received: from emil@baymountain.com by mail.baymountain.com by uid 501 with
	qmail-scanner-1.16 (spamassassin: 2.53.  Clear:SA:0(0.0/7.0):.
	Processed in 0.888931 secs); 07 Oct 2005 19:03:52 -0000
Received: from unknown (HELO briggspack.com)
	(emil@briggspack.com@24.211.148.77)
	by mail.baymountain.com with SMTP; 7 Oct 2005 19:03:51 -0000
From: Emil Briggs <emil@baymountain.com>
Reply-To: emil@baymountain.com
To: pgsql-performance@postgresql.org
Subject: Re: Status of Opteron vs Xeon
Date: Fri, 7 Oct 2005 15:03:47 -0400
User-Agent: KMail/1.7.1
Cc: Chris Browne <cbbrowne@acm.org>
References: <Pine.LNX.4.64.0510061654080.21147@discord.dyndns.org>
	<60r7axjkpj.fsf@dba2.int.libertyrms.com>
In-Reply-To: <60r7axjkpj.fsf@dba2.int.libertyrms.com>
Organization: Baymountain, Inc.
MIME-Version: 1.0
Content-Type: text/plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Message-Id: <200510071503.47373.emil@baymountain.com>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.038 required=5 tests=[AWL=-0.012,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/148
X-Sequence-Number: 14916

>
> Furthermore, it does not do anything to address the consideration that
> memory access on Opterons seem to be intrinsically faster than on Xeon
> due to differences in the memory bus architecture.
>

I have been running some tests using different numa policies on a quad Opteron 
server and have found some significant performance differences depending on 
the type of load the system is under. It's not clear to me yet if I can draw 
any general conclusions from the results though.

Emil

From pgsql-performance-owner@postgresql.org  Fri Oct  7 20:55:46 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 5FE5DDA4A5
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri,  7 Oct 2005 20:55:41 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 81217-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri,  7 Oct 2005 23:55:35 +0000 (GMT)
Received: from mail.mi8.com (d01gw02.mi8.com [63.240.6.46])
	by svr1.postgresql.org (Postfix) with ESMTP id D697CD9E0C
	for <pgsql-performance@postgresql.org>;
	Fri,  7 Oct 2005 20:55:35 -0300 (ADT)
Received: from 172.16.1.110 by mail.mi8.com with ESMTP (- Welcome to Mi8
	Corporation www.Mi8.com (D2)); Fri, 07 Oct 2005 19:55:30 -0400
X-Server-Uuid: 7829E76E-BB9E-4995-8473-3C0929DF7DD1
Received: from MI8NYCMAIL06.Mi8.com ([172.16.1.175]) by
	D01SMTP01.Mi8.com with Microsoft SMTPSVC(6.0.3790.211); Fri, 7 Oct 2005
	19:55:30 -0400
Received: from 67.103.45.218 ([67.103.45.218]) by MI8NYCMAIL06.Mi8.com (
	[172.16.1.219]) via Exchange Front-End Server mi8owa.mi8.com (
	[172.16.1.104]) with Microsoft Exchange Server HTTP-DAV ; Fri, 7 Oct
	2005 19:55:29 -0500
User-Agent: Microsoft-Entourage/11.2.0.050811
Date: Fri, 07 Oct 2005 16:55:28 -0700
Subject: Re: [HACKERS] A Better External Sort?
From: "Luke Lonergan" <llonergan@greenplum.com>
To: "Steinar H. Gunderson" <sgunderson@bigfoot.com>,
	pgsql-performance@postgresql.org
Message-ID: <BF6C5900.10E05%llonergan@greenplum.com>
Thread-Topic: [HACKERS] [PERFORM] A Better External Sort?
Thread-Index: AcXLmpes1joU+DeNEdqS5AANk63kWA==
In-Reply-To: <20051006001239.GB7856@uio.no>
MIME-Version: 1.0
X-OriginalArrivalTime: 07 Oct 2005 23:55:30.0331 (UTC)
	FILETIME=[991046B0:01C5CB9A]
X-WSS-ID: 6F59D5780IW716784-01-01
Content-Type: text/plain;
 charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=1.573 required=5 tests=[AWL=-0.008,
	FORGED_RCVD_HELO=0.05, RCVD_NUMERIC_HELO=1.531]
X-Spam-Level: *
X-Archive-Number: 200510/149
X-Sequence-Number: 14917

Steinar,

On 10/5/05 5:12 PM, "Steinar H. Gunderson" <sgunderson@bigfoot.com> wrote:

> What? strlen is definitely not in the kernel, and thus won't count as system
> time.

System time on Linux includes time spent in glibc routines.

- Luke




From pgsql-performance-owner@postgresql.org  Fri Oct  7 21:32:19 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 3B22EDA5B7
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri,  7 Oct 2005 21:32:15 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 43075-06
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat,  8 Oct 2005 00:32:08 +0000 (GMT)
Received: from mail.envyfinancial.com (unknown [206.248.142.186])
	by svr1.postgresql.org (Postfix) with ESMTP id 47C0FD83C7
	for <pgsql-performance@postgresql.org>;
	Fri,  7 Oct 2005 21:32:09 -0300 (ADT)
Received: from localhost (localhost.localdomain [127.0.0.1])
	by mail.envyfinancial.com (Postfix) with ESMTP id BE6BE234BD;
	Fri,  7 Oct 2005 20:17:04 -0400 (EDT)
Received: from mail.envyfinancial.com ([127.0.0.1])
	by localhost (mark.mielke.cc [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 10491-08; Fri,  7 Oct 2005 20:17:04 -0400 (EDT)
Received: by mail.envyfinancial.com (Postfix, from userid 500)
	id 8CAFA234B8; Fri,  7 Oct 2005 20:17:04 -0400 (EDT)
Date: Fri, 7 Oct 2005 20:17:04 -0400
From: mark@mark.mielke.cc
To: Luke Lonergan <llonergan@greenplum.com>
Cc: "Steinar H. Gunderson" <sgunderson@bigfoot.com>,
	pgsql-performance@postgresql.org
Subject: Re: [HACKERS] A Better External Sort?
Message-ID: <20051008001704.GA11677@mark.mielke.cc>
References: <20051006001239.GB7856@uio.no>
	<BF6C5900.10E05%llonergan@greenplum.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <BF6C5900.10E05%llonergan@greenplum.com>
User-Agent: Mutt/1.4.2.1i
X-Virus-Scanned: amavisd-new at mail.envyfinancial.com
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.191 required=5 tests=[AWL=0.013, NO_REAL_NAME=0.178]
X-Spam-Level: 
X-Archive-Number: 200510/150
X-Sequence-Number: 14918

On Fri, Oct 07, 2005 at 04:55:28PM -0700, Luke Lonergan wrote:
> On 10/5/05 5:12 PM, "Steinar H. Gunderson" <sgunderson@bigfoot.com> wrote:
> > What? strlen is definitely not in the kernel, and thus won't count as
> > system time.
> System time on Linux includes time spent in glibc routines.

Do you have a reference for this?

I believe this statement to be 100% false.

Cheers,
mark

-- 
mark@mielke.cc / markm@ncf.ca / markm@nortel.com     __________________________
.  .  _  ._  . .   .__    .  . ._. .__ .   . . .__  | Neighbourhood Coder
|\/| |_| |_| |/    |_     |\/|  |  |_  |   |/  |_   | 
|  | | | | \ | \   |__ .  |  | .|. |__ |__ | \ |__  | Ottawa, Ontario, Canada

  One ring to rule them all, one ring to find them, one ring to bring them all
                       and in the darkness bind them...

                           http://mark.mielke.cc/


From pgsql-performance-owner@postgresql.org  Sat Oct  8 01:21:18 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 1549FDA5F6
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat,  8 Oct 2005 01:21:17 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 23539-07
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat,  8 Oct 2005 04:21:13 +0000 (GMT)
Received: from mail.mi8.com (d01gw02.mi8.com [63.240.6.46])
	by svr1.postgresql.org (Postfix) with ESMTP id 5B464DA5F4
	for <pgsql-performance@postgresql.org>;
	Sat,  8 Oct 2005 01:21:12 -0300 (ADT)
Received: from 172.16.1.112 by mail.mi8.com with ESMTP (- Welcome to Mi8
	Corporation www.Mi8.com (D2)); Sat, 08 Oct 2005 00:21:02 -0400
X-Server-Uuid: 7829E76E-BB9E-4995-8473-3C0929DF7DD1
Received: from MI8NYCMAIL06.Mi8.com ([172.16.1.175]) by
	D01SMTP02.Mi8.com with Microsoft SMTPSVC(6.0.3790.211); Sat, 8 Oct 2005
	00:21:01 -0400
Received: from 69.181.100.71 ([69.181.100.71]) by MI8NYCMAIL06.Mi8.com (
	[172.16.1.219]) via Exchange Front-End Server mi8owa.mi8.com (
	[172.16.1.106]) with Microsoft Exchange Server HTTP-DAV ; Sat, 8 Oct
	2005 00:21:01 -0500
User-Agent: Microsoft-Entourage/11.2.0.050811
Date: Fri, 07 Oct 2005 21:20:59 -0700
Subject: Re: [HACKERS] A Better External Sort?
From: "Luke Lonergan" <llonergan@greenplum.com>
To: mark@mark.mielke.cc
Cc: "Steinar H. Gunderson" <sgunderson@bigfoot.com>,
	pgsql-performance@postgresql.org
Message-ID: <BF6C973B.10E2B%llonergan@greenplum.com>
Thread-Topic: [HACKERS] [PERFORM] A Better External Sort?
Thread-Index: AcXLv69K7ZnY8jeyEdqtDAANk63kWA==
In-Reply-To: <20051008001704.GA11677@mark.mielke.cc>
MIME-Version: 1.0
X-OriginalArrivalTime: 08 Oct 2005 04:21:01.0963 (UTC)
	FILETIME=[B10E65B0:01C5CBBF]
X-WSS-ID: 6F5996A40IW847127-01-01
Content-Type: text/plain;
 charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=1.556 required=5 tests=[AWL=-0.025,
	FORGED_RCVD_HELO=0.05, RCVD_NUMERIC_HELO=1.531]
X-Spam-Level: *
X-Archive-Number: 200510/151
X-Sequence-Number: 14919

Mark,

On 10/7/05 5:17 PM, "mark@mark.mielke.cc" <mark@mark.mielke.cc> wrote:

> On Fri, Oct 07, 2005 at 04:55:28PM -0700, Luke Lonergan wrote:
>> On 10/5/05 5:12 PM, "Steinar H. Gunderson" <sgunderson@bigfoot.com> wrote:
>>> What? strlen is definitely not in the kernel, and thus won't count as
>>> system time.
>> System time on Linux includes time spent in glibc routines.
> 
> Do you have a reference for this?
> 
> I believe this statement to be 100% false.

How about 99%? OK, you're right, I had this confused with the profiling
problem where glibc routines aren't included in dynamic linked profiles.

Back to the statements earlier - the output of time had much of time for a
dd spent in system, which means kernel, so where in the kernel would that be
exactly?

- Luke



From pgsql-performance-owner@postgresql.org  Sat Oct  8 07:44:10 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 4F874DA590
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat,  8 Oct 2005 07:44:09 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 29970-06
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat,  8 Oct 2005 10:44:06 +0000 (GMT)
Received: from qproxy.gmail.com (qproxy.gmail.com [72.14.204.204])
	by svr1.postgresql.org (Postfix) with ESMTP id 8624ED9D1F
	for <pgsql-performance@postgresql.org>;
	Sat,  8 Oct 2005 07:44:06 -0300 (ADT)
Received: by qproxy.gmail.com with SMTP id z1so647899qbc
	for <pgsql-performance@postgresql.org>;
	Sat, 08 Oct 2005 03:44:09 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:references;
	b=CC8+9nElxnYxl7kTrnoBtsrcp1P3BxtDGQ0a95nYXh1YuhaZOFOKqGQlZVSlHwJT3y7YVJ3rKsD1MCzFXnhIoelmNLRXumpup4IKMmnOsBh4Zlb6oTco/j/iacTrRy+didLZKuVCAFDV51PUqlT5PgNuNr0pkLji6Dx1fyLa3Qw=
Received: by 10.64.196.3 with SMTP id t3mr1961096qbf;
	Sat, 08 Oct 2005 03:44:09 -0700 (PDT)
Received: by 10.64.195.4 with HTTP; Sat, 8 Oct 2005 03:44:09 -0700 (PDT)
Message-ID: <9e4684ce0510080344v1dfa36f7nea19ddb1ad38f652@mail.gmail.com>
Date: Sat, 8 Oct 2005 12:44:09 +0200
From: hubert depesz lubaczewski <depesz@gmail.com>
Reply-To: hubert depesz lubaczewski <depesz@gmail.com>
To: Cestmir Hybl <cestmirl@freeside.sk>
Subject: Re: count(*) using index scan in "query often,
	update rarely" environment
Cc: pgsql-performance@postgresql.org
In-Reply-To: <9d5b01c5cb27$e7a1c970$131fc39e@stratos>
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="----=_Part_25997_11295934.1128768249494"
References: <935801c5cb20$dcf93a00$131fc39e@stratos>
	<9e4684ce0510070254v67e08bcfhb725715803a5de25@mail.gmail.com>
	<9d5b01c5cb27$e7a1c970$131fc39e@stratos>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=1.888 required=5 tests=[AWL=-0.055, HTML_40_50=0.086,
	HTML_MESSAGE=0.001, RCVD_BY_IP=0.024,
	RCVD_IN_BL_SPAMCOP_NET=1.832]
X-Spam-Level: *
X-Archive-Number: 200510/152
X-Sequence-Number: 14920

------=_Part_25997_11295934.1128768249494
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

On 10/7/05, Cestmir Hybl <cestmirl@freeside.sk> wrote:
>
> No, I can't speed-up evaluation of generic "count(*) where ()" queries
> this way.
>

no you can't speed up generic where(), *but* you can check what are the mos=
t
common "where"'s (like usually i do where on one column like:
select count(*) from table where some_particular_column =3D 'some value';
where you can simply make the trigger aware of the fact that it should coun=
t
based on value in some_particular_column.
works good enough for me not to look for alternatives.

depesz

------=_Part_25997_11295934.1128768249494
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

On 10/7/05, <b class=3D"gmail_sendername">Cestmir Hybl</b> &lt;<a href=3D"m=
ailto:cestmirl@freeside.sk">cestmirl@freeside.sk</a>&gt; wrote:<div><span c=
lass=3D"gmail_quote"></span><blockquote class=3D"gmail_quote" style=3D"bord=
er-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-l=
eft: 1ex;">
<div><font face=3D"Arial" size=3D"2">No, I can't speed-up evaluation of gen=
eric=20
&quot;count(*) where ()&quot; queries this way.</font></div></blockquote></=
div><br>
no you can't speed up generic where(), *but* you can check what are the
most common &quot;where&quot;'s (like usually i do where on one column like=
:<br>
select count(*) from table where some_particular_column =3D 'some value';<b=
r>
where you can simply make the trigger aware of the fact that it should coun=
t based on value in some_particular_column.<br>
works good enough for me not to look for alternatives.<br>
<br>
depesz<br>
<br>
<br>

------=_Part_25997_11295934.1128768249494--

From pgsql-performance-owner@postgresql.org  Sat Oct  8 10:44:58 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id DBB30D7A13
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat,  8 Oct 2005 10:44:57 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 94357-07
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat,  8 Oct 2005 13:44:52 +0000 (GMT)
Received: from mail.envyfinancial.com (mark.mielke.cc [206.248.142.186])
	by svr1.postgresql.org (Postfix) with ESMTP id C57A5D7775
	for <pgsql-performance@postgresql.org>;
	Sat,  8 Oct 2005 10:44:54 -0300 (ADT)
Received: from localhost (localhost.localdomain [127.0.0.1])
	by mail.envyfinancial.com (Postfix) with ESMTP id B505B234B8;
	Sat,  8 Oct 2005 09:31:06 -0400 (EDT)
Received: from mail.envyfinancial.com ([127.0.0.1])
	by localhost (mark.mielke.cc [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 24033-06; Sat,  8 Oct 2005 09:31:06 -0400 (EDT)
Received: by mail.envyfinancial.com (Postfix, from userid 500)
	id 600A6234B3; Sat,  8 Oct 2005 09:31:06 -0400 (EDT)
Date: Sat, 8 Oct 2005 09:31:06 -0400
From: mark@mark.mielke.cc
To: Luke Lonergan <llonergan@greenplum.com>
Cc: "Steinar H. Gunderson" <sgunderson@bigfoot.com>,
	pgsql-performance@postgresql.org
Subject: Re: [HACKERS] A Better External Sort?
Message-ID: <20051008133106.GB23913@mark.mielke.cc>
References: <20051008001704.GA11677@mark.mielke.cc>
	<BF6C973B.10E2B%llonergan@greenplum.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <BF6C973B.10E2B%llonergan@greenplum.com>
User-Agent: Mutt/1.4.2.1i
X-Virus-Scanned: amavisd-new at mail.envyfinancial.com
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.216 required=5 tests=[AWL=-0.012,
	FORGED_RCVD_HELO=0.05, NO_REAL_NAME=0.178]
X-Spam-Level: 
X-Archive-Number: 200510/153
X-Sequence-Number: 14921

On Fri, Oct 07, 2005 at 09:20:59PM -0700, Luke Lonergan wrote:
> On 10/7/05 5:17 PM, "mark@mark.mielke.cc" <mark@mark.mielke.cc> wrote:
> > On Fri, Oct 07, 2005 at 04:55:28PM -0700, Luke Lonergan wrote:
> >> On 10/5/05 5:12 PM, "Steinar H. Gunderson" <sgunderson@bigfoot.com> wrote:
> >>> What? strlen is definitely not in the kernel, and thus won't count as
> >>> system time.
> >> System time on Linux includes time spent in glibc routines.
> > Do you have a reference for this?
> > I believe this statement to be 100% false.
> How about 99%? OK, you're right, I had this confused with the profiling
> problem where glibc routines aren't included in dynamic linked profiles.

Sorry to emphasize the 100%. It wasn't meant to judge you. It was meant
to indicate that I believe 100% of system time is accounted for, while
the system call is actually active, which is not possible while glibc
is active.

I believe the way it works, is that a periodic timer interrupt
increments a specific integer every time it wakes up. If it finds
itself within the kernel, it increments the system time for the active
process, if it finds itself outside the kernel, it incremenets the
user time for the active process.

> Back to the statements earlier - the output of time had much of time for a
> dd spent in system, which means kernel, so where in the kernel would that be
> exactly?

Not really an expert here. I only play around. At a minimum, their is a
cost to switching from user context to system context and back, and then
filling in the zero bits. There may be other inefficiencies, however.
Perhaps /dev/zero always fill in a whole block (8192 usually), before
allowing the standard file system code to read only one byte.

I dunno.

But, I see this oddity too:

$ time dd if=/dev/zero of=/dev/zero bs=1 count=10000000
10000000+0 records in
10000000+0 records out
dd if=/dev/zero of=/dev/zero bs=1 count=10000000  4.05s user 11.13s system 94% cpu 16.061 total

$ time dd if=/dev/zero of=/dev/zero bs=10 count=1000000
1000000+0 records in
1000000+0 records out
dd if=/dev/zero of=/dev/zero bs=10 count=1000000  0.37s user 1.37s system 100% cpu 1.738 total

 From my numbers, it looks like 1 byte reads are hard in both the user context
and the system context. It looks almost linearly, even:

$ time dd if=/dev/zero of=/dev/zero bs=100 count=100000
100000+0 records in
100000+0 records out
dd if=/dev/zero of=/dev/zero bs=100 count=100000  0.04s user 0.15s system 95% cpu 0.199 total

$ time dd if=/dev/zero of=/dev/zero bs=1000 count=10000
10000+0 records in
10000+0 records out
dd if=/dev/zero of=/dev/zero bs=1000 count=10000  0.01s user 0.02s system 140% cpu 0.021 total

At least some of this gets into the very in-depth discussions as to
whether kernel threads, or user threads, are more efficient. Depending
on the application, user threads can switch many times faster than
kernel threads. Other parts of this may just mean that /dev/zero isn't
implemented optimally.

Cheers,
mark

-- 
mark@mielke.cc / markm@ncf.ca / markm@nortel.com     __________________________
.  .  _  ._  . .   .__    .  . ._. .__ .   . . .__  | Neighbourhood Coder
|\/| |_| |_| |/    |_     |\/|  |  |_  |   |/  |_   | 
|  | | | | \ | \   |__ .  |  | .|. |__ |__ | \ |__  | Ottawa, Ontario, Canada

  One ring to rule them all, one ring to find them, one ring to bring them all
                       and in the darkness bind them...

                           http://mark.mielke.cc/


From pgsql-performance-owner@postgresql.org  Sat Oct  8 10:48:22 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 8B4B4D7E8D
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat,  8 Oct 2005 10:48:21 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 76922-10
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat,  8 Oct 2005 13:48:16 +0000 (GMT)
Received: from mail.envyfinancial.com (mark.mielke.cc [206.248.142.186])
	by svr1.postgresql.org (Postfix) with ESMTP id 2B57BD7E05
	for <pgsql-performance@postgresql.org>;
	Sat,  8 Oct 2005 10:48:19 -0300 (ADT)
Received: from localhost (localhost.localdomain [127.0.0.1])
	by mail.envyfinancial.com (Postfix) with ESMTP id 6F6C3234B8
	for <pgsql-performance@postgresql.org>;
	Sat,  8 Oct 2005 09:34:32 -0400 (EDT)
Received: from mail.envyfinancial.com ([127.0.0.1])
	by localhost (mark.mielke.cc [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 24033-07 for <pgsql-performance@postgresql.org>;
	Sat,  8 Oct 2005 09:34:32 -0400 (EDT)
Received: by mail.envyfinancial.com (Postfix, from userid 500)
	id 43EC0234B3; Sat,  8 Oct 2005 09:34:32 -0400 (EDT)
Date: Sat, 8 Oct 2005 09:34:32 -0400
From: mark@mark.mielke.cc
To: pgsql-performance@postgresql.org
Subject: Re: count(*) using index scan in "query often,
	update rarely" environment
Message-ID: <20051008133432.GC23913@mark.mielke.cc>
References: <935801c5cb20$dcf93a00$131fc39e@stratos>
	<20051007104816.GA8371@uio.no>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20051007104816.GA8371@uio.no>
User-Agent: Mutt/1.4.2.1i
X-Virus-Scanned: amavisd-new at mail.envyfinancial.com
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.216 required=5 tests=[AWL=-0.012,
	FORGED_RCVD_HELO=0.05, NO_REAL_NAME=0.178]
X-Spam-Level: 
X-Archive-Number: 200510/154
X-Sequence-Number: 14922

On Fri, Oct 07, 2005 at 12:48:16PM +0200, Steinar H. Gunderson wrote:
> On Fri, Oct 07, 2005 at 11:24:05AM +0200, Cestmir Hybl wrote:
> > Isn't it possible (and reasonable) for these environments to keep track of
> > whether there is a transaction in progress with update to given table and
> > if not, use an index scan (count(*) where) or cached value (count(*)) to
> > perform this kind of query?
> Even if there is no running update, there might still be dead rows in the
> table. In any case, of course, a new update could always be occurring while
> your counting query was still running.

I don't see this being different from count(*) as it is today.

Updating a count column is certainly clever. If using a trigger,
perhaps it would allow the equivalent of:

    select count(*) from table for update;

:-)

Cheers,
mark

(not that this is necessarily a good thing!)

-- 
mark@mielke.cc / markm@ncf.ca / markm@nortel.com     __________________________
.  .  _  ._  . .   .__    .  . ._. .__ .   . . .__  | Neighbourhood Coder
|\/| |_| |_| |/    |_     |\/|  |  |_  |   |/  |_   | 
|  | | | | \ | \   |__ .  |  | .|. |__ |__ | \ |__  | Ottawa, Ontario, Canada

  One ring to rule them all, one ring to find them, one ring to bring them all
                       and in the darkness bind them...

                           http://mark.mielke.cc/


From pgsql-performance-owner@postgresql.org  Sat Oct  8 19:56:24 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id C4005D7336;
	Sat,  8 Oct 2005 19:51:50 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 14681-01; Sat,  8 Oct 2005 22:51:42 +0000 (GMT)
Received: from flake.decibel.org (flake.decibel.org [67.100.216.10])
	by svr1.postgresql.org (Postfix) with ESMTP id 1DEA8D8BE2;
	Sat,  8 Oct 2005 19:51:47 -0300 (ADT)
Received: by flake.decibel.org (Postfix, from userid 1001)
	id E526215255; Sat,  8 Oct 2005 17:51:55 -0500 (CDT)
Date: Sat, 8 Oct 2005 17:51:55 -0500
From: "Jim C. Nasby" <jnasby@pervasive.com>
To: Zeugswetter Andreas DAZ SD <ZeugswetterA@spardat.at>
Cc: Ron Peacetree <rjpeace@earthlink.net>,
	"Jeffrey W. Baker" <jwbaker@acm.org>, pgsql-hackers@postgresql.org,
	pgsql-performance@postgresql.org
Subject: Re: [HACKERS] A Better External Sort?
Message-ID: <20051008225155.GA16679@pervasive.com>
References: <E1539E0ED7043848906A8FF995BDA5797EFA40@m0143.s-mxs.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <E1539E0ED7043848906A8FF995BDA5797EFA40@m0143.s-mxs.net>
X-Operating-System: FreeBSD 4.11-RELEASE-p10 i386
X-Distributed: Join the Effort!  http://www.distributed.net
User-Agent: Mutt/1.5.9i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.008 required=5 tests=[AWL=0.008]
X-Spam-Level: 
X-Archive-Number: 200510/155
X-Sequence-Number: 14923

On Thu, Sep 29, 2005 at 03:28:27PM +0200, Zeugswetter Andreas DAZ SD wrote:
> 
> > In my original example, a sequential scan of the 1TB of 2KB 
> > or 4KB records, => 250M or 500M records of data, being sorted 
> > on a binary value key will take ~1000x more time than reading 
> > in the ~1GB Btree I described that used a Key+RID (plus node 
> > pointers) representation of the data.
> 
> Imho you seem to ignore the final step your algorithm needs of
> collecting the
> data rows. After you sorted the keys the collect step will effectively
> access the 
> tuples in random order (given a sufficiently large key range).
> 
> This random access is bad. It effectively allows a competing algorithm
> to read the
> whole data at least 40 times sequentially, or write the set 20 times
> sequentially. 
> (Those are the random/sequential ratios of modern discs)

True, but there is a compromise... not shuffling full tuples around when
sorting in memory. Do your sorting with pointers, then write the full
tuples out to 'tape' if needed.

Of course the other issue here is that as correlation improves it
becomes better and better to do full pointer-based sorting.
-- 
Jim C. Nasby, Sr. Engineering Consultant      jnasby@pervasive.com
Pervasive Software      http://pervasive.com    work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf       cell: 512-569-9461

From pgsql-performance-owner@postgresql.org  Mon Oct 10 01:41:20 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 2C756D9A46
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 01:41:19 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 85868-09
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 04:41:14 +0000 (GMT)
Received: from sccimhc91.asp.att.net (sccimhc91.asp.att.net [63.240.76.165])
	by svr1.postgresql.org (Postfix) with ESMTP id 97121D8CD9
	for <pgsql-performance@postgresql.org>;
	Mon, 10 Oct 2005 00:03:41 -0300 (ADT)
Received: from krunk (12-202-107-96.client.insightbb.com[12.202.107.96])
	by sccimhc91.asp.att.net (sccimhc91) with SMTP
	id <20051010030339i91001dftte>; Mon, 10 Oct 2005 03:03:39 +0000
From: "Announce" <truthhurts@insightbb.com>
To: <pgsql-performance@postgresql.org>
Subject: What's the cost of a few extra columns?
Date: Sun, 9 Oct 2005 22:03:33 -0500
Message-ID: <KBEKKNMFLELKGIADDEPEAEEPCBAA.truthhurts@insightbb.com>
MIME-Version: 1.0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0)
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
Importance: Normal
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0 required=5 tests=[none]
X-Spam-Level: 
X-Archive-Number: 200510/156
X-Sequence-Number: 14924

What's goin on pg-people?

I have a table PRODUCTIONS that is central to the DB and ties a lot of other
information together:

PRODUCTIONS (table)
----------------------------------
prod_id		primary key
type_id		foreign key
level_id		foreign key
tour_id		foreign key
show_id		foreign key
venue_id		foreign key
title			varchar(255); not null indexed
version		char;
details		text
open_date		date
close_date		date
preview_open	date
preview_close	date
perform_tot		int
preview_tot		int
park_info		text
phone_nos		text
some_other_info	text
seating_info	text
this			text
that			text
create_tstmp	timestamptz; NOW()
mod_tstmp		timestamptz;triggered
delete_tstmp	timestamptz;default null
is_complete		bool


As it stands now, there are approximately 25-30 columns on the table. Since
this table is very central to the database, would it be more efficient to
break some of the columns (especially the TEXT ones) out into a separate
INFO table since some queries on the web will not care about all of these
text columns anyway? I know that pg can handle A LOT more columns and if
there IS no performance hit for keeping them all on the same table, I would
like to do that because the relation between PRODUCTIONS and the INFO will
always be 1-to-1.

My implementation of this INFO table would look a little somethin' like
this:

PROD_INFO (table)
-------------------------------
prod_id		pkey/fkey
open_date		date
close_date		date
preview_open	date
preview_close	date
perform_tot		int
preview_tot		int
park_info		text
phone_nos		text
some_other_info	text
seating_info	text
this			text
that			text
(the rest would stay in in the original PRODUCTIONS table)


I am open to ANY suggestions, criticisms, mockery, etc.

Thanks,

Aaron


From pgsql-performance-owner@postgresql.org  Mon Oct 10 05:40:06 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 43574D9A92
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 05:40:04 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 87064-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 08:40:01 +0000 (GMT)
Received: from ar-sd.net (unknown [82.77.155.72])
	by svr1.postgresql.org (Postfix) with ESMTP id B4B9ED7F3F
	for <pgsql-performance@postgresql.org>;
	Mon, 10 Oct 2005 05:40:01 -0300 (ADT)
Received: from localhost (localhost [127.0.0.1])
	by ar-sd.net (Postfix) with ESMTP id 6E4853498E
	for <pgsql-performance@postgresql.org>;
	Mon, 10 Oct 2005 11:24:00 +0300 (EEST)
Received: from ar-sd.net ([127.0.0.1])
	by localhost (linz [127.0.0.1]) (amavisd-new, port 10024) with ESMTP
	id 30889-05 for <pgsql-performance@postgresql.org>;
	Mon, 10 Oct 2005 11:23:59 +0300 (EEST)
Received: from forge (unknown [192.168.0.11])
	by ar-sd.net (Postfix) with SMTP id 539603176B
	for <pgsql-performance@postgresql.org>;
	Mon, 10 Oct 2005 11:23:59 +0300 (EEST)
Message-ID: <006f01c5cd76$2b166490$0b00a8c0@forge>
From: "Andy" <frum@ar-sd.net>
To: <pgsql-performance@postgresql.org>
Subject: Server misconfiguration???
Date: Mon, 10 Oct 2005 11:39:45 +0300
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="----=_NextPart_000_006A_01C5CD8F.4FD95DF0"
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-Virus-Scanned: by amavisd-new at ar-sd.net
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.313 required=5 tests=[AWL=0.235,
	FORGED_RCVD_HELO=0.05, HTML_60_70=0.027, HTML_MESSAGE=0.001]
X-Spam-Level: 
X-Archive-Number: 200510/157
X-Sequence-Number: 14925

This is a multi-part message in MIME format.

------=_NextPart_000_006A_01C5CD8F.4FD95DF0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi to all,=20

I have the following configuration:
Dual Xeon 2.8 Ghz, 1G RAM and postgre 8.0.3 installed.

Modified configuration parameters:

max_connections =3D 100=20

shared_buffers =3D 64000  # 500MB =3D 500 x 1024 x 1024 / (8 x 1024) =
(8KB)
work_mem =3D 51200  # 50MB =3D 50 x 1024 KB
maintenance_work_mem =3D 102400 # 50MB =3D 100 x 1024 KB=20

checkpoint_segments =3D 10

effective_cache_size =3D 25600 # 200MB =3D 50 x 1024 / 8=20

client_min_messages =3D notice=20
log_min_messages =3D notice
log_min_duration_statement =3D 2000



I get the feeling the server is somehow missconfigured or it does not =
work at full parameter. If I look at memory allocation, it never goes =
over 250MB whatever I do with the database. The kernel shmmax is set to =
600MB. Database Size is around 550MB.=20


Need some advise.=20

Thanks.=20
Andy.

------=_NextPart_000_006A_01C5CD8F.4FD95DF0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2900.2722" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi to all, </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I have the following =
configuration:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Dual Xeon 2.8 Ghz, 1G RAM and postgre =
8.0.3=20
installed.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Modified configuration =
parameters:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>max_connections =3D 100 </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>shared_buffers =3D 64000&nbsp;&nbsp;# =
500MB =3D 500 x=20
1024 x 1024 / (8 x 1024) (8KB)<BR>work_mem =3D 51200&nbsp;&nbsp;# 50MB =
=3D 50 x 1024=20
KB<BR>maintenance_work_mem =3D 102400&nbsp;# 50MB =3D 100 x 1024 KB =
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>checkpoint_segments =3D 10</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>effective_cache_size =3D 25600&nbsp;# =
200MB =3D 50 x=20
1024 / 8 </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>client_min_messages =3D =
notice&nbsp;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>log_min_messages =3D =
notice</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>log_min_duration_statement =3D =
2000</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I get the feeling the server is somehow =

missconfigured or it does not work at full parameter. If I look at =
memory=20
allocation, it never goes&nbsp;over 250MB whatever I do with the =
database. The=20
kernel shmmax is set to 600MB. Database Size is around 550MB. =
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Need some advise. </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks. </FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Andy.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_006A_01C5CD8F.4FD95DF0--


From pgsql-performance-owner@postgresql.org  Mon Oct 10 05:55:20 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 0FEE5D9995
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 05:55:19 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 53503-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 08:55:16 +0000 (GMT)
Received: from houston.familyhealth.com.au (houston.au.fhnetwork.com
	[203.22.197.21])
	by svr1.postgresql.org (Postfix) with ESMTP id CA5F1D9B17
	for <pgsql-performance@postgresql.org>;
	Mon, 10 Oct 2005 05:55:16 -0300 (ADT)
Received: from houston.familyhealth.com.au (localhost [127.0.0.1])
	by houston.familyhealth.com.au (Postfix) with ESMTP id 52AFF2505A;
	Mon, 10 Oct 2005 16:55:15 +0800 (WST)
Received: from [127.0.0.1] (work-40.internal [192.168.0.40])
	by houston.familyhealth.com.au (Postfix) with ESMTP id 1FD4A24FF7;
	Mon, 10 Oct 2005 16:55:14 +0800 (WST)
Message-ID: <434A2C8B.3040803@familyhealth.com.au>
Date: Mon, 10 Oct 2005 16:55:39 +0800
From: Christopher Kings-Lynne <chriskl@familyhealth.com.au>
User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: Andy <frum@ar-sd.net>
Cc: pgsql-performance@postgresql.org
Subject: Re: Server misconfiguration???
References: <006f01c5cd76$2b166490$0b00a8c0@forge>
In-Reply-To: <006f01c5cd76$2b166490$0b00a8c0@forge>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-familyhealth-MailScanner-Information: Please contact the ISP for more
	information
X-familyhealth-MailScanner: Found to be clean
X-familyhealth-MailScanner-From: chriskl@familyhealth.com.au
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.061 required=5 tests=[AWL=0.011,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/158
X-Sequence-Number: 14926

A lot of them are too large.  Try:

Andy wrote:
> Hi to all,
>  
> I have the following configuration:
> Dual Xeon 2.8 Ghz, 1G RAM and postgre 8.0.3 installed.
>  
> Modified configuration parameters:
>  
> max_connections = 100
>  
> shared_buffers = 64000  # 500MB = 500 x 1024 x 1024 / (8 x 1024) (8KB)

shared_buffers = 10000

> work_mem = 51200  # 50MB = 50 x 1024 KB

work_mem = 4096

> maintenance_work_mem = 102400 # 50MB = 100 x 1024 KB
>  
> checkpoint_segments = 10
>  
> effective_cache_size = 25600 # 200MB = 50 x 1024 / 8
>  
> client_min_messages = notice 
> log_min_messages = notice
> log_min_duration_statement = 2000
>  
>  
>  
> I get the feeling the server is somehow missconfigured or it does not 
> work at full parameter. If I look at memory allocation, it never 
> goes over 250MB whatever I do with the database. The kernel shmmax is 
> set to 600MB. Database Size is around 550MB.

That's because you have work_mem set massively high.  Remember that's 
PER SORT.  If you have 10 queries running each doing 3 sorts that's 30x 
the work_mem right there.

Chris


From pgsql-performance-owner@postgresql.org  Mon Oct 10 06:43:04 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id B12AED9A62
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 06:43:03 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 14849-10
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 09:43:00 +0000 (GMT)
Received: from ar-sd.net (unknown [82.77.155.72])
	by svr1.postgresql.org (Postfix) with ESMTP id 9AD17D97D5
	for <pgsql-performance@postgresql.org>;
	Mon, 10 Oct 2005 06:43:01 -0300 (ADT)
Received: from localhost (localhost [127.0.0.1])
	by ar-sd.net (Postfix) with ESMTP id F3E8234D76;
	Mon, 10 Oct 2005 12:26:59 +0300 (EEST)
Received: from ar-sd.net ([127.0.0.1])
	by localhost (linz [127.0.0.1]) (amavisd-new, port 10024) with ESMTP
	id 00681-02; Mon, 10 Oct 2005 12:26:57 +0300 (EEST)
Received: from forge (unknown [192.168.0.11])
	by ar-sd.net (Postfix) with SMTP id 32F5B34C4E;
	Mon, 10 Oct 2005 12:26:57 +0300 (EEST)
Message-ID: <00dc01c5cd7e$f6f127a0$0b00a8c0@forge>
From: "Andy" <frum@ar-sd.net>
To: "Christopher Kings-Lynne" <chriskl@familyhealth.com.au>
Cc: <pgsql-performance@postgresql.org>
References: <006f01c5cd76$2b166490$0b00a8c0@forge>
	<434A2C8B.3040803@familyhealth.com.au>
Subject: Re: Server misconfiguration???
Date: Mon, 10 Oct 2005 12:42:43 +0300
MIME-Version: 1.0
Content-Type: text/plain; format=flowed; charset="iso-8859-1";
	reply-type=response
Content-Transfer-Encoding: 7bit
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-Virus-Scanned: by amavisd-new at ar-sd.net
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.276 required=5 tests=[AWL=0.226,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/159
X-Sequence-Number: 14927

Yes you're right it really bosst a little.
I want to improve the system performance. Are there any more tipps?

On this server runs only a webserver with php application which uses postgre 
Db. Should I give more memory to postgre? From what I noticed this is the 
most memory "needing" service from this system.


Andy.

----- Original Message ----- 
From: "Christopher Kings-Lynne" <chriskl@familyhealth.com.au>
To: "Andy" <frum@ar-sd.net>
Cc: <pgsql-performance@postgresql.org>
Sent: Monday, October 10, 2005 11:55 AM
Subject: Re: [PERFORM] Server misconfiguration???


>A lot of them are too large.  Try:
>
> Andy wrote:
>> Hi to all,
>>  I have the following configuration:
>> Dual Xeon 2.8 Ghz, 1G RAM and postgre 8.0.3 installed.
>>  Modified configuration parameters:
>>  max_connections = 100
>>  shared_buffers = 64000  # 500MB = 500 x 1024 x 1024 / (8 x 1024) (8KB)
>
> shared_buffers = 10000
>
>> work_mem = 51200  # 50MB = 50 x 1024 KB
>
> work_mem = 4096
>
>> maintenance_work_mem = 102400 # 50MB = 100 x 1024 KB
>>  checkpoint_segments = 10
>>  effective_cache_size = 25600 # 200MB = 50 x 1024 / 8
>>  client_min_messages = notice log_min_messages = notice
>> log_min_duration_statement = 2000
>>  I get the feeling the server is somehow missconfigured or it does not 
>> work at full parameter. If I look at memory allocation, it never goes 
>> over 250MB whatever I do with the database. The kernel shmmax is set to 
>> 600MB. Database Size is around 550MB.
>
> That's because you have work_mem set massively high.  Remember that's PER 
> SORT.  If you have 10 queries running each doing 3 sorts that's 30x the 
> work_mem right there.
>
> Chris
>
>
> 


From pgsql-performance-owner@postgresql.org  Mon Oct 10 08:24:16 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 82F57D80DD
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 08:24:15 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 18434-04
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 11:24:08 +0000 (GMT)
Received: from ki-communication.com (unknown [202.147.194.21])
	by svr1.postgresql.org (Postfix) with ESMTP id CD928D7F3F
	for <pgsql-performance@postgresql.org>;
	Mon, 10 Oct 2005 08:24:05 -0300 (ADT)
Received: from iacn01wks ([192.168.0.128]) by ki-communication.com with
	Microsoft SMTPSVC(6.0.3790.1830); Mon, 10 Oct 2005 18:28:17 +0700
From: "Ahmad Fajar" <gendowo@konphalindo.or.id>
To: "'Cristian Prieto'" <cristian@clickdiario.com>
Cc: <pgsql-performance@postgresql.org>
Subject: Re: Text/Varchar performance...
Date: Mon, 10 Oct 2005 18:28:23 +0700
Keywords: Postgresql
MIME-Version: 1.0
Content-Type: text/plain;
	charset="US-ASCII"
Content-Transfer-Encoding: 7bit
X-Mailer: Microsoft Office Outlook, Build 11.0.6353
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
Thread-Index: AcXJ2Z4us8IFwjmGTVOiJdhYl6kVMADs2VkQ
In-Reply-To: <20051005182803.0E6B0100E5@mail.clickdiario.com>
Message-ID: <SVONE1yEXUIEAOeIiGX0000000c@ki-communication.com>
X-OriginalArrivalTime: 10 Oct 2005 11:28:17.0968 (UTC)
	FILETIME=[B621D300:01C5CD8D]
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.379 required=5 tests=[AWL=-0.113,
	DNS_FROM_RFC_WHOIS=0.492]
X-Spam-Level: 
X-Archive-Number: 200510/160
X-Sequence-Number: 14928

Dear Cristian,

If you need to index the field, you must know that it limit the length up to
1000 bytes. So if you need to index the field you must limit the field type,
ex: varchar(250), than you can index the field and you can gain better
perfomance in searching base on the fields, because the search uses the
index you have been created.
If you do not need to index the field, you can use the text field. Because
text field can store data up to 4 Gbytes.

Regards,
ahmad fajar

-----Original Message-----
From: pgsql-performance-owner@postgresql.org
[mailto:pgsql-performance-owner@postgresql.org] On Behalf Of Cristian Prieto
Sent: Kamis, 06 Oktober 2005 1:22
To: pgsql-general@postgresql.org; pgsql-performance@postgresql.org
Subject: [PERFORM] Text/Varchar performance...

Hello, just a little question, It's preferable to use Text Fields or
varchar(255) fields in a table? Are there any performance differences in the
use of any of them?

Thanks a lot for your answer!


---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

               http://archives.postgresql.org


From pgsql-performance-owner@postgresql.org  Mon Oct 10 09:19:09 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 74014D80DD
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 09:19:08 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 18910-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 12:19:02 +0000 (GMT)
Received: from ucsns.ucs.co.za (ucsns.ucs.co.za [196.23.43.2])
	by svr1.postgresql.org (Postfix) with ESMTP id 3DADFD9603
	for <pgsql-performance@postgresql.org>;
	Mon, 10 Oct 2005 09:19:04 -0300 (ADT)
Received: from ucspost.ucs.co.za (mailgw1.ucs.co.za [196.23.43.253])
	by ucsns.ucs.co.za (Postfix) with ESMTP id 88D522BE36
	for <pgsql-performance@postgresql.org>;
	Mon, 10 Oct 2005 14:17:22 +0200 (SAST)
Received: from jhb.ucs.co.za (jhb.ucs.co.za [172.31.1.3])
	by ucspost.ucs.co.za (Postfix) with ESMTP id 84A6BD9DF5
	for <pgsql-performance@postgresql.org>;
	Mon, 10 Oct 2005 14:17:22 +0200 (SAST)
Received: from svb.ucs.co.za (svb.ucs.co.za [172.31.1.148])
	by jhb.ucs.co.za (Postfix) with ESMTP id 12DB1977EA
	for <pgsql-performance@postgresql.org>;
	Mon, 10 Oct 2005 14:17:22 +0200 (SAST)
Date: Mon, 10 Oct 2005 14:17:21 +0200
From: Stef <svb@ucs.co.za>
To: pgsql-performance@postgresql.org
Subject: Compression of text columns
Message-ID: <20051010141721.0bebbaa7@svb.ucs.co.za>
X-Mailer: Sylpheed-Claws 1.9.6cvs1 (GTK+ 2.6.10; i486-pc-linux-gnu)
User-Agent: sillypheed-claws (anti-aliased)
X-Face: +lU/o'$=Zv9%Xjo]Kq[_{n&Kb`f{YE<S+T;
	pGztI>WH4&Y#M]'6BkD?VoWe#*@S\MWyD'I>s:0v4{#\[J]l*?]t2uaO(j$d*77Ca-UHo.tkl2)0$B3Jxww\o:xor]<:*Yfx9Vceh)9I/'2g\RKhGTxIIsR^ke^`LVeZ9ksb*:$kQeR@
X-Operating-System: sid
X-X-X: _-^-_
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.145 required=5 tests=[AWL=0.145]
X-Spam-Level: 
X-Archive-Number: 200510/161
X-Sequence-Number: 14929

I have a table in the databases I work with,
that contains two text columns with XML data 
stored inside them.

This table is by far the biggest table in the databases,
and the text columns use up the most space. 
I saw that the default storage type for text columns is
"EXTENDED" which, according to the documentation, uses up extra
space to make possible substring functioning faster. 

Suppose that the data in those columns are only really ever
_used_ once, but may be needed in future for viewing purposes mostly,
and I cannot really change the underlying structure of the table,
what can I possibly do to maximally reduce the amount of disk space
used by the table on disk. (There are no indexes on these two columns.)
I've thought about compression using something like :
ztext http://www.mahalito.net/~harley/sw/postgres/

but I have to change the table structure a lot and I've already 
encountered problems unzipping the data again.
The other problem with this solution, is that database dumps almost double
in size, because of double compression.

Any suggestions much appreciated

TIA 
Stefan 

From pgsql-performance-owner@postgresql.org  Mon Oct 10 09:27:21 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 1CFFBD80DD
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 09:27:21 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 83411-10
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 12:27:16 +0000 (GMT)
Received: from service-web.de (p15093784.pureserver.info [217.160.106.224])
	by svr1.postgresql.org (Postfix) with ESMTP id E090CD7DBE
	for <pgsql-performance@postgresql.org>;
	Mon, 10 Oct 2005 09:27:17 -0300 (ADT)
Received: from [10.100.1.50] (074-016-066-080.eggenet.de [80.66.16.74])
	by service-web.de (Postfix) with ESMTP id C463E200038;
	Mon, 10 Oct 2005 14:27:20 +0200 (CEST)
Message-ID: <434A5E22.9040500@wildenhain.de>
Date: Mon, 10 Oct 2005 14:27:14 +0200
From: Tino Wildenhain <tino@wildenhain.de>
User-Agent: Mozilla Thunderbird 1.0.6 (X11/20050929)
X-Accept-Language: de-DE, de, en-us, en
MIME-Version: 1.0
To: Stef <svb@ucs.co.za>
Cc: pgsql-performance@postgresql.org
Subject: Re: Compression of text columns
References: <20051010141721.0bebbaa7@svb.ucs.co.za>
In-Reply-To: <20051010141721.0bebbaa7@svb.ucs.co.za>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.071 required=5 tests=[AWL=0.021,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/162
X-Sequence-Number: 14930

Stef schrieb:
> I have a table in the databases I work with,
> that contains two text columns with XML data 
> stored inside them.
> 
> This table is by far the biggest table in the databases,
> and the text columns use up the most space. 
> I saw that the default storage type for text columns is
> "EXTENDED" which, according to the documentation, uses up extra
> space to make possible substring functioning faster. 
> 
> Suppose that the data in those columns are only really ever
> _used_ once, but may be needed in future for viewing purposes mostly,
> and I cannot really change the underlying structure of the table,
> what can I possibly do to maximally reduce the amount of disk space
> used by the table on disk. (There are no indexes on these two columns.)
> I've thought about compression using something like :
> ztext http://www.mahalito.net/~harley/sw/postgres/
> 
> but I have to change the table structure a lot and I've already 
> encountered problems unzipping the data again.
> The other problem with this solution, is that database dumps almost double
> in size, because of double compression.
> 
> Any suggestions much appreciated

Well, text columns are automatically compressed via the toast mechanism.
This is handled transparently for you.


From pgsql-performance-owner@postgresql.org  Mon Oct 10 09:54:29 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 608C8D7ECA
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 09:54:28 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 10777-07
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 12:54:21 +0000 (GMT)
Received: from cassarossa.samfundet.no (cassarossa.samfundet.no
	[129.241.93.19])
	by svr1.postgresql.org (Postfix) with ESMTP id 3366FD9B26
	for <pgsql-performance@postgresql.org>;
	Mon, 10 Oct 2005 09:54:22 -0300 (ADT)
Received: from trofast.sesse.net ([129.241.93.32])
	by cassarossa.samfundet.no with esmtp (Exim 4.50) id 1EOxAe-0001WH-F1
	for pgsql-performance@postgresql.org; Mon, 10 Oct 2005 14:54:25 +0200
Received: from sesse by trofast.sesse.net with local (Exim 3.36 #1 (Debian))
	id 1EOxAc-00020M-00
	for <pgsql-performance@postgresql.org>; Mon, 10 Oct 2005 14:54:22 +0200
Date: Mon, 10 Oct 2005 14:54:22 +0200
From: "Steinar H. Gunderson" <sgunderson@bigfoot.com>
To: pgsql-performance@postgresql.org
Subject: Re: Text/Varchar performance...
Message-ID: <20051010125422.GA7454@uio.no>
Mail-Followup-To: pgsql-performance@postgresql.org
References: <20051005182803.0E6B0100E5@mail.clickdiario.com>
	<SVONE1yEXUIEAOeIiGX0000000c@ki-communication.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
In-Reply-To: <SVONE1yEXUIEAOeIiGX0000000c@ki-communication.com>
X-Operating-System: Linux 2.6.11.8 on a i686
X-Message-Flag: Outlook? --> http://www.mozilla.org/products/thunderbird/
User-Agent: Mutt/1.5.11
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.012 required=5 tests=[AWL=0.012]
X-Spam-Level: 
X-Archive-Number: 200510/163
X-Sequence-Number: 14931

On Mon, Oct 10, 2005 at 06:28:23PM +0700, Ahmad Fajar wrote:
> than you can index the field and you can gain better
> perfomance in searching base on the fields, because the search uses the
> index you have been created.

That really depends on the queries. An index will help some queries (notably
<, = or > comparisons, or LIKE 'foo%' with the C locale), but definitely not
all (it will help you nothing for LIKE '%foo%').

> If you do not need to index the field, you can use the text field. Because
> text field can store data up to 4 Gbytes.

So can varchar.

/* Steinar */
-- 
Homepage: http://www.sesse.net/

From pgsql-performance-owner@postgresql.org  Mon Oct 10 09:57:02 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 4C9BCD90E3
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 09:57:01 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 43057-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 12:56:56 +0000 (GMT)
Received: from ucsns.ucs.co.za (ucsns.ucs.co.za [196.23.43.2])
	by svr1.postgresql.org (Postfix) with ESMTP id 606B4D8D8D
	for <pgsql-performance@postgresql.org>;
	Mon, 10 Oct 2005 09:56:58 -0300 (ADT)
Received: from ucspost.ucs.co.za (mailgw1.ucs.co.za [196.23.43.253])
	by ucsns.ucs.co.za (Postfix) with ESMTP id DE5242BD6B;
	Mon, 10 Oct 2005 14:57:01 +0200 (SAST)
Received: from jhb.ucs.co.za (jhb.ucs.co.za [172.31.1.3])
	by ucspost.ucs.co.za (Postfix) with ESMTP id E637CD9DF4;
	Mon, 10 Oct 2005 14:57:01 +0200 (SAST)
Received: from svb.ucs.co.za (svb.ucs.co.za [172.31.1.148])
	by jhb.ucs.co.za (Postfix) with ESMTP id 153DE977D8;
	Mon, 10 Oct 2005 14:57:01 +0200 (SAST)
Date: Mon, 10 Oct 2005 14:57:00 +0200
From: Stef <svb@ucs.co.za>
To: Tino Wildenhain <tino@wildenhain.de>
Cc: pgsql-performance@postgresql.org
Subject: Re: Compression of text columns
Message-ID: <20051010145700.586dc488@svb.ucs.co.za>
In-Reply-To: <434A5E22.9040500@wildenhain.de>
References: <20051010141721.0bebbaa7@svb.ucs.co.za>
	<434A5E22.9040500@wildenhain.de>
X-Mailer: Sylpheed-Claws 1.9.6cvs1 (GTK+ 2.6.10; i486-pc-linux-gnu)
User-Agent: sillypheed-claws (anti-aliased)
X-Face: +lU/o'$=Zv9%Xjo]Kq[_{n&Kb`f{YE<S+T;
	pGztI>WH4&Y#M]'6BkD?VoWe#*@S\MWyD'I>s:0v4{#\[J]l*?]t2uaO(j$d*77Ca-UHo.tkl2)0$B3Jxww\o:xor]<:*Yfx9Vceh)9I/'2g\RKhGTxIIsR^ke^`LVeZ9ksb*:$kQeR@
X-Operating-System: sid
X-X-X: _-^-_
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.133 required=5 tests=[AWL=0.133]
X-Spam-Level: 
X-Archive-Number: 200510/164
X-Sequence-Number: 14932

Tino Wildenhain mentioned :
=> Well, text columns are automatically compressed via the toast mechanism.
=> This is handled transparently for you.

OK, I misread the documentation, and I forgot to mention that
I'm using postgres 7.3 and 8.0
It's actually the EXTERNAL storage type that is larger, not EXTENDED. 
What kind of compression is used in the EXTERNAL storage type?
Is there any way to achieve better compression?

From pgsql-performance-owner@postgresql.org  Mon Oct 10 10:27:09 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id ECF2BD8C85
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 10:27:07 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 31632-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 13:27:01 +0000 (GMT)
Received: from liveye.net (host15-195-149-62.serverdedicati.aruba.it
	[62.149.195.15])
	by svr1.postgresql.org (Postfix) with ESMTP id 678C6D9A51
	for <pgsql-performance@postgresql.org>;
	Mon, 10 Oct 2005 10:27:02 -0300 (ADT)
Received: from [192.168.1.33] by liveye.net (MDaemon.PRO.v7.2.3.R)
	with ESMTP id md50000031925.msg
	for <pgsql-performance@postgresql.org>; Mon, 10 Oct 2005 15:27:03 +0200
Message-ID: <434A6C2D.9070207@liveye.net>
Date: Mon, 10 Oct 2005 15:27:09 +0200
From: "Federico Simonetti (Liveye)" <federico@liveye.net>
User-Agent: Mozilla Thunderbird 1.0.7 (Windows/20050923)
X-Accept-Language: it, it-it, en-us, en
MIME-Version: 1.0
To: pgsql-performance@postgresql.org
Subject: Query performance on ILIKE with AND operator...
X-Enigmail-Version: 0.93.0.0
Content-Type: text/plain; charset=ISO-8859-15
Content-Transfer-Encoding: 7bit
X-Authenticated-Sender: federico@liveye.net
X-Spam-Processed: liveye.net, Mon, 10 Oct 2005 15:27:03 +0200
	(not processed: spam filter disabled)
X-MDRemoteIP: 213.140.22.64
X-Return-Path: federico@liveye.net
X-MDaemon-Deliver-To: pgsql-performance@postgresql.org
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.05 required=5 tests=[FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/165
X-Sequence-Number: 14933

Hello all,

I'm encountering a quite strange performance problem. Look at the
following two queries and their execution times. The only difference is
the first query has OR operator and the second query has AND operator.
Any ideas?

Thank you in advance,
Federico


[FIRST QUERY: EXEC TIME 0.015 SECS]

    explain analyze SELECT * FROM ViewHttp
    WHERE txContentType ilike '%html%' OR vchost ilike '%www.%'
    ORDER BY iDStart DESC, iS_ID DESC, iF_ID DESC, iSubID DESC
    OFFSET 0 LIMIT 201

"Limit  (cost=12.75..3736.66 rows=201 width=1250) (actual
time=0.000..15.000 rows=201 loops=1)"
"  ->  Nested Loop  (cost=12.75..1996879.04 rows=107782 width=1250)
(actual time=0.000..15.000 rows=201 loops=1)"
"        ->  Nested Loop  (cost=12.75..1524883.03 rows=6334 width=1106)
(actual time=0.000..15.000 rows=201 loops=1)"
"              Join Filter: ("outer".isensorid = "inner".isensorid)"
"              ->  Index Scan Backward using idx_0009_ord4 on
detail0009  (cost=0.00..1489241.53 rows=6334 width=1005) (actual
time=0.000..15.000 rows=201 loops=1)"
"                    Filter: ((txcontenttype ~~* '%html%'::text) OR
((vchost)::text ~~* '%www.%'::text))"
"              ->  Materialize  (cost=12.75..15.25 rows=250 width=101)
(actual time=0.000..0.000 rows=1 loops=201)"
"                    ->  Seq Scan on sensors  (cost=0.00..12.50 rows=250
width=101) (actual time=0.000..0.000 rows=1 loops=1)"
"        ->  Index Scan using connections_pkey on connections 
(cost=0.00..74.25 rows=18 width=168) (actual time=0.000..0.000 rows=1
loops=201)"
"              Index Cond: (("outer".is_id = connections.is_id) AND
("outer".if_id = connections.if_id))"
"Total runtime: 15.000 ms"




[SECOND QUERY: EXEC TIME 13.844 SECS]

    explain analyze SELECT * FROM ViewHttp
    WHERE txContentType ilike '%html%' AND vchost ilike '%www.%'
    ORDER BY iDStart DESC, iS_ID DESC, iF_ID DESC, iSubID DESC
    OFFSET 0 LIMIT 201

"Limit  (cost=22476.81..22477.31 rows=201 width=1250) (actual
time=13187.000..13187.000 rows=201 loops=1)"
"  ->  Sort  (cost=22476.81..22477.92 rows=443 width=1250) (actual
time=13187.000..13187.000 rows=201 loops=1)"
"        Sort Key: detail0009.idstart, detail0009.isensorid,
detail0009.iforensicid, detail0009.isubid"
"        ->  Hash Join  (cost=13.13..22457.34 rows=443 width=1250)
(actual time=469.000..10966.000 rows=53559 loops=1)"
"              Hash Cond: ("outer".isensorid = "inner".isensorid)"
"              ->  Nested Loop  (cost=0.00..22437.57 rows=443
width=1165) (actual time=469.000..10201.000 rows=53559 loops=1)"
"                    ->  Seq Scan on detail0009  (cost=0.00..20500.11
rows=26 width=1005) (actual time=453.000..5983.000 rows=53588 loops=1)"
"                          Filter: ((txcontenttype ~~* '%html%'::text)
AND ((vchost)::text ~~* '%www.%'::text))"
"                    ->  Index Scan using connections_pkey on
connections  (cost=0.00..74.25 rows=18 width=168) (actual
time=0.063..0.065 rows=1 loops=53588)"
"                          Index Cond: (("outer".isensorid =
connections.isensorid) AND ("outer".iforensicid = connections.iforensicid))"
"              ->  Hash  (cost=12.50..12.50 rows=250 width=101) (actual
time=0.000..0.000 rows=0 loops=1)"
"                    ->  Seq Scan on sensors  (cost=0.00..12.50 rows=250
width=101) (actual time=0.000..0.000 rows=1 loops=1)"
"Total runtime: 13844.000 ms"



From pgsql-performance-owner@postgresql.org  Mon Oct 10 11:19:07 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id E702BD8CEC
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 11:19:05 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 33618-09
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 14:18:55 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id C4B5ED9CA8
	for <pgsql-performance@postgresql.org>;
	Mon, 10 Oct 2005 11:18:57 -0300 (ADT)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j9AEIj8N020488;
	Mon, 10 Oct 2005 10:18:45 -0400 (EDT)
To: "Andy" <frum@ar-sd.net>
Cc: pgsql-performance@postgresql.org
Subject: Re: Server misconfiguration??? 
In-reply-to: <006f01c5cd76$2b166490$0b00a8c0@forge> 
References: <006f01c5cd76$2b166490$0b00a8c0@forge>
Comments: In-reply-to "Andy" <frum@ar-sd.net>
	message dated "Mon, 10 Oct 2005 11:39:45 +0300"
Date: Mon, 10 Oct 2005 10:18:45 -0400
Message-ID: <20487.1128953925@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/166
X-Sequence-Number: 14934

"Andy" <frum@ar-sd.net> writes:
> I get the feeling the server is somehow missconfigured or it does not
> work at full parameter. If I look at memory allocation, it never goes
> over 250MB whatever I do with the database.

That is not wrong.  Postgres expects the kernel to be doing disk
caching, so the amount of memory that's effectively being used for
database work includes not only what is shown as belonging to the
PG processes, but some portion of the kernel disk buffers as well.
You don't really *want* the processes eating all of available RAM.

I concur with Chris K-L's comments that you should reduce rather
than increase your settings.

			regards, tom lane

From pgsql-performance-owner@postgresql.org  Mon Oct 10 11:31:33 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 0800CD9D07
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 11:31:32 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 52575-09
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 14:31:23 +0000 (GMT)
Received: from ar-sd.net (unknown [82.77.155.72])
	by svr1.postgresql.org (Postfix) with ESMTP id 036BAD9C62
	for <pgsql-performance@postgresql.org>;
	Mon, 10 Oct 2005 11:31:26 -0300 (ADT)
Received: from localhost (localhost [127.0.0.1])
	by ar-sd.net (Postfix) with ESMTP id 4ED4CE6A5;
	Mon, 10 Oct 2005 17:15:26 +0300 (EEST)
Received: from ar-sd.net ([127.0.0.1])
	by localhost (linz [127.0.0.1]) (amavisd-new, port 10024) with ESMTP
	id 02547-09; Mon, 10 Oct 2005 17:15:24 +0300 (EEST)
Received: from forge (unknown [192.168.0.11])
	by ar-sd.net (Postfix) with SMTP id 4F94FE442;
	Mon, 10 Oct 2005 17:15:24 +0300 (EEST)
Message-ID: <001201c5cda7$4314b430$0b00a8c0@forge>
From: "Andy" <frum@ar-sd.net>
To: "Tom Lane" <tgl@sss.pgh.pa.us>
Cc: <pgsql-performance@postgresql.org>
References: <006f01c5cd76$2b166490$0b00a8c0@forge>
	<20487.1128953925@sss.pgh.pa.us>
Subject: Re: Server misconfiguration??? 
Date: Mon, 10 Oct 2005 17:31:10 +0300
MIME-Version: 1.0
Content-Type: text/plain; format=flowed; charset="iso-8859-1";
	reply-type=original
Content-Transfer-Encoding: 7bit
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-Virus-Scanned: by amavisd-new at ar-sd.net
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.257 required=5 tests=[AWL=0.207,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/167
X-Sequence-Number: 14935

When I ment memory allocation, I look with htop to see the process list, CPU 
load, memory, swap. So I didn't ment the a postgre process uses that amount 
of memory.

I read some tuning things, I made the things that are written there, but I 
think that there improvements can be made.

regards,
Andy.

----- Original Message ----- 
From: "Tom Lane" <tgl@sss.pgh.pa.us>
To: "Andy" <frum@ar-sd.net>
Cc: <pgsql-performance@postgresql.org>
Sent: Monday, October 10, 2005 5:18 PM
Subject: Re: [PERFORM] Server misconfiguration???


> "Andy" <frum@ar-sd.net> writes:
>> I get the feeling the server is somehow missconfigured or it does not
>> work at full parameter. If I look at memory allocation, it never goes
>> over 250MB whatever I do with the database.
>
> That is not wrong.  Postgres expects the kernel to be doing disk
> caching, so the amount of memory that's effectively being used for
> database work includes not only what is shown as belonging to the
> PG processes, but some portion of the kernel disk buffers as well.
> You don't really *want* the processes eating all of available RAM.
>
> I concur with Chris K-L's comments that you should reduce rather
> than increase your settings.
>
> regards, tom lane
>
> 


From pgsql-performance-owner@postgresql.org  Mon Oct 10 11:39:52 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 4A27FD99D6
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 11:38:11 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 67084-04
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 14:38:01 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id 1C836D9C82
	for <pgsql-performance@postgresql.org>;
	Mon, 10 Oct 2005 11:38:03 -0300 (ADT)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j9AEc8sk020647;
	Mon, 10 Oct 2005 10:38:08 -0400 (EDT)
To: Stef <svb@ucs.co.za>
Cc: pgsql-performance@postgresql.org
Subject: Re: Compression of text columns 
In-reply-to: <20051010141721.0bebbaa7@svb.ucs.co.za> 
References: <20051010141721.0bebbaa7@svb.ucs.co.za>
Comments: In-reply-to Stef <svb@ucs.co.za>
	message dated "Mon, 10 Oct 2005 14:17:21 +0200"
Date: Mon, 10 Oct 2005 10:38:08 -0400
Message-ID: <20646.1128955088@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/168
X-Sequence-Number: 14936

Stef <svb@ucs.co.za> writes:
> I saw that the default storage type for text columns is
> "EXTENDED" which, according to the documentation, uses up extra
> space to make possible substring functioning faster. 

You misread it.  EXTENDED does compression by default on long strings.
EXTERNAL is the one that suppresses compression.

			regards, tom lane

From pgsql-performance-owner@postgresql.org  Mon Oct 10 11:56:53 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id A6606D9E16
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 11:56:51 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 23346-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 14:56:31 +0000 (GMT)
Received: from vscan01.westnet.com.au (vscan01.westnet.com.au [203.10.1.131])
	by svr1.postgresql.org (Postfix) with ESMTP id 7668BD9E0E
	for <pgsql-performance@postgresql.org>;
	Mon, 10 Oct 2005 11:56:33 -0300 (ADT)
Received: from localhost (localhost.localdomain [127.0.0.1])
	by localhost (Postfix) with ESMTP id 40BEE76085E;
	Mon, 10 Oct 2005 22:56:39 +0800 (WST)
Received: from vscan01.westnet.com.au ([127.0.0.1])
	by localhost (vscan01.westnet.com.au [127.0.0.1]) (amavisd-new,
	port 10024)
	with ESMTP id 14678-20; Mon, 10 Oct 2005 22:56:39 +0800 (WST)
Received: from [202.72.133.22] (dsl-202-72-133-22.wa.westnet.com.au
	[202.72.133.22])
	by vscan01.westnet.com.au (Postfix) with ESMTP id D0AB27607ED;
	Mon, 10 Oct 2005 22:56:38 +0800 (WST)
Message-ID: <434A8129.30308@familyhealth.com.au>
Date: Mon, 10 Oct 2005 22:56:41 +0800
From: Christopher Kings-Lynne <chriskl@familyhealth.com.au>
User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: Andy <frum@ar-sd.net>
Cc: pgsql-performance@postgresql.org
Subject: Re: Server misconfiguration???
References: <006f01c5cd76$2b166490$0b00a8c0@forge>
	<434A2C8B.3040803@familyhealth.com.au>
	<00dc01c5cd7e$f6f127a0$0b00a8c0@forge>
In-Reply-To: <00dc01c5cd7e$f6f127a0$0b00a8c0@forge>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.009 required=5 tests=[AWL=0.009]
X-Spam-Level: 
X-Archive-Number: 200510/169
X-Sequence-Number: 14937

> Yes you're right it really bosst a little.
> I want to improve the system performance. Are there any more tipps?

The rest of the numbers look vaguely ok...

> On this server runs only a webserver with php application which uses 
> postgre Db. Should I give more memory to postgre? From what I noticed 
> this is the most memory "needing" service from this system.

The best thing you can do is use two servers so that pgsql does not 
compete with web server for RAM...  Personally I'd start looking at my 
queries themselves next, see where I could optimise them.

Chris

From pgsql-performance-owner@postgresql.org  Mon Oct 10 11:58:20 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id C7FBAD90E3
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 11:58:18 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 09183-10
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 14:58:12 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id 61A66D905E
	for <pgsql-performance@postgresql.org>;
	Mon, 10 Oct 2005 11:58:14 -0300 (ADT)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j9AEwF6x020805;
	Mon, 10 Oct 2005 10:58:16 -0400 (EDT)
To: "Federico Simonetti (Liveye)" <federico@liveye.net>
Cc: pgsql-performance@postgresql.org
Subject: Re: Query performance on ILIKE with AND operator... 
In-reply-to: <434A6C2D.9070207@liveye.net> 
References: <434A6C2D.9070207@liveye.net>
Comments: In-reply-to "Federico Simonetti (Liveye)" <federico@liveye.net>
	message dated "Mon, 10 Oct 2005 15:27:09 +0200"
Date: Mon, 10 Oct 2005 10:58:15 -0400
Message-ID: <20804.1128956295@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/170
X-Sequence-Number: 14938

"Federico Simonetti (Liveye)" <federico@liveye.net> writes:
> I'm encountering a quite strange performance problem.

The problem stems from the horrid misestimation of the number of rows
fetched from detail0009:

> "                    ->  Seq Scan on detail0009  (cost=0.00..20500.11
> rows=26 width=1005) (actual time=453.000..5983.000 rows=53588 loops=1)"
> "                          Filter: ((txcontenttype ~~* '%html%'::text)
> AND ((vchost)::text ~~* '%www.%'::text))"

When the planner is off by a factor of two thousand about the number of
rows involved, it's not very likely to produce a good plan :-(

In the OR case the rowcount estimate is 6334, which is somewhat closer
to reality (only about a factor of 10 off, looks like), and that changes
the plan to something that works acceptably well.

Assuming that this is web-log data, the prevalence of www and html
together is hardly surprising, but PG's statistical mechanisms will
never realize it.  Not sure about a good workaround.  Does it make
sense to combine the two conditions into one?
	(vchost || txcontenttype) ilike '%www.%html%'

			regards, tom lane

From pgsql-performance-owner@postgresql.org  Mon Oct 10 12:17:59 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 61CA5D85EA
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 12:17:58 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 66226-06
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 15:17:56 +0000 (GMT)
Received: from liveye.net (host15-195-149-62.serverdedicati.aruba.it
	[62.149.195.15])
	by svr1.postgresql.org (Postfix) with ESMTP id B1B26D79CF
	for <pgsql-performance@postgresql.org>;
	Mon, 10 Oct 2005 12:17:55 -0300 (ADT)
Received: from [192.168.1.33] by liveye.net (MDaemon.PRO.v7.2.3.R)
	with ESMTP id md50000031988.msg
	for <pgsql-performance@postgresql.org>; Mon, 10 Oct 2005 17:17:55 +0200
Message-ID: <434A862C.9010701@liveye.net>
Date: Mon, 10 Oct 2005 17:18:04 +0200
From: "Federico Simonetti (Liveye)" <federico@liveye.net>
User-Agent: Mozilla Thunderbird 1.0.7 (Windows/20050923)
X-Accept-Language: it, it-it, en-us, en
MIME-Version: 1.0
To: pgsql-performance@postgresql.org
Subject: Re: Query performance on ILIKE with AND operator...
References: <434A6C2D.9070207@liveye.net> <20804.1128956295@sss.pgh.pa.us>
In-Reply-To: <20804.1128956295@sss.pgh.pa.us>
X-Enigmail-Version: 0.93.0.0
Content-Type: multipart/alternative;
	boundary="------------070904090901040505090904"
X-Authenticated-Sender: federico@liveye.net
X-Spam-Processed: liveye.net, Mon, 10 Oct 2005 17:17:55 +0200
	(not processed: spam filter disabled)
X-MDRemoteIP: 213.140.22.64
X-Return-Path: federico@liveye.net
X-MDaemon-Deliver-To: pgsql-performance@postgresql.org
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.303 required=5 tests=[AWL=-0.253,
	FORGED_RCVD_HELO=0.05, HTML_20_30=0.504, HTML_MESSAGE=0.001]
X-Spam-Level: 
X-Archive-Number: 200510/171
X-Sequence-Number: 14939

This is a multi-part message in MIME format.
--------------070904090901040505090904
Content-Type: text/plain; charset=ISO-8859-15
Content-Transfer-Encoding: 7bit

Sorry but this does not seem to improve performance, it takes even more
time, have a look at these data:

explain analyze SELECT * FROM ViewHttp
WHERE (vchost || txcontenttype) ilike '%www.%html%'
ORDER BY iDStart DESC, iSensorID DESC, iForensicID DESC, iSubID DESC
OFFSET 0 LIMIT 201


"Limit  (cost=22740.77..22741.28 rows=201 width=1250) (actual
time=14234.000..14234.000 rows=201 loops=1)"
"  ->  Sort  (cost=22740.77..22741.89 rows=447 width=1250) (actual
time=14234.000..14234.000 rows=201 loops=1)"
"        Sort Key: detail0009.idstart, detail0009.isensorid,
detail0009.iforensicid, detail0009.isubid"
"        ->  Hash Join  (cost=13.13..22721.10 rows=447 width=1250)
(actual time=469.000..12140.000 rows=54035 loops=1)"
"              Hash Cond: ("outer".isensorid = "inner".isensorid)"
"              ->  Nested Loop  (cost=0.00..22701.27 rows=447
width=1165) (actual time=469.000..11428.000 rows=54035 loops=1)"
"                    ->  Seq Scan on detail0009  (cost=0.00..20763.77
rows=26 width=1005) (actual time=453.000..6345.000 rows=54064 loops=1)"
"                          Filter: (((vchost)::text || txcontenttype)
~~* '%www.%html%'::text)"
"                    ->  Index Scan using connections_pkey on
connections  (cost=0.00..74.25 rows=18 width=168) (actual
time=0.073..0.077 rows=1 loops=54064)"
"                          Index Cond: (("outer".isensorid =
connections.isensorid) AND ("outer".iforensicid = connections.iforensicid))"
"              ->  Hash  (cost=12.50..12.50 rows=250 width=101) (actual
time=0.000..0.000 rows=0 loops=1)"
"                    ->  Seq Scan on sensors  (cost=0.00..12.50 rows=250
width=101) (actual time=0.000..0.000 rows=1 loops=1)"
"Total runtime: 14234.000 ms"


Thanks for your help anyway...

Federico






Tom Lane ha scritto:

>"Federico Simonetti (Liveye)" <federico@liveye.net> writes:
>  
>
>>I'm encountering a quite strange performance problem.
>>    
>>
>
>The problem stems from the horrid misestimation of the number of rows
>fetched from detail0009:
>
>  
>
>>"                    ->  Seq Scan on detail0009  (cost=0.00..20500.11
>>rows=26 width=1005) (actual time=453.000..5983.000 rows=53588 loops=1)"
>>"                          Filter: ((txcontenttype ~~* '%html%'::text)
>>AND ((vchost)::text ~~* '%www.%'::text))"
>>    
>>
>
>When the planner is off by a factor of two thousand about the number of
>rows involved, it's not very likely to produce a good plan :-(
>
>In the OR case the rowcount estimate is 6334, which is somewhat closer
>to reality (only about a factor of 10 off, looks like), and that changes
>the plan to something that works acceptably well.
>
>Assuming that this is web-log data, the prevalence of www and html
>together is hardly surprising, but PG's statistical mechanisms will
>never realize it.  Not sure about a good workaround.  Does it make
>sense to combine the two conditions into one?
>	(vchost || txcontenttype) ilike '%www.%html%'
>
>			regards, tom lane
>
>---------------------------(end of broadcast)---------------------------
>TIP 6: explain analyze is your friend
>
>
>  
>

--------------070904090901040505090904
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-15"
 http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Sorry but this does not seem to improve performance, it takes even more
time, have a look at these data:<br>
<br>
explain analyze SELECT * FROM ViewHttp<br>
WHERE (vchost || txcontenttype) ilike '%www.%html%'<br>
ORDER BY iDStart DESC, iSensorID DESC, iForensicID DESC, iSubID DESC <br>
OFFSET 0 LIMIT 201<br>
<br>
<br>
"Limit� (cost=22740.77..22741.28 rows=201 width=1250) (actual
time=14234.000..14234.000 rows=201 loops=1)"<br>
"� -&gt;� Sort� (cost=22740.77..22741.89 rows=447 width=1250) (actual
time=14234.000..14234.000 rows=201 loops=1)"<br>
"������� Sort Key: detail0009.idstart, detail0009.isensorid,
detail0009.iforensicid, detail0009.isubid"<br>
"������� -&gt;� Hash Join� (cost=13.13..22721.10 rows=447 width=1250)
(actual time=469.000..12140.000 rows=54035 loops=1)"<br>
"������������� Hash Cond: ("outer".isensorid = "inner".isensorid)"<br>
"������������� -&gt;� Nested Loop� (cost=0.00..22701.27 rows=447
width=1165) (actual time=469.000..11428.000 rows=54035 loops=1)"<br>
"������������������� -&gt;� Seq Scan on detail0009�
(cost=0.00..20763.77 rows=26 width=1005) (actual time=453.000..6345.000
rows=54064 loops=1)"<br>
"������������������������� Filter: (((vchost)::text || txcontenttype)
~~* '%www.%html%'::text)"<br>
"������������������� -&gt;� Index Scan using connections_pkey on
connections� (cost=0.00..74.25 rows=18 width=168) (actual
time=0.073..0.077 rows=1 loops=54064)"<br>
"������������������������� Index Cond: (("outer".isensorid =
connections.isensorid) AND ("outer".iforensicid =
connections.iforensicid))"<br>
"������������� -&gt;� Hash� (cost=12.50..12.50 rows=250 width=101)
(actual time=0.000..0.000 rows=0 loops=1)"<br>
"������������������� -&gt;� Seq Scan on sensors� (cost=0.00..12.50
rows=250 width=101) (actual time=0.000..0.000 rows=1 loops=1)"<br>
"Total runtime: 14234.000 ms"<br>
<br>
<br>
Thanks for your help anyway...<br>
<br>
Federico<br>
<br>
<br>
<br>
<br>
<br>
<br>
Tom Lane ha scritto:
<blockquote cite="mid20804.1128956295@sss.pgh.pa.us" type="cite">
  <pre wrap="">"Federico Simonetti (Liveye)" <a class="moz-txt-link-rfc2396E" href="mailto:federico@liveye.net">&lt;federico@liveye.net&gt;</a> writes:
  </pre>
  <blockquote type="cite">
    <pre wrap="">I'm encountering a quite strange performance problem.
    </pre>
  </blockquote>
  <pre wrap=""><!---->
The problem stems from the horrid misestimation of the number of rows
fetched from detail0009:

  </pre>
  <blockquote type="cite">
    <pre wrap="">"                    -&gt;  Seq Scan on detail0009  (cost=0.00..20500.11
rows=26 width=1005) (actual time=453.000..5983.000 rows=53588 loops=1)"
<a class="moz-txt-link-rfc2396E" href="Filter:((txcontenttype~~*'%html%'::text)AND((vchost)::text~~*'%www.%'::text))">"                          Filter: ((txcontenttype ~~* '%html%'::text)
AND ((vchost)::text ~~* '%www.%'::text))"</a>
    </pre>
  </blockquote>
  <pre wrap=""><!---->
When the planner is off by a factor of two thousand about the number of
rows involved, it's not very likely to produce a good plan :-(

In the OR case the rowcount estimate is 6334, which is somewhat closer
to reality (only about a factor of 10 off, looks like), and that changes
the plan to something that works acceptably well.

Assuming that this is web-log data, the prevalence of www and html
together is hardly surprising, but PG's statistical mechanisms will
never realize it.  Not sure about a good workaround.  Does it make
sense to combine the two conditions into one?
	(vchost || txcontenttype) ilike '%www.%html%'

			regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend


  </pre>
</blockquote>
</body>
</html>

--------------070904090901040505090904--


From pgsql-performance-owner@postgresql.org  Mon Oct 10 18:29:45 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 26EA2D9062
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 18:29:40 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 33110-04
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 21:29:36 +0000 (GMT)
Received: from mail1.npci.com (mail.npcinternational.com [63.76.154.140])
	by svr1.postgresql.org (Postfix) with ESMTP id E620CD9F38
	for <pgsql-performance@postgresql.org>;
	Mon, 10 Oct 2005 18:29:37 -0300 (ADT)
Received: from [172.16.10.91] ([172.16.10.91]) by mail1.npci.com (MOS
 3.5.9-GR)
	with ESMTP id BTW00223 (AUTH via LOGINBEFORESMTP);
	Mon, 10 Oct 2005 16:24:12 -0500 (CDT)
Message-ID: <434ADD46.5060206@npcinternational.com>
Date: Mon, 10 Oct 2005 16:29:42 -0500
From: Jon Brisbin <jon.brisbin@npcinternational.com>
User-Agent: Mozilla Thunderbird 1.0.5 (Windows/20050711)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: pgsql-performance@postgresql.org
Subject: Performance on SUSE w/ reiserfs
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.537 required=5 tests=[AWL=0.487,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/172
X-Sequence-Number: 14940

I have a SUSE 9 box that is running Postgres 8.0.1 compiled from source. 
Over time, I see the memory usage of the box go way way up (it's got 
8GBs in it and by the end of the day, it'll be all used up) with what 
looks like cached inodes relating to the extreme IO generated by 
postgres. We replicate about 10GBs of data every day from our AS/400 
into postgres, and it is the main database for our intranet portal, 
which will server 40,000 pages on a good day.

I was wondering if there is something I'm doing wrong with my default 
settings of postgres that is keeping all that stuff cached, or if I just 
need to switch to XFS or if there is some setting in postgres that I can 
tweak that will make this problem go away. It's gone beyond an annoyance 
and is now into the realm of getting me in trouble if I can't keep this 
DB server up and running. Even a minute or two of downtime in a restart 
is often too much.

Any help you can give in this would be extrememly helpful as I'm very 
far from an expert on Linux filesystems and postgres tuning.

Thanks!

-- 

Jon Brisbin
Webmaster
NPC International, Inc.

From pgsql-performance-owner@postgresql.org  Mon Oct 10 18:45:45 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 9C2AFD9062
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 18:45:43 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 73001-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 21:45:40 +0000 (GMT)
Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.197])
	by svr1.postgresql.org (Postfix) with ESMTP id 885C1D9E34
	for <pgsql-performance@postgresql.org>;
	Mon, 10 Oct 2005 18:45:41 -0300 (ADT)
Received: by wproxy.gmail.com with SMTP id 71so141786wra
	for <pgsql-performance@postgresql.org>;
	Mon, 10 Oct 2005 14:45:44 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references;
	b=EDgS4tv4bdHqDE1+iE9WA3bNWioYZQms8H/4q9gDQE5GVPUXqOWoFh6NO3u94hsedfKJa8KfV3zvk7iK5nMsUXWc/l/IxWGdd98TBJ6rYZ/wgq0RG0HzW33uAf3iK/s0SQSvZgDFfrKqMSF4iMvLHAy8UEocQfN4dfaNtZ2IIa0=
Received: by 10.54.71.5 with SMTP id t5mr3358784wra;
	Mon, 10 Oct 2005 14:45:44 -0700 (PDT)
Received: by 10.54.144.4 with HTTP; Mon, 10 Oct 2005 14:45:44 -0700 (PDT)
Message-ID: <b41c75520510101445jd8a9f06k@mail.gmail.com>
Date: Mon, 10 Oct 2005 23:45:44 +0200
From: Claus Guttesen <kometen@gmail.com>
To: Jon Brisbin <jon.brisbin@npcinternational.com>
Subject: Re: Performance on SUSE w/ reiserfs
Cc: pgsql-performance@postgresql.org
In-Reply-To: <434ADD46.5060206@npcinternational.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
References: <434ADD46.5060206@npcinternational.com>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.024 required=5 tests=[AWL=-0.000, RCVD_BY_IP=0.024]
X-Spam-Level: 
X-Archive-Number: 200510/173
X-Sequence-Number: 14941

> I have a SUSE 9 box that is running Postgres 8.0.1 compiled from source.
> Over time, I see the memory usage of the box go way way up (it's got
> 8GBs in it and by the end of the day, it'll be all used up) with what
> looks like cached inodes relating to the extreme IO generated by
>
> I was wondering if there is something I'm doing wrong with my default
> settings of postgres that is keeping all that stuff cached, or if I just
> need to switch to XFS or if there is some setting in postgres that I can
> tweak that will make this problem go away. It's gone beyond an annoyance
> and is now into the realm of getting me in trouble if I can't keep this
> DB server up and running. Even a minute or two of downtime in a restart
> is often too much.
>
> Any help you can give in this would be extrememly helpful as I'm very
> far from an expert on Linux filesystems and postgres tuning.

You may want to submit your postgresql.conf. Upgrading to the latest
stable version may also help, although my experience is related to
FreeBSD and postgresql 7.4.8.

regards
Claus

From pgsql-performance-owner@postgresql.org  Mon Oct 10 18:54:57 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 7B608D9F4A
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 18:54:56 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 85516-04
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 21:54:53 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id 9AA2DD9ED1
	for <pgsql-performance@postgresql.org>;
	Mon, 10 Oct 2005 18:54:54 -0300 (ADT)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j9ALsnuE006248;
	Mon, 10 Oct 2005 17:54:49 -0400 (EDT)
To: Jon Brisbin <jon.brisbin@npcinternational.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Performance on SUSE w/ reiserfs 
In-reply-to: <434ADD46.5060206@npcinternational.com> 
References: <434ADD46.5060206@npcinternational.com>
Comments: In-reply-to Jon Brisbin <jon.brisbin@npcinternational.com>
	message dated "Mon, 10 Oct 2005 16:29:42 -0500"
Date: Mon, 10 Oct 2005 17:54:49 -0400
Message-ID: <6247.1128981289@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/174
X-Sequence-Number: 14942

Jon Brisbin <jon.brisbin@npcinternational.com> writes:
> I have a SUSE 9 box that is running Postgres 8.0.1 compiled from source. 
> Over time, I see the memory usage of the box go way way up (it's got 
> 8GBs in it and by the end of the day, it'll be all used up) with what 
> looks like cached inodes relating to the extreme IO generated by 
> postgres. We replicate about 10GBs of data every day from our AS/400 
> into postgres, and it is the main database for our intranet portal, 
> which will server 40,000 pages on a good day.

Are you sure it's not cached data pages, rather than cached inodes?
If so, the above behavior is *good*.

People often have a mistaken notion that having near-zero free RAM means
they have a problem.  In point of fact, that is the way it is supposed
to be (at least on Unix-like systems).  This is just a reflection of the
kernel doing what it is supposed to do, which is to use all spare RAM
for caching recently accessed disk pages.  If you're not swapping then
you do not have a problem.

You should be looking at swap I/O rates (see vmstat or iostat) to
determine if you have memory pressure, not "free RAM".

			regards, tom lane

From pgsql-performance-owner@postgresql.org  Mon Oct 10 19:14:05 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 25D46D9EF1
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 19:13:53 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 82807-10
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 22:13:49 +0000 (GMT)
Received: from mail1.npci.com (mail.npcinternational.com [63.76.154.140])
	by svr1.postgresql.org (Postfix) with ESMTP id D906AD9062
	for <pgsql-performance@postgresql.org>;
	Mon, 10 Oct 2005 19:13:48 -0300 (ADT)
Received: from [172.16.10.91] ([172.16.10.91]) by mail1.npci.com (MOS
 3.5.9-GR)
	with ESMTP id BTW00647 (AUTH via LOGINBEFORESMTP);
	Mon, 10 Oct 2005 17:08:23 -0500 (CDT)
Message-ID: <434AE7A1.3050700@npcinternational.com>
Date: Mon, 10 Oct 2005 17:13:53 -0500
From: Jon Brisbin <jon.brisbin@npcinternational.com>
User-Agent: Mozilla Thunderbird 1.0.5 (Windows/20050711)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: pgsql-performance@postgresql.org
Subject: Re: Performance on SUSE w/ reiserfs
References: <434ADD46.5060206@npcinternational.com>
	<b41c75520510101445jd8a9f06k@mail.gmail.com>
In-Reply-To: <b41c75520510101445jd8a9f06k@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.415 required=5 tests=[AWL=0.365,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/176
X-Sequence-Number: 14944

More info:

apps:/home/jbrisbin # free -mo
              total       used       free     shared    buffers    cached
Mem:          8116       5078       3038          0         92      4330
Swap:         1031          0       1031


apps:/home/jbrisbin # cat /proc/meminfo
MemTotal:      8311188 kB
MemFree:       3111668 kB
Buffers:         94604 kB
Cached:        4434764 kB
SwapCached:          0 kB
Active:        4844344 kB
Inactive:       279556 kB
HighTotal:     7469996 kB
HighFree:      2430976 kB
LowTotal:       841192 kB
LowFree:        680692 kB
SwapTotal:     1056124 kB
SwapFree:      1056124 kB
Dirty:             436 kB
Writeback:           0 kB
Mapped:         581924 kB
Slab:            48264 kB
Committed_AS:   651128 kB
PageTables:       4020 kB
VmallocTotal:   112632 kB
VmallocUsed:     13104 kB
VmallocChunk:    97284 kB
HugePages_Total:     0
HugePages_Free:      0
Hugepagesize:     2048 kB

apps:/home/jbrisbin # cat /proc/slabinfo
slabinfo - version: 2.0
...
reiser_inode_cache 28121  28140    512    7    1 : tunables
...
radix_tree_node    28092  28154    276   14    1 : tunables
...
inode_cache         1502   1520    384   10    1 : tunables
dentry_cache       40763  40794    152   26    1 : tunables
...
buffer_head        83929  94643     52   71    1 : tunables


Claus Guttesen wrote:

> You may want to submit your postgresql.conf. Upgrading to the latest
> stable version may also help, although my experience is related to
> FreeBSD and postgresql 7.4.8.

# -----------------------------
# PostgreSQL configuration file
# -----------------------------
#
# This file consists of lines of the form:
#
#   name = value
#
# (The '=' is optional.) White space may be used. Comments are introduced
# with '#' anywhere on a line. The complete list of option names and
# allowed values can be found in the PostgreSQL documentation. The
# commented-out settings shown in this file represent the default values.
#
# Please note that re-commenting a setting is NOT sufficient to revert it
# to the default value, unless you restart the postmaster.
#
# Any option can also be given as a command line switch to the
# postmaster, e.g. 'postmaster -c log_connections=on'. Some options
# can be changed at run-time with the 'SET' SQL command.
#
# This file is read on postmaster startup and when the postmaster
# receives a SIGHUP. If you edit the file on a running system, you have
# to SIGHUP the postmaster for the changes to take effect, or use
# "pg_ctl reload". Some settings, such as listen_address, require
# a postmaster shutdown and restart to take effect.


#---------------------------------------------------------------------------
# FILE LOCATIONS
#---------------------------------------------------------------------------

# The default values of these variables are driven from the -D command line
# switch or PGDATA environment variable, represented here as ConfigDir.
# data_directory = 'ConfigDir'          # use data in another directory
# hba_file = 'ConfigDir/pg_hba.conf'    # the host-based authentication file
# ident_file = 'ConfigDir/pg_ident.conf'  # the IDENT configuration file

# If external_pid_file is not explicitly set, no extra pid file is written.
# external_pid_file = '(none)'          # write an extra pid file


#---------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#---------------------------------------------------------------------------

# - Connection Settings -

listen_addresses = '*'  # what IP interface(s) to listen on;
                                 # defaults to localhost, '*' = any
#port = 5432
max_connections = 100
         # note: increasing max_connections costs about 500 bytes of shared
         # memory per connection slot, in addition to costs from 
shared_buffers
         # and max_locks_per_transaction.
#superuser_reserved_connections = 2
#unix_socket_directory = ''
#unix_socket_group = ''
#unix_socket_permissions = 0777 # octal
#rendezvous_name = ''           # defaults to the computer name

# - Security & Authentication -

#authentication_timeout = 60    # 1-600, in seconds
#ssl = false
#password_encryption = true
#krb_server_keyfile = ''
#db_user_namespace = false


#---------------------------------------------------------------------------
# RESOURCE USAGE (except WAL)
#---------------------------------------------------------------------------

# - Memory -

shared_buffers = 1000           # min 16, at least max_connections*2, 
8KB each
#work_mem = 1024                # min 64, size in KB
#maintenance_work_mem = 16384   # min 1024, size in KB
#max_stack_depth = 2048         # min 100, size in KB

# - Free Space Map -

#max_fsm_pages = 20000          # min max_fsm_relations*16, 6 bytes each
#max_fsm_relations = 1000       # min 100, ~50 bytes each

# - Kernel Resource Usage -

#max_files_per_process = 1000   # min 25
#preload_libraries = ''

# - Cost-Based Vacuum Delay -

#vacuum_cost_delay = 0          # 0-1000 milliseconds
#vacuum_cost_page_hit = 1       # 0-10000 credits
#vacuum_cost_page_miss = 10     # 0-10000 credits
#vacuum_cost_page_dirty = 20    # 0-10000 credits
#vacuum_cost_limit = 200        # 0-10000 credits

# - Background writer -

#bgwriter_delay = 200           # 10-10000 milliseconds between rounds
#bgwriter_percent = 1           # 0-100% of dirty buffers in each round
#bgwriter_maxpages = 100        # 0-1000 buffers max per round


#---------------------------------------------------------------------------
# WRITE AHEAD LOG
#---------------------------------------------------------------------------

# - Settings -

#fsync = true                   # turns forced synchronization on or off
#wal_sync_method = fsync        # the default varies across platforms:
                                 # fsync, fdatasync, open_sync, or 
open_datasync
#wal_buffers = 8                # min 4, 8KB each
#commit_delay = 0               # range 0-100000, in microseconds
#commit_siblings = 5            # range 1-1000

# - Checkpoints -

#checkpoint_segments = 3        # in logfile segments, min 1, 16MB each
#checkpoint_timeout = 300       # range 30-3600, in seconds
#checkpoint_warning = 30        # 0 is off, in seconds

# - Archiving -

#archive_command = ''           # command to use to archive a logfile 
segment


#---------------------------------------------------------------------------
# QUERY TUNING
#---------------------------------------------------------------------------

# - Planner Method Configuration -

#enable_hashagg = true
#enable_hashjoin = true
#enable_indexscan = true
#enable_mergejoin = true
#enable_nestloop = true
#enable_seqscan = true
#enable_sort = true
#enable_tidscan = true

# - Planner Cost Constants -

#effective_cache_size = 1000    # typically 8KB each
#random_page_cost = 4           # units are one sequential page fetch cost
#cpu_tuple_cost = 0.01          # (same)
#cpu_index_tuple_cost = 0.001   # (same)
#cpu_operator_cost = 0.0025     # (same)

# - Genetic Query Optimizer -

#geqo = true
#geqo_threshold = 12
#geqo_effort = 5                # range 1-10
#geqo_pool_size = 0             # selects default based on effort
#geqo_generations = 0           # selects default based on effort
#geqo_selection_bias = 2.0      # range 1.5-2.0

# - Other Planner Options -

#default_statistics_target = 10 # range 1-1000
#from_collapse_limit = 8
#join_collapse_limit = 8        # 1 disables collapsing of explicit JOINs


#---------------------------------------------------------------------------
# ERROR REPORTING AND LOGGING
#---------------------------------------------------------------------------

# - Where to Log -

log_destination = 'syslog'      # Valid values are combinations of stderr,
                                 # syslog and eventlog, depending on
                                 # platform.

# This is relevant when logging to stderr:
redirect_stderr = true    # Enable capturing of stderr into log files.
# These are only relevant if redirect_stderr is true:
log_directory = 'pg_log'   # Directory where log files are written.
                             # May be specified absolute or relative to 
PGDATA
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' # Log file name pattern.
                             # May include strftime() escapes
#log_truncate_on_rotation = false  # If true, any existing log file of the
                             # same name as the new log file will be 
truncated
                             # rather than appended to.  But such truncation
                             # only occurs on time-driven rotation,
                             # not on restarts or size-driven rotation.
                             # Default is false, meaning append to existing
                             # files in all cases.
#log_rotation_age = 1440    # Automatic rotation of logfiles will happen 
after
                             # so many minutes.  0 to disable.
#log_rotation_size = 10240  # Automatic rotation of logfiles will happen 
after
                             # so many kilobytes of log output.  0 to 
disable.

# These are relevant when logging to syslog:
syslog_facility = 'LOCAL0'
syslog_ident = 'postgres'


# - When to Log -

client_min_messages = notice    # Values, in order of decreasing detail:
                                 #   debug5, debug4, debug3, debug2, debug1,
                                 #   log, notice, warning, error

log_min_messages = notice       # Values, in order of decreasing detail:
                                 #   debug5, debug4, debug3, debug2, debug1,
                                 #   info, notice, warning, error, log, 
fatal,
                                 #   panic

log_error_verbosity = default   # terse, default, or verbose messages

log_min_error_statement = notice # Values in order of increasing severity:
                                  #   debug5, debug4, debug3, debug2, 
debug1,
                                  #   info, notice, warning, error, 
panic(off)

#log_min_duration_statement = -1 # -1 is disabled, in milliseconds.

#silent_mode = false             # DO NOT USE without syslog or 
redirect_stderr

# - What to Log -

#debug_print_parse = false
#debug_print_rewritten = false
#debug_print_plan = false
#debug_pretty_print = false
#log_connections = false
#log_disconnections = false
#log_duration = false
#log_line_prefix = ''           # e.g. '<%u%%%d> '
                                 # %u=user name %d=database name
                                 # %r=remote host and port
                                 # %p=PID %t=timestamp %i=command tag
                                 # %c=session id %l=session line number
                                 # %s=session start timestamp 
%x=transaction id
                                 # %q=stop here in non-session processes
                                 # %%='%'
#log_statement = 'none'         # none, mod, ddl, all
log_hostname = true


#---------------------------------------------------------------------------
# RUNTIME STATISTICS
#---------------------------------------------------------------------------

# - Statistics Monitoring -

#log_parser_stats = false
#log_planner_stats = false
#log_executor_stats = false
#log_statement_stats = false

# - Query/Index Statistics Collector -

#stats_start_collector = true
#stats_command_string = false
#stats_block_level = false
#stats_row_level = false
#stats_reset_on_server_start = true


#---------------------------------------------------------------------------
# CLIENT CONNECTION DEFAULTS
#---------------------------------------------------------------------------

# - Statement Behavior -

#search_path = '$user,public'   # schema names
#default_tablespace = ''        # a tablespace name, or '' for default
#check_function_bodies = true
#default_transaction_isolation = 'read committed'
#default_transaction_read_only = false
#statement_timeout = 0          # 0 is disabled, in milliseconds

# - Locale and Formatting -

#datestyle = 'iso, mdy'
#timezone = unknown             # actually, defaults to TZ environment 
setting
#australian_timezones = false
#extra_float_digits = 0         # min -15, max 2
#client_encoding = sql_ascii    # actually, defaults to database encoding

# These settings are initialized by initdb -- they might be changed
lc_messages = 'C'               # locale for system error message strings
lc_monetary = 'C'               # locale for monetary formatting
lc_numeric = 'C'                # locale for number formatting
lc_time = 'C'                   # locale for time formatting

# - Other Defaults -

#explain_pretty_print = true
#dynamic_library_path = '$libdir'


#---------------------------------------------------------------------------
# LOCK MANAGEMENT
#---------------------------------------------------------------------------

#deadlock_timeout = 1000        # in milliseconds
#max_locks_per_transaction = 64 # min 10, ~200*max_connections bytes each


#---------------------------------------------------------------------------
# VERSION/PLATFORM COMPATIBILITY
#---------------------------------------------------------------------------

# - Previous Postgres Versions -

#add_missing_from = true
#regex_flavor = advanced        # advanced, extended, or basic
#sql_inheritance = true
#default_with_oids = true

# - Other Platforms & Clients -

#transform_null_equals = false


-- 

Jon Brisbin
Webmaster
NPC International, Inc.

From pgsql-performance-owner@postgresql.org  Mon Oct 10 19:15:26 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 7A476D9F13
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 19:15:24 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 10594-03
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 22:15:21 +0000 (GMT)
Received: from mail1.npci.com (mail.npcinternational.com [63.76.154.140])
	by svr1.postgresql.org (Postfix) with ESMTP id 7B417D9F2A
	for <pgsql-performance@postgresql.org>;
	Mon, 10 Oct 2005 19:15:22 -0300 (ADT)
Received: from [172.16.10.91] ([172.16.10.91]) by mail1.npci.com (MOS
 3.5.9-GR)
	with ESMTP id BTW00654 (AUTH via LOGINBEFORESMTP);
	Mon, 10 Oct 2005 17:09:58 -0500 (CDT)
Message-ID: <434AE7FF.4000705@npcinternational.com>
Date: Mon, 10 Oct 2005 17:15:27 -0500
From: Jon Brisbin <jon.brisbin@npcinternational.com>
User-Agent: Mozilla Thunderbird 1.0.5 (Windows/20050711)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: pgsql-performance@postgresql.org
Subject: Re: Performance on SUSE w/ reiserfs
References: <434ADD46.5060206@npcinternational.com>
	<6247.1128981289@sss.pgh.pa.us>
In-Reply-To: <6247.1128981289@sss.pgh.pa.us>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.374 required=5 tests=[AWL=0.324,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/177
X-Sequence-Number: 14945

Tom Lane wrote:
> 
> Are you sure it's not cached data pages, rather than cached inodes?
> If so, the above behavior is *good*.
> 
> People often have a mistaken notion that having near-zero free RAM means
> they have a problem.  In point of fact, that is the way it is supposed
> to be (at least on Unix-like systems).  This is just a reflection of the
> kernel doing what it is supposed to do, which is to use all spare RAM
> for caching recently accessed disk pages.  If you're not swapping then
> you do not have a problem.

Except for the fact that my Java App server crashes when all the 
available memory is being used by caching and not reclaimed :-)

If it wasn't for the app server going down, I probably wouldn't care.

-- 

Jon Brisbin
Webmaster
NPC International, Inc.

From pgsql-performance-owner@postgresql.org  Mon Oct 10 19:11:50 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 68991D9F0E
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 19:11:49 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 01567-04
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 22:11:41 +0000 (GMT)
Received: from davinci.ethosmedia.com (server227.ethosmedia.com
	[209.128.84.227])
	by svr1.postgresql.org (Postfix) with ESMTP id DCF55D9EDD
	for <pgsql-performance@postgresql.org>;
	Mon, 10 Oct 2005 19:11:42 -0300 (ADT)
X-EthosMedia-Virus-Scanned: no infections found
Received: from [64.81.245.111] (account josh@agliodbs.com HELO
	temoku.sf.agliodbs.com)
	by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.1.8)
	with ESMTP id 8242595; Mon, 10 Oct 2005 15:14:11 -0700
From: Josh Berkus <josh@agliodbs.com>
Reply-To: josh@agliodbs.com
Organization: Aglio Database Solutions
To: pgsql-performance@postgresql.org
Subject: Re: Performance on SUSE w/ reiserfs
Date: Mon, 10 Oct 2005 15:15:40 -0700
User-Agent: KMail/1.8
Cc: Jon Brisbin <jon.brisbin@npcinternational.com>
References: <434ADD46.5060206@npcinternational.com>
In-Reply-To: <434ADD46.5060206@npcinternational.com>
MIME-Version: 1.0
Content-Type: text/plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Message-Id: <200510101515.40364.josh@agliodbs.com>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.046 required=5 tests=[AWL=-0.004,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/175
X-Sequence-Number: 14943

Jon,

> Any help you can give in this would be extrememly helpful as I'm very
> far from an expert on Linux filesystems and postgres tuning.

See Tom's response; it may be that you don't have an issue at all.

If you do, it's probably the kernel, not the FS.  2.6.8 and a few other 
2.6.single-digit kernels had memory leaks in shmem that would cause 
gradually escalating swappage.  The solution to that one is to upgrade to 
2.6.11.

-- 
--Josh

Josh Berkus
Aglio Database Solutions
San Francisco

From pgsql-performance-owner@postgresql.org  Mon Oct 10 19:28:54 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 844C7D9F65
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 19:28:50 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 96559-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 22:28:46 +0000 (GMT)
Received: from mail.tecarta.com (66.238.115.135.ptr.us.xo.net
 [66.238.115.135])
	by svr1.postgresql.org (Postfix) with ESMTP id 4A44DD9F22
	for <pgsql-performance@postgresql.org>;
	Mon, 10 Oct 2005 19:28:47 -0300 (ADT)
Received: from mail pickup service by mail.tecarta.com with Microsoft SMTPSVC;
	Mon, 10 Oct 2005 15:32:58 -0700
Received: from mail.tecarta.com ([192.168.160.1]) by mail.tecarta.com with
	Microsoft SMTPSVC(6.0.3790.0); Mon, 10 Oct 2005 15:32:57 -0700
Received: from barracuda.tecarta.com ([192.168.160.200])
	by mail.tecarta.com (SAVSMTP 3.1.0.29) with SMTP id
	M2005101015325728202
	for <pgsql_performance_postgresql_org@tecarta.com>;
	Mon, 10 Oct 2005 15:32:57 -0700
X-ASG-Debug-ID: 1128983329-26939-3-0
X-Barracuda-URL: http://192.168.160.200:8000/cgi-bin/mark.cgi
Received: from mail2 (mail2.hq.corp [192.168.160.6])
	by barracuda.tecarta.com (Spam Firewall) with SMTP id 6310F2016CA1
	for <pgsql_performance_postgresql_org@tecarta.com>;
	Mon, 10 Oct 2005 15:28:49 -0700 (PDT)
Received: from [10.0.0.174] ([63.193.127.22]) by mail.tecarta.com with
	Microsoft SMTPSVC(6.0.3790.1830); Mon, 10 Oct 2005 15:32:51 -0700
X-ASG-Orig-Subj: XFS External Log on Pg 7.4.8 Pg_xlog drives?
Subject: XFS External Log on Pg 7.4.8 Pg_xlog drives?
From: Steve Poe <spoe@sfnet.cc>
To: pgsql-performance@postgresql.org
Content-Type: text/plain
Date: Mon, 10 Oct 2005 15:28:42 -0700
Message-Id: <1128983322.18140.41.camel@amd64-gentoo-laptop>
Mime-Version: 1.0
X-Mailer: Evolution 2.2.3 
Content-Transfer-Encoding: 7bit
X-OriginalArrivalTime: 10 Oct 2005 22:32:51.0333 (UTC)
	FILETIME=[8C827B50:01C5CDEA]
X-Virus-Scanned: by Barracuda Spam Firewall at tecarta.com
X-Barracuda-Spam-Score: 0.00
X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=4.0
	QUARANTINE_LEVEL=1000.0 KILL_LEVEL=7.0 tests=
X-Barracuda-Spam-Report: Code version 3.02, rules version 3.0.4459
	Rule breakdown below pts rule name              description
	---- ----------------------
	--------------------------------------------------
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.05 required=5 tests=[FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/178
X-Sequence-Number: 14946

Fellow Postgresql users,

I have a Pg 7.4.8 data on XFS RAID10 6-disc (U320 SCSI on LSI MegaRAID
w/bbu). The pg_xlog is on its own RAID1 with nothing else.

I don't have room for more drives, but I am considering moving the XFS
external log of the data directory to the RAID1 where the pg_xlog
exists. Unfortunately, I don't have room on the RAID1 that the OS exists
on(Centos Linux 4.1).

Anyone have any experience moving the XFS log to the pg_xlog? The
guessing the the benefit / cost will cancel each other out. 

Thanks.

Steve Poe


From pgsql-performance-owner@postgresql.org  Mon Oct 10 19:29:45 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id BB9C6D9F92
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 19:29:41 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 64162-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 22:29:33 +0000 (GMT)
Received: from mx1.surnet.cl (mx1.surnet.cl [216.155.73.180])
	by svr1.postgresql.org (Postfix) with ESMTP id 61475D9F7E
	for <pgsql-performance@postgresql.org>;
	Mon, 10 Oct 2005 19:29:34 -0300 (ADT)
Received: from unknown (HELO cluster.surnet.cl) ([216.155.73.165])
	by mx1.surnet.cl with ESMTP; 10 Oct 2005 19:30:14 -0300
Received: from alvh.no-ip.org (216.155.78.167) by cluster.surnet.cl (7.0.043)
	(authenticated as alvherre@surnet.cl)
	id 433A601F006C8271; Mon, 10 Oct 2005 19:29:36 -0300
Received: by alvh.no-ip.org (Postfix, from userid 1000)
	id 8CA31C4F1EC; Mon, 10 Oct 2005 19:29:37 -0300 (CLST)
Date: Mon, 10 Oct 2005 19:29:37 -0300
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
To: Jon Brisbin <jon.brisbin@npcinternational.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Performance on SUSE w/ reiserfs
Message-ID: <20051010222937.GL5848@surnet.cl>
Mail-Followup-To: Jon Brisbin <jon.brisbin@npcinternational.com>,
	pgsql-performance@postgresql.org
References: <434ADD46.5060206@npcinternational.com>
	<6247.1128981289@sss.pgh.pa.us>
	<434AE7FF.4000705@npcinternational.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <434AE7FF.4000705@npcinternational.com>
User-Agent: Mutt/1.5.10i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=2.341 required=5 tests=[AWL=-0.435,
	DNS_FROM_RFC_ABUSE=0.374, DNS_FROM_RFC_POST=1.376,
	RCVD_IN_NJABL_PROXY=1.026]
X-Spam-Level: **
X-Archive-Number: 200510/179
X-Sequence-Number: 14947

Jon Brisbin wrote:
> Tom Lane wrote:
> >
> >Are you sure it's not cached data pages, rather than cached inodes?
> >If so, the above behavior is *good*.
> >
> >People often have a mistaken notion that having near-zero free RAM means
> >they have a problem.  In point of fact, that is the way it is supposed
> >to be (at least on Unix-like systems).  This is just a reflection of the
> >kernel doing what it is supposed to do, which is to use all spare RAM
> >for caching recently accessed disk pages.  If you're not swapping then
> >you do not have a problem.
> 
> Except for the fact that my Java App server crashes when all the 
> available memory is being used by caching and not reclaimed :-)

Ah, so you have a different problem.  What you should be asking is why
the appserver crashes.  You still seem to have a lot of free swap,
judging by a nearby post.  But maybe the problem is that the swap is
completely used too, and so the OOM killer (is this Linux?) comes around
and kills the appserver.

Certainly the problem is not the caching.  You should be monitoring when
and why the appserver dies.

-- 
Alvaro Herrera                         Architect, http://www.EnterpriseDB.com
"On the other flipper, one wrong move and we're Fatal Exceptions"
(T.U.X.: Term Unit X  - http://www.thelinuxreview.com/TUX/)

From pgsql-performance-owner@postgresql.org  Mon Oct 10 19:36:02 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 224DCD9106
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 19:36:00 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 35842-10
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 22:35:52 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id 52142D9F22
	for <pgsql-performance@postgresql.org>;
	Mon, 10 Oct 2005 19:35:53 -0300 (ADT)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j9AMZtkK006746;
	Mon, 10 Oct 2005 18:35:55 -0400 (EDT)
To: Jon Brisbin <jon.brisbin@npcinternational.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Performance on SUSE w/ reiserfs 
In-reply-to: <434AE7FF.4000705@npcinternational.com> 
References: <434ADD46.5060206@npcinternational.com>
	<6247.1128981289@sss.pgh.pa.us>
	<434AE7FF.4000705@npcinternational.com>
Comments: In-reply-to Jon Brisbin <jon.brisbin@npcinternational.com>
	message dated "Mon, 10 Oct 2005 17:15:27 -0500"
Date: Mon, 10 Oct 2005 18:35:55 -0400
Message-ID: <6745.1128983755@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/180
X-Sequence-Number: 14948

Jon Brisbin <jon.brisbin@npcinternational.com> writes:
> Tom Lane wrote:
>> If you're not swapping then you do not have a problem.

> Except for the fact that my Java App server crashes when all the 
> available memory is being used by caching and not reclaimed :-)

That's a kernel bug (or possibly a Java bug ;-)).  I concur with Josh's
suggestion that you need a newer kernel.

			regards, tom lane

From pgsql-performance-owner@postgresql.org  Mon Oct 10 19:48:46 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id A9617D9F49
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 19:48:44 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 92590-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 22:48:35 +0000 (GMT)
Received: from vms046pub.verizon.net (vms046pub.verizon.net [206.46.252.46])
	by svr1.postgresql.org (Postfix) with ESMTP id 48E73D9EDD
	for <pgsql-performance@postgresql.org>;
	Mon, 10 Oct 2005 19:48:35 -0300 (ADT)
Received: from osgiliath.mathom.us ([70.108.61.78])
	by vms046.mailsrvcs.net (Sun Java System Messaging Server 6.2 HotFix
	0.04 (built Dec 24 2004)) with ESMTPA id
	<0IO600EM020YY082@vms046.mailsrvcs.net> for
	pgsql-performance@postgresql.org; Mon, 10 Oct 2005 17:48:35 -0500 (CDT)
Received: from localhost (localhost [127.0.0.1])
	by osgiliath.mathom.us (Postfix) with ESMTP id 568166002A2	for
	<pgsql-performance@postgresql.org>;
	Mon, 10 Oct 2005 18:48:34 -0400 (EDT)
Received: from osgiliath.mathom.us ([127.0.0.1])
	by localhost (osgiliath [127.0.0.1]) (amavisd-new, port 10024)
	with LMTP id 25719-04-7 for <pgsql-performance@postgresql.org>; Mon,
	10 Oct 2005 18:48:34 -0400 (EDT)
Received: by osgiliath.mathom.us (Postfix, from userid 1000)
	id 3B4E4600291; Mon, 10 Oct 2005 18:48:34 -0400 (EDT)
Date: Mon, 10 Oct 2005 18:48:34 -0400
From: Michael Stone <mstone+postgres@mathom.us>
Subject: Re: XFS External Log on Pg 7.4.8 Pg_xlog drives?
In-reply-to: <1128983322.18140.41.camel@amd64-gentoo-laptop>
To: pgsql-performance@postgresql.org
Mail-Followup-To: pgsql-performance@postgresql.org
Message-id: <20051010224834.GO17398@mathom.us>
MIME-version: 1.0
Content-type: text/plain; charset=us-ascii; format=flowed
Content-disposition: inline
X-Pgp-Fingerprint: 53 FF 38 00 E7 DD 0A 9C  84 52 84 C5 EE DF 7C 88
X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at mathom.us
References: <1128983322.18140.41.camel@amd64-gentoo-laptop>
User-Agent: Mutt/1.5.11
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.003 required=5 tests=[AWL=0.003]
X-Spam-Level: 
X-Archive-Number: 200510/181
X-Sequence-Number: 14949

On Mon, Oct 10, 2005 at 03:28:42PM -0700, Steve Poe wrote:
>I don't have room for more drives, but I am considering moving the XFS
>external log 

There is absolutely no reason to move the xfs log on a system that
small. 

Mike Stone

From pgsql-performance-owner@postgresql.org  Mon Oct 10 21:12:50 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id D3E1FD9FA6
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 21:12:47 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 42634-10
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 11 Oct 2005 00:12:44 +0000 (GMT)
Received: from flake.decibel.org (flake.decibel.org [67.100.216.10])
	by svr1.postgresql.org (Postfix) with ESMTP id C1EFBD9F81
	for <pgsql-performance@postgresql.org>;
	Mon, 10 Oct 2005 21:12:45 -0300 (ADT)
Received: by flake.decibel.org (Postfix, from userid 1001)
	id 53E4A1525A; Mon, 10 Oct 2005 19:12:49 -0500 (CDT)
Date: Mon, 10 Oct 2005 19:12:49 -0500
From: "Jim C. Nasby" <jnasby@pervasive.com>
To: Announce <truthhurts@insightbb.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: What's the cost of a few extra columns?
Message-ID: <20051011001249.GJ39569@pervasive.com>
References: <KBEKKNMFLELKGIADDEPEAEEPCBAA.truthhurts@insightbb.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <KBEKKNMFLELKGIADDEPEAEEPCBAA.truthhurts@insightbb.com>
X-Operating-System: FreeBSD 4.11-RELEASE-p10 i386
X-Distributed: Join the Effort!  http://www.distributed.net
User-Agent: Mutt/1.5.9i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.009 required=5 tests=[AWL=0.009]
X-Spam-Level: 
X-Archive-Number: 200510/182
X-Sequence-Number: 14950

What you're describing is known as vertical partitioning (think of
splitting a table vertically), and can be a good technique for
increasing performance when used properly. The key is to try and get the
average row size down, since that means more rows per page which means
less I/O. Some things to consider:

First rule of performance tuning: don't. In other words, you should be
able to verify with benchmark numbers that a) you need to do this and b)
how much it's actually helping.

How will splitting the table affect *_tstmp, especially mod_tstmp?

How will you handle inserts and joining these two tables together? Will
you always do a left join (preferably via a view), or will you have a
trigger/rule that inserts into production_info whenever a row is
inserted into productions?

On Sun, Oct 09, 2005 at 10:03:33PM -0500, Announce wrote:
> What's goin on pg-people?
> 
> I have a table PRODUCTIONS that is central to the DB and ties a lot of other
> information together:
> 
> PRODUCTIONS (table)
> ----------------------------------
> prod_id		primary key
> type_id		foreign key
> level_id		foreign key
> tour_id		foreign key
> show_id		foreign key
> venue_id		foreign key
> title			varchar(255); not null indexed
> version		char;
> details		text
> open_date		date
> close_date		date
> preview_open	date
> preview_close	date
> perform_tot		int
> preview_tot		int
> park_info		text
> phone_nos		text
> some_other_info	text
> seating_info	text
> this			text
> that			text
> create_tstmp	timestamptz; NOW()
> mod_tstmp		timestamptz;triggered
> delete_tstmp	timestamptz;default null
> is_complete		bool
> 
> 
> As it stands now, there are approximately 25-30 columns on the table. Since
> this table is very central to the database, would it be more efficient to
> break some of the columns (especially the TEXT ones) out into a separate
> INFO table since some queries on the web will not care about all of these
> text columns anyway? I know that pg can handle A LOT more columns and if
> there IS no performance hit for keeping them all on the same table, I would
> like to do that because the relation between PRODUCTIONS and the INFO will
> always be 1-to-1.
> 
> My implementation of this INFO table would look a little somethin' like
> this:
> 
> PROD_INFO (table)
> -------------------------------
> prod_id		pkey/fkey
> open_date		date
> close_date		date
> preview_open	date
> preview_close	date
> perform_tot		int
> preview_tot		int
> park_info		text
> phone_nos		text
> some_other_info	text
> seating_info	text
> this			text
> that			text
> (the rest would stay in in the original PRODUCTIONS table)
> 
> 
> I am open to ANY suggestions, criticisms, mockery, etc.
> 
> Thanks,
> 
> Aaron
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 5: don't forget to increase your free space map settings
> 

-- 
Jim C. Nasby, Sr. Engineering Consultant      jnasby@pervasive.com
Pervasive Software      http://pervasive.com    work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf       cell: 512-569-9461

From pgsql-performance-owner@postgresql.org  Mon Oct 10 23:14:19 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 55437DA097
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 10 Oct 2005 23:14:18 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 63233-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 11 Oct 2005 02:14:13 +0000 (GMT)
Received: from sccimhc92.asp.att.net (sccimhc92.asp.att.net [63.240.76.166])
	by svr1.postgresql.org (Postfix) with ESMTP id 29CCFDA0CF
	for <pgsql-performance@postgresql.org>;
	Mon, 10 Oct 2005 23:14:15 -0300 (ADT)
Received: from krunk (12-202-107-96.client.insightbb.com[12.202.107.96])
	by sccimhc92.asp.att.net (sccimhc92) with SMTP
	id <20051011021419i92001u8ehe>; Tue, 11 Oct 2005 02:14:19 +0000
From: "Announce" <truthhurts@insightbb.com>
To: "Jim C. Nasby" <jnasby@pervasive.com>
Cc: <pgsql-performance@postgresql.org>
Subject: Re: What's the cost of a few extra columns?
Date: Mon, 10 Oct 2005 21:14:12 -0500
Message-ID: <KBEKKNMFLELKGIADDEPEOEFHCBAA.truthhurts@insightbb.com>
MIME-Version: 1.0
Content-Type: text/plain;
	charset="windows-1250"
Content-Transfer-Encoding: 7bit
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0)
In-Reply-To: <20051011001249.GJ39569@pervasive.com>
Importance: Normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0 required=5 tests=[none]
X-Spam-Level: 
X-Archive-Number: 200510/183
X-Sequence-Number: 14951

Thanks a lot.

Well, if I'm understanding you correctly, then doing the vertical splitting
for some of the text columns WOULD decrease the average row size returned in
my slimmer PRODUCTIONS table. I don't plan on using any of the "prod_info"
columns in a WHERE clause (except open_date and close_date now that I think
of it so they would stay in the original table).

There will be a lot of queries where I just want to return quick pri-key,
prod_name and prod_date results from a PRODUCTION search.  Then, there would
be a detail query that would then need all of the PRODUCTION and INFO data
for a single row.

Thanks again,

Aaron
-----Original Message-----
Subject: Re: [PERFORM] What's the cost of a few extra columns?

What you're describing is known as vertical partitioning (think of
splitting a table vertically), and can be a good technique for
increasing performance when used properly. The key is to try and get the
average row size down, since that means more rows per page which means
less I/O. Some things to consider:

First rule of performance tuning: don't. In other words, you should be
able to verify with benchmark numbers that a) you need to do this and b)
how much it's actually helping.

How will splitting the table affect *_tstmp, especially mod_tstmp?

How will you handle inserts and joining these two tables together? Will
you always do a left join (preferably via a view), or will you have a
trigger/rule that inserts into production_info whenever a row is
inserted into productions?

On Sun, Oct 09, 2005 at 10:03:33PM -0500, Announce wrote:


From pgsql-performance-owner@postgresql.org  Tue Oct 11 08:39:38 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id CA91FD7274
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 11 Oct 2005 08:39:08 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 93399-09
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 11 Oct 2005 11:38:58 +0000 (GMT)
Received: from svr2.postgresql.org (svr2.postgresql.org [65.19.161.25])
	by svr1.postgresql.org (Postfix) with ESMTP id 59274D79A2
	for <pgsql-performance@postgresql.org>;
	Tue, 11 Oct 2005 08:36:23 -0300 (ADT)
Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.204])
	by svr2.postgresql.org (Postfix) with ESMTP id EA3DFF119C
	for <pgsql-performance@postgresql.org>;
	Tue, 11 Oct 2005 08:31:11 +0100 (BST)
Received: by wproxy.gmail.com with SMTP id 71so178057wra
	for <pgsql-performance@postgresql.org>;
	Tue, 11 Oct 2005 00:41:32 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references;
	b=cHtvEgwfuoVW2I7lVQ34kRGUwZ0qwunEaDhg36PnKGjG6gpZNaHQHlVUhKGXkEgGTrvE3LJ1b03gebdSl6ACpsCVMgHKr1yp16l3Nisou4a3YFXpNQ5i4XKTIzOVpFrpC2Ad9X4NR81yjM0B252mf7Hg6iarCkvN6kevWVW2wLk=
Received: by 10.54.117.4 with SMTP id p4mr3474023wrc;
	Tue, 11 Oct 2005 00:41:32 -0700 (PDT)
Received: by 10.54.144.4 with HTTP; Tue, 11 Oct 2005 00:41:32 -0700 (PDT)
Message-ID: <b41c75520510110041j4b3d4017y@mail.gmail.com>
Date: Tue, 11 Oct 2005 09:41:32 +0200
From: Claus Guttesen <kometen@gmail.com>
To: Jon Brisbin <jon.brisbin@npcinternational.com>
Subject: Re: Performance on SUSE w/ reiserfs
Cc: pgsql-performance@postgresql.org
In-Reply-To: <434AE7A1.3050700@npcinternational.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
References: <434ADD46.5060206@npcinternational.com>
	<b41c75520510101445jd8a9f06k@mail.gmail.com>
	<434AE7A1.3050700@npcinternational.com>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.024 required=5 tests=[RCVD_BY_IP=0.024]
X-Spam-Level: 
X-Archive-Number: 200510/186
X-Sequence-Number: 14954

I have a postgresql 7.4.8-server with 4 GB ram.

> #max_fsm_pages =3D 20000          # min max_fsm_relations*16, 6 bytes eac=
h
> #max_fsm_relations =3D 1000       # min 100, ~50 bytes each

If you do a vacuum verbose (when it's convenient) the last couple of
lines will tell you something like this:

INFO:  free space map: 143 relations, 62034 pages stored; 63792 total
pages needed
DETAIL:  Allocated FSM size: 300 relations + 75000 pages =3D 473 kB shared =
memory.

It says 143 relations and 63792 total pages needed, so I up'ed my
values to these settings:

max_fsm_relations =3D 300         # min 10, fsm is free space map, ~40 byte=
s
max_fsm_pages =3D 75000           # min 1000, fsm is free space map, ~6 byt=
es

> #effective_cache_size =3D 1000    # typically 8KB each

This is computed by sysctl -n vfs.hibufspace / 8192 (on FreeBSD). So I
changed it to:

effective_cache_size =3D 27462    # typically 8KB each

Bear in mind that this is 7.4.8 and FreeBSD so these suggestions may
not apply to your environment. These suggestions could be validated by
the other members of this list.

regards
Claus

From pgsql-performance-owner@postgresql.org  Tue Oct 11 08:37:52 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 75547D720B
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 11 Oct 2005 08:37:50 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 83374-09
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 11 Oct 2005 11:37:32 +0000 (GMT)
Received: from svr2.postgresql.org (svr2.postgresql.org [65.19.161.25])
	by svr1.postgresql.org (Postfix) with ESMTP id C4443D76DC
	for <pgsql-performance@postgresql.org>;
	Tue, 11 Oct 2005 08:35:58 -0300 (ADT)
Received: from ar-sd.net (unknown [82.77.155.72])
	by svr2.postgresql.org (Postfix) with ESMTP id 86BBEF11D2
	for <pgsql-performance@postgresql.org>;
	Tue, 11 Oct 2005 08:36:34 +0100 (BST)
Received: from localhost (localhost [127.0.0.1])
	by ar-sd.net (Postfix) with ESMTP id 9562F21396
	for <pgsql-performance@postgresql.org>;
	Tue, 11 Oct 2005 10:31:15 +0300 (EEST)
Received: from ar-sd.net ([127.0.0.1])
	by localhost (linz [127.0.0.1]) (amavisd-new, port 10024) with ESMTP
	id 07680-08 for <pgsql-performance@postgresql.org>;
	Tue, 11 Oct 2005 10:31:14 +0300 (EEST)
Received: from forge (unknown [192.168.0.11])
	by ar-sd.net (Postfix) with SMTP id 90DDCE791
	for <pgsql-performance@postgresql.org>;
	Tue, 11 Oct 2005 10:31:14 +0300 (EEST)
Message-ID: <00bd01c5ce37$f8a4cc00$0b00a8c0@forge>
From: "Andy" <frum@ar-sd.net>
To: <pgsql-performance@postgresql.org>
Subject: Massive delete performance
Date: Tue, 11 Oct 2005 10:47:03 +0300
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="----=_NextPart_000_00BA_01C5CE51.1D679E50"
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-Virus-Scanned: by amavisd-new at ar-sd.net
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.254 required=5 tests=[AWL=0.176,
	FORGED_RCVD_HELO=0.05, HTML_60_70=0.027, HTML_MESSAGE=0.001]
X-Spam-Level: 
X-Archive-Number: 200510/185
X-Sequence-Number: 14953

This is a multi-part message in MIME format.

------=_NextPart_000_00BA_01C5CE51.1D679E50
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi to all,=20

I have the following problem: I have a client to which we send every =
night a "dump" with a the database in which there are only their data's. =
It is a stupid solution but I choose this solution because I couldn't =
find any better. The target machine is a windows 2003. =20

So, I have a replication only with the tables that I need to send, then =
I make a copy of this replication, and from this copy I delete all the =
data's that are not needed.=20

How can I increase this DELETE procedure because it is really slow???  =
There are of corse a lot of data's to be deleted.=20



Or is there any other solution for this?=20
DB -> (replication) RE_DB -> (copy) -> COPY_DB -> (Delete unnecesary =
data) -> CLIENT_DB -> (ISDN connection) -> Data's to the client.=20

Regards,=20
Andy.



------=_NextPart_000_00BA_01C5CE51.1D679E50
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2900.2722" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi to all, </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I have the following problem: I have a =
client to=20
which we send every night a "dump" with a the database in which there =
are only=20
their data's. It is a stupid solution but&nbsp;I choose this solution =
because I=20
couldn't find any better. The target machine is a windows 2003.=20
&nbsp;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>So, I have a replication only with the =
tables that=20
I need to send, then I make a copy of this replication, and from this =
copy I=20
delete all the data's that are not needed. </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>How can I increase this DELETE =
procedure because it=20
is really slow??? &nbsp;There are of corse a lot of data's to be =
deleted.=20
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Or is there any other solution for =
this?=20
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>DB -&gt; (replication) RE_DB -&gt; =
(copy) -&gt;=20
COPY_DB -&gt; (Delete unnecesary data) -&gt; CLIENT_DB -&gt; (ISDN =
connection)=20
-&gt; Data's to the client. </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Regards, </FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Andy.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Times New Roman, Times, serif" size=3D2><FONT=20
color=3D#ffcc00></FONT></FONT>&nbsp;</DIV>
<DIV><FONT color=3D#ffcc00 size=3D2></FONT>&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_00BA_01C5CE51.1D679E50--


From pgsql-performance-owner@postgresql.org  Tue Oct 11 05:03:09 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id D3156D6DF5
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 11 Oct 2005 05:03:06 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 60974-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 11 Oct 2005 08:03:04 +0000 (GMT)
Received: from smtp.nildram.co.uk (smtp.nildram.co.uk [195.112.4.54])
	by svr1.postgresql.org (Postfix) with ESMTP id 01289D6DB0
	for <pgsql-performance@postgresql.org>;
	Tue, 11 Oct 2005 05:03:04 -0300 (ADT)
Received: from 192.168.0.3 (unknown [84.12.188.233])
	by smtp.nildram.co.uk (Postfix) with ESMTP
	id A881A254B75; Tue, 11 Oct 2005 09:03:04 +0100 (BST)
Subject: Re: Compression of text columns
From: Simon Riggs <simon@2ndquadrant.com>
To: Stef <svb@ucs.co.za>
Cc: Tino Wildenhain <tino@wildenhain.de>,
	pgsql-performance@postgresql.org
In-Reply-To: <20051010145700.586dc488@svb.ucs.co.za>
References: <20051010141721.0bebbaa7@svb.ucs.co.za>
	<434A5E22.9040500@wildenhain.de>
	<20051010145700.586dc488@svb.ucs.co.za>
Content-Type: text/plain
Organization: 2nd Quadrant
Date: Tue, 11 Oct 2005 09:02:57 +0100
Message-Id: <1129017777.8300.354.camel@localhost.localdomain>
Mime-Version: 1.0
X-Mailer: Evolution 2.0.2 (2.0.2-3) 
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.047 required=5 tests=[AWL=-0.003,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/184
X-Sequence-Number: 14952

On Mon, 2005-10-10 at 14:57 +0200, Stef wrote:
> Is there any way to achieve better compression?

You can use XML schema aware compression techniques, but PostgreSQL
doesn't know about those. You have to do it yourself, or translate the
XML into an infoset-preserving form that will still allow XPath and
friends.

Best Regards, Simon Riggs


From pgsql-performance-owner@postgresql.org  Tue Oct 11 08:54:43 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 7EBFFD6FA8
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 11 Oct 2005 08:54:42 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 07655-09
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 11 Oct 2005 11:54:37 +0000 (GMT)
Received: from wimpy.net.nih.gov (wimpy.net.nih.gov [128.231.88.106])
	by svr1.postgresql.org (Postfix) with ESMTP id 89E57D6F96
	for <pgsql-performance@postgresql.org>;
	Tue, 11 Oct 2005 08:54:38 -0300 (ADT)
Received: from wimpy.net.nih.gov (localhost [127.0.0.1])
	by wimpy.net.nih.gov (8.12.11/8.11.7) with ESMTP id j9BBseLH009707
	for <pgsql-performance@postgresql.org>;
	Tue, 11 Oct 2005 07:54:42 -0400 (EDT)
Received: from [128.231.145.14] (holmes.nhgri.nih.gov [128.231.145.14])
	by wimpy.net.nih.gov (8.12.11/8.11.7) with ESMTP id j9BBsevU009698;
	Tue, 11 Oct 2005 07:54:40 -0400 (EDT)
User-Agent: Microsoft-Entourage/10.1.4.030702.0
Date: Tue, 11 Oct 2005 07:54:39 -0400
Subject: Re: Massive delete performance
From: Sean Davis <sdavis2@mail.nih.gov>
To: Andy <frum@ar-sd.net>, <pgsql-performance@postgresql.org>
Message-ID: <BF71203F.10300%sdavis2@mail.nih.gov>
In-Reply-To: <00bd01c5ce37$f8a4cc00$0b00a8c0@forge>
Mime-version: 1.0
Content-type: text/plain; charset="US-ASCII"
Content-transfer-encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.013 required=5 tests=[AWL=0.013]
X-Spam-Level: 
X-Archive-Number: 200510/187
X-Sequence-Number: 14955

On 10/11/05 3:47 AM, "Andy" <frum@ar-sd.net> wrote:

> Hi to all, 
> 
> I have the following problem: I have a client to which we send every night a
> "dump" with a the database in which there are only their data's. It is a
> stupid solution but I choose this solution because I couldn't find any better.
> The target machine is a windows 2003.
> 
> So, I have a replication only with the tables that I need to send, then I make
> a copy of this replication, and from this copy I delete all the data's that
> are not needed. 
> 
> How can I increase this DELETE procedure because it is really slow???  There
> are of corse a lot of data's to be deleted.

Do you have foreign key relationships that must be followed for cascade
delete?  If so, make sure that you have indices on them.  Are you running
any type of vacuum after the whole process?  What kind?

Sean


From pgsql-performance-owner@postgresql.org  Tue Oct 11 09:07:17 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id DB322D6F08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 11 Oct 2005 09:06:14 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 37658-07
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 11 Oct 2005 12:06:10 +0000 (GMT)
Received: from ar-sd.net (unknown [82.77.155.72])
	by svr1.postgresql.org (Postfix) with ESMTP id EDEFDD6D71
	for <pgsql-performance@postgresql.org>;
	Tue, 11 Oct 2005 09:06:11 -0300 (ADT)
Received: from localhost (localhost [127.0.0.1])
	by ar-sd.net (Postfix) with ESMTP id 39997215A9;
	Tue, 11 Oct 2005 14:50:06 +0300 (EEST)
Received: from ar-sd.net ([127.0.0.1])
	by localhost (linz [127.0.0.1]) (amavisd-new, port 10024) with ESMTP
	id 10841-04; Tue, 11 Oct 2005 14:50:04 +0300 (EEST)
Received: from forge (unknown [192.168.0.11])
	by ar-sd.net (Postfix) with SMTP id B9430215A7;
	Tue, 11 Oct 2005 14:50:04 +0300 (EEST)
Message-ID: <017601c5ce5c$219e1b10$0b00a8c0@forge>
From: "Andy" <frum@ar-sd.net>
To: "Sean Davis" <sdavis2@mail.nih.gov>,
	<pgsql-performance@postgresql.org>
References: <BF71203F.10300%sdavis2@mail.nih.gov>
Subject: Re: Massive delete performance
Date: Tue, 11 Oct 2005 15:05:52 +0300
MIME-Version: 1.0
Content-Type: text/plain; format=flowed; charset="iso-8859-1";
	reply-type=original
Content-Transfer-Encoding: 7bit
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-Virus-Scanned: by amavisd-new at ar-sd.net
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.226 required=5 tests=[AWL=0.176,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/188
X-Sequence-Number: 14956

> Do you have foreign key relationships that must be followed for cascade
> delete?  If so, make sure that you have indices on them.
Yes I have such things. Indexes are on these fields. >> To be onest this 
delete is taking the longest time, but it involves about 10 tables.

> Are you running
> any type of vacuum after the whole process?  What kind?
Full vacuum. (cmd: vacuumdb -f)

Is there any configuration parameter for delete speed up?


----- Original Message ----- 
From: "Sean Davis" <sdavis2@mail.nih.gov>
To: "Andy" <frum@ar-sd.net>; <pgsql-performance@postgresql.org>
Sent: Tuesday, October 11, 2005 2:54 PM
Subject: Re: [PERFORM] Massive delete performance


> On 10/11/05 3:47 AM, "Andy" <frum@ar-sd.net> wrote:
>
>> Hi to all,
>>
>> I have the following problem: I have a client to which we send every 
>> night a
>> "dump" with a the database in which there are only their data's. It is a
>> stupid solution but I choose this solution because I couldn't find any 
>> better.
>> The target machine is a windows 2003.
>>
>> So, I have a replication only with the tables that I need to send, then I 
>> make
>> a copy of this replication, and from this copy I delete all the data's 
>> that
>> are not needed.
>>
>> How can I increase this DELETE procedure because it is really slow??? 
>> There
>> are of corse a lot of data's to be deleted.
>
> Do you have foreign key relationships that must be followed for cascade
> delete?  If so, make sure that you have indices on them.  Are you running
> any type of vacuum after the whole process?  What kind?
>
> Sean
>
>
> 


From pgsql-performance-owner@postgresql.org  Tue Oct 11 09:12:12 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 669C1D6F80
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 11 Oct 2005 09:12:11 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 49349-06
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 11 Oct 2005 12:12:07 +0000 (GMT)
Received: from wimpy.net.nih.gov (wimpy.net.nih.gov [128.231.88.106])
	by svr1.postgresql.org (Postfix) with ESMTP id 72467D6FEA
	for <pgsql-performance@postgresql.org>;
	Tue, 11 Oct 2005 09:12:09 -0300 (ADT)
Received: from wimpy.net.nih.gov (localhost [127.0.0.1])
	by wimpy.net.nih.gov (8.12.11/8.11.7) with ESMTP id j9BCCCPH016476
	for <pgsql-performance@postgresql.org>;
	Tue, 11 Oct 2005 08:12:13 -0400 (EDT)
Received: from [128.231.145.14] (holmes.nhgri.nih.gov [128.231.145.14])
	by wimpy.net.nih.gov (8.12.11/8.11.7) with ESMTP id j9BCCCbI016467;
	Tue, 11 Oct 2005 08:12:12 -0400 (EDT)
User-Agent: Microsoft-Entourage/10.1.4.030702.0
Date: Tue, 11 Oct 2005 08:12:11 -0400
Subject: Re: Massive delete performance
From: Sean Davis <sdavis2@mail.nih.gov>
To: Andy <frum@ar-sd.net>, <pgsql-performance@postgresql.org>
Message-ID: <BF71245B.10304%sdavis2@mail.nih.gov>
In-Reply-To: <017601c5ce5c$219e1b10$0b00a8c0@forge>
Mime-version: 1.0
Content-type: text/plain; charset="US-ASCII"
Content-transfer-encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.013 required=5 tests=[AWL=0.013]
X-Spam-Level: 
X-Archive-Number: 200510/189
X-Sequence-Number: 14957

On 10/11/05 8:05 AM, "Andy" <frum@ar-sd.net> wrote:

>> Do you have foreign key relationships that must be followed for cascade
>> delete?  If so, make sure that you have indices on them.
> Yes I have such things. Indexes are on these fields. >> To be onest this
> delete is taking the longest time, but it involves about 10 tables.

Can you post explain analyze output of the next delete?

Sean


From pgsql-performance-owner@postgresql.org  Tue Oct 11 09:19:55 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 68C1BD701B
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 11 Oct 2005 09:19:54 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 59218-10
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 11 Oct 2005 12:19:45 +0000 (GMT)
Received: from cassarossa.samfundet.no (cassarossa.samfundet.no
	[129.241.93.19])
	by svr1.postgresql.org (Postfix) with ESMTP id 6E3E0D7061
	for <pgsql-performance@postgresql.org>;
	Tue, 11 Oct 2005 09:19:44 -0300 (ADT)
Received: from trofast.sesse.net ([129.241.93.32])
	by cassarossa.samfundet.no with esmtp (Exim 4.50) id 1EPJ6g-0000Wq-DQ
	for pgsql-performance@postgresql.org; Tue, 11 Oct 2005 14:19:47 +0200
Received: from sesse by trofast.sesse.net with local (Exim 3.36 #1 (Debian))
	id 1EPJ6c-0006ln-00
	for <pgsql-performance@postgresql.org>; Tue, 11 Oct 2005 14:19:42 +0200
Date: Tue, 11 Oct 2005 14:19:42 +0200
From: "Steinar H. Gunderson" <sgunderson@bigfoot.com>
To: pgsql-performance@postgresql.org
Subject: Re: Massive delete performance
Message-ID: <20051011121942.GA25543@uio.no>
Mail-Followup-To: pgsql-performance@postgresql.org
References: <00bd01c5ce37$f8a4cc00$0b00a8c0@forge>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
In-Reply-To: <00bd01c5ce37$f8a4cc00$0b00a8c0@forge>
X-Operating-System: Linux 2.6.11.8 on a i686
X-Message-Flag: Outlook? --> http://www.mozilla.org/products/thunderbird/
User-Agent: Mutt/1.5.11
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.012 required=5 tests=[AWL=0.012]
X-Spam-Level: 
X-Archive-Number: 200510/190
X-Sequence-Number: 14958

On Tue, Oct 11, 2005 at 10:47:03AM +0300, Andy wrote:
> So, I have a replication only with the tables that I need to send, then I
> make a copy of this replication, and from this copy I delete all the data's
> that are not needed. 
> 
> How can I increase this DELETE procedure because it is really slow???
> There are of corse a lot of data's to be deleted. 

Instead of copying and then deleting, could you try just selecting out what
you wanted in the first place?

/* Steinar */
-- 
Homepage: http://www.sesse.net/

From pgsql-performance-owner@postgresql.org  Tue Oct 11 10:28:14 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 2C9EFD7095
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 11 Oct 2005 10:28:14 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 22355-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 11 Oct 2005 13:28:07 +0000 (GMT)
Received: from ar-sd.net (unknown [82.77.155.72])
	by svr1.postgresql.org (Postfix) with ESMTP id 8E362D7047
	for <pgsql-performance@postgresql.org>;
	Tue, 11 Oct 2005 10:28:09 -0300 (ADT)
Received: from localhost (localhost [127.0.0.1])
	by ar-sd.net (Postfix) with ESMTP id 431F0215A3;
	Tue, 11 Oct 2005 16:12:04 +0300 (EEST)
Received: from ar-sd.net ([127.0.0.1])
	by localhost (linz [127.0.0.1]) (amavisd-new, port 10024) with ESMTP
	id 11529-02; Tue, 11 Oct 2005 16:12:00 +0300 (EEST)
Received: from forge (unknown [192.168.0.11])
	by ar-sd.net (Postfix) with SMTP id AC1201EE89;
	Tue, 11 Oct 2005 16:12:00 +0300 (EEST)
Message-ID: <01e401c5ce67$93d65de0$0b00a8c0@forge>
From: "Andy" <frum@ar-sd.net>
To: "Steinar H. Gunderson" <sgunderson@bigfoot.com>,
	<pgsql-performance@postgresql.org>
References: <00bd01c5ce37$f8a4cc00$0b00a8c0@forge>
	<20051011121942.GA25543@uio.no>
Subject: Re: Massive delete performance
Date: Tue, 11 Oct 2005 16:27:48 +0300
MIME-Version: 1.0
Content-Type: text/plain; format=flowed; charset="utf-8"; reply-type=original
Content-Transfer-Encoding: 7bit
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-Virus-Scanned: by amavisd-new at ar-sd.net
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.214 required=5 tests=[AWL=0.164,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/191
X-Sequence-Number: 14959

We run the DB on a linux system. The client has a windows system. The
application is almost the same (so the database structure is 80% the same).
The difference is that the client does not need all the tables.

So, in the remaining tables there are a lot of extra data's that don't
belong to this client. We have to send every night a updated "info" to the
client database. Our (have to admin) "fast and not the best" solution was so
replicated the needed tables, and delete from these the info that is not
needed.

So, I send to this client a "dump" from the database.

I also find the ideea "not the best", but couldn't find in two days another
fast solution. And it works this way for 4 months.

Out database is not THAT big (500MB), the replication about (300MB)...
everything works fast enough except this delete....


How can I evidence the cascade deletes also on explain analyze?

The answer for Sean Davis <sdavis2@mail.nih.gov>:

EXPLAIN ANALYZE
DELETE FROM report WHERE id_order IN
(SELECT o.id FROM orders o WHERE o.id_ag NOT IN (SELECT cp.id_ag FROM users 
u INNER JOIN
contactpartner cp ON cp.id_user=u.id WHERE u.name in ('dc') ORDER BY 
cp.id_ag))

Hash IN Join  (cost=3532.83..8182.33 rows=32042 width=6) (actual 
time=923.456..2457.323 rows=59557 loops=1)
  Hash Cond: ("outer".id_order = "inner".id)
  ->  Seq Scan on report  (cost=0.00..2613.83 rows=64083 width=10) (actual 
time=33.269..1159.024 rows=64083 loops=1)
  ->  Hash  (cost=3323.31..3323.31 rows=32608 width=4) (actual 
time=890.021..890.021 rows=0 loops=1)
        ->  Seq Scan on orders o  (cost=21.12..3323.31 rows=32608 width=4) 
(actual time=58.428..825.306 rows=60596 loops=1)
              Filter: (NOT (hashed subplan))
              SubPlan
                ->  Sort  (cost=21.11..21.12 rows=3 width=4) (actual 
time=47.612..47.612 rows=1 loops=1)
                      Sort Key: cp.id_ag
                      ->  Nested Loop  (cost=0.00..21.08 rows=3 width=4) 
(actual time=47.506..47.516 rows=1 loops=1)
                            ->  Index Scan using users_name_idx on users u 
(cost=0.00..5.65 rows=1 width=4) (actual time=20.145..20.148 rows=1 loops=1)
                                  Index Cond: ((name)::text = 'dc'::text)
                            ->  Index Scan using contactpartner_id_user_idx 
on contactpartner cp  (cost=0.00..15.38 rows=4 width=8) (actual 
time=27.348..27.352 rows=1 loops=1)
                                  Index Cond: (cp.id_user = "outer".id)
Total runtime: 456718.658 ms




----- Original Message ----- 
From: "Steinar H. Gunderson" <sgunderson@bigfoot.com>
To: <pgsql-performance@postgresql.org>
Sent: Tuesday, October 11, 2005 3:19 PM
Subject: Re: [PERFORM] Massive delete performance


> On Tue, Oct 11, 2005 at 10:47:03AM +0300, Andy wrote:
>> So, I have a replication only with the tables that I need to send, then I
>> make a copy of this replication, and from this copy I delete all the
>> data's
>> that are not needed.
>>
>> How can I increase this DELETE procedure because it is really slow???
>> There are of corse a lot of data's to be deleted.
>
> Instead of copying and then deleting, could you try just selecting out
> what
> you wanted in the first place?
>
> /* Steinar */
> -- 
> Homepage: http://www.sesse.net/
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: don't forget to increase your free space map settings
>
>


From pgsql-performance-owner@postgresql.org  Tue Oct 11 10:49:52 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id E4836D6FF2
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 11 Oct 2005 10:49:50 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 02519-03
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 11 Oct 2005 13:49:43 +0000 (GMT)
Received: from smtp-gw-cl-c.dmv.com (smtp-gw-cl-c.dmv.com [216.240.97.41])
	by svr1.postgresql.org (Postfix) with ESMTP id 81E73D6D78
	for <pgsql-performance@postgresql.org>;
	Tue, 11 Oct 2005 10:49:45 -0300 (ADT)
Received: from mail-gw-cl-b.dmv.com (mail-gw-cl-b.dmv.com [216.240.97.39])
	by smtp-gw-cl-c.dmv.com (8.12.10/8.12.10) with ESMTP id j9BDnZQb070417;
	Tue, 11 Oct 2005 09:49:35 -0400 (EDT) (envelope-from sven@dmv.com)
Received: from lanshark.dmv.com (lanshark.dmv.com [216.240.97.46])
	by mail-gw-cl-b.dmv.com (8.12.9/8.12.9) with ESMTP id j9BDnVGC000999;
	Tue, 11 Oct 2005 09:49:31 -0400 (EDT) (envelope-from sven@dmv.com)
Subject: Re: Performance on SUSE w/ reiserfs
From: Sven Willenberger <sven@dmv.com>
To: Claus Guttesen <kometen@gmail.com>
Cc: Jon Brisbin <jon.brisbin@npcinternational.com>,
	pgsql-performance@postgresql.org
In-Reply-To: <b41c75520510110041j4b3d4017y@mail.gmail.com>
References: <434ADD46.5060206@npcinternational.com>
	<b41c75520510101445jd8a9f06k@mail.gmail.com>
	<434AE7A1.3050700@npcinternational.com>
	<b41c75520510110041j4b3d4017y@mail.gmail.com>
Content-Type: text/plain
Date: Tue, 11 Oct 2005 09:52:30 -0400
Message-Id: <1129038750.1975.13.camel@lanshark.dmv.com>
Mime-Version: 1.0
X-Mailer: Evolution 2.2.1.1 
Content-Transfer-Encoding: 7bit
X-Scanned-By: MIMEDefang 2.39
X-Scanned-By: MIMEDefang 2.48 on 216.240.97.39
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.33 required=5 tests=[AWL=-0.162,
	DNS_FROM_RFC_WHOIS=0.492]
X-Spam-Level: 
X-Archive-Number: 200510/192
X-Sequence-Number: 14960

On Tue, 2005-10-11 at 09:41 +0200, Claus Guttesen wrote:
> I have a postgresql 7.4.8-server with 4 GB ram.

<snip>
> 
> > #effective_cache_size = 1000    # typically 8KB each
> 
> This is computed by sysctl -n vfs.hibufspace / 8192 (on FreeBSD). So I
> changed it to:
> 
> effective_cache_size = 27462    # typically 8KB each

Apparently this formula is no longer relevant on the FreeBSD systems as
it can cache up to almost all the available RAM. With 4GB of RAM, one
could specify most of the RAM as being available for caching, assuming
that nothing but PostgreSQL runs on the server -- certainly 1/2 the RAM
would be a reasonable value to tell the planner.

(This was verified by using dd: 
dd if=/dev/zero of=/usr/local/pgsql/iotest bs=128k count=16384 to create
a 2G file then
dd if=/usr/local/pgsql/iotest of=/dev/null

If you run systat -vmstat 2 you will see 0% diskaccess during the read
of the 2G file indicating that it has, in fact, been cached)


Sven


From pgsql-performance-owner@postgresql.org  Tue Oct 11 11:18:53 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 063E3D7057
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 11 Oct 2005 11:17:30 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 48567-10
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 11 Oct 2005 14:17:21 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id 54BC0D6E41
	for <pgsql-performance@postgresql.org>;
	Tue, 11 Oct 2005 11:17:23 -0300 (ADT)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j9BEHCNv013906;
	Tue, 11 Oct 2005 10:17:12 -0400 (EDT)
To: "Andy" <frum@ar-sd.net>
Cc: "Steinar H. Gunderson" <sgunderson@bigfoot.com>,
	pgsql-performance@postgresql.org
Subject: Re: Massive delete performance 
In-reply-to: <01e401c5ce67$93d65de0$0b00a8c0@forge> 
References: <00bd01c5ce37$f8a4cc00$0b00a8c0@forge>
	<20051011121942.GA25543@uio.no>
	<01e401c5ce67$93d65de0$0b00a8c0@forge>
Comments: In-reply-to "Andy" <frum@ar-sd.net>
	message dated "Tue, 11 Oct 2005 16:27:48 +0300"
Date: Tue, 11 Oct 2005 10:17:12 -0400
Message-ID: <13905.1129040232@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/193
X-Sequence-Number: 14961

"Andy" <frum@ar-sd.net> writes:
> EXPLAIN ANALYZE
> DELETE FROM report WHERE id_order IN
> ...

> Hash IN Join  (cost=3532.83..8182.33 rows=32042 width=6) (actual 
> time=923.456..2457.323 rows=59557 loops=1)
> ...
> Total runtime: 456718.658 ms

So the runtime is all in the delete triggers.  The usual conclusion from
this is that there is a foreign key column pointing at this table that
does not have an index, or is not the same datatype as the column it
references.  Either condition will force a fairly inefficient way of
handling the FK deletion check.

			regards, tom lane

From pgsql-performance-owner@postgresql.org  Tue Oct 11 11:27:40 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 54ABAD7104
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 11 Oct 2005 11:27:39 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 25062-03
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 11 Oct 2005 14:27:29 +0000 (GMT)
Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.198])
	by svr1.postgresql.org (Postfix) with ESMTP id BD440D70AE
	for <pgsql-performance@postgresql.org>;
	Tue, 11 Oct 2005 11:27:31 -0300 (ADT)
Received: by wproxy.gmail.com with SMTP id 71so207812wra
	for <pgsql-performance@postgresql.org>;
	Tue, 11 Oct 2005 07:27:36 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references;
	b=WiqiTigW5D6l6HzD4nmvIF3CUwOJEXYb8WtOjdabC4us974FtYKcI+8NMc+N0xAbLnLFVHcu6SILZv2Uou84UgmlPyR2F+Cmm809kRfoNjMQGb8kKnS6Uf6jQq9VfItBzxqdr4E8BVmMoJz9rrjmlKD/kRyF2MDRRErngyFYJmE=
Received: by 10.54.72.8 with SMTP id u8mr3541801wra;
	Tue, 11 Oct 2005 07:27:36 -0700 (PDT)
Received: by 10.54.84.8 with HTTP; Tue, 11 Oct 2005 07:27:36 -0700 (PDT)
Message-ID: <33c6269f0510110727q62a797a1g9493661e1dc905d4@mail.gmail.com>
Date: Tue, 11 Oct 2005 10:27:36 -0400
From: Alex Turner <armtuk@gmail.com>
To: Jon Brisbin <jon.brisbin@npcinternational.com>
Subject: Re: Performance on SUSE w/ reiserfs
Cc: pgsql-performance@postgresql.org
In-Reply-To: <434AE7FF.4000705@npcinternational.com>
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="----=_Part_5190_20364293.1129040856481"
References: <434ADD46.5060206@npcinternational.com>
	<6247.1128981289@sss.pgh.pa.us>
	<434AE7FF.4000705@npcinternational.com>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.355 required=5 tests=[AWL=-0.174, HTML_20_30=0.504,
	HTML_MESSAGE=0.001, RCVD_BY_IP=0.024]
X-Spam-Level: 
X-Archive-Number: 200510/194
X-Sequence-Number: 14962

------=_Part_5190_20364293.1129040856481
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Realise also that unless you are running the 1.5 x86-64 build, java will no=
t
use more than 1Gig, and if the app server requests more than 1gig, Java wil=
l
die (I've been there) with an out of memory error, even though there is
plenty of free mem available. This can easily be cause by a lazy GC thread
if the applicaiton is running high on CPU usage.

The kernel will not report memory used for caching pages as being
unavailable, if a program calls a malloc, the kernel will just swap out the
oldest disk page and give the memory to the application.

Your free -mo shows 3 gig free even with cached disk pages. It looks to me
more like either a Java problem, or a kernel problem...

Alex Turner
NetEconomist

On 10/10/05, Jon Brisbin <jon.brisbin@npcinternational.com> wrote:
>
> Tom Lane wrote:
> >
> > Are you sure it's not cached data pages, rather than cached inodes?
> > If so, the above behavior is *good*.
> >
> > People often have a mistaken notion that having near-zero free RAM mean=
s
> > they have a problem. In point of fact, that is the way it is supposed
> > to be (at least on Unix-like systems). This is just a reflection of the
> > kernel doing what it is supposed to do, which is to use all spare RAM
> > for caching recently accessed disk pages. If you're not swapping then
> > you do not have a problem.
>
> Except for the fact that my Java App server crashes when all the
> available memory is being used by caching and not reclaimed :-)
>
> If it wasn't for the app server going down, I probably wouldn't care.
>
> --
>
> Jon Brisbin
> Webmaster
> NPC International, Inc.
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
>

------=_Part_5190_20364293.1129040856481
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Realise also that unless you are running the 1.5 x86-64 build, java
will not use more than 1Gig, and if the app server requests more than
1gig, Java will die (I've been there) with an out of memory error, even
though there is plenty of free mem available.&nbsp; This can easily be
cause by a lazy GC thread if the applicaiton is running high on CPU
usage.<br>
<br>
The kernel will not report memory used for caching pages as being
unavailable, if a program calls a malloc, the kernel will just swap out
the oldest disk page and give the memory to the application.<br>
<br>
Your free -mo shows 3 gig free even with cached disk pages.&nbsp; It
looks to me more like either a Java problem, or a kernel problem...<br>
<br>
Alex Turner<br>
NetEconomist<br><br><div><span class=3D"gmail_quote">On 10/10/05, <b class=
=3D"gmail_sendername">Jon Brisbin</b> &lt;<a href=3D"mailto:jon.brisbin@npc=
international.com">jon.brisbin@npcinternational.com</a>&gt; wrote:</span><b=
lockquote class=3D"gmail_quote" style=3D"border-left: 1px solid rgb(204, 20=
4, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Tom Lane wrote:<br>&gt;<br>&gt; Are you sure it's not cached data pages, ra=
ther than cached inodes?<br>&gt; If so, the above behavior is *good*.<br>&g=
t;<br>&gt; People often have a mistaken notion that having near-zero free R=
AM means
<br>&gt; they have a problem.&nbsp;&nbsp;In point of fact, that is the way =
it is supposed<br>&gt; to be (at least on Unix-like systems).&nbsp;&nbsp;Th=
is is just a reflection of the<br>&gt; kernel doing what it is supposed to =
do, which is to use all spare RAM
<br>&gt; for caching recently accessed disk pages.&nbsp;&nbsp;If you're not=
 swapping then<br>&gt; you do not have a problem.<br><br>Except for the fac=
t that my Java App server crashes when all the<br>available memory is being=
 used by caching and not reclaimed :-)
<br><br>If it wasn't for the app server going down, I probably wouldn't car=
e.<br><br>--<br><br>Jon Brisbin<br>Webmaster<br>NPC International, Inc.<br>=
<br>---------------------------(end of broadcast)--------------------------=
-
<br>TIP 1: if posting/reading through Usenet, please send an appropriate<br=
>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; subscribe-nomail command to <a href=
=3D"mailto:majordomo@postgresql.org">majordomo@postgresql.org</a> so that y=
our<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; message can get through to the =
mailing list cleanly
<br></blockquote></div><br>

------=_Part_5190_20364293.1129040856481--

From pgsql-performance-owner@postgresql.org  Tue Oct 11 11:27:45 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 2E1E9D7129
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 11 Oct 2005 11:27:44 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 76328-10
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 11 Oct 2005 14:27:39 +0000 (GMT)
Received: from ar-sd.net (unknown [82.77.155.72])
	by svr1.postgresql.org (Postfix) with ESMTP id 1E2E6D710C
	for <pgsql-performance@postgresql.org>;
	Tue, 11 Oct 2005 11:27:42 -0300 (ADT)
Received: from localhost (localhost [127.0.0.1])
	by ar-sd.net (Postfix) with ESMTP id 110E62164D;
	Tue, 11 Oct 2005 17:11:37 +0300 (EEST)
Received: from ar-sd.net ([127.0.0.1])
	by localhost (linz [127.0.0.1]) (amavisd-new, port 10024) with ESMTP
	id 11529-08; Tue, 11 Oct 2005 17:11:33 +0300 (EEST)
Received: from forge (unknown [192.168.0.11])
	by ar-sd.net (Postfix) with SMTP id 56C5121649;
	Tue, 11 Oct 2005 17:11:33 +0300 (EEST)
Message-ID: <001101c5ce6f$f0f4e480$0b00a8c0@forge>
From: "Andy" <frum@ar-sd.net>
To: "Tom Lane" <tgl@sss.pgh.pa.us>
Cc: "Steinar H. Gunderson" <sgunderson@bigfoot.com>,
	<pgsql-performance@postgresql.org>
References: <00bd01c5ce37$f8a4cc00$0b00a8c0@forge>
	<20051011121942.GA25543@uio.no>
	<01e401c5ce67$93d65de0$0b00a8c0@forge>
	<13905.1129040232@sss.pgh.pa.us>
Subject: Re: Massive delete performance 
Date: Tue, 11 Oct 2005 17:27:40 +0300
MIME-Version: 1.0
Content-Type: text/plain; format=flowed; charset="iso-8859-1";
	reply-type=original
Content-Transfer-Encoding: 7bit
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-Virus-Scanned: by amavisd-new at ar-sd.net
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.203 required=5 tests=[AWL=0.153,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/195
X-Sequence-Number: 14963

Ups folks,

Indeed there were 2 important indexes missing. Now it runs about 10 times 
faster. Sorry for the caused trouble :) and thanx for help.


Hash IN Join  (cost=3307.49..7689.47 rows=30250 width=6) (actual 
time=227.666..813.786 rows=56374 loops=1)
  Hash Cond: ("outer".id_order = "inner".id)
  ->  Seq Scan on report  (cost=0.00..2458.99 rows=60499 width=10) (actual 
time=0.035..269.422 rows=60499 loops=1)
  ->  Hash  (cost=3109.24..3109.24 rows=30901 width=4) (actual 
time=227.459..227.459 rows=0 loops=1)
        ->  Seq Scan on orders o  (cost=9.73..3109.24 rows=30901 width=4) 
(actual time=0.429..154.219 rows=57543 loops=1)
              Filter: (NOT (hashed subplan))
              SubPlan
                ->  Sort  (cost=9.71..9.72 rows=3 width=4) (actual 
time=0.329..0.330 rows=1 loops=1)
                      Sort Key: cp.id_ag
                      ->  Nested Loop  (cost=0.00..9.69 rows=3 width=4) 
(actual time=0.218..0.224 rows=1 loops=1)
                            ->  Index Scan using users_name_idx on users u 
(cost=0.00..5.61 rows=1 width=4) (actual time=0.082..0.084 rows=1 loops=1)
                                  Index Cond: ((name)::text = 'dc'::text)
                            ->  Index Scan using contactpartner_id_user_idx 
on contactpartner cp  (cost=0.00..4.03 rows=3 width=8) (actual 
time=0.125..0.127 rows=1 loops=1)
                                  Index Cond: (cp.id_user = "outer".id)
Total runtime: 31952.811 ms



----- Original Message ----- 
From: "Tom Lane" <tgl@sss.pgh.pa.us>
To: "Andy" <frum@ar-sd.net>
Cc: "Steinar H. Gunderson" <sgunderson@bigfoot.com>; 
<pgsql-performance@postgresql.org>
Sent: Tuesday, October 11, 2005 5:17 PM
Subject: Re: [PERFORM] Massive delete performance


> "Andy" <frum@ar-sd.net> writes:
>> EXPLAIN ANALYZE
>> DELETE FROM report WHERE id_order IN
>> ...
>
>> Hash IN Join  (cost=3532.83..8182.33 rows=32042 width=6) (actual
>> time=923.456..2457.323 rows=59557 loops=1)
>> ...
>> Total runtime: 456718.658 ms
>
> So the runtime is all in the delete triggers.  The usual conclusion from
> this is that there is a foreign key column pointing at this table that
> does not have an index, or is not the same datatype as the column it
> references.  Either condition will force a fairly inefficient way of
> handling the FK deletion check.
>
> regards, tom lane
>
> 


From pgsql-performance-owner@postgresql.org  Tue Oct 11 11:51:56 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id A73CAD78EB
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 11 Oct 2005 11:51:55 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 90968-03
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 11 Oct 2005 14:51:46 +0000 (GMT)
Received: from unicorn.rentec.com (unicorn.rentec.com [216.223.240.9])
	by svr1.postgresql.org (Postfix) with ESMTP id 7C402D766F
	for <pgsql-performance@postgresql.org>;
	Tue, 11 Oct 2005 11:51:47 -0300 (ADT)
Received: from ram.rentec.com (mailhost [192.5.35.66])
	by unicorn.rentec.com (8.13.1/8.12.1) with ESMTP id j9BEphSW019031
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO);
	Tue, 11 Oct 2005 10:51:44 -0400 (EDT)
X-Source: non-mednet
Received: from [172.26.132.145] (hoopoe.rentec.com [172.26.132.145])
	by ram.rentec.com (8.13.1/8.12.1) with ESMTP id j9BEpgbQ020929;
	Tue, 11 Oct 2005 10:51:42 -0400 (EDT)
Message-ID: <434BD17E.7000605@rentec.com>
Date: Tue, 11 Oct 2005 10:51:42 -0400
From: Alan Stange <stange@rentec.com>
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.8) Gecko/20050519
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: Alex Turner <armtuk@gmail.com>
Cc: Jon Brisbin <jon.brisbin@npcinternational.com>,
	pgsql-performance@postgresql.org
Subject: Re: Performance on SUSE w/ reiserfs
References: <434ADD46.5060206@npcinternational.com>	
	<6247.1128981289@sss.pgh.pa.us>	
	<434AE7FF.4000705@npcinternational.com>
	<33c6269f0510110727q62a797a1g9493661e1dc905d4@mail.gmail.com>
In-Reply-To: <33c6269f0510110727q62a797a1g9493661e1dc905d4@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Logged: Logged by unicorn.rentec.com as j9BEphSW019031 at Tue Oct 11
	10:51:44 2005
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.014 required=5 tests=[AWL=0.014]
X-Spam-Level: 
X-Archive-Number: 200510/196
X-Sequence-Number: 14964

Alex Turner wrote:

> Realise also that unless you are running the 1.5 x86-64 build, java 
> will not use more than 1Gig, and if the app server requests more than 
> 1gig, Java will die (I've been there) with an out of memory error, 
> even though there is plenty of free mem available.  This can easily be 
> cause by a lazy GC thread if the applicaiton is running high on CPU usage.

On my side of Planet Earth, the standard non-x64 1.5 JVM will happily 
use more than 1G of memory (on linux and Solaris, can't speak for 
Windows).  If you're running larger programs, it's probably a good idea 
to use the -server compiler in the JVM as well.  I regularly run with 
-Xmx1800m and regularly have >1GB heap sizes.

The standard GC will not cause on OOM error if space remains for the 
requested object.  The GC thread blocks all other threads during its 
activity, whatever else is happening on the machine.   The 
newer/experimental GC's did have some potential race conditions, but I 
believe those have been resolved in the 1.5 JVMs.  

Finally, note that the latest _05 release of the 1.5 JVM also now 
supports large page sizes on Linux and Windows:
-XX:+UseLargePages   this can be quite beneficial depending on the 
memory patterns in your programs.

-- Alan

From pgsql-performance-owner@postgresql.org  Tue Oct 11 11:54:29 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 86593D7147
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 11 Oct 2005 11:54:28 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 88598-09
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 11 Oct 2005 14:54:24 +0000 (GMT)
Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.201])
	by svr1.postgresql.org (Postfix) with ESMTP id 6EA15D7055
	for <pgsql-performance@postgresql.org>;
	Tue, 11 Oct 2005 11:54:26 -0300 (ADT)
Received: by wproxy.gmail.com with SMTP id i20so679745wra
	for <pgsql-performance@postgresql.org>;
	Tue, 11 Oct 2005 07:54:31 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:to:subject:cc:mime-version:content-type:content-transfer-encoding:content-disposition;
	b=T1oHGcnYwyp7rTOxZJ3JuIUk6P8DDusaxYdx6rS2GPjY+54ML0IuuzqENFiyM34Xd6wzStriEHstYOfbCyas3n70jvIdKx5815qUNYp1N0WE0MJlTy5wICoTk8oUVld2KgRxUJGJ56hZZ2m+L3F6FMlw/9MlDd6QKGi8G5rfQHg=
Received: by 10.54.99.18 with SMTP id w18mr3590387wrb;
	Tue, 11 Oct 2005 07:54:31 -0700 (PDT)
Received: by 10.54.144.4 with HTTP; Tue, 11 Oct 2005 07:54:31 -0700 (PDT)
Message-ID: <b41c75520510110754g534d9fa8u@mail.gmail.com>
Date: Tue, 11 Oct 2005 16:54:31 +0200
From: Claus Guttesen <kometen@gmail.com>
To: Sven Willenberger <sven@dmv.com>
Subject: effective cache size on FreeBSD (WAS: Performance on SUSE w/
 reiserfs)
Cc: Jon Brisbin <jon.brisbin@npcinternational.com>,
	pgsql-performance@postgresql.org
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.024 required=5 tests=[RCVD_BY_IP=0.024]
X-Spam-Level: 
X-Archive-Number: 200510/197
X-Sequence-Number: 14965

> > I have a postgresql 7.4.8-server with 4 GB ram.
> > #effective_cache_size =3D 1000    # typically 8KB each
> >
> > This is computed by sysctl -n vfs.hibufspace / 8192 (on FreeBSD). So I
> > changed it to:
> >
> > effective_cache_size =3D 27462    # typically 8KB each
>
> Apparently this formula is no longer relevant on the FreeBSD systems as
> it can cache up to almost all the available RAM. With 4GB of RAM, one
> could specify most of the RAM as being available for caching, assuming
> that nothing but PostgreSQL runs on the server -- certainly 1/2 the RAM
> would be a reasonable value to tell the planner.
>
> (This was verified by using dd:
> dd if=3D/dev/zero of=3D/usr/local/pgsql/iotest bs=3D128k count=3D16384 to=
 create
> a 2G file then
> dd if=3D/usr/local/pgsql/iotest of=3D/dev/null
>
> If you run systat -vmstat 2 you will see 0% diskaccess during the read
> of the 2G file indicating that it has, in fact, been cached)

Thank you for your reply. Does this apply to FreeBSD 5.4 or 6.0 on
amd64 (or both)?

regards
Claus

From pgsql-performance-owner@postgresql.org  Tue Oct 11 11:57:12 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 80A89D701B
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 11 Oct 2005 11:57:10 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 88880-09
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 11 Oct 2005 14:57:02 +0000 (GMT)
Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.206])
	by svr1.postgresql.org (Postfix) with ESMTP id E2169D6F2D
	for <pgsql-performance@postgresql.org>;
	Tue, 11 Oct 2005 11:57:04 -0300 (ADT)
Received: by wproxy.gmail.com with SMTP id 71so211100wra
	for <pgsql-performance@postgresql.org>;
	Tue, 11 Oct 2005 07:57:10 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references;
	b=Iohpfsfq3uf+I4IPt8Rizn/iHrqbxobFUOaFXsnpOwx5498M/FVR+dorvpIA4jg2OavKxBdqQxCBvPRdGERydnE7qS1OwgMCvO0+znTIlFmCrf9JkkdJl+X7HMUA1bBmrZI8YgAceRj0aez+3haw1kvhYM5N6W6JG95hkiPO+CY=
Received: by 10.54.114.10 with SMTP id m10mr61726wrc;
	Tue, 11 Oct 2005 07:57:10 -0700 (PDT)
Received: by 10.54.84.8 with HTTP; Tue, 11 Oct 2005 07:57:10 -0700 (PDT)
Message-ID: <33c6269f0510110757v1632b9c5te578b699db922f45@mail.gmail.com>
Date: Tue, 11 Oct 2005 10:57:10 -0400
From: Alex Turner <armtuk@gmail.com>
To: Alan Stange <stange@rentec.com>
Subject: Re: Performance on SUSE w/ reiserfs
Cc: Jon Brisbin <jon.brisbin@npcinternational.com>,
	pgsql-performance@postgresql.org
In-Reply-To: <434BD17E.7000605@rentec.com>
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="----=_Part_5593_33551402.1129042630161"
References: <434ADD46.5060206@npcinternational.com>
	<6247.1128981289@sss.pgh.pa.us>
	<434AE7FF.4000705@npcinternational.com>
	<33c6269f0510110727q62a797a1g9493661e1dc905d4@mail.gmail.com>
	<434BD17E.7000605@rentec.com>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.356 required=5 tests=[AWL=-0.173, HTML_20_30=0.504,
	HTML_MESSAGE=0.001, RCVD_BY_IP=0.024]
X-Spam-Level: 
X-Archive-Number: 200510/198
X-Sequence-Number: 14966

------=_Part_5593_33551402.1129042630161
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Perhaps this is true for 1.5 on x86-32 (I've only used it on x86-64) but I
was more thinking 1.4 which many folks are still using.

Alex

On 10/11/05, Alan Stange <stange@rentec.com> wrote:
>
> Alex Turner wrote:
>
> > Realise also that unless you are running the 1.5 x86-64 build, java
> > will not use more than 1Gig, and if the app server requests more than
> > 1gig, Java will die (I've been there) with an out of memory error,
> > even though there is plenty of free mem available. This can easily be
> > cause by a lazy GC thread if the applicaiton is running high on CPU
> usage.
>
> On my side of Planet Earth, the standard non-x64 1.5 JVM will happily
> use more than 1G of memory (on linux and Solaris, can't speak for
> Windows). If you're running larger programs, it's probably a good idea
> to use the -server compiler in the JVM as well. I regularly run with
> -Xmx1800m and regularly have >1GB heap sizes.
>
> The standard GC will not cause on OOM error if space remains for the
> requested object. The GC thread blocks all other threads during its
> activity, whatever else is happening on the machine. The
> newer/experimental GC's did have some potential race conditions, but I
> believe those have been resolved in the 1.5 JVMs.
>
> Finally, note that the latest _05 release of the 1.5 JVM also now
> supports large page sizes on Linux and Windows:
> -XX:+UseLargePages this can be quite beneficial depending on the
> memory patterns in your programs.
>
> -- Alan
>

------=_Part_5593_33551402.1129042630161
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Perhaps this is true for 1.5 on x86-32 (I've only used it on x86-64)
but I was more thinking 1.4 which many folks are still using.<br>
<br>
Alex<br><br><div><span class=3D"gmail_quote">On 10/11/05, <b class=3D"gmail=
_sendername">Alan Stange</b> &lt;<a href=3D"mailto:stange@rentec.com">stang=
e@rentec.com</a>&gt; wrote:</span><blockquote class=3D"gmail_quote" style=
=3D"border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; p=
adding-left: 1ex;">
Alex Turner wrote:<br><br>&gt; Realise also that unless you are running the=
 1.5 x86-64 build, java<br>&gt; will not use more than 1Gig, and if the app=
 server requests more than<br>&gt; 1gig, Java will die (I've been there) wi=
th an out of memory error,
<br>&gt; even though there is plenty of free mem available.&nbsp;&nbsp;This=
 can easily be<br>&gt; cause by a lazy GC thread if the applicaiton is runn=
ing high on CPU usage.<br><br>On my side of Planet Earth, the standard non-=
x64 1.5
 JVM will happily<br>use more than 1G of memory (on linux and Solaris, can'=
t speak for<br>Windows).&nbsp;&nbsp;If you're running larger programs, it's=
 probably a good idea<br>to use the -server compiler in the JVM as well.&nb=
sp;&nbsp;I regularly run with
<br>-Xmx1800m and regularly have &gt;1GB heap sizes.<br><br>The standard GC=
 will not cause on OOM error if space remains for the<br>requested object.&=
nbsp;&nbsp;The GC thread blocks all other threads during its<br>activity, w=
hatever else is happening on the machine.&nbsp;&nbsp; The
<br>newer/experimental GC's did have some potential race conditions, but I<=
br>believe those have been resolved in the 1.5 JVMs.<br><br>Finally, note t=
hat the latest _05 release of the 1.5 JVM also now<br>supports large page s=
izes on Linux and Windows:
<br>-XX:+UseLargePages&nbsp;&nbsp; this can be quite beneficial depending o=
n the<br>memory patterns in your programs.<br><br>-- Alan<br></blockquote><=
/div><br>

------=_Part_5593_33551402.1129042630161--

From pgsql-performance-owner@postgresql.org  Tue Oct 11 12:03:24 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 855CCD6D71
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 11 Oct 2005 12:01:39 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 21956-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 11 Oct 2005 15:01:36 +0000 (GMT)
Received: from smtp-gw-cl-c.dmv.com (smtp-gw-cl-c.dmv.com [216.240.97.41])
	by svr1.postgresql.org (Postfix) with ESMTP id 25D27D722D
	for <pgsql-performance@postgresql.org>;
	Tue, 11 Oct 2005 12:01:35 -0300 (ADT)
Received: from mail-gw-cl-a.dmv.com (mail-gw-cl-a.dmv.com [216.240.97.38])
	by smtp-gw-cl-c.dmv.com (8.12.10/8.12.10) with ESMTP id j9BF1PQb074223;
	Tue, 11 Oct 2005 11:01:25 -0400 (EDT) (envelope-from sven@dmv.com)
Received: from lanshark.dmv.com (lanshark.dmv.com [216.240.97.46])
	by mail-gw-cl-a.dmv.com (8.12.9/8.12.9) with ESMTP id j9BF1PLR019756;
	Tue, 11 Oct 2005 11:01:25 -0400 (EDT) (envelope-from sven@dmv.com)
Subject: Re: effective cache size on FreeBSD (WAS: Performance on SUSE w/
From: Sven Willenberger <sven@dmv.com>
To: Claus Guttesen <kometen@gmail.com>
Cc: Jon Brisbin <jon.brisbin@npcinternational.com>,
	pgsql-performance@postgresql.org
In-Reply-To: <b41c75520510110754g534d9fa8u@mail.gmail.com>
References: <b41c75520510110754g534d9fa8u@mail.gmail.com>
Content-Type: text/plain
Date: Tue, 11 Oct 2005 11:04:24 -0400
Message-Id: <1129043064.1975.22.camel@lanshark.dmv.com>
Mime-Version: 1.0
X-Mailer: Evolution 2.2.1.1 
Content-Transfer-Encoding: 7bit
X-Scanned-By: MIMEDefang 2.39
X-Scanned-By: MIMEDefang 2.48 on 216.240.97.38
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.33 required=5 tests=[AWL=-0.162,
	DNS_FROM_RFC_WHOIS=0.492]
X-Spam-Level: 
X-Archive-Number: 200510/199
X-Sequence-Number: 14967

On Tue, 2005-10-11 at 16:54 +0200, Claus Guttesen wrote:
> > > I have a postgresql 7.4.8-server with 4 GB ram.
> > > #effective_cache_size = 1000    # typically 8KB each
> > >
> > > This is computed by sysctl -n vfs.hibufspace / 8192 (on FreeBSD). So I
> > > changed it to:
> > >
> > > effective_cache_size = 27462    # typically 8KB each
> >
> > Apparently this formula is no longer relevant on the FreeBSD systems as
> > it can cache up to almost all the available RAM. With 4GB of RAM, one
> > could specify most of the RAM as being available for caching, assuming
> > that nothing but PostgreSQL runs on the server -- certainly 1/2 the RAM
> > would be a reasonable value to tell the planner.
> >
> > (This was verified by using dd:
> > dd if=/dev/zero of=/usr/local/pgsql/iotest bs=128k count=16384 to create
> > a 2G file then
> > dd if=/usr/local/pgsql/iotest of=/dev/null
> >
> > If you run systat -vmstat 2 you will see 0% diskaccess during the read
> > of the 2G file indicating that it has, in fact, been cached)
> 
> Thank you for your reply. Does this apply to FreeBSD 5.4 or 6.0 on
> amd64 (or both)?
> 

Not sure about 6.0 (but I don't know why it would change) but definitely
on 5.4 amd64 (and I would imagine i386 as well).

Sven


From pgsql-performance-owner@postgresql.org  Tue Oct 11 12:28:41 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 5F0CCD6F46
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 11 Oct 2005 12:28:40 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 96661-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 11 Oct 2005 15:28:35 +0000 (GMT)
Received: from unicorn.rentec.com (unicorn.rentec.com [216.223.240.9])
	by svr1.postgresql.org (Postfix) with ESMTP id 26487D6D71
	for <pgsql-performance@postgresql.org>;
	Tue, 11 Oct 2005 12:28:35 -0300 (ADT)
Received: from ram.rentec.com (mailhost [192.5.35.66])
	by unicorn.rentec.com (8.13.1/8.12.1) with ESMTP id j9BFSUvK021335
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO);
	Tue, 11 Oct 2005 11:28:31 -0400 (EDT)
X-Source: non-mednet
Received: from [172.26.132.145] (hoopoe.rentec.com [172.26.132.145])
	by ram.rentec.com (8.13.1/8.12.1) with ESMTP id j9BFSUim025504;
	Tue, 11 Oct 2005 11:28:30 -0400 (EDT)
Message-ID: <434BDA1E.5030804@rentec.com>
Date: Tue, 11 Oct 2005 11:28:30 -0400
From: Alan Stange <stange@rentec.com>
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.8) Gecko/20050519
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: Alex Turner <armtuk@gmail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Performance on SUSE w/ reiserfs
References: <434ADD46.5060206@npcinternational.com>	
	<6247.1128981289@sss.pgh.pa.us>	
	<434AE7FF.4000705@npcinternational.com>	
	<33c6269f0510110727q62a797a1g9493661e1dc905d4@mail.gmail.com>	
	<434BD17E.7000605@rentec.com>
	<33c6269f0510110757v1632b9c5te578b699db922f45@mail.gmail.com>
In-Reply-To: <33c6269f0510110757v1632b9c5te578b699db922f45@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Logged: Logged by unicorn.rentec.com as j9BFSUvK021335 at Tue Oct 11
	11:28:31 2005
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.014 required=5 tests=[AWL=0.014]
X-Spam-Level: 
X-Archive-Number: 200510/200
X-Sequence-Number: 14968

Alex Turner wrote:

> Perhaps this is true for 1.5 on x86-32 (I've only used it on x86-64) 
> but I was more thinking 1.4 which many folks are still using.

The 1.4.x JVM's will also work just fine with much more than 1GB of 
memory.   Perhaps you'd like to try again?

-- Alan

>
> On 10/11/05, *Alan Stange* <stange@rentec.com 
> <mailto:stange@rentec.com>> wrote:
>
>     Alex Turner wrote:
>
>     > Realise also that unless you are running the 1.5 x86-64 build, java
>     > will not use more than 1Gig, and if the app server requests more
>     than
>     > 1gig, Java will die (I've been there) with an out of memory error,
>     > even though there is plenty of free mem available.  This can
>     easily be
>     > cause by a lazy GC thread if the applicaiton is running high on
>     CPU usage.
>
>     On my side of Planet Earth, the standard non-x64 1.5 JVM will happily
>     use more than 1G of memory (on linux and Solaris, can't speak for
>     Windows).  If you're running larger programs, it's probably a good
>     idea
>     to use the -server compiler in the JVM as well.  I regularly run with
>     -Xmx1800m and regularly have >1GB heap sizes.
>
>     The standard GC will not cause on OOM error if space remains for the
>     requested object.  The GC thread blocks all other threads during its
>     activity, whatever else is happening on the machine.   The
>     newer/experimental GC's did have some potential race conditions, but I
>     believe those have been resolved in the 1.5 JVMs.
>
>     Finally, note that the latest _05 release of the 1.5 JVM also now
>     supports large page sizes on Linux and Windows:
>     -XX:+UseLargePages   this can be quite beneficial depending on the
>     memory patterns in your programs.
>
>     -- Alan
>
>


From pgsql-performance-owner@postgresql.org  Tue Oct 11 14:24:03 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id D9663D6D71
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 11 Oct 2005 14:24:02 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 90094-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 11 Oct 2005 17:23:59 +0000 (GMT)
Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.195])
	by svr1.postgresql.org (Postfix) with ESMTP id B11CBD6F01
	for <pgsql-performance@postgresql.org>;
	Tue, 11 Oct 2005 14:23:58 -0300 (ADT)
Received: by wproxy.gmail.com with SMTP id 71so227590wra
	for <pgsql-performance@postgresql.org>;
	Tue, 11 Oct 2005 10:23:59 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references;
	b=J8v7z+Ie2XncbYsGdS1FlURpOjGNy+BsCszZRMx1Pfh5a88/NAvfltnfOMOGX1nc+9/AkLiPfAKHSB7xG8XmNMfZp0XsfkKhXI4Mjx9j6r5W7NW8lzXwyhWHoqBITiwRKhMwXII2wm4nztJmYNL71wBYA/gq45KiKuZfMzaF48Y=
Received: by 10.54.69.10 with SMTP id r10mr3646364wra;
	Tue, 11 Oct 2005 10:23:59 -0700 (PDT)
Received: by 10.54.144.4 with HTTP; Tue, 11 Oct 2005 10:23:59 -0700 (PDT)
Message-ID: <b41c75520510111023n7ae48ff8j@mail.gmail.com>
Date: Tue, 11 Oct 2005 19:23:59 +0200
From: Claus Guttesen <kometen@gmail.com>
To: Sven Willenberger <sven@dmv.com>
Subject: Re: effective cache size on FreeBSD (WAS: Performance on SUSE w/
Cc: Jon Brisbin <jon.brisbin@npcinternational.com>,
	pgsql-performance@postgresql.org
In-Reply-To: <1129043064.1975.22.camel@lanshark.dmv.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
References: <b41c75520510110754g534d9fa8u@mail.gmail.com>
	<1129043064.1975.22.camel@lanshark.dmv.com>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.024 required=5 tests=[RCVD_BY_IP=0.024]
X-Spam-Level: 
X-Archive-Number: 200510/201
X-Sequence-Number: 14969

> > > Apparently this formula is no longer relevant on the FreeBSD systems =
as
> > > it can cache up to almost all the available RAM. With 4GB of RAM, one
> > > could specify most of the RAM as being available for caching, assumin=
g
> > > that nothing but PostgreSQL runs on the server -- certainly 1/2 the R=
AM
> > > would be a reasonable value to tell the planner.
> > >
> > > (This was verified by using dd:
> > > dd if=3D/dev/zero of=3D/usr/local/pgsql/iotest bs=3D128k count=3D1638=
4 to create
> > > a 2G file then
> > > dd if=3D/usr/local/pgsql/iotest of=3D/dev/null
> > >
> > > If you run systat -vmstat 2 you will see 0% diskaccess during the rea=
d
> > > of the 2G file indicating that it has, in fact, been cached)
> >
> > Thank you for your reply. Does this apply to FreeBSD 5.4 or 6.0 on
> > amd64 (or both)?
> >
>
> Not sure about 6.0 (but I don't know why it would change) but definitely
> on 5.4 amd64 (and I would imagine i386 as well).

Works on FreeBSD 6.0 RC1 as well. Tried using count=3D4096 on a 1 GB ram
box. Same behaviour as you describe above.

regards
Claus

From pgsql-performance-owner@postgresql.org  Tue Oct 11 15:11:09 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id E73C9D7237
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 11 Oct 2005 15:11:07 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 79401-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 11 Oct 2005 18:11:01 +0000 (GMT)
Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.196])
	by svr1.postgresql.org (Postfix) with ESMTP id 932D8D6FCB
	for <pgsql-performance@postgresql.org>;
	Tue, 11 Oct 2005 15:11:01 -0300 (ADT)
Received: by wproxy.gmail.com with SMTP id 71so232799wra
	for <pgsql-performance@postgresql.org>;
	Tue, 11 Oct 2005 11:11:02 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references;
	b=rIGJAJBgGyCB726XCSdK9fJ3Z+4iKpYPj8kWI54LJlMcpexHuy5Ui5Dbkal4EIutPz36qAe1EzqyP/vn/QwXFv7u4An2UxUJx++KM3ni8LTTG5P92BthxSGzmbDlT0xVX0eR8jLDdhkDHYW31zMap6w6qGzrXucxH6YIdTsQ2ug=
Received: by 10.54.69.10 with SMTP id r10mr3663000wra;
	Tue, 11 Oct 2005 11:11:02 -0700 (PDT)
Received: by 10.54.84.8 with HTTP; Tue, 11 Oct 2005 11:11:02 -0700 (PDT)
Message-ID: <33c6269f0510111111i676a2e50h57cd06757c59a3da@mail.gmail.com>
Date: Tue, 11 Oct 2005 14:11:02 -0400
From: Alex Turner <armtuk@gmail.com>
To: Alan Stange <stange@rentec.com>
Subject: Re: Performance on SUSE w/ reiserfs
Cc: pgsql-performance@postgresql.org
In-Reply-To: <434BDA1E.5030804@rentec.com>
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="----=_Part_185_19277859.1129054262473"
References: <434ADD46.5060206@npcinternational.com>
	<6247.1128981289@sss.pgh.pa.us>
	<434AE7FF.4000705@npcinternational.com>
	<33c6269f0510110727q62a797a1g9493661e1dc905d4@mail.gmail.com>
	<434BD17E.7000605@rentec.com>
	<33c6269f0510110757v1632b9c5te578b699db922f45@mail.gmail.com>
	<434BDA1E.5030804@rentec.com>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.149 required=5 tests=[AWL=0.038, HTML_40_50=0.086,
	HTML_MESSAGE=0.001, RCVD_BY_IP=0.024]
X-Spam-Level: 
X-Archive-Number: 200510/202
X-Sequence-Number: 14970

------=_Part_185_19277859.1129054262473
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Well - to each his own I guess - we did extensive testing on 1.4, and it
refused to allocate much past 1gig on both Linux x86/x86-64 and Windows.

Alex

On 10/11/05, Alan Stange <stange@rentec.com> wrote:
>
> Alex Turner wrote:
>
> > Perhaps this is true for 1.5 on x86-32 (I've only used it on x86-64)
> > but I was more thinking 1.4 which many folks are still using.
>
> The 1.4.x JVM's will also work just fine with much more than 1GB of
> memory. Perhaps you'd like to try again?
>
> -- Alan
>
> >
> > On 10/11/05, *Alan Stange* <stange@rentec.com
> > <mailto:stange@rentec.com>> wrote:
> >
> > Alex Turner wrote:
> >
> > > Realise also that unless you are running the 1.5 x86-64 build, java
> > > will not use more than 1Gig, and if the app server requests more
> > than
> > > 1gig, Java will die (I've been there) with an out of memory error,
> > > even though there is plenty of free mem available. This can
> > easily be
> > > cause by a lazy GC thread if the applicaiton is running high on
> > CPU usage.
> >
> > On my side of Planet Earth, the standard non-x64 1.5 JVM will happily
> > use more than 1G of memory (on linux and Solaris, can't speak for
> > Windows). If you're running larger programs, it's probably a good
> > idea
> > to use the -server compiler in the JVM as well. I regularly run with
> > -Xmx1800m and regularly have >1GB heap sizes.
> >
> > The standard GC will not cause on OOM error if space remains for the
> > requested object. The GC thread blocks all other threads during its
> > activity, whatever else is happening on the machine. The
> > newer/experimental GC's did have some potential race conditions, but I
> > believe those have been resolved in the 1.5 JVMs.
> >
> > Finally, note that the latest _05 release of the 1.5 JVM also now
> > supports large page sizes on Linux and Windows:
> > -XX:+UseLargePages this can be quite beneficial depending on the
> > memory patterns in your programs.
> >
> > -- Alan
> >
> >
>
>

------=_Part_185_19277859.1129054262473
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Well - to each his own I guess - we did extensive testing on 1.4, and
it refused to allocate much past 1gig on both Linux x86/x86-64 and
Windows.<br>
<br>
Alex<br><br><div><span class=3D"gmail_quote">On 10/11/05, <b class=3D"gmail=
_sendername">Alan Stange</b> &lt;<a href=3D"mailto:stange@rentec.com">stang=
e@rentec.com</a>&gt; wrote:</span><blockquote class=3D"gmail_quote" style=
=3D"border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; p=
adding-left: 1ex;">
Alex Turner wrote:<br><br>&gt; Perhaps this is true for 1.5 on x86-32 (I've=
 only used it on x86-64)<br>&gt; but I was more thinking 1.4 which many fol=
ks are still using.<br><br>The 1.4.x JVM's will also work just fine with mu=
ch more than 1GB of
<br>memory.&nbsp;&nbsp; Perhaps you'd like to try again?<br><br>-- Alan<br>=
<br>&gt;<br>&gt; On 10/11/05, *Alan Stange* &lt;<a href=3D"mailto:stange@re=
ntec.com">stange@rentec.com</a><br>&gt; &lt;mailto:<a href=3D"mailto:stange=
@rentec.com">
stange@rentec.com</a>&gt;&gt; wrote:<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp=
; Alex Turner wrote:<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; Realise a=
lso that unless you are running the 1.5 x86-64 build, java<br>&gt;&nbsp;&nb=
sp;&nbsp;&nbsp; &gt; will not use more than 1Gig, and if the app server req=
uests more
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; than<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; =
1gig, Java will die (I've been there) with an out of memory error,<br>&gt;&=
nbsp;&nbsp;&nbsp;&nbsp; &gt; even though there is plenty of free mem availa=
ble.&nbsp;&nbsp;This can<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; easily be<br>&gt;&=
nbsp;&nbsp;&nbsp;&nbsp; &gt; cause by a lazy GC thread if the applicaiton i=
s running high on
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; CPU usage.<br>&gt;<br>&gt;&nbsp;&nbsp;&nbs=
p;&nbsp; On my side of Planet Earth, the standard non-x64 1.5 JVM will happ=
ily<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; use more than 1G of memory (on linux an=
d Solaris, can't speak for<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Windows).&nbsp;&=
nbsp;If you're running larger programs, it's probably a good
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; idea<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; to us=
e the -server compiler in the JVM as well.&nbsp;&nbsp;I regularly run with<=
br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; -Xmx1800m and regularly have &gt;1GB heap s=
izes.<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; The standard GC will not caus=
e on OOM error if space remains for the
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; requested object.&nbsp;&nbsp;The GC thread=
 blocks all other threads during its<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; activi=
ty, whatever else is happening on the machine.&nbsp;&nbsp; The<br>&gt;&nbsp=
;&nbsp;&nbsp;&nbsp; newer/experimental GC's did have some potential race co=
nditions, but I
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; believe those have been resolved in the 1.=
5 JVMs.<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Finally, note that the late=
st _05 release of the 1.5 JVM also now<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; supp=
orts large page sizes on Linux and Windows:<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;=
 -XX:+UseLargePages&nbsp;&nbsp; this can be quite beneficial depending on t=
he
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; memory patterns in your programs.<br>&gt;<=
br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; -- Alan<br>&gt;<br>&gt;<br><br></blockquote=
></div><br>

------=_Part_185_19277859.1129054262473--

From pgsql-performance-owner@postgresql.org  Tue Oct 11 17:10:01 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 3F637D77B2
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 11 Oct 2005 17:09:59 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 64335-03
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 11 Oct 2005 20:09:56 +0000 (GMT)
Received: from yertle.kcilink.com (yertle.kcilink.com [65.205.34.180])
	by svr1.postgresql.org (Postfix) with ESMTP id 329FCD77BE
	for <pgsql-performance@postgresql.org>;
	Tue, 11 Oct 2005 17:09:56 -0300 (ADT)
Received: from [192.168.7.103] (host-103.int.kcilink.com [192.168.7.103])
	by yertle.kcilink.com (Postfix) with ESMTP id 5ACE9B81E
	for <pgsql-performance@postgresql.org>;
	Tue, 11 Oct 2005 16:09:58 -0400 (EDT)
Mime-Version: 1.0 (Apple Message framework v734)
In-Reply-To: <b41c75520510110754g534d9fa8u@mail.gmail.com>
References: <b41c75520510110754g534d9fa8u@mail.gmail.com>
Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed
Message-Id: <A3542834-9359-4FAC-95E4-F6EC8F635B61@khera.org>
Content-Transfer-Encoding: 7bit
From: Vivek Khera <vivek@khera.org>
Subject: Re: effective cache size on FreeBSD (WAS: Performance on SUSE w/
	reiserfs)
Date: Tue, 11 Oct 2005 16:09:56 -0400
To: Postgresql Performance <pgsql-performance@postgresql.org>
X-Mailer: Apple Mail (2.734)
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.029 required=5 tests=[AWL=0.029]
X-Spam-Level: 
X-Archive-Number: 200510/203
X-Sequence-Number: 14971

On Oct 11, 2005, at 10:54 AM, Claus Guttesen wrote:

> Thank you for your reply. Does this apply to FreeBSD 5.4 or 6.0 on
> amd64 (or both)?
>

It applies to FreeBSD >= 5.0.

However, I have not been able to get a real answer from the FreeBSD  
hacker community on what the max buffer space usage will be to  
properly set this.  The `sysctl -n vfs.hibufspace` / 8192 estimation  
works very well for me, still, and I continue to use it.


From pgsql-performance-owner@postgresql.org  Tue Oct 11 18:48:55 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 599D0D77D2
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 11 Oct 2005 18:48:54 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 45545-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 11 Oct 2005 21:48:49 +0000 (GMT)
Received: from metux.de (seven.metux.de [193.16.1.1])
	by svr1.postgresql.org (Postfix) with ESMTP id 8F52DD72F6
	for <pgsql-performance@postgresql.org>;
	Tue, 11 Oct 2005 18:48:50 -0300 (ADT)
Received: (from weigelt@localhost)
	by metux.de (8.12.10/8.12.10) id j9BLmoWc004153
	for pgsql-performance@postgresql.org; Tue, 11 Oct 2005 23:48:50 +0200
Date: Tue, 11 Oct 2005 23:48:50 +0200
From: Enrico Weigelt <weigelt@metux.de>
To: pgsql-performance@postgresql.org
Subject: Re: Massive delete performance
Message-ID: <20051011214849.GA23769@nibiru.local>
Reply-To: weigelt@metux.de
Mail-Followup-To: pgsql-performance@postgresql.org
References: <00bd01c5ce37$f8a4cc00$0b00a8c0@forge>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <00bd01c5ce37$f8a4cc00$0b00a8c0@forge>
User-Agent: Mutt/1.4.1i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.005 required=5 tests=[AWL=0.005]
X-Spam-Level: 
X-Archive-Number: 200510/204
X-Sequence-Number: 14972

* Andy <frum@ar-sd.net> wrote:

<snip>
>    I have the following problem: I have a client to which we send every
>    night a "dump" with a the database in which there are only their
>    data's. It is a stupid solution but I choose this solution because I
>    couldn't find any better. The target machine is a windows 2003.
> 
>    So, I have a replication only with the tables that I need to send,
>    then I make a copy of this replication, and from this copy I delete
>    all the data's that are not needed.

Why not filtering out as much unnecessary stuff as possible on copying ?

<snip>

>    How can I increase this DELETE procedure because it is really slow???
>     There are of corse a lot of data's to be deleted.

Have you set up the right indices ?


cu
-- 
---------------------------------------------------------------------
 Enrico Weigelt    ==   metux IT service
  phone:     +49 36207 519931         www:       http://www.metux.de/
  fax:       +49 36207 519932         email:     contact@metux.de
---------------------------------------------------------------------
  Realtime Forex/Stock Exchange trading powered by postgreSQL :))
                                            http://www.fxignal.net/
---------------------------------------------------------------------

From pgsql-performance-owner@postgresql.org  Wed Oct 12 09:14:48 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id C7F16D7C2B
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 12 Oct 2005 09:14:47 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 54713-09
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 12 Oct 2005 12:14:40 +0000 (GMT)
Received: from Herge.rcsinc.local (mail.rcsonline.com [70.89.208.142])
	by svr1.postgresql.org (Postfix) with ESMTP id E5BE3D7B2C
	for <pgsql-performance@postgresql.org>;
	Wed, 12 Oct 2005 09:14:41 -0300 (ADT)
Content-class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0
Subject: Re: SELECT LIMIT 1 VIEW Performance Issue
Date: Wed, 12 Oct 2005 08:14:44 -0400
Message-ID: <6EE64EF3AB31D5448D0007DD34EEB3417DD58A@Herge.rcsinc.local>
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
Thread-Topic: [PERFORM] SELECT LIMIT 1 VIEW Performance Issue
Thread-Index: AcXCb2w5DEFRirSnQBqccg8coSwifAMtpLhQ
From: "Merlin Moncure" <merlin.moncure@rcsonline.com>
To: "K C Lau" <kclau60@netvigator.com>
Cc: <pgsql-performance@postgresql.org>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.04 required=5 tests=[AWL=-0.010,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/205
X-Sequence-Number: 14973

KC wrote:
>=20
> So I guess it all comes back to the basic question:
>=20
> For the query select distinct on (PlayerID) * from Player a where
> PlayerID=3D'22220' order by PlayerId Desc, AtDate Desc;
> can the optimizer recognise the fact the query is selecting by the
primary
> key (PlayerID,AtDate), so it can skip the remaining rows for that
> PlayerID,
> as if LIMIT 1 is implied?
>=20
> Best regards, KC.

Hi KC, have you tried:
select * from player where playerid =3D '22220' and atdate < 9999999999
order by platerid desc, atdate desc limit 1;

??
Merlin

From pgsql-performance-owner@postgresql.org  Wed Oct 12 10:00:22 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 23F9ED7E31
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 12 Oct 2005 10:00:21 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 90720-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 12 Oct 2005 13:00:14 +0000 (GMT)
Received: from imsm057dat.netvigator.com (imsm057.netvigator.com
	[218.102.48.210])
	by svr1.postgresql.org (Postfix) with ESMTP id 2C70AD7E11
	for <pgsql-performance@postgresql.org>;
	Wed, 12 Oct 2005 10:00:15 -0300 (ADT)
Received: from n2.netvigator.com ([218.102.147.167])
	by imsm057dat.netvigator.com
	(InterMail vM.6.01.05.02 201-2131-123-102-20050715) with ESMTP id
	<20051012130018.GZT14795.imsm057dat.netvigator.com@n2.netvigator.com>;
	Wed, 12 Oct 2005 21:00:18 +0800
Message-Id: <6.2.1.2.0.20051012203443.0512a588@localhost>
X-Mailer: QUALCOMM Windows Eudora Version 6.2.1.2
Date: Wed, 12 Oct 2005 21:00:15 +0800
To: "Merlin Moncure" <merlin.moncure@rcsonline.com>,
	pgsql-performance@postgresql.org
From: K C Lau <kclau60@netvigator.com>
Subject: Re: SELECT LIMIT 1 VIEW Performance Issue
In-Reply-To: <6EE64EF3AB31D5448D0007DD34EEB3417DD58A@Herge.rcsinc.local>
References: <6EE64EF3AB31D5448D0007DD34EEB3417DD58A@Herge.rcsinc.local>
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"; format=flowed
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=1.536 required=5 tests=[AWL=-0.356,
	DNS_FROM_RFC_POST=1.376, FROM_ENDS_IN_NUMS=0.516]
X-Spam-Level: *
X-Archive-Number: 200510/206
X-Sequence-Number: 14974

Dear Merlin and all,

That direct SQL returns in 0 ms. The problem only appears when a view is used.

What we've done to work around this problem is to modify the table to add a 
field DataStatus which is set to 1 for the latest record for each player, 
and reset to 0 when it is superceded.

A partial index is then created as:
CREATE INDEX IDX_CurPlayer on Player (PlayerID) where DataStatus = 1;

The VCurPlayer view is changed to:
CREATE or REPLACE VIEW VCurPlayer as select * from Player where DataStatus = 1;
and it now returns in 0 ms.

This is not the best solution, but until (if ever) the original problem is 
fixed, we have not found an alternative work around.

The good news is that even with the additional overhead of maintaining an 
extra index and the problem of vacuuming, pg 8.0.3 still performs 
significantly faster on Windows than MS Sql 2000 in our OLTP application 
testing so far.

Thanks to all for your help.

Best regards,
KC.

At 20:14 05/10/12, you wrote:
>KC wrote:
> >
> > So I guess it all comes back to the basic question:
> >
> > For the query select distinct on (PlayerID) * from Player a where
> > PlayerID='22220' order by PlayerId Desc, AtDate Desc;
> > can the optimizer recognise the fact the query is selecting by the
>primary
> > key (PlayerID,AtDate), so it can skip the remaining rows for that
> > PlayerID,
> > as if LIMIT 1 is implied?
> >
> > Best regards, KC.
>
>Hi KC, have you tried:
>select * from player where playerid = '22220' and atdate < 9999999999
>order by platerid desc, atdate desc limit 1;
>
>??
>Merlin


From pgsql-performance-owner@postgresql.org  Wed Oct 12 11:45:25 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id BE170D7117
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 12 Oct 2005 11:45:23 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 34500-06
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 12 Oct 2005 14:45:19 +0000 (GMT)
Received: from mail.ecircle.de (mail.ecircle.de [195.140.186.200])
	by svr1.postgresql.org (Postfix) with ESMTP id 95D32D7C31
	for <pgsql-performance@postgresql.org>;
	Wed, 12 Oct 2005 11:45:19 -0300 (ADT)
Received: from [192.168.1.110] (unknown [192.168.1.110])
	by mail.ecircle.de (READY) with ESMTP id 6A10A954283
	for <pgsql-performance@postgresql.org>;
	Wed, 12 Oct 2005 16:45:24 +0200 (CEST)
Subject: Help tuning postgres
From: Csaba Nagy <nagy@ecircle-ag.com>
To: pgsql-performance@postgresql.org
Content-Type: multipart/mixed; boundary="=-CkBFuzSsClN9FDm0vkaR"
Message-Id: <1129128315.2995.174.camel@coppola.muc.ecircle.de>
Mime-Version: 1.0
X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) 
Date: Wed, 12 Oct 2005 16:45:15 +0200
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.013 required=5 tests=[AWL=0.013]
X-Spam-Level: 
X-Archive-Number: 200510/207
X-Sequence-Number: 14975


--=-CkBFuzSsClN9FDm0vkaR
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi all,

After a long time of reading the general list it's time to subscribe to
this one...

We have adapted our application (originally written for oracle) to
postgres, and switched part of our business to a postgres data base.

The data base has in the main tables around 150 million rows, the whole
data set takes ~ 30G after the initial migration. After ~ a month of
usage that bloated to ~ 100G. We installed autovacuum after ~ 2 weeks.

The main table is heavily updated during the active periods of usage,
which is coming in bursts.

Now Oracle on the same hardware has no problems handling it (the load),
but postgres comes to a crawl. Examining the pg_stats_activity table I
see the updates on the main table as being the biggest problem, they are
very slow. The table has a few indexes on it, I wonder if they are
updated too on an update ? The index fields are not changing. In any
case, I can't explain why the updates are so much slower on postgres.

Sorry for being fuzzy a bit, I spent quite some time figuring out what I
can do and now I have to give up and ask for help.

The machine running the DB is a debian linux, details:

$ cat /proc/cpuinfo
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 11
model name      : Intel(R) Pentium(R) III CPU family      1266MHz
stepping        : 1
cpu MHz         : 1263.122
cache size      : 512 KB
fdiv_bug        : no
hlt_bug         : no
f00f_bug        : no
coma_bug        : no
fpu             : yes
fpu_exception   : yes
cpuid level     : 2
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge
mca cmov pat pse36 mmx fxsr sse
bogomips        : 2490.36
 
processor       : 1
vendor_id       : GenuineIntel
cpu family      : 6
model           : 11
model name      : Intel(R) Pentium(R) III CPU family      1266MHz
stepping        : 1
cpu MHz         : 1263.122
cache size      : 512 KB
fdiv_bug        : no
hlt_bug         : no
f00f_bug        : no
coma_bug        : no
fpu             : yes
fpu_exception   : yes
cpuid level     : 2
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge
mca cmov pat pse36 mmx fxsr sse
bogomips        : 2514.94
 

$ uname -a
Linux *** 2.6.12.3 #1 SMP Tue Oct 11 13:13:00 CEST 2005 i686 GNU/Linux


$ cat /proc/meminfo
MemTotal:      4091012 kB
MemFree:        118072 kB
Buffers:         18464 kB
Cached:        3393436 kB
SwapCached:          0 kB
Active:         947508 kB
Inactive:      2875644 kB
HighTotal:     3211264 kB
HighFree:          868 kB
LowTotal:       879748 kB
LowFree:        117204 kB
SwapTotal:           0 kB
SwapFree:            0 kB
Dirty:           13252 kB
Writeback:           0 kB
Mapped:         829300 kB
Slab:            64632 kB
CommitLimit:   2045504 kB
Committed_AS:  1148064 kB
PageTables:      75916 kB
VmallocTotal:   114680 kB
VmallocUsed:        96 kB
VmallocChunk:   114568 kB


The disk used for the data is an external raid array, I don't know much
about that right now except I think is some relatively fast IDE stuff.
In any case the operations should be cache friendly, we don't scan over
and over the big tables...

The postgres server configuration is attached.

I have looked in the postgres statistics tables, looks like most of the
needed data is always cached, as in the most accessed tables the
load/hit ratio is mostly something like 1/100, or at least 1/30.


Is anything in the config I got very wrong for the given machine, or
what else should I investigate further ? If I can't make this fly, the
obvious solution will be to move back to Oracle, cash out the license
and forget about postgres forever...

TIA,
Csaba.


--=-CkBFuzSsClN9FDm0vkaR
Content-Disposition: attachment; filename=postgresql.conf
Content-Type: text/plain; name=postgresql.conf; charset=UTF-8
Content-Transfer-Encoding: 7bit

# -----------------------------
# PostgreSQL configuration file
# -----------------------------
#
# This file consists of lines of the form:
#
#   name = value
#
# (The '=' is optional.) White space may be used. Comments are introduced
# with '#' anywhere on a line. The complete list of option names and
# allowed values can be found in the PostgreSQL documentation. The
# commented-out settings shown in this file represent the default values.
#
# Please note that re-commenting a setting is NOT sufficient to revert it
# to the default value, unless you restart the postmaster.
#
# Any option can also be given as a command line switch to the
# postmaster, e.g. 'postmaster -c log_connections=on'. Some options
# can be changed at run-time with the 'SET' SQL command.
#
# This file is read on postmaster startup and when the postmaster
# receives a SIGHUP. If you edit the file on a running system, you have 
# to SIGHUP the postmaster for the changes to take effect, or use 
# "pg_ctl reload". Some settings, such as listen_address, require
# a postmaster shutdown and restart to take effect.


#---------------------------------------------------------------------------
# FILE LOCATIONS
#---------------------------------------------------------------------------

# The default values of these variables are driven from the -D command line
# switch or PGDATA environment variable, represented here as ConfigDir.
# data_directory = 'ConfigDir'		# use data in another directory
# hba_file = 'ConfigDir/pg_hba.conf'	# the host-based authentication file
# ident_file = 'ConfigDir/pg_ident.conf'  # the IDENT configuration file

# If external_pid_file is not explicitly set, no extra pid file is written.
# external_pid_file = '(none)'		# write an extra pid file


#---------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#---------------------------------------------------------------------------

# - Connection Settings -

listen_addresses = '*'	# what IP interface(s) to listen on; 
				# defaults to localhost, '*' = any
#port = 5432
max_connections = 400
	# note: increasing max_connections costs about 500 bytes of shared
	# memory per connection slot, in addition to costs from shared_buffers
	# and max_locks_per_transaction.
#superuser_reserved_connections = 2
#unix_socket_directory = ''
#unix_socket_group = ''
#unix_socket_permissions = 0777	# octal
#rendezvous_name = ''		# defaults to the computer name

# - Security & Authentication -

#authentication_timeout = 60	# 1-600, in seconds
#ssl = false
#password_encryption = true
#krb_server_keyfile = ''
#db_user_namespace = false


#---------------------------------------------------------------------------
# RESOURCE USAGE (except WAL)
#---------------------------------------------------------------------------

# - Memory -

shared_buffers = 50000		# min 16, at least max_connections*2, 8KB each
#work_mem = 1024		# min 64, size in KB
work_mem = 4096
#maintenance_work_mem = 16384	# min 1024, size in KB
maintenance_work_mem = 131072
#max_stack_depth = 2048		# min 100, size in KB

# - Free Space Map -

#max_fsm_pages = 20000		# min max_fsm_relations*16, 6 bytes each
max_fsm_pages = 12000000
#max_fsm_relations = 1000	# min 100, ~50 bytes each
max_fsm_relations = 5000

# - Kernel Resource Usage -

#max_files_per_process = 1000	# min 25
#preload_libraries = ''

# - Cost-Based Vacuum Delay -

#vacuum_cost_delay = 0		# 0-1000 milliseconds
vacuum_cost_delay = 100
#vacuum_cost_page_hit = 1	# 0-10000 credits
#vacuum_cost_page_miss = 10	# 0-10000 credits
#vacuum_cost_page_dirty = 20	# 0-10000 credits
#vacuum_cost_limit = 200	# 0-10000 credits

# - Background writer -

#bgwriter_delay = 200		# 10-10000 milliseconds between rounds
#bgwriter_percent = 1		# 0-100% of dirty buffers in each round
#bgwriter_maxpages = 100	# 0-1000 buffers max per round


#---------------------------------------------------------------------------
# WRITE AHEAD LOG
#---------------------------------------------------------------------------

# - Settings -

#fsync = true			# turns forced synchronization on or off
#wal_sync_method = fsync	# the default varies across platforms:
				# fsync, fdatasync, fsync_writethrough,
				# open_sync, open_datasync
#wal_buffers = 8		# min 4, 8KB each
wal_buffers = 64
#commit_delay = 500		# range 0-100000, in microseconds
#commit_siblings = 5		# range 1-1000

# - Checkpoints -

checkpoint_segments = 64	# in logfile segments, min 1, 16MB each
#checkpoint_timeout = 300	# range 30-3600, in seconds
checkpoint_timeout = 600
#checkpoint_warning = 30	# 0 is off, in seconds

# - Archiving -

archive_command = 'scp %p ******@******:/sbarchlogs/%f'

#---------------------------------------------------------------------------
# QUERY TUNING
#---------------------------------------------------------------------------

# - Planner Method Configuration -

#enable_hashagg = true
#enable_hashjoin = true
#enable_indexscan = true
#enable_mergejoin = true
#enable_nestloop = true
#enable_seqscan = true
#enable_sort = true
#enable_tidscan = true

# - Planner Cost Constants -

effective_cache_size = 350000	# typically 8KB each
random_page_cost = 1.5		# units are one sequential page fetch cost
#cpu_tuple_cost = 0.01		# (same)
#cpu_index_tuple_cost = 0.001	# (same)
#cpu_operator_cost = 0.0025	# (same)

# - Genetic Query Optimizer -

#geqo = true
#geqo_threshold = 12
#geqo_effort = 5		# range 1-10
#geqo_pool_size = 0		# selects default based on effort
#geqo_generations = 0		# selects default based on effort
#geqo_selection_bias = 2.0	# range 1.5-2.0

# - Other Planner Options -

#default_statistics_target = 10	# range 1-1000
#from_collapse_limit = 8
#join_collapse_limit = 8	# 1 disables collapsing of explicit JOINs


#---------------------------------------------------------------------------
# ERROR REPORTING AND LOGGING
#---------------------------------------------------------------------------

# - Where to Log -

#log_destination = 'stderr'	# Valid values are combinations of stderr,
                                # syslog and eventlog, depending on
                                # platform.

# This is relevant when logging to stderr:
#redirect_stderr = false    # Enable capturing of stderr into log files.
# These are only relevant if redirect_stderr is true:
#log_directory = 'pg_log'   # Directory where log files are written.
                            # May be specified absolute or relative to PGDATA
#log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' # Log file name pattern.
                            # May include strftime() escapes
#log_truncate_on_rotation = false  # If true, any existing log file of the 
                            # same name as the new log file will be truncated
                            # rather than appended to.  But such truncation
                            # only occurs on time-driven rotation,
                            # not on restarts or size-driven rotation.
                            # Default is false, meaning append to existing 
                            # files in all cases.
#log_rotation_age = 1440    # Automatic rotation of logfiles will happen after
                            # so many minutes.  0 to disable.
#log_rotation_size = 10240  # Automatic rotation of logfiles will happen after
                            # so many kilobytes of log output.  0 to disable.

# These are relevant when logging to syslog:
#syslog_facility = 'LOCAL0'
#syslog_ident = 'postgres'


# - When to Log -

#client_min_messages = notice	# Values, in order of decreasing detail:
				#   debug5, debug4, debug3, debug2, debug1,
				#   log, notice, warning, error

log_min_messages = info  	# Values, in order of decreasing detail:               # Dragos: debug1
				#   debug5, debug4, debug3, debug2, debug1,
				#   info, notice, warning, error, log, fatal,
				#   panic

log_error_verbosity = default	# terse, default, or verbose messages

#log_min_error_statement = panic # Values in order of increasing severity:
				 #   debug5, debug4, debug3, debug2, debug1,
				 #   info, notice, warning, error, panic(off)
				 
#log_min_duration_statement = -1 # -1 is disabled, in milliseconds.
log_min_duration_statement = 2000

#silent_mode = false		 # DO NOT USE without syslog or redirect_stderr

# - What to Log -

debug_print_parse = false 
debug_print_rewritten = false 
debug_print_plan = false
debug_pretty_print = false
#log_connections = false
#log_disconnections = false
log_duration = false
#log_line_prefix = ''		# e.g. '<%u%%%d> ' 
				# %u=user name %d=database name
				# %r=remote host and port
				# %p=PID %t=timestamp %i=command tag
				# %c=session id %l=session line number
				# %s=session start timestamp %x=transaction id
				# %q=stop here in non-session processes
				# %%='%'
log_line_prefix = '%d:%p:%r:%t:'
log_statement = 'none'		# none, mod, ddl, all
#log_hostname = false


#---------------------------------------------------------------------------
# RUNTIME STATISTICS
#---------------------------------------------------------------------------

# - Statistics Monitoring -

log_parser_stats = false 
log_planner_stats = false
log_executor_stats = false
log_statement_stats = false

# - Query/Index Statistics Collector -

stats_start_collector = true 
stats_command_string = true
stats_block_level = true
stats_row_level = true
stats_reset_on_server_start = false


#---------------------------------------------------------------------------
# CLIENT CONNECTION DEFAULTS
#---------------------------------------------------------------------------

# - Statement Behavior -

#search_path = '$user,public'	# schema names
#default_tablespace = ''	# a tablespace name, or '' for default
#check_function_bodies = true
#default_transaction_isolation = 'read committed'
#default_transaction_read_only = false
#statement_timeout = 0		# 0 is disabled, in milliseconds

# - Locale and Formatting -

#datestyle = 'iso, mdy'
#timezone = unknown		# actually, defaults to TZ environment setting
#australian_timezones = false
#extra_float_digits = 0		# min -15, max 2
#client_encoding = sql_ascii	# actually, defaults to database encoding

# These settings are initialized by initdb -- they might be changed
lc_messages = 'de_DE@euro'		# locale for system error message strings
lc_monetary = 'de_DE@euro'		# locale for monetary formatting
lc_numeric = 'de_DE@euro'		# locale for number formatting
lc_time = 'de_DE@euro'			# locale for time formatting

# - Other Defaults -

#explain_pretty_print = true
#dynamic_library_path = '$libdir'


#---------------------------------------------------------------------------
# LOCK MANAGEMENT
#---------------------------------------------------------------------------

deadlock_timeout = 2000	# in milliseconds
#max_locks_per_transaction = 64	# min 10, ~200*max_connections bytes each


#---------------------------------------------------------------------------
# VERSION/PLATFORM COMPATIBILITY
#---------------------------------------------------------------------------

# - Previous Postgres Versions -

add_missing_from = true
#regex_flavor = advanced	# advanced, extended, or basic
#sql_inheritance = true
#default_with_oids = true

# - Other Platforms & Clients -

#transform_null_equals = false

--=-CkBFuzSsClN9FDm0vkaR--


From pgsql-performance-owner@postgresql.org  Wed Oct 12 12:12:31 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 37C02D7D91
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 12 Oct 2005 12:12:29 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 38486-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 12 Oct 2005 15:12:22 +0000 (GMT)
Received: from mail.baymountain.com (mail.baymountain.com [8.7.96.19])
	by svr1.postgresql.org (Postfix) with SMTP id 8F955D7DE6
	for <pgsql-performance@postgresql.org>;
	Wed, 12 Oct 2005 12:12:19 -0300 (ADT)
Received: (qmail 27868 invoked by uid 504); 12 Oct 2005 15:12:17 -0000
Received: from emil@baymountain.com by mail.baymountain.com by uid 501 with
	qmail-scanner-1.16 (spamassassin: 2.53.  Clear:SA:0(0.0/7.0):.
	Processed in 0.244036 secs); 12 Oct 2005 15:12:17 -0000
Received: from unknown (HELO briggspack.com)
	(emil@briggspack.com@24.211.148.77)
	by mail.baymountain.com with SMTP; 12 Oct 2005 15:12:17 -0000
From: Emil Briggs <emil@baymountain.com>
Reply-To: emil@baymountain.com
To: pgsql-performance@postgresql.org
Subject: Re: Help tuning postgres
Date: Wed, 12 Oct 2005 11:12:11 -0400
User-Agent: KMail/1.7.1
References: <1129128315.2995.174.camel@coppola.muc.ecircle.de>
In-Reply-To: <1129128315.2995.174.camel@coppola.muc.ecircle.de>
Organization: Baymountain, Inc.
MIME-Version: 1.0
Content-Type: text/plain;
  charset="utf-8"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Message-Id: <200510121112.11486.emil@baymountain.com>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.038 required=5 tests=[AWL=-0.012,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/208
X-Sequence-Number: 14976

> Hi all,
>
> After a long time of reading the general list it's time to subscribe to
> this one...
>
> We have adapted our application (originally written for oracle) to
> postgres, and switched part of our business to a postgres data base.
>
> The data base has in the main tables around 150 million rows, the whole
> data set takes ~ 30G after the initial migration. After ~ a month of
> usage that bloated to ~ 100G. We installed autovacuum after ~ 2 weeks.
>

Have you tried reindexing your active tables?

Emil

From pgsql-performance-owner@postgresql.org  Wed Oct 12 12:18:06 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 71BDFD7DA5
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 12 Oct 2005 12:18:05 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 43943-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 12 Oct 2005 15:18:03 +0000 (GMT)
Received: from mail.ecircle.de (mail.ecircle.de [195.140.186.200])
	by svr1.postgresql.org (Postfix) with ESMTP id 17D8DD7D91
	for <pgsql-performance@postgresql.org>;
	Wed, 12 Oct 2005 12:18:03 -0300 (ADT)
Received: from [192.168.1.110] (unknown [192.168.1.110])
	by mail.ecircle.de (READY) with ESMTP id 2A1D49540FC;
	Wed, 12 Oct 2005 17:18:02 +0200 (CEST)
Subject: Re: Help tuning postgres
From: Csaba Nagy <nagy@ecircle-ag.com>
To: emil@baymountain.com
Cc: postgres performance list <pgsql-performance@postgresql.org>
In-Reply-To: <200510121112.11486.emil@baymountain.com>
References: <1129128315.2995.174.camel@coppola.muc.ecircle.de>
	<200510121112.11486.emil@baymountain.com>
Content-Type: text/plain
Message-Id: <1129130273.2995.177.camel@coppola.muc.ecircle.de>
Mime-Version: 1.0
X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) 
Date: Wed, 12 Oct 2005 17:17:53 +0200
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.013 required=5 tests=[AWL=0.013]
X-Spam-Level: 
X-Archive-Number: 200510/209
X-Sequence-Number: 14977

[snip]
> Have you tried reindexing your active tables?
> 
Not yet, the db is in production use and I have to plan for a down-time
for that... or is it not impacting the activity on the table ?

> Emil
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 9: In versions below 8.0, the planner will ignore your desire to
>        choose an index scan if your joining column's datatypes do not
>        match


From pgsql-performance-owner@postgresql.org  Wed Oct 12 12:34:11 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 07D51D7DA5
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 12 Oct 2005 12:34:10 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 47856-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 12 Oct 2005 15:34:03 +0000 (GMT)
Received: from mail.baymountain.com (mail.baymountain.com [8.7.96.19])
	by svr1.postgresql.org (Postfix) with SMTP id 6DC1AD7DDB
	for <pgsql-performance@postgresql.org>;
	Wed, 12 Oct 2005 12:34:03 -0300 (ADT)
Received: (qmail 29471 invoked by uid 504); 12 Oct 2005 15:34:01 -0000
Received: from emil@baymountain.com by mail.baymountain.com by uid 501 with
	qmail-scanner-1.16 (spamassassin: 2.53.  Clear:SA:0(0.0/7.0):.
	Processed in 0.237651 secs); 12 Oct 2005 15:34:01 -0000
Received: from unknown (HELO briggspack.com)
	(emil@briggspack.com@24.211.148.77)
	by mail.baymountain.com with SMTP; 12 Oct 2005 15:34:01 -0000
From: Emil Briggs <emil@baymountain.com>
Reply-To: emil@baymountain.com
Organization: Baymountain, Inc.
To: Csaba Nagy <nagy@ecircle-ag.com>
Subject: Re: Help tuning postgres
Date: Wed, 12 Oct 2005 11:33:56 -0400
User-Agent: KMail/1.7.1
References: <1129128315.2995.174.camel@coppola.muc.ecircle.de>
	<200510121112.11486.emil@baymountain.com>
	<1129130273.2995.177.camel@coppola.muc.ecircle.de>
In-Reply-To: <1129130273.2995.177.camel@coppola.muc.ecircle.de>
Cc: pgsql-performance@postgresql.org
MIME-Version: 1.0
Content-Type: text/plain;
  charset="utf-8"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Message-Id: <200510121133.56955.emil@baymountain.com>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.038 required=5 tests=[AWL=-0.012,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/210
X-Sequence-Number: 14978

> [snip]
>
> > Have you tried reindexing your active tables?
>
> Not yet, the db is in production use and I have to plan for a down-time
> for that... or is it not impacting the activity on the table ?
>

It will cause some performance hit while you are doing it. It sounds like 
something is bloating rapidly on your system and the indexes is one possible 
place that could be happening.

From pgsql-performance-owner@postgresql.org  Wed Oct 12 12:54:21 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 69932D7EA9
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 12 Oct 2005 12:54:20 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 52917-03
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 12 Oct 2005 15:54:18 +0000 (GMT)
Received: from Herge.rcsinc.local (mail.rcsonline.com [70.89.208.142])
	by svr1.postgresql.org (Postfix) with ESMTP id 48E1BD7E87
	for <pgsql-performance@postgresql.org>;
	Wed, 12 Oct 2005 12:54:18 -0300 (ADT)
Content-class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0
Subject: Re: Help tuning postgres
Date: Wed, 12 Oct 2005 11:54:17 -0400
Message-ID: <6EE64EF3AB31D5448D0007DD34EEB3417DD595@Herge.rcsinc.local>
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
Thread-Topic: [PERFORM] Help tuning postgres
Thread-Index: AcXPPB8c+ilAcA+IS9+AN9xbEinb5AACGrFg
From: "Merlin Moncure" <merlin.moncure@rcsonline.com>
To: "Csaba Nagy" <nagy@ecircle-ag.com>
Cc: <pgsql-performance@postgresql.org>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.042 required=5 tests=[AWL=-0.008,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/211
X-Sequence-Number: 14979

> The disk used for the data is an external raid array, I don't know
much
> about that right now except I think is some relatively fast IDE stuff.
> In any case the operations should be cache friendly, we don't scan
over
> and over the big tables...

Maybe you are I/O bound.  Do you know if your RAID array is caching your
writes?  Easy way to check is to run fsync off and look for obvious
performance differences.  Maybe playing with sync method could help
here.

Merlin


From pgsql-performance-owner@postgresql.org  Wed Oct 12 13:41:36 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 0DB93D77A5
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 12 Oct 2005 13:39:56 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 63984-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 12 Oct 2005 16:39:50 +0000 (GMT)
Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.197])
	by svr1.postgresql.org (Postfix) with ESMTP id 38BE2D7F1C
	for <pgsql-performance@postgresql.org>;
	Wed, 12 Oct 2005 13:39:49 -0300 (ADT)
Received: by xproxy.gmail.com with SMTP id i30so88731wxd
	for <pgsql-performance@postgresql.org>;
	Wed, 12 Oct 2005 09:39:50 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references;
	b=AppSrkF+WkN/G6H11Jkdv4zoMdDRYGHoXs9TxIucunYatFWJe+QqD749gz76wSJREWz5KbH9LywleF0kP/XuAjBPd1dzWE6SCoJ/8JQbSTu9wWVKN3T5HuplvO3dweDQDvZrpmNCKXqvhqUlUNKPb9mFO5UuEriNY3qDt4ehwOg=
Received: by 10.70.89.8 with SMTP id m8mr242254wxb;
	Wed, 12 Oct 2005 09:39:50 -0700 (PDT)
Received: by 10.70.128.19 with HTTP; Wed, 12 Oct 2005 09:39:50 -0700 (PDT)
Message-ID: <f3c0b4080510120939x6c08feebvfad37c98df306538@mail.gmail.com>
Date: Wed, 12 Oct 2005 11:39:50 -0500
From: Matthew Nuzum <mattnuzum@gmail.com>
Reply-To: newz@bearfruit.org
To: Csaba Nagy <nagy@ecircle-ag.com>
Subject: Re: Help tuning postgres
Cc: pgsql-performance@postgresql.org
In-Reply-To: <1129128315.2995.174.camel@coppola.muc.ecircle.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
References: <1129128315.2995.174.camel@coppola.muc.ecircle.de>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.369 required=5 tests=[AWL=0.345, RCVD_BY_IP=0.024]
X-Spam-Level: 
X-Archive-Number: 200510/212
X-Sequence-Number: 14980

On 10/12/05, Csaba Nagy <nagy@ecircle-ag.com> wrote:

> We have adapted our application (originally written for oracle) to
> postgres, and switched part of our business to a postgres data base.

> The data base has in the main tables around 150 million rows, the whole
> data set takes ~ 30G after the initial migration. After ~ a month of
> usage that bloated to ~ 100G. We installed autovacuum after ~ 2 weeks.
>
> The main table is heavily updated during the active periods of usage,
> which is coming in bursts.
>
> Now Oracle on the same hardware has no problems handling it (the load),
> but postgres comes to a crawl. Examining the pg_stats_activity table I
> see the updates on the main table as being the biggest problem, they are
> very slow. The table has a few indexes on it, I wonder if they are
> updated too on an update ? The index fields are not changing. In any
> case, I can't explain why the updates are so much slower on postgres.

I'm not the most experience person on this list, but I've got some big
tables I work with. Doing an update on these big tables often involves
a sequential scan which can be quite slow.

I would suggest posting the explain analyze output for one of your
slow updates. I'll bet it is much more revealing and takes out a lot
of the guesswork.

--
Matthew Nuzum
www.bearfruit.org

From pgsql-performance-owner@postgresql.org  Wed Oct 12 13:55:44 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 846FAD7F1D
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 12 Oct 2005 13:55:43 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 69849-03
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 12 Oct 2005 16:55:40 +0000 (GMT)
Received: from mail.ecircle.de (mail.ecircle.de [195.140.186.200])
	by svr1.postgresql.org (Postfix) with ESMTP id 68119D7F17
	for <pgsql-performance@postgresql.org>;
	Wed, 12 Oct 2005 13:55:40 -0300 (ADT)
Received: from [192.168.1.110] (unknown [192.168.1.110])
	by mail.ecircle.de (READY) with ESMTP id 0F64C95429E;
	Wed, 12 Oct 2005 18:55:40 +0200 (CEST)
Subject: Re: Help tuning postgres
From: Csaba Nagy <nagy@ecircle-ag.com>
To: newz@bearfruit.org
Cc: postgres performance list <pgsql-performance@postgresql.org>
In-Reply-To: <f3c0b4080510120939x6c08feebvfad37c98df306538@mail.gmail.com>
References: <1129128315.2995.174.camel@coppola.muc.ecircle.de>
	<f3c0b4080510120939x6c08feebvfad37c98df306538@mail.gmail.com>
Content-Type: text/plain
Message-Id: <1129136130.2995.188.camel@coppola.muc.ecircle.de>
Mime-Version: 1.0
X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) 
Date: Wed, 12 Oct 2005 18:55:30 +0200
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.012 required=5 tests=[AWL=0.012]
X-Spam-Level: 
X-Archive-Number: 200510/213
X-Sequence-Number: 14981

Ok, that was the first thing I've done, checking out the explain of the
query. I don't really need the analyze part, as the plan is going for
the index, which is the right decision. The updates are simple one-row
updates of one column, qualified by the primary key condition.
This part is OK, the query is not taking extremely long, but the problem
is that we execute 500 in a transaction, and that takes too long and
blocks other activities.
Actually I've done an iostat run in the meantime (just learned how to
use it), and looks like the disk is 100 saturated. So it clearly is a
disk issue in this case. And it turns out the Oracle hardware has an
edge of 3 years over what I have for postgres, so that might very well
explain the performance difference... Oh well.

Next we'll upgrade the postgres hardware, and then I'll come back to
report if it's working better... sorry for the noise for now.

Cheers,
Csaba.

BTW, is the config file good enough for the kind of machine I have ?
Cause it's the first time I had to make a production configuration and
most of the stuff is according to the commented config guid from varlena
with some guesswork added...

> I'm not the most experience person on this list, but I've got some big
> tables I work with. Doing an update on these big tables often involves
> a sequential scan which can be quite slow.
> 
> I would suggest posting the explain analyze output for one of your
> slow updates. I'll bet it is much more revealing and takes out a lot
> of the guesswork.
> 
> --
> Matthew Nuzum
> www.bearfruit.org


From pgsql-performance-owner@postgresql.org  Wed Oct 12 14:24:55 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id CA28BD7F40
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 12 Oct 2005 14:21:30 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 77934-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 12 Oct 2005 17:21:25 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id CC8F8D7E2E
	for <pgsql-performance@postgresql.org>;
	Wed, 12 Oct 2005 14:21:25 -0300 (ADT)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j9CHLO8T002742;
	Wed, 12 Oct 2005 13:21:24 -0400 (EDT)
To: emil@baymountain.com
Cc: Csaba Nagy <nagy@ecircle-ag.com>,
	pgsql-performance@postgresql.org
Subject: Re: Help tuning postgres 
In-reply-to: <200510121133.56955.emil@baymountain.com> 
References: <1129128315.2995.174.camel@coppola.muc.ecircle.de>
	<200510121112.11486.emil@baymountain.com>
	<1129130273.2995.177.camel@coppola.muc.ecircle.de>
	<200510121133.56955.emil@baymountain.com>
Comments: In-reply-to Emil Briggs <emil@baymountain.com>
	message dated "Wed, 12 Oct 2005 11:33:56 -0400"
Date: Wed, 12 Oct 2005 13:21:24 -0400
Message-ID: <2741.1129137684@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/214
X-Sequence-Number: 14982

Emil Briggs <emil@baymountain.com> writes:
>> Not yet, the db is in production use and I have to plan for a down-time
>> for that... or is it not impacting the activity on the table ?

> It will cause some performance hit while you are doing it.

It'll also lock out writes on the table until the index is rebuilt,
so he does need to schedule downtime.

			regards, tom lane

From pgsql-performance-owner@postgresql.org  Wed Oct 12 14:32:30 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 185ACD7F97
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 12 Oct 2005 14:32:20 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 81360-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 12 Oct 2005 17:32:15 +0000 (GMT)
Received: from mail.tecarta.com (66.238.115.135.ptr.us.xo.net
 [66.238.115.135])
	by svr1.postgresql.org (Postfix) with ESMTP id 7D8E2D7F3E
	for <pgsql-performance@postgresql.org>;
	Wed, 12 Oct 2005 14:32:15 -0300 (ADT)
Received: from mail pickup service by mail.tecarta.com with Microsoft SMTPSVC;
	Wed, 12 Oct 2005 10:36:24 -0700
Received: from mail.tecarta.com ([192.168.160.1]) by mail.tecarta.com with
	Microsoft SMTPSVC(6.0.3790.0); Wed, 12 Oct 2005 10:36:23 -0700
Received: from barracuda.tecarta.com ([192.168.160.200])
	by mail.tecarta.com (SAVSMTP 3.1.0.29) with SMTP id
	M2005101210362303555
	for <pgsql_performance_postgresql_org@tecarta.com>;
	Wed, 12 Oct 2005 10:36:23 -0700
X-ASG-Debug-ID: 1129138334-25686-6-0
X-Barracuda-URL: http://192.168.160.200:8000/cgi-bin/mark.cgi
Received: from mail2 (mail2.hq.corp [192.168.160.6])
	by barracuda.tecarta.com (Spam Firewall) with SMTP id 5D29D201798B
	for <pgsql_performance_postgresql_org@tecarta.com>;
	Wed, 12 Oct 2005 10:32:14 -0700 (PDT)
Received: from amd64-gentoo-laptop ([63.206.203.145]) by mail.tecarta.com with
	Microsoft SMTPSVC(6.0.3790.1830); Wed, 12 Oct 2005 10:36:15 -0700
X-ASG-Orig-Subj: Re: [PERFORM] Help tuning postgres
Subject: Re: Help tuning postgres
From: Steve Poe <spoe@sfnet.cc>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-performance@postgresql.org,
	Csaba Nagy <nagy@ecircle-ag.com>, emil@baymountain.com
In-Reply-To: <2741.1129137684@sss.pgh.pa.us>
References: <1129128315.2995.174.camel@coppola.muc.ecircle.de>
	<200510121112.11486.emil@baymountain.com>
	<1129130273.2995.177.camel@coppola.muc.ecircle.de>
	<200510121133.56955.emil@baymountain.com>
	<2741.1129137684@sss.pgh.pa.us>
Content-Type: text/plain
Date: Wed, 12 Oct 2005 10:32:05 -0700
Message-Id: <1129138325.26659.14.camel@amd64-gentoo-laptop>
Mime-Version: 1.0
X-Mailer: Evolution 2.2.3 
Content-Transfer-Encoding: 7bit
X-OriginalArrivalTime: 12 Oct 2005 17:36:15.0430 (UTC)
	FILETIME=[7226AE60:01C5CF53]
X-Virus-Scanned: by Barracuda Spam Firewall at tecarta.com
X-Barracuda-Spam-Score: 0.00
X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=4.0
	QUARANTINE_LEVEL=1000.0 KILL_LEVEL=7.0 tests=
X-Barracuda-Spam-Report: Code version 3.02, rules version 3.0.4502
	Rule breakdown below pts rule name              description
	---- ----------------------
	--------------------------------------------------
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.201 required=5 tests=[AWL=0.151,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/215
X-Sequence-Number: 14983


Would it not be faster to do a dump/reload of the table than reindex or
is it about the same? 

Steve Poe

On Wed, 2005-10-12 at 13:21 -0400, Tom Lane wrote:
> Emil Briggs <emil@baymountain.com> writes:
> >> Not yet, the db is in production use and I have to plan for a down-time
> >> for that... or is it not impacting the activity on the table ?
> 
> > It will cause some performance hit while you are doing it.
> 
> It'll also lock out writes on the table until the index is rebuilt,
> so he does need to schedule downtime.
> 
> 			regards, tom lane
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
>        subscribe-nomail command to majordomo@postgresql.org so that your
>        message can get through to the mailing list cleanly


From pgsql-performance-owner@postgresql.org  Wed Oct 12 15:17:55 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id D53C2D7F4D
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 12 Oct 2005 15:17:53 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 91299-06
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 12 Oct 2005 18:17:47 +0000 (GMT)
Received: from Herge.rcsinc.local (mail.rcsonline.com [70.89.208.142])
	by svr1.postgresql.org (Postfix) with ESMTP id 11D80D7CF9
	for <pgsql-performance@postgresql.org>;
	Wed, 12 Oct 2005 15:17:47 -0300 (ADT)
X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0
Content-class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Subject: Re: Help tuning postgres
Date: Wed, 12 Oct 2005 14:17:47 -0400
Message-ID: <6EE64EF3AB31D5448D0007DD34EEB3417DD59C@Herge.rcsinc.local>
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
Thread-Topic: [PERFORM] Help tuning postgres
Thread-Index: AcXPU/JoL3s/d26DQyGNlE0RQ4DixAABJGLA
From: "Merlin Moncure" <merlin.moncure@rcsonline.com>
To: "Steve Poe" <spoe@sfnet.cc>
Cc: <pgsql-performance@postgresql.org>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.042 required=5 tests=[AWL=-0.008,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/216
X-Sequence-Number: 14984

>=20
> Would it not be faster to do a dump/reload of the table than reindex
or
> is it about the same?
>=20
reindex is probably faster, but that's not the point. you can reindex a
running system whereas dump/restore requires downtime unless you work
everything into a transaction, which is headache, and dangerous.

reindex locking is very granular, in that it only acquires a excl. lock
on one index at a time and while doing so reading is possible (writes
will wait).

in 8.1 we get a fire and forget reindex database xyz which is about as
good as it gets without a dump/load or full vacuum.

Merlin

From pgsql-performance-owner@postgresql.org  Fri Oct 14 15:08:09 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 82AC6D7F5A
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 12 Oct 2005 17:31:16 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 19910-06
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 12 Oct 2005 20:31:13 +0000 (GMT)
Received: from floppy.pyrenet.fr (floppy.pyrenet.fr [194.116.145.2])
	by svr1.postgresql.org (Postfix) with ESMTP id 03B54D7F59
	for <pgsql-performance@postgresql.org>;
	Wed, 12 Oct 2005 17:31:14 -0300 (ADT)
Received: by floppy.pyrenet.fr (Postfix, from userid 106)
	id 7D4A331059; Wed, 12 Oct 2005 22:31:15 +0200 (MET DST)
From: Martin Nickel <martin@portant.com>
X-Newsgroups: pgsql.performance
Subject: Sequential scan on FK join
Date: Wed, 12 Oct 2005 15:40:24 -0500
Organization: Hub.Org Networking Services
Lines: 31
Message-ID: <pan.2005.10.12.20.40.22.703085@portant.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Complaints-To: usenet@news.hub.org
User-Agent: Pan/0.14.2 (This is not a psychotic episode. It's a cleansing
	moment of clarity.)
To: pgsql-performance@postgresql.org
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0 required=5 tests=[none]
X-Spam-Level: 
X-Archive-Number: 200510/237
X-Sequence-Number: 15005

All,

I can see why the query below is slow.  The lead table is 34 million rows,
and a sequential scan always takes 3+ minutes.  Mailing_id is the PK for
mailing and is constrained as a foreign key (NULLS allowed) in lead. 
There is an index on lead.mailing_id.  I've just run VACUUM ANALYZE on
lead.  I don't understand why it isn't being used.

Thanks for your help,
Martin Nickel

SELECT m.mailcode, l.lead_id
  FROM mailing m 
 INNER JOIN lead l ON m.mailing_id = l.mailing_id 
 WHERE (m.maildate >= '2005-7-01'::date 
         AND m.maildate < '2005-8-01'::date) 
-- takes 510,145 ms

EXPLAIN SELECT m.mailcode, l.lead_id
  FROM mailing m 
 INNER JOIN lead l ON m.mailing_id = l.mailing_id 
 WHERE (m.maildate >= '2005-7-01'::date 
         AND m.maildate < '2005-8-01'::date) 

Hash Join  (cost=62.13..2001702.55 rows=2711552 width=20)
  Hash Cond: ("outer".mailing_id = "inner".mailing_id)
  ->  Seq Scan on lead l  (cost=0.00..1804198.60 rows=34065260 width=8)
  ->  Hash  (cost=61.22..61.22 rows=362 width=20)
        ->  Index Scan using mailing_maildate_idx on mailing m  (cost=0.00..61.22 rows=362 width=20)
              Index Cond: ((maildate >= '2005-07-01'::date) AND (maildate < '2005-08-01'::date))


From pgsql-performance-owner@postgresql.org  Wed Oct 12 19:00:44 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id A4371D794E
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 12 Oct 2005 19:00:42 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 47599-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 12 Oct 2005 22:00:33 +0000 (GMT)
Received: from smtp105.rog.mail.re2.yahoo.com (smtp105.rog.mail.re2.yahoo.com
	[206.190.36.83])
	by svr1.postgresql.org (Postfix) with SMTP id EEE88D8185
	for <pgsql-performance@postgresql.org>;
	Wed, 12 Oct 2005 19:00:34 -0300 (ADT)
Received: (qmail 47290 invoked from network); 12 Oct 2005 22:00:37 -0000
Received: from unknown (HELO phlogiston.dydns.org)
	(a.sullivan@rogers.com@209.222.54.227 with login)
	by smtp105.rog.mail.re2.yahoo.com with SMTP; 12 Oct 2005 22:00:37 -0000
Received: by phlogiston.dydns.org (Postfix, from userid 1000)
	id 438534173; Wed, 12 Oct 2005 18:00:36 -0400 (EDT)
Date: Wed, 12 Oct 2005 18:00:36 -0400
From: Andrew Sullivan <ajs@crankycanuck.ca>
To: pgsql-performance@postgresql.org
Subject: Re: Help tuning postgres
Message-ID: <20051012220036.GE13571@phlogiston.dyndns.org>
References: <1129128315.2995.174.camel@coppola.muc.ecircle.de>
	<f3c0b4080510120939x6c08feebvfad37c98df306538@mail.gmail.com>
	<1129136130.2995.188.camel@coppola.muc.ecircle.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <1129136130.2995.188.camel@coppola.muc.ecircle.de>
User-Agent: Mutt/1.5.9i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.032 required=5 tests=[AWL=-0.018,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/217
X-Sequence-Number: 14985

On Wed, Oct 12, 2005 at 06:55:30PM +0200, Csaba Nagy wrote:
> Ok, that was the first thing I've done, checking out the explain of the
> query. I don't really need the analyze part, as the plan is going for
> the index, which is the right decision. The updates are simple one-row

How do you know?  You _do_ need the ANALYSE, because it'll tell you
what the query _actually did_ as opposed to what the planner thought
it was going to do.  

Note that EXPLAIN ANALYSE actually performs the work, so you better
do it in a transaction and ROLLBACK if it's a production system.

> Actually I've done an iostat run in the meantime (just learned how to
> use it), and looks like the disk is 100 saturated. So it clearly is a
> disk issue in this case. And it turns out the Oracle hardware has an

Yes, but it could be a disk issue because you're doing more work than
you need to.  If your UPDATEs are chasing down a lot of dead tuples,
for instance, you'll peg your I/O even though you ought to have I/O
to burn.

A

-- 
Andrew Sullivan  | ajs@crankycanuck.ca
The whole tendency of modern prose is away from concreteness.
		--George Orwell

From pgsql-performance-owner@postgresql.org  Thu Oct 13 05:15:22 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id C629CD8506
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 13 Oct 2005 05:15:20 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 14188-10
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 13 Oct 2005 08:15:17 +0000 (GMT)
Received: from mail.ecircle.de (mail.ecircle.de [195.140.186.200])
	by svr1.postgresql.org (Postfix) with ESMTP id 864B5D8478
	for <pgsql-performance@postgresql.org>;
	Thu, 13 Oct 2005 05:15:18 -0300 (ADT)
Received: from [192.168.1.110] (unknown [192.168.1.110])
	by mail.ecircle.de (READY) with ESMTP id 1F9A7954283;
	Thu, 13 Oct 2005 10:15:19 +0200 (CEST)
Subject: Re: Help tuning postgres
From: Csaba Nagy <nagy@ecircle-ag.com>
To: Andrew Sullivan <ajs@crankycanuck.ca>
Cc: postgres performance list <pgsql-performance@postgresql.org>
In-Reply-To: <20051012220036.GE13571@phlogiston.dyndns.org>
References: <1129128315.2995.174.camel@coppola.muc.ecircle.de>
	<f3c0b4080510120939x6c08feebvfad37c98df306538@mail.gmail.com>
	<1129136130.2995.188.camel@coppola.muc.ecircle.de>
	<20051012220036.GE13571@phlogiston.dyndns.org>
Content-Type: text/plain
Message-Id: <1129191303.2995.192.camel@coppola.muc.ecircle.de>
Mime-Version: 1.0
X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) 
Date: Thu, 13 Oct 2005 10:15:03 +0200
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.012 required=5 tests=[AWL=0.012]
X-Spam-Level: 
X-Archive-Number: 200510/218
X-Sequence-Number: 14986

[snip]
> Yes, but it could be a disk issue because you're doing more work than
> you need to.  If your UPDATEs are chasing down a lot of dead tuples,
> for instance, you'll peg your I/O even though you ought to have I/O
> to burn.

OK, this sounds interesting, but I don't understand: why would an update
"chase down a lot of dead tuples" ? Should I read up on some docs, cause
I obviously don't know enough about how updates work on postgres...

And how would the analyze help in finding this out ? I thought it would
only show me additionally the actual timings, not more detail in what
was done...

Thanks,
Csaba.



From pgsql-performance-owner@postgresql.org  Thu Oct 13 06:54:02 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id F1F49D85B7
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 13 Oct 2005 06:54:01 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 38502-09
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 13 Oct 2005 09:53:56 +0000 (GMT)
Received: from moutng.kundenserver.de (moutng.kundenserver.de
	[212.227.126.177])
	by svr1.postgresql.org (Postfix) with ESMTP id 87EB9D854B
	for <pgsql-performance@postgresql.org>;
	Thu, 13 Oct 2005 06:53:57 -0300 (ADT)
Received: from p508E65E8.dip.t-dialin.net [80.142.101.232]
	(helo=swtexchange2.technology.de)
	by mrelayeu.kundenserver.de with ESMTP (Nemesis),
	id 0MKwh2-1EPzmg3Ttz-0007On; Thu, 13 Oct 2005 11:53:58 +0200
content-class: urn:content-classes:message
Subject: Optimizer misconfigured ?
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="----_=_NextPart_001_01C5CFDC.07A4960E"
Date: Thu, 13 Oct 2005 11:53:57 +0200
X-MimeOLE: Produced By Microsoft Exchange V6.0.6556.0
Message-ID: 
 <16F953410A0F1346848DCB476A989CFE01D52D@swtexchange2.technology.de>
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
Thread-Topic: Optimizer misconfigured ?
Thread-Index: AcXP3AfeUE8Qtq0TTjCmTU9RRV9p2Q==
From: =?iso-8859-1?Q?N=F6rder-Tuitje=2C_Marcus?=
 <noerder-tuitje@technology.de>
To: <pgsql-performance@postgresql.org>
X-Provags-ID: kundenserver.de abuse@kundenserver.de
	login:24478085a861b01e05bdc3b8f80dc176
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.353 required=5 tests=[FORGED_RCVD_HELO=0.05,
	HTML_50_60=0.095, HTML_MESSAGE=0.001, UPPERCASE_25_50=0.207]
X-Spam-Level: 
X-Archive-Number: 200510/219
X-Sequence-Number: 14987

This is a multi-part message in MIME format.

------_=_NextPart_001_01C5CFDC.07A4960E
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable



Hello,=20

I have a strange effect on upcoming structure :


DEX_OBJ  ---< DEX_STRUCT >--- DEX_LIT

DEX_OBJ : 100 records (#DOO_ID, DOO_NAME)
DEX_STRUCT : 2,5 million records  (#(DST_SEQ, FK_DOO_ID, FK_LIT_ID))
DEX_LIT : 150K records  (#LIT_ID, LIT_TEXT)

(# marks primary key)

i'd like to count all LIT occurences in struct for a set of LITs.

so i indexed DEX_STRUCT using (FK_LIT_ID, FK_DOO_ID)
and i indexed DEX_LIT using BTREE (LIT_TEXT, LIT_ID)

but if i query

SELECT DOO_ID
    ,	 COUNT(FK_LIT_ID) AS occurences
   FROM DEX_STRUCT  STR
      ,	 DEX_LITERAL  LIT
WHERE STR.FK_LIT_ID =3D LIT.LIT_ID
     AND  LIT_TEXT IN ('foo', 'bar', 'foobar')
  GROUP BY DOO_ID

postgresql always runs a seq scan on DEX_STRUCT. I tried several indices =
and also very different kinds of queries (from EXISTS via INNER JOIN up =
to subqueries), but Pgsql does not use any index on dex_struct.

What can I do ? Is this a optimizer misconfiguration (hence, it is still =
in default config) ?

How can I make Pg using the indices on doc_struct ? The index on LIT is =
used :-(

I expect 30 - 60 millions of records in the struct table, so I urgently =
need indexed access.

Thanks a lot !

Marcus


------_=_NextPart_001_01C5CFDC.07A4960E
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Diso-8859-1">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
6.0.6556.0">
<TITLE>Optimizer misconfigured ?</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->
<BR>
<BR>

<P><FONT SIZE=3D2 FACE=3D"Arial">Hello, </FONT>
</P>

<P><FONT SIZE=3D2 FACE=3D"Arial">I have a strange effect on upcoming =
structure :</FONT>
</P>
<BR>

<P><FONT SIZE=3D2 FACE=3D"Arial">DEX_OBJ&nbsp; ---&lt; DEX_STRUCT =
&gt;--- DEX_LIT</FONT>
</P>

<P><FONT SIZE=3D2 FACE=3D"Arial">DEX_OBJ : 100 records (#DOO_ID, =
DOO_NAME)</FONT>

<BR><FONT SIZE=3D2 FACE=3D"Arial">DEX_STRUCT : 2,5 million records&nbsp; =
(#(DST_SEQ, FK_DOO_ID, FK_LIT_ID))</FONT>

<BR><FONT SIZE=3D2 FACE=3D"Arial">DEX_LIT : 150K records&nbsp; (#LIT_ID, =
LIT_TEXT)</FONT>
</P>

<P><FONT SIZE=3D2 FACE=3D"Arial">(# marks primary key)</FONT>
</P>

<P><FONT SIZE=3D2 FACE=3D"Arial">i'd like to count all LIT occurences in =
struct for a set of LITs.</FONT>
</P>

<P><FONT SIZE=3D2 FACE=3D"Arial">so i indexed DEX_STRUCT using =
(FK_LIT_ID, FK_DOO_ID)</FONT>

<BR><FONT SIZE=3D2 FACE=3D"Arial">and i indexed DEX_LIT using BTREE =
(LIT_TEXT, LIT_ID)</FONT>
</P>

<P><FONT SIZE=3D2 FACE=3D"Arial">but if i query</FONT>
<BR>

<BR><FONT SIZE=3D2 FACE=3D"Arial">SELECT DOO_ID</FONT>

<BR><FONT SIZE=3D2 FACE=3D"Arial">&nbsp;&nbsp;&nbsp; ,&nbsp;&nbsp;&nbsp; =
COUNT(FK_LIT_ID) AS occurences</FONT>

<BR><FONT SIZE=3D2 FACE=3D"Arial">&nbsp;&nbsp; FROM DEX_STRUCT&nbsp; =
STR</FONT>

<BR><FONT SIZE=3D2 FACE=3D"Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ,&nbsp; =
DEX_LITERAL&nbsp; LIT</FONT>

<BR><FONT SIZE=3D2 FACE=3D"Arial">WHERE STR.FK_LIT_ID =3D =
LIT.LIT_ID</FONT>

<BR><FONT SIZE=3D2 FACE=3D"Arial">&nbsp;&nbsp;&nbsp;&nbsp; AND&nbsp; =
LIT_TEXT IN ('foo', 'bar', 'foobar')</FONT>

<BR><FONT SIZE=3D2 FACE=3D"Arial">&nbsp; GROUP BY DOO_ID</FONT>
</P>

<P><FONT SIZE=3D2 FACE=3D"Arial">postgresql always runs a seq scan on =
DEX_STRUCT. I tried several indices and also very different kinds of =
queries (from EXISTS via INNER JOIN up to subqueries), but Pgsql does =
not use any index on dex_struct.</FONT></P>

<P><FONT SIZE=3D2 FACE=3D"Arial">What can I do ? Is this a optimizer =
misconfiguration (hence, it is still in default config) ?</FONT>
</P>

<P><FONT SIZE=3D2 FACE=3D"Arial">How can I make Pg using the indices on =
doc_struct ? The index on LIT is used :-(</FONT>
</P>

<P><FONT SIZE=3D2 FACE=3D"Arial">I expect 30 - 60 millions of records in =
the struct table, so I urgently need indexed access.</FONT>
</P>

<P><FONT SIZE=3D2 FACE=3D"Arial">Thanks a lot !</FONT>
</P>

<P><FONT SIZE=3D2 FACE=3D"Arial">Marcus</FONT>
</P>

</BODY>
</HTML>
------_=_NextPart_001_01C5CFDC.07A4960E--

From pgsql-performance-owner@postgresql.org  Thu Oct 13 07:16:57 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 57EF6D83F2
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 13 Oct 2005 07:16:56 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 46421-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 13 Oct 2005 10:16:50 +0000 (GMT)
Received: from dozer.computec.de (dozer.computec.de [212.123.108.12])
	by svr1.postgresql.org (Postfix) with ESMTP id A223CD81D9
	for <pgsql-performance@postgresql.org>;
	Thu, 13 Oct 2005 07:16:50 -0300 (ADT)
content-class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
X-MimeOLE: Produced By Microsoft Exchange V6.0.6487.1
Subject: Re: Help tuning postgres
Date: Thu, 13 Oct 2005 12:16:49 +0200
Message-ID: <2266D0630E43BB4290742247C8910575082D360B@dozer.computec.de>
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
Thread-Topic: [PERFORM] Help tuning postgres
Thread-Index: AcXPQtxBmuNADRV1RAWZ1YBirzDLkgAm1tIw
From: "Markus Wollny" <Markus.Wollny@computec.de>
To: <emil@baymountain.com>, "Csaba Nagy" <nagy@ecircle-ag.com>
Cc: <pgsql-performance@postgresql.org>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=1.257 required=5 tests=[AWL=-0.493,
	DNS_FROM_RFC_ABUSE=0.374, DNS_FROM_RFC_POST=1.376]
X-Spam-Level: *
X-Archive-Number: 200510/220
X-Sequence-Number: 14988

pgsql-performance-owner@postgresql.org wrote:

>>> Have you tried reindexing your active tables?

> It will cause some performance hit while you are doing it. It
> sounds like something is bloating rapidly on your system and
> the indexes is one possible place that could be happening.

You might consider using contrib/oid2name to monitor physical growth of
tables and indexes. There have been some issues with bloat in PostgreSQL
versions prior to 8.0, however there might still be some issues under
certain circumstances even now, so it does pay to cast an eye on what's
going on. If you haven't run vaccum regularly, this might lead to
regular vacuums not reclaiming enough dead tuples in one go, so if
you've had quite a lot of UPDATE/DELETE activity going onin the past and
only just started to use pg_autovacuum after the DB has been in
production for quite a while, you might indeed have to run a VACUUM FULL
and/or REINDEX on the affected tables, both of which will more or less
lock out any client access to the tables als long as they're running.

Kind regards

   Markus

From pgsql-performance-owner@postgresql.org  Thu Oct 13 07:25:28 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 587E5D80AA
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 13 Oct 2005 07:25:25 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 47673-03
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 13 Oct 2005 10:25:17 +0000 (GMT)
Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75])
	by svr1.postgresql.org (Postfix) with ESMTP id 9AFC7D85D4
	for <pgsql-performance@postgresql.org>;
	Thu, 13 Oct 2005 07:25:18 -0300 (ADT)
Received: from mainbox.archonet.com
	(84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99])
	by smtp.metronet.co.uk (MetroNet Mail) with ESMTP
	id 9606C41411C; Thu, 13 Oct 2005 11:25:12 +0100 (BST)
Received: from localhost (localhost.localdomain [127.0.0.1])
	by mainbox.archonet.com (Postfix) with ESMTP id 55BD015ED9;
	Thu, 13 Oct 2005 11:22:01 +0100 (BST)
Received: from mainbox.archonet.com ([127.0.0.1])
	by localhost (mainbox [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 22681-01; Thu, 13 Oct 2005 11:21:59 +0100 (BST)
Received: from [192.168.1.17] (client17.office.archonet.com [192.168.1.17])
	by mainbox.archonet.com (Postfix) with ESMTP id DEBB215ED5;
	Thu, 13 Oct 2005 11:21:58 +0100 (BST)
Message-ID: <434E3546.4090900@archonet.com>
Date: Thu, 13 Oct 2005 11:21:58 +0100
From: Richard Huxton <dev@archonet.com>
User-Agent: Thunderbird 1.4.1 (X11/20051006)
MIME-Version: 1.0
To: Marcus <noerder-tuitje@technology.de>
Cc: pgsql-performance@postgresql.org
Subject: Re: Optimizer misconfigured ?
References: 
 <16F953410A0F1346848DCB476A989CFE01D52D@swtexchange2.technology.de>
In-Reply-To: 
 <16F953410A0F1346848DCB476A989CFE01D52D@swtexchange2.technology.de>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: quoted-printable
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.059 required=5 tests=[AWL=0.009,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/222
X-Sequence-Number: 14990

N=F6rder-Tuitje wrote:
>=20
> Hello,=20
>=20
> I have a strange effect on upcoming structure :

People will be wanting the output of EXPLAIN ANALYSE on that query.

They'll also ask whether you've VACUUMed, ANALYSEd and configured your=20
postgresql.conf correctly.

--=20
   Richard Huxton
   Archonet Ltd



From pgsql-performance-owner@postgresql.org  Thu Oct 13 07:24:32 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 1ED7CD83F2
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 13 Oct 2005 07:24:31 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 45172-09
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 13 Oct 2005 10:24:27 +0000 (GMT)
Received: from dozer.computec.de (dozer.computec.de [212.123.108.12])
	by svr1.postgresql.org (Postfix) with ESMTP id 20C73D80AA
	for <pgsql-performance@postgresql.org>;
	Thu, 13 Oct 2005 07:24:28 -0300 (ADT)
content-class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
X-MimeOLE: Produced By Microsoft Exchange V6.0.6487.1
Subject: Re: Help tuning postgres
Date: Thu, 13 Oct 2005 12:24:31 +0200
Message-ID: <2266D0630E43BB4290742247C8910575082D361D@dozer.computec.de>
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
Thread-Topic: [PERFORM] Help tuning postgres
Thread-Index: AcXPThnLGqi/eykPRSesn5Ne6vrJ0QAkSf0g
From: "Markus Wollny" <Markus.Wollny@computec.de>
To: "Csaba Nagy" <nagy@ecircle-ag.com>, <newz@bearfruit.org>
Cc: "postgres performance list" <pgsql-performance@postgresql.org>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=1.268 required=5 tests=[AWL=-0.482,
	DNS_FROM_RFC_ABUSE=0.374, DNS_FROM_RFC_POST=1.376]
X-Spam-Level: *
X-Archive-Number: 200510/221
X-Sequence-Number: 14989

pgsql-performance-owner@postgresql.org wrote:

> Next we'll upgrade the postgres hardware, and then I'll come
> back to report if it's working better... sorry for the noise for now.

There have been some discussions about which hardware suits PostgreSQL's
needs best under certain load-characteristics. We have experienced quite
a write-performance burst just from switching from a RAID5-config to a
RAID10 (mirroring&striping), even though we had been using some
supposedly sufficiently powerful dedicated battery-backuped
SCSI-RAID-adapters with lots of on-board cache. You can't beat simple,
although it will cost disk-space. Anyway, you might want to search the
archives for discussion on RAID-configurations.

From pgsql-performance-owner@postgresql.org  Thu Oct 13 09:40:10 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 20929D87C7
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 13 Oct 2005 09:40:10 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 83252-03
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 13 Oct 2005 12:40:03 +0000 (GMT)
Received: from smtp104.rog.mail.re2.yahoo.com (smtp104.rog.mail.re2.yahoo.com
	[206.190.36.82])
	by svr1.postgresql.org (Postfix) with SMTP id A5490D87C9
	for <pgsql-performance@postgresql.org>;
	Thu, 13 Oct 2005 09:40:05 -0300 (ADT)
Received: (qmail 75924 invoked from network); 13 Oct 2005 12:40:09 -0000
Received: from unknown (HELO phlogiston.dydns.org)
	(a.sullivan@rogers.com@209.222.54.227 with login)
	by smtp104.rog.mail.re2.yahoo.com with SMTP; 13 Oct 2005 12:40:08 -0000
Received: by phlogiston.dydns.org (Postfix, from userid 1000)
	id A65FF40E6; Thu, 13 Oct 2005 08:40:07 -0400 (EDT)
Date: Thu, 13 Oct 2005 08:40:07 -0400
From: Andrew Sullivan <ajs@crankycanuck.ca>
To: postgres performance list <pgsql-performance@postgresql.org>
Subject: Re: Help tuning postgres
Message-ID: <20051013124007.GA15592@phlogiston.dyndns.org>
Mail-Followup-To: postgres performance list <pgsql-performance@postgresql.org>
References: <1129128315.2995.174.camel@coppola.muc.ecircle.de>
	<f3c0b4080510120939x6c08feebvfad37c98df306538@mail.gmail.com>
	<1129136130.2995.188.camel@coppola.muc.ecircle.de>
	<20051012220036.GE13571@phlogiston.dyndns.org>
	<1129191303.2995.192.camel@coppola.muc.ecircle.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <1129191303.2995.192.camel@coppola.muc.ecircle.de>
User-Agent: Mutt/1.5.9i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.032 required=5 tests=[AWL=-0.018,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/223
X-Sequence-Number: 14991

On Thu, Oct 13, 2005 at 10:15:03AM +0200, Csaba Nagy wrote:
> 
> OK, this sounds interesting, but I don't understand: why would an update
> "chase down a lot of dead tuples" ? Should I read up on some docs, cause
> I obviously don't know enough about how updates work on postgres...

Right.  Here's the issue:

MVCC does not replace rows when you update.  Instead, it marks the
old row as expired, and sets the new values.  The old row is still
there, and it's available for other transactions who need to see it. 
As the docs say (see
<http://www.postgresql.org/docs/8.0/interactive/transaction-iso.html>),
"In effect, a SELECT query sees a snapshot of the database as of the
instant that that query begins to run."  And that can be true because
the original data is still there, although marked as expired for
subsequent transactions.

UPDATE works the same was as SELECT in terms of searching for rows
(so does any command that searches for data).  

Now, when you select data, you actually have to traverse all the
existing versions of the tuple in order to get the one that's live
for you.  This is normally not a problem: VACUUM goes around and
cleans out old, expired data that is not live for _anyone_.  It does
this by looking for the oldest transaction that is open.  (As far as
I understand it, this is actually the oldest transaction in the
entire back end; but I've never understood why that should the the
case, and I'm too incompetent/dumb to understand the code, so I may
be wrong on this point.)  If you have very long-running transactions,
then, you can end up with a lot of versions of dead tuples on the
table, and so reading the few records you want can turn out actually
to be a very expensive operation, even though it ought to be cheap.

You can see this by using the VERBOSE option to VACUUM:

test=# VACUUM VERBOSE eval1 ;
INFO:  vacuuming "public.eval1"
INFO:  "eval1": found 0 removable, 0 nonremovable row versions in 0
pages
DETAIL:  0 dead row versions cannot be removed yet.
There were 0 unused item pointers.
0 pages are entirely empty.
CPU 0.00s/0.00u sec elapsed 0.00 sec.
INFO:  vacuuming "pg_toast.pg_toast_18831"
INFO:  index "pg_toast_18831_index" now contains 0 row versions in 1
pages
DETAIL:  0 index pages have been deleted, 0 are currently reusable.
CPU 0.00s/0.00u sec elapsed 0.00 sec.
INFO:  "pg_toast_18831": found 0 removable, 0 nonremovable row
versions in 0 pages
DETAIL:  0 dead row versions cannot be removed yet.
There were 0 unused item pointers.
0 pages are entirely empty.
CPU 0.00s/0.00u sec elapsed 0.00 sec.
VACUUM

Note those "removable" and "nonremovable" row versions.  It's the
unremovable ones that can hurt.  WARNING: doing VACUUM on a big table
on a disk that's already pegged is going to cause you performance
pain, because it scans the whole table.  In some cases, though, you
have no choice: if the winds are already out of your sails, and
you're effectively stopped, anything that might get you moving again
is an improvement.

> And how would the analyze help in finding this out ? I thought it would
> only show me additionally the actual timings, not more detail in what
> was done...

Yes, it shows the actual timings, and the actual number of rows.  But
if the estimates that the planner makes are wildly different than the
actual results, then you know your statistics are wrong, and that the
planner is going about things the wrong way.  ANALYSE is a big help. 
There's also a verbose option to it, but it's usually less useful in
production situations.

A

-- 
Andrew Sullivan  | ajs@crankycanuck.ca
It is above all style through which power defers to reason.
		--J. Robert Oppenheimer

From pgsql-performance-owner@postgresql.org  Thu Oct 13 10:15:01 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id D24B2D87B6
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 13 Oct 2005 10:15:00 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 88181-09
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 13 Oct 2005 13:14:55 +0000 (GMT)
Received: from mail.ecircle.de (mail.ecircle.de [195.140.186.200])
	by svr1.postgresql.org (Postfix) with ESMTP id 6B416D8795
	for <pgsql-performance@postgresql.org>;
	Thu, 13 Oct 2005 10:14:57 -0300 (ADT)
Received: from [192.168.1.110] (unknown [192.168.1.110])
	by mail.ecircle.de (READY) with ESMTP id 3A91095435C;
	Thu, 13 Oct 2005 15:15:01 +0200 (CEST)
Subject: Re: Help tuning postgres
From: Csaba Nagy <nagy@ecircle-ag.com>
To: Andrew Sullivan <ajs@crankycanuck.ca>
Cc: postgres performance list <pgsql-performance@postgresql.org>
In-Reply-To: <20051013124007.GA15592@phlogiston.dyndns.org>
References: <1129128315.2995.174.camel@coppola.muc.ecircle.de>
	<f3c0b4080510120939x6c08feebvfad37c98df306538@mail.gmail.com>
	<1129136130.2995.188.camel@coppola.muc.ecircle.de>
	<20051012220036.GE13571@phlogiston.dyndns.org>
	<1129191303.2995.192.camel@coppola.muc.ecircle.de>
	<20051013124007.GA15592@phlogiston.dyndns.org>
Content-Type: text/plain
Message-Id: <1129209283.2995.226.camel@coppola.muc.ecircle.de>
Mime-Version: 1.0
X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) 
Date: Thu, 13 Oct 2005 15:14:44 +0200
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.012 required=5 tests=[AWL=0.012]
X-Spam-Level: 
X-Archive-Number: 200510/224
X-Sequence-Number: 14992

Thanks Andrew, this explanation about the dead rows was enlightening.
Might be the reason for the slowdown I see on occasions, but not for the
case which I was first observing. In that case the updated rows are
different for each update. It is possible that each row has a few dead
versions, but not too many, each row is updated just a limited number of
times.

However, we have other updates which access the same row 1000s of times
(up to millions of times), and that could hurt if it's like you said,
i.e. if each update has to crawl over all the dead rows... I have now
autovacuum in place, and I'm sure it will kick in at ~ a few 10000s of
updates, but in the meantime it could get bad.
In any case, I suppose that those disk pages should be in OS cache
pretty soon and stay there, so I still don't understand why the disk
usage is 100% in this case (with very low CPU activity, the CPUs are
mostly waiting/idle)... the amount of actively used data is not that
big.

I'll try to vacuum through cron jobs the most exposed tables to this
multiple-dead-row-versions symptom, cause autovacuum probably won't do
it often enough. Let's see if it helps...

Thanks,
Csaba.


On Thu, 2005-10-13 at 14:40, Andrew Sullivan wrote:
> On Thu, Oct 13, 2005 at 10:15:03AM +0200, Csaba Nagy wrote:
> > 
> > OK, this sounds interesting, but I don't understand: why would an update
> > "chase down a lot of dead tuples" ? Should I read up on some docs, cause
> > I obviously don't know enough about how updates work on postgres...
> 
> Right.  Here's the issue:
> 
> MVCC does not replace rows when you update.  Instead, it marks the
> old row as expired, and sets the new values.  The old row is still
> there, and it's available for other transactions who need to see it. 
> As the docs say (see
> <http://www.postgresql.org/docs/8.0/interactive/transaction-iso.html>),
> "In effect, a SELECT query sees a snapshot of the database as of the
> instant that that query begins to run."  And that can be true because
> the original data is still there, although marked as expired for
> subsequent transactions.
> 
> UPDATE works the same was as SELECT in terms of searching for rows
> (so does any command that searches for data).  
> 
> Now, when you select data, you actually have to traverse all the
> existing versions of the tuple in order to get the one that's live
> for you.  This is normally not a problem: VACUUM goes around and
> cleans out old, expired data that is not live for _anyone_.  It does
> this by looking for the oldest transaction that is open.  (As far as
> I understand it, this is actually the oldest transaction in the
> entire back end; but I've never understood why that should the the
> case, and I'm too incompetent/dumb to understand the code, so I may
> be wrong on this point.)  If you have very long-running transactions,
> then, you can end up with a lot of versions of dead tuples on the
> table, and so reading the few records you want can turn out actually
> to be a very expensive operation, even though it ought to be cheap.
> 
> You can see this by using the VERBOSE option to VACUUM:
> 
> test=# VACUUM VERBOSE eval1 ;
> INFO:  vacuuming "public.eval1"
> INFO:  "eval1": found 0 removable, 0 nonremovable row versions in 0
> pages
> DETAIL:  0 dead row versions cannot be removed yet.
> There were 0 unused item pointers.
> 0 pages are entirely empty.
> CPU 0.00s/0.00u sec elapsed 0.00 sec.
> INFO:  vacuuming "pg_toast.pg_toast_18831"
> INFO:  index "pg_toast_18831_index" now contains 0 row versions in 1
> pages
> DETAIL:  0 index pages have been deleted, 0 are currently reusable.
> CPU 0.00s/0.00u sec elapsed 0.00 sec.
> INFO:  "pg_toast_18831": found 0 removable, 0 nonremovable row
> versions in 0 pages
> DETAIL:  0 dead row versions cannot be removed yet.
> There were 0 unused item pointers.
> 0 pages are entirely empty.
> CPU 0.00s/0.00u sec elapsed 0.00 sec.
> VACUUM
> 
> Note those "removable" and "nonremovable" row versions.  It's the
> unremovable ones that can hurt.  WARNING: doing VACUUM on a big table
> on a disk that's already pegged is going to cause you performance
> pain, because it scans the whole table.  In some cases, though, you
> have no choice: if the winds are already out of your sails, and
> you're effectively stopped, anything that might get you moving again
> is an improvement.
> 
> > And how would the analyze help in finding this out ? I thought it would
> > only show me additionally the actual timings, not more detail in what
> > was done...
> 
> Yes, it shows the actual timings, and the actual number of rows.  But
> if the estimates that the planner makes are wildly different than the
> actual results, then you know your statistics are wrong, and that the
> planner is going about things the wrong way.  ANALYSE is a big help. 
> There's also a verbose option to it, but it's usually less useful in
> production situations.
> 
> A


From pgsql-performance-owner@postgresql.org  Thu Oct 13 11:50:41 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 2A761D80D6
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 13 Oct 2005 11:50:40 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 19079-04
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 13 Oct 2005 14:50:33 +0000 (GMT)
Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.204])
	by svr1.postgresql.org (Postfix) with ESMTP id 25833D80A8
	for <pgsql-performance@postgresql.org>;
	Thu, 13 Oct 2005 11:50:35 -0300 (ADT)
Received: by xproxy.gmail.com with SMTP id i30so239313wxd
	for <pgsql-performance@postgresql.org>;
	Thu, 13 Oct 2005 07:50:40 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references;
	b=aEnvjfOwYz/NiGPRmh0Aqzh9uA9J9rirfxdHYUa9oXVmD2NipChg431OJ75DrSBh+bjBNE/oXvovGpkadk35lkTeutg8tVURdQVjNazAV8Z6wGYEYDqZMdgs/orxl4xEMAdcqPHWT2eiJzql6r0tIoMhzgrf8JGoWTEw2CMpSEM=
Received: by 10.70.76.12 with SMTP id y12mr719697wxa;
	Thu, 13 Oct 2005 07:50:40 -0700 (PDT)
Received: by 10.70.128.19 with HTTP; Thu, 13 Oct 2005 07:50:40 -0700 (PDT)
Message-ID: <f3c0b4080510130750w3f8398fs404acc2f0ee77c9@mail.gmail.com>
Date: Thu, 13 Oct 2005 09:50:40 -0500
From: Matthew Nuzum <mattnuzum@gmail.com>
Reply-To: newz@bearfruit.org
To: Csaba Nagy <nagy@ecircle-ag.com>
Subject: Re: Help tuning postgres
Cc: postgres performance list <pgsql-performance@postgresql.org>
In-Reply-To: <1129209283.2995.226.camel@coppola.muc.ecircle.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
References: <1129128315.2995.174.camel@coppola.muc.ecircle.de>
	<f3c0b4080510120939x6c08feebvfad37c98df306538@mail.gmail.com>
	<1129136130.2995.188.camel@coppola.muc.ecircle.de>
	<20051012220036.GE13571@phlogiston.dyndns.org>
	<1129191303.2995.192.camel@coppola.muc.ecircle.de>
	<20051013124007.GA15592@phlogiston.dyndns.org>
	<1129209283.2995.226.camel@coppola.muc.ecircle.de>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.319 required=5 tests=[AWL=0.295, RCVD_BY_IP=0.024]
X-Spam-Level: 
X-Archive-Number: 200510/225
X-Sequence-Number: 14993

On 10/13/05, Csaba Nagy <nagy@ecircle-ag.com> wrote:
> On Thu, 2005-10-13 at 14:40, Andrew Sullivan wrote:
> > On Thu, Oct 13, 2005 at 10:15:03AM +0200, Csaba Nagy wrote:
> > > And how would the analyze help in finding this out ? I thought it wou=
ld
> > > only show me additionally the actual timings, not more detail in what
> > > was done...
> >
> > Yes, it shows the actual timings, and the actual number of rows.  But
> > if the estimates that the planner makes are wildly different than the
> > actual results, then you know your statistics are wrong, and that the
> > planner is going about things the wrong way.  ANALYSE is a big help.
> > There's also a verbose option to it, but it's usually less useful in
> > production situations.

This is the point I was trying to make. I've seen special instances
where people have posted an explain annalyze for a select/update to
the list and suggestions have arisen allowing major performance
improvements.

If this task is where your database is performing its worst then it is
the best place to start with optimizing, short of the obvious stuff,
which it sounds like you've covered.

Sometimes, and I think this has often been true for databases that are
either very large or very small, statistics can be tweaked to get
better performance. One good example is when a sequential scan is
being chosen when an index scan may be better; something like this
would definately peg your disk i/o.

Throwing more hardware at your problem will definately help, but I'm a
performance freak and I like to optimize everything to the max.
*Sometimes* you can get drastic improvements without adding any
hardware. I have seen some truly miraculus turn-arounds by tweaking
some non-obvious settings based on suggestions made on this list.
--
Matthew Nuzum
www.bearfruit.org

From pgsql-performance-owner@postgresql.org  Thu Oct 13 12:01:26 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 12671D7D59
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 13 Oct 2005 12:01:25 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 19147-09
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 13 Oct 2005 15:01:20 +0000 (GMT)
Received: from smtp101.rog.mail.re2.yahoo.com (smtp101.rog.mail.re2.yahoo.com
	[206.190.36.79])
	by svr1.postgresql.org (Postfix) with SMTP id 460D2D78E8
	for <pgsql-performance@postgresql.org>;
	Thu, 13 Oct 2005 12:01:20 -0300 (ADT)
Received: (qmail 84456 invoked from network); 13 Oct 2005 15:01:19 -0000
Received: from unknown (HELO phlogiston.dydns.org)
	(a.sullivan@rogers.com@209.222.54.227 with login)
	by smtp101.rog.mail.re2.yahoo.com with SMTP; 13 Oct 2005 15:01:19 -0000
Received: by phlogiston.dydns.org (Postfix, from userid 1000)
	id 37880412B; Thu, 13 Oct 2005 11:01:18 -0400 (EDT)
Date: Thu, 13 Oct 2005 11:01:18 -0400
From: Andrew Sullivan <ajs@crankycanuck.ca>
To: pgsql-performance@postgresql.org
Subject: Re: Server misconfiguration???
Message-ID: <20051013150118.GC16317@phlogiston.dyndns.org>
References: <006f01c5cd76$2b166490$0b00a8c0@forge>
	<20487.1128953925@sss.pgh.pa.us>
	<001201c5cda7$4314b430$0b00a8c0@forge>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <001201c5cda7$4314b430$0b00a8c0@forge>
User-Agent: Mutt/1.5.9i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.033 required=5 tests=[AWL=-0.017,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/226
X-Sequence-Number: 14994

On Mon, Oct 10, 2005 at 05:31:10PM +0300, Andy wrote:
> I read some tuning things, I made the things that are written there, but I 
> think that there improvements can be made.

Have you tried the suggestions people made?  Because if I were you,
I'd be listing very carefully to what Chris and Tom were telling me
about how to tune my database.

A

-- 
Andrew Sullivan  | ajs@crankycanuck.ca
In the future this spectacle of the middle classes shocking the avant-
garde will probably become the textbook definition of Postmodernism. 
                --Brad Holland

From pgsql-performance-owner@postgresql.org  Thu Oct 13 13:11:18 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 4B31DD82E9
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 13 Oct 2005 13:07:19 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 42163-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 13 Oct 2005 16:07:16 +0000 (GMT)
Received: from smtp103.rog.mail.re2.yahoo.com (smtp103.rog.mail.re2.yahoo.com
	[206.190.36.81])
	by svr1.postgresql.org (Postfix) with SMTP id AAF60D82F6
	for <pgsql-performance@postgresql.org>;
	Thu, 13 Oct 2005 13:07:16 -0300 (ADT)
Received: (qmail 772 invoked from network); 13 Oct 2005 16:07:16 -0000
Received: from unknown (HELO phlogiston.dydns.org)
	(a.sullivan@rogers.com@209.222.54.227 with login)
	by smtp103.rog.mail.re2.yahoo.com with SMTP; 13 Oct 2005 16:07:15 -0000
Received: by phlogiston.dydns.org (Postfix, from userid 1000)
	id AA8CE413D; Thu, 13 Oct 2005 12:07:14 -0400 (EDT)
Date: Thu, 13 Oct 2005 12:07:14 -0400
From: Andrew Sullivan <ajs@crankycanuck.ca>
To: postgres performance list <pgsql-performance@postgresql.org>
Subject: Re: Help tuning postgres
Message-ID: <20051013160714.GG16317@phlogiston.dyndns.org>
Mail-Followup-To: postgres performance list <pgsql-performance@postgresql.org>
References: <1129128315.2995.174.camel@coppola.muc.ecircle.de>
	<f3c0b4080510120939x6c08feebvfad37c98df306538@mail.gmail.com>
	<1129136130.2995.188.camel@coppola.muc.ecircle.de>
	<20051012220036.GE13571@phlogiston.dyndns.org>
	<1129191303.2995.192.camel@coppola.muc.ecircle.de>
	<20051013124007.GA15592@phlogiston.dyndns.org>
	<1129209283.2995.226.camel@coppola.muc.ecircle.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <1129209283.2995.226.camel@coppola.muc.ecircle.de>
User-Agent: Mutt/1.5.9i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.033 required=5 tests=[AWL=-0.017,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/227
X-Sequence-Number: 14995

On Thu, Oct 13, 2005 at 03:14:44PM +0200, Csaba Nagy wrote:
> In any case, I suppose that those disk pages should be in OS cache
> pretty soon and stay there, so I still don't understand why the disk
> usage is 100% in this case (with very low CPU activity, the CPUs are
> mostly waiting/idle)... the amount of actively used data is not that
> big.

Ah, but if the sum of all the dead rows is large enough that they
start causing your shared memory (== Postgres buffers) to thrash,
then you start causing the memory subsystem to thrash on the box,
which means less RAM is available for disk buffers because the OS is
doing more work; and the disk buffers are full of a lot of garbage
_anyway_, so then you may find that you're ending up hitting the disk
for some of these reads after all.  Around the office I have called
this the "buffer death spiral".  And note that once you've managed to
get into a vacuum-starvation case, your free space map might be
exceeded, at which point your database performance really won't
recover until you've done VACUUM FULL (prior to 7.4 there's also an
index problem that's even worse, and that needs occasional REINDEX to
solve; I forget which version you said you were using).

The painful part about tuning a production system is really that you
have to keep about 50 variables juggling in your head, just so you
can uncover the one thing that you have to put your finger on to make
it all play nice.

A

-- 
Andrew Sullivan  | ajs@crankycanuck.ca
A certain description of men are for getting out of debt, yet are
against all taxes for raising money to pay it off.
		--Alexander Hamilton

From pgsql-performance-owner@postgresql.org  Thu Oct 13 13:37:52 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 68185D818D
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 13 Oct 2005 13:34:47 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 48430-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 13 Oct 2005 16:34:42 +0000 (GMT)
Received: from fdlnint02.fds.com (fdlnint02.fds.com [208.15.91.51])
	by svr1.postgresql.org (Postfix) with ESMTP id 0B7A3D8185
	for <pgsql-performance@postgresql.org>;
	Thu, 13 Oct 2005 13:34:42 -0300 (ADT)
Subject: slow update
To: postgres performance list <pgsql-performance@postgresql.org>
X-Mailer: Lotus Notes Release 6.5.4 March 27, 2005
Message-ID: 
 <OFA8DB89A3.5A1EFBC0-ON88257099.005948E9-88257099.005B0CF7@FDS.com>
From: Patrick Hatcher <PHatcher@macys.com>
Date: Thu, 13 Oct 2005 09:34:39 -0700
X-MIMETrack: Serialize by Router on FDLNINT02/FSG/SVR/FDS(Release 6.5.2|June
	01, 2004) at 10/13/2005 12:34:46 PM
MIME-Version: 1.0
Content-type: text/plain; charset=US-ASCII
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.17 required=5 tests=[AWL=0.170]
X-Spam-Level: 
X-Archive-Number: 200510/228
X-Sequence-Number: 14996


Pg 7.4.5
RH 7.3
Quad Xeon 3Gz
12G ram

Trying to do a update of fields on 23M row database.
Is it normal for this process to take 16hrs and still clocking?  Both join
fields are indexed and I have removed any indexes on the updated columns.
Also both tables are vacuumed regularly.
I'm weary to cancel the job for fear that it is just slow and I'll have to
repeat the 16hr job.
Any suggestions of what I can check for the bottleneck?

Below is my update statement and table structure:

update cdm.cdm_ddw_tran_item
set dept_id = dept,
vend_id = vend,
mkstyl = mstyle
from flbasics
where flbasics.upc = cdm.cdm_ddw_tran_item.item_upc;


CREATE TABLE cdm.cdm_ddw_tran_item
(
  appl_xref varchar(22),
  intr_xref varchar(13),
  tran_typ_id char(1),
  tran_ship_amt numeric(8,2),
  fill_store_div int4,
  soldto_cust_id int8,
  soldto_cust_seq int4,
  shipto_cust_id int8,
  shipto_cust_seq int4,
  itm_qty int4,
  itm_price numeric(8,2),
  item_id int8,
  item_upc int8,
  item_pid varchar(20),
  item_desc varchar(30),
  nrf_color_name varchar(10),
  nrf_size_name varchar(10),
  dept_id int4,
  vend_id int4,
  mkstyl int4,
  ddw_tran_key bigserial NOT NULL,
  price_type_id int2 DEFAULT 999,
  last_update date DEFAULT ('now'::text)::date,
  CONSTRAINT ddw_tritm_pk PRIMARY KEY (ddw_tran_key)
)
WITHOUT OIDS;

CREATE TABLE flbasics
(
  upc int8,
  dept int4,
  vend int4,
  mstyle int4,
  xcolor int4,
  size int4,
  owned float8,
  cost float8,
  xclass int2,
  firstticket float8,
  status char(2),
  last_receipt date,
  description varchar(50),
  pack_qty int2,
  discontinue_date date,
  std_rcv_units int4,
  std_rcv_cost float8,
  std_rcv_retail float8,
  first_receipt date,
  last_pchange varchar(9),
  ticket float8,
  std_mkd_units int4,
  std_mkd_dollars float8
)
WITHOUT OIDS;

Patrick Hatcher
Development Manager  Analytics/MIO
Macys.com



From pgsql-performance-owner@postgresql.org  Thu Oct 13 15:34:10 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 39C3FD828B
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 13 Oct 2005 15:34:08 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 76448-04
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 13 Oct 2005 18:34:05 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id 8BD03D8155
	for <pgsql-performance@postgresql.org>;
	Thu, 13 Oct 2005 15:34:05 -0300 (ADT)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j9DIY5Br024584;
	Thu, 13 Oct 2005 14:34:05 -0400 (EDT)
To: Patrick Hatcher <PHatcher@macys.com>
Cc: postgres performance list <pgsql-performance@postgresql.org>
Subject: Re: slow update 
In-reply-to: 
 <OFA8DB89A3.5A1EFBC0-ON88257099.005948E9-88257099.005B0CF7@FDS.com>
References: 
 <OFA8DB89A3.5A1EFBC0-ON88257099.005948E9-88257099.005B0CF7@FDS.com>
Comments: In-reply-to Patrick Hatcher <PHatcher@macys.com>
	message dated "Thu, 13 Oct 2005 09:34:39 -0700"
Date: Thu, 13 Oct 2005 14:34:05 -0400
Message-ID: <24583.1129228445@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/229
X-Sequence-Number: 14997

Patrick Hatcher <PHatcher@macys.com> writes:
> Pg 7.4.5

> Trying to do a update of fields on 23M row database.
> Is it normal for this process to take 16hrs and still clocking?

Are there foreign keys pointing at the table being updated?  If so,
failure to index the referencing columns could create this sort of
performance problem.  Also, in 7.4 you'd better be sure the referencing
columns are the same datatype as the referenced column.

			regards, tom lane

From pgsql-performance-owner@postgresql.org  Thu Oct 13 15:39:19 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id E832CD8348
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 13 Oct 2005 15:38:17 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 78366-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 13 Oct 2005 18:38:14 +0000 (GMT)
Received: from fdlnint02.fds.com (fdlnint02.fds.com [208.15.91.51])
	by svr1.postgresql.org (Postfix) with ESMTP id 4F049D83DF
	for <pgsql-performance@postgresql.org>;
	Thu, 13 Oct 2005 15:38:15 -0300 (ADT)
In-Reply-To: <24583.1129228445@sss.pgh.pa.us>
Subject: Re: slow update
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: postgres performance list <pgsql-performance@postgresql.org>
X-Mailer: Lotus Notes Release 6.5.4 March 27, 2005
Message-ID: 
 <OFD4D36CA2.A21FD871-ON88257099.006613A9-88257099.006647D8@FDS.com>
From: Patrick Hatcher <PHatcher@macys.com>
Date: Thu, 13 Oct 2005 11:37:09 -0700
X-MIMETrack: Serialize by Router on FDLNINT02/FSG/SVR/FDS(Release 6.5.2|June
	01, 2004) at 10/13/2005 02:38:20 PM
MIME-Version: 1.0
Content-type: text/plain; charset=US-ASCII
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.163 required=5 tests=[AWL=0.163]
X-Spam-Level: 
X-Archive-Number: 200510/230
X-Sequence-Number: 14998

Thanks.  No foreign keys and I've been bitten by the mismatch datatypes and
checked that before sending out the message :)

Patrick Hatcher
Development Manager  Analytics/MIO
Macys.com




                                                                           
             Tom Lane                                                      
             <tgl@sss.pgh.pa.u                                             
             s>                                                         To 
                                       Patrick Hatcher                     
             10/13/2005 11:34          <PHatcher@macys.com>                
             AM                                                         cc 
                                       postgres performance list           
                                       <pgsql-performance@postgresql.org>  
                                                                   Subject 
                                       Re: [PERFORM] slow update           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           




Patrick Hatcher <PHatcher@macys.com> writes:
> Pg 7.4.5

> Trying to do a update of fields on 23M row database.
> Is it normal for this process to take 16hrs and still clocking?

Are there foreign keys pointing at the table being updated?  If so,
failure to index the referencing columns could create this sort of
performance problem.  Also, in 7.4 you'd better be sure the referencing
columns are the same datatype as the referenced column.

                                     regards, tom lane



From pgsql-performance-owner@postgresql.org  Fri Oct 14 04:23:52 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 08EF7D7F27
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 14 Oct 2005 04:23:51 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 72946-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 14 Oct 2005 07:23:46 +0000 (GMT)
Received: from ar-sd.net (unknown [82.77.155.72])
	by svr1.postgresql.org (Postfix) with ESMTP id 10136D7F1F
	for <pgsql-performance@postgresql.org>;
	Fri, 14 Oct 2005 04:23:47 -0300 (ADT)
Received: from localhost (localhost [127.0.0.1])
	by ar-sd.net (Postfix) with ESMTP id D90E521E49;
	Fri, 14 Oct 2005 10:07:23 +0300 (EEST)
Received: from ar-sd.net ([127.0.0.1])
	by localhost (linz [127.0.0.1]) (amavisd-new, port 10024) with ESMTP
	id 01705-02; Fri, 14 Oct 2005 10:07:21 +0300 (EEST)
Received: from forge (unknown [192.168.0.11])
	by ar-sd.net (Postfix) with SMTP id 0FAFE21DB4;
	Fri, 14 Oct 2005 10:07:21 +0300 (EEST)
Message-ID: <007301c5d090$319bcf90$0b00a8c0@forge>
From: "Andy" <frum@ar-sd.net>
To: "Andrew Sullivan" <ajs@crankycanuck.ca>,
 <pgsql-performance@postgresql.org>
References: <006f01c5cd76$2b166490$0b00a8c0@forge>
	<20487.1128953925@sss.pgh.pa.us>
	<001201c5cda7$4314b430$0b00a8c0@forge>
	<20051013150118.GC16317@phlogiston.dyndns.org>
Subject: Re: Server misconfiguration???
Date: Fri, 14 Oct 2005 10:23:18 +0300
MIME-Version: 1.0
Content-Type: text/plain; format=flowed; charset="iso-8859-1";
	reply-type=original
Content-Transfer-Encoding: 7bit
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-Virus-Scanned: by amavisd-new at ar-sd.net
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.181 required=5 tests=[AWL=0.131,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/231
X-Sequence-Number: 14999

Yes I did, and it works better(on a test server). I had no time to put it in 
production.
I will try to do small steps to see what happens.

Regards,
Andy.


----- Original Message ----- 
From: "Andrew Sullivan" <ajs@crankycanuck.ca>
To: <pgsql-performance@postgresql.org>
Sent: Thursday, October 13, 2005 6:01 PM
Subject: Re: [PERFORM] Server misconfiguration???


> On Mon, Oct 10, 2005 at 05:31:10PM +0300, Andy wrote:
>> I read some tuning things, I made the things that are written there, but 
>> I
>> think that there improvements can be made.
>
> Have you tried the suggestions people made?  Because if I were you,
> I'd be listing very carefully to what Chris and Tom were telling me
> about how to tune my database.
>
> A
>
> -- 
> Andrew Sullivan  | ajs@crankycanuck.ca
> In the future this spectacle of the middle classes shocking the avant-
> garde will probably become the textbook definition of Postmodernism.
>                --Brad Holland
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
>               http://www.postgresql.org/docs/faq
>
> 


From pgsql-performance-owner@postgresql.org  Fri Oct 14 04:31:40 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id D521AD70A1
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 14 Oct 2005 04:31:38 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 75875-10
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 14 Oct 2005 07:31:34 +0000 (GMT)
Received: from moutng.kundenserver.de (moutng.kundenserver.de
	[212.227.126.187])
	by svr1.postgresql.org (Postfix) with ESMTP id 4068CD6DC2
	for <pgsql-performance@postgresql.org>;
	Fri, 14 Oct 2005 04:31:35 -0300 (ADT)
Received: from p508E5D07.dip.t-dialin.net [80.142.93.7]
	(helo=swtexchange2.technology.de)
	by mrelayeu.kundenserver.de with ESMTP (Nemesis),
	id 0ML2ov-1EQK2R2VmC-0006MX; Fri, 14 Oct 2005 09:31:35 +0200
content-class: urn:content-classes:message
Subject: Re: Optimizer misconfigured ?
MIME-Version: 1.0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Date: Fri, 14 Oct 2005 09:31:34 +0200
X-MimeOLE: Produced By Microsoft Exchange V6.0.6556.0
Message-ID: <16F953410A0F1346848DCB476A989CFE34B4@swtexchange2.technology.de>
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
Thread-Topic: [PERFORM] Optimizer misconfigured ?
Thread-Index: AcXP4Sr/TDBCFwcdQBujqvd+eRnPWAArSx2A
From: =?iso-8859-1?Q?N=F6rder-Tuitje=2C_Marcus?=
 <noerder-tuitje@technology.de>
To: "Richard Huxton" <dev@archonet.com>
Cc: <pgsql-performance@postgresql.org>
X-Provags-ID: kundenserver.de abuse@kundenserver.de
	login:24478085a861b01e05bdc3b8f80dc176
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.193 required=5 tests=[AWL=0.143,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/232
X-Sequence-Number: 15000

Hi,

meanwhile I have received the hint to make postgres use the index via

SET ENABLE_SEQSCAN=3DFALSE;

which fits perfectly. The execution plan now indicates full use of =
index.

Nevertheless this is merely a workaround. Maybe the io-costs are =
configured to cheap.

thanks :-)


-----Urspr=FCngliche Nachricht-----
Von: Richard Huxton [mailto:dev@archonet.com]
Gesendet: Donnerstag, 13. Oktober 2005 12:22
An: N=F6rder-Tuitje, Marcus
Cc: pgsql-performance@postgresql.org
Betreff: Re: [PERFORM] Optimizer misconfigured ?


N=F6rder-Tuitje wrote:
>=20
> Hello,=20
>=20
> I have a strange effect on upcoming structure :

People will be wanting the output of EXPLAIN ANALYSE on that query.

They'll also ask whether you've VACUUMed, ANALYSEd and configured your=20
postgresql.conf correctly.

--=20
   Richard Huxton
   Archonet Ltd





From pgsql-performance-owner@postgresql.org  Fri Oct 14 04:40:31 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id F2CB0D815A
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 14 Oct 2005 04:40:29 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 82162-03
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 14 Oct 2005 07:40:27 +0000 (GMT)
Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75])
	by svr1.postgresql.org (Postfix) with ESMTP id 1AA38D7FEA
	for <pgsql-performance@postgresql.org>;
	Fri, 14 Oct 2005 04:40:28 -0300 (ADT)
Received: from mainbox.archonet.com
	(84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99])
	by smtp.metronet.co.uk (MetroNet Mail) with ESMTP
	id 278B04142AF; Fri, 14 Oct 2005 08:40:25 +0100 (BST)
Received: from localhost (localhost.localdomain [127.0.0.1])
	by mainbox.archonet.com (Postfix) with ESMTP id DDFBF15ED9;
	Fri, 14 Oct 2005 08:38:41 +0100 (BST)
Received: from mainbox.archonet.com ([127.0.0.1])
	by localhost (mainbox [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 22826-05; Fri, 14 Oct 2005 08:38:39 +0100 (BST)
Received: from [192.168.1.17] (client17.office.archonet.com [192.168.1.17])
	by mainbox.archonet.com (Postfix) with ESMTP id 5D30715ED5;
	Fri, 14 Oct 2005 08:38:39 +0100 (BST)
Message-ID: <434F607F.8080100@archonet.com>
Date: Fri, 14 Oct 2005 08:38:39 +0100
From: Richard Huxton <dev@archonet.com>
User-Agent: Thunderbird 1.4.1 (X11/20051006)
MIME-Version: 1.0
To: Nörder-Tuitje@archonet.com,
	Marcus <noerder-tuitje@Technology.de>
Cc: pgsql-performance@postgresql.org
Subject: Re: Optimizer misconfigured ?
References: <16F953410A0F1346848DCB476A989CFE34B4@swtexchange2.technology.de>
In-Reply-To: <16F953410A0F1346848DCB476A989CFE34B4@swtexchange2.technology.de>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: quoted-printable
X-Virus-Scanned: by amavisd-new at hub.org
X-Amavis-Alert: BAD HEADER Non-encoded 8-bit data (char C3 hex) in message
	header 'To': To: N\303\266rder-Tuitje@ar...
X-Spam-Status: No, hits=0.059 required=5 tests=[AWL=0.009,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/233
X-Sequence-Number: 15001

N=F6rder-Tuitje wrote:
> Hi,
>=20
> meanwhile I have received the hint to make postgres use the index via
>=20
>=20
> SET ENABLE_SEQSCAN=3DFALSE;
>=20
> which fits perfectly. The execution plan now indicates full use of
> index.

What execution plan? I still only see one message on the list.

> Nevertheless this is merely a workaround. Maybe the io-costs are
> configured to cheap.

Possibly - the explain analyse will show you.
--
   Richard Huxton
   Archonet Ltd


From pgsql-performance-owner@postgresql.org  Fri Oct 14 13:06:21 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 212B0D90C4
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 14 Oct 2005 13:06:20 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 31142-04
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 14 Oct 2005 16:06:12 +0000 (GMT)
Received: from mgw-ext04.nokia.com (mgw-ext04.nokia.com [131.228.20.96])
	by svr1.postgresql.org (Postfix) with ESMTP id 4B793D834D
	for <pgsql-performance@postgresql.org>;
	Fri, 14 Oct 2005 13:06:11 -0300 (ADT)
Received: from esebh105.NOE.Nokia.com (esebh105.ntc.nokia.com
 [172.21.138.211])
	by mgw-ext04.nokia.com (Switch-3.1.7/Switch-3.1.7) with ESMTP id
	j9EG2wCD005415
	for <pgsql-performance@postgresql.org>; Fri, 14 Oct 2005 19:03:02 +0300
Received: from esebh102.NOE.Nokia.com ([172.21.138.183]) by
	esebh105.NOE.Nokia.com with Microsoft SMTPSVC(6.0.3790.1830);
	Fri, 14 Oct 2005 19:06:08 +0300
Received: from duebe101.NOE.Nokia.com ([172.25.112.32]) by
	esebh102.NOE.Nokia.com with Microsoft SMTPSVC(6.0.3790.1830);
	Fri, 14 Oct 2005 19:02:57 +0300
x-mimeole: Produced By Microsoft Exchange V6.5.7226.0
Content-class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Subject: Best way to get all different values in a column
Date: Fri, 14 Oct 2005 18:02:56 +0200
Message-ID: <EA23CCFEC4F57A4D92C5B163C6946F1986C9BB@duebe101.NOE.Nokia.com>
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
Thread-Topic: Best way to get all different values in a column
Thread-Index: AcXP4z5WRencJXtPRuqm8UklbyFheAA9FJZg
From: <ext-christian.roche@nokia.com>
To: <pgsql-performance@postgresql.org>
X-OriginalArrivalTime: 14 Oct 2005 16:02:57.0692 (UTC)
	FILETIME=[BE7725C0:01C5D0D8]
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.178 required=5 tests=[AWL=0.000, NO_REAL_NAME=0.178]
X-Spam-Level: 
X-Archive-Number: 200510/234
X-Sequence-Number: 15002

Ok, since my question got no answer on the general list, I'm reposting
it here since this list seems in fact better suited to it.
=20
Does anyone here know what  is  the most efficient way to  list all
different values of a given column with low cardinality ?  For instance
I have a table with columns DAY, NAME, ID, etc.  The table is updated
about each week with thousands of records with the same (current) date.
Now I would like to list all values for DAY, only if possible without
scanning all the table each time I submit the request.
=20
I can think of:
=20
Solution 1: SELECT DAY FROM TABLE GROUP BY DAY;
=20
Solution 2: SELECT DISTINCT DAY FROM TABLE;
=20
(BTW why do those two yield such different performances, the later being
seemingly *much* slower than the former  ?)
=20
Solution 3: Improve performance through an index scan by using DAY as
the first element of the PK,  (PRIMARY KEY (DAY, ID) ), although DAY has
a low cardinality ?
=20
Solution 4: Create a separate index on column DAY ?
=20
Solution 5: Use some kind of view / stored procedure that would be
precomputed when TABLE is updated or cached when called for the first
time ? Does something like that exist ?
=20
Solution 6: Store the values in a separate table, recreated each time
TABLE is updated.
=20
This looks to me as a very common problem. Is there an obvious / best /
standard solution there ? What would be the expected performance of the
different solutions above ? (I guess some are probably non-sense)
=20
Thank you all !
Christian
=20

From pgsql-performance-owner@postgresql.org  Fri Oct 14 13:53:10 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id C3ADFD8B81
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 14 Oct 2005 13:53:09 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 42551-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 14 Oct 2005 16:53:06 +0000 (GMT)
Received: from mail.envyfinancial.com (unknown [206.248.142.186])
	by svr1.postgresql.org (Postfix) with ESMTP id 83467D863C
	for <pgsql-performance@postgresql.org>;
	Fri, 14 Oct 2005 13:53:06 -0300 (ADT)
Received: from localhost (localhost.localdomain [127.0.0.1])
	by mail.envyfinancial.com (Postfix) with ESMTP id 48AC51CBF0;
	Fri, 14 Oct 2005 12:38:20 -0400 (EDT)
Received: from mail.envyfinancial.com ([127.0.0.1])
	by localhost (mark.mielke.cc [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 26745-07; Fri, 14 Oct 2005 12:38:20 -0400 (EDT)
Received: by mail.envyfinancial.com (Postfix, from userid 500)
	id F355E1CBF1; Fri, 14 Oct 2005 12:38:19 -0400 (EDT)
Date: Fri, 14 Oct 2005 12:38:19 -0400
From: mark@mark.mielke.cc
To: ext-christian.roche@nokia.com
Cc: pgsql-performance@postgresql.org
Subject: Re: Best way to get all different values in a column
Message-ID: <20051014163819.GA26955@mark.mielke.cc>
References: <EA23CCFEC4F57A4D92C5B163C6946F1986C9BB@duebe101.NOE.Nokia.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <EA23CCFEC4F57A4D92C5B163C6946F1986C9BB@duebe101.NOE.Nokia.com>
User-Agent: Mutt/1.4.2.1i
X-Virus-Scanned: amavisd-new at mail.envyfinancial.com
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.191 required=5 tests=[AWL=0.013, NO_REAL_NAME=0.178]
X-Spam-Level: 
X-Archive-Number: 200510/235
X-Sequence-Number: 15003

On Fri, Oct 14, 2005 at 06:02:56PM +0200, ext-christian.roche@nokia.com wrote:
> Does anyone here know what  is  the most efficient way to  list all
> different values of a given column with low cardinality ?  For instance
> I have a table with columns DAY, NAME, ID, etc.  The table is updated
> about each week with thousands of records with the same (current) date.
> Now I would like to list all values for DAY, only if possible without
> scanning all the table each time I submit the request.
> I can think of:
> ...
> Solution 6: Store the values in a separate table, recreated each time
> TABLE is updated.

I've found a variant on 6 to work well for this problem domain.

Why not insert into the separate table, when you insert into the table?
Either as a trigger, or in your application.

Cheers,
mark

-- 
mark@mielke.cc / markm@ncf.ca / markm@nortel.com     __________________________
.  .  _  ._  . .   .__    .  . ._. .__ .   . . .__  | Neighbourhood Coder
|\/| |_| |_| |/    |_     |\/|  |  |_  |   |/  |_   | 
|  | | | | \ | \   |__ .  |  | .|. |__ |__ | \ |__  | Ottawa, Ontario, Canada

  One ring to rule them all, one ring to find them, one ring to bring them all
                       and in the darkness bind them...

                           http://mark.mielke.cc/


From pgsql-performance-owner@postgresql.org  Fri Oct 14 14:10:48 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 77AAED9A05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 14 Oct 2005 14:07:17 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 43736-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 14 Oct 2005 17:07:14 +0000 (GMT)
Received: from gp.word-to-the-wise.com (gp.word-to-the-wise.com
 [64.71.176.18])
	by svr1.postgresql.org (Postfix) with ESMTP id 2015ED98C8
	for <pgsql-performance@postgresql.org>;
	Fri, 14 Oct 2005 14:07:13 -0300 (ADT)
Received: by gp.word-to-the-wise.com (Postfix, from userid 500)
	id DD4008FC08E; Fri, 14 Oct 2005 10:04:24 -0700 (PDT)
Date: Fri, 14 Oct 2005 10:04:24 -0700
From: Steve Atkins <steve@blighty.com>
To: pgsql-performance@postgresql.org
Subject: Re: Best way to get all different values in a column
Message-ID: <20051014170424.GA25578@gp.word-to-the-wise.com>
References: <EA23CCFEC4F57A4D92C5B163C6946F1986C9BB@duebe101.NOE.Nokia.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <EA23CCFEC4F57A4D92C5B163C6946F1986C9BB@duebe101.NOE.Nokia.com>
User-Agent: Mutt/1.4.1i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.891 required=5 tests=[AWL=-0.485,
	DNS_FROM_RFC_POST=1.376]
X-Spam-Level: 
X-Archive-Number: 200510/236
X-Sequence-Number: 15004

On Fri, Oct 14, 2005 at 06:02:56PM +0200, ext-christian.roche@nokia.com wrote:
> Ok, since my question got no answer on the general list, I'm reposting
> it here since this list seems in fact better suited to it.
>  
> Does anyone here know what  is  the most efficient way to  list all
> different values of a given column with low cardinality ?  For instance
> I have a table with columns DAY, NAME, ID, etc.  The table is updated
> about each week with thousands of records with the same (current) date.
> Now I would like to list all values for DAY, only if possible without
> scanning all the table each time I submit the request.
>  
> I can think of:
>  
> Solution 1: SELECT DAY FROM TABLE GROUP BY DAY;
>  
> Solution 2: SELECT DISTINCT DAY FROM TABLE;
>  
> (BTW why do those two yield such different performances, the later being
> seemingly *much* slower than the former  ?)
>  
> Solution 3: Improve performance through an index scan by using DAY as
> the first element of the PK,  (PRIMARY KEY (DAY, ID) ), although DAY has
> a low cardinality ?
>  
> Solution 4: Create a separate index on column DAY ?
>  
> Solution 5: Use some kind of view / stored procedure that would be
> precomputed when TABLE is updated or cached when called for the first
> time ? Does something like that exist ?
>  
> Solution 6: Store the values in a separate table, recreated each time
> TABLE is updated.
>  
> This looks to me as a very common problem. Is there an obvious / best /
> standard solution there ? What would be the expected performance of the
> different solutions above ? (I guess some are probably non-sense)
>  

There's not going to be a single "best" solution, as it'll depend on
your requirements, and on your application level constraints.

You say that the table is seldom updated (a few thousand a week is "almost
never"). If it's updated in a single batch you could simply generate
a table of the distinct values after each update pretty easily (solution
6).

If you don't have such a well-defined update then using a trigger on
inserts, updates and deletes of the table to update a separate table
to keep track of the counts of each distinct values, then you can
just select any row with a non-zero count from that table (solution 5).
(You need the counts to be able to deal with deletes efficiently). That
would increase the cost of updating the main table significantly, but
you're putting very little traffic through it, so that's unlikely to
be a problem.

I doubt that solutions 3 or 4 are worth looking at at all, and the first
two are what they are and you know their performance already.

You could probably do this far more efficiently with some of the work
being done in the application layer, rather than in the database - for
instance you could update the counts table one time per transaction,
rather than one time per operation - but that would lose you the
convenience of maintaining the counts correctly when you futz with
the data manually or using tools not aware of the count table.

Cheers,
  Steve

From pgsql-performance-owner@postgresql.org  Mon Oct 17 14:09:45 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id E3146D9F49
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 14 Oct 2005 19:33:33 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 30748-06
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 14 Oct 2005 22:33:30 +0000 (GMT)
Received: from moonunit2.moonview.localnet (wsip-68-15-5-150.sd.sd.cox.net
	[68.15.5.150])
	by svr1.postgresql.org (Postfix) with ESMTP id 7D585D9F02
	for <pgsql-performance@postgresql.org>;
	Fri, 14 Oct 2005 19:33:30 -0300 (ADT)
Received: from [192.168.0.3] (moonunit3.moonview.localnet [192.168.0.3])
	by moonunit2.moonview.localnet (8.13.1/8.13.1) with ESMTP id
	j9EMbodI009040
	for <pgsql-performance@postgresql.org>; Fri, 14 Oct 2005 15:37:50 -0700
Message-ID: <435031DF.4080306@modgraph-usa.com>
Date: Fri, 14 Oct 2005 15:31:59 -0700
From: "Craig A. James" <cjames@modgraph-usa.com>
User-Agent: Mozilla Thunderbird 1.0.6 (X11/20050716)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: pgsql-performance@postgresql.org
Subject: tsearch2/GIST performance factors?
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.05 required=5 tests=[FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/254
X-Sequence-Number: 15022

We are indexing about 5 million small documents using tsearch2/GIST.  Each "document" contains 2 to 50 words.  This is a "write once, read many" situation.  Write performance is unimportant, and the database contents are static.  (We build it offline.)

We're having problems with inconsistent performance, and it's very hard to separate the effects of various factors.  Here are the things we think may be relevant.

1. Total number of words

Our documents currently contain about 110,000 unique words.  Oleg wrote: "[The limit is] 100K, but it's very fuzzy limit." By trial and error, we've learned that 50,000 works well, and 150,000 works poorly, so Oleg's comment appears to be a good rule-of-thumb.  (With SIGLENINT enlarged, as mentioned above.)  But there may be other factors that affect this conclusion (such as shared memory, total memory, etc.).


2. Total size of the table

8 million documents is not a very big database (each document is a few to a few hundred bytes), so we don't think this is relevant.


3. Number of documents per word

There seems to be a VERY strong effect related to "common" words.  When a word occurs in more than about 1% of the documents (say 50,000 to 150,000 documents), performance goes WAY down.  Not just for that specific query, but it screws up tsearch2/GIST completely.

We have a test of 100 queries that return 382,000 documents total.  The first time we run it, it's slow, about 20 minutes (as expected).  The second time we run it, it's very fast, about 72 seconds -- very fast!!  As long as we avoid queries with common words, performance is very good.

But, if we run just one query that contains a common word (a word that's in more than about 2% of the documents, roughly 150,000 documents), then the next time we run the 100 test queries, it will take 20 minutes again.

We can't simply eliminate these common words.  First of all, they can be very significant.  Second, it doesn't seem like 2% is "common".  I can understand that a words like "the" which occur in most documents shouldn't be indexed.  But a word that occurs in 2% of the database seems like a very good word to index, yet it causes us great problems.

I've read a bit about tsearchd, and wonder if it would solve our problem.  For our application, consistent performance is VERY important.  If we could lock the GIST index into memory, I think it would fix our problem.

I tried copying the GIST indexes (which are in a separate tablespace) to a 1 GB RAM disk, and it made the initial query faster, but overall performance seemed worse, probably because the RAM disk was using memory that could have been used by the file-system cache.


4. Available RAM and Disk drives

Would more RAM help?  How would we tell Postgres to use it effectively?  The GIST indexes are currently about 2.6 GB on the disk.

Would more disks help?  I know they would make it faster -- the 20-minute initial query would be reduce with a RAID drive, etc.  But I'm not concerned about the 20-minute initial query, I'm concerned about keeping the system in that super-fast state where the GIST indexes are all in memory.


Hardware:
   Dual-CPU Xeon Dell server with 4 GB memory and a single SATA 7200 RPM 150GB disk.

tsearch2/gistidx.h
   modified as: #define SIGLENINT  120

System configuration:
   echo 2147483648 >/proc/sys/kernel/shmmax
   echo 4096      >/proc/sys/kernel/shmmni
   echo 2097152   >/proc/sys/kernel/shmall

Postgres Configuration:
   shared_buffers = 20000	
   work_mem = 32768
   effective_cache_size = 300000

Thanks very much for any comments and advice.

Craig



From pgsql-performance-owner@postgresql.org  Sat Oct 15 10:20:56 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 48EF7D9B85
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 15 Oct 2005 10:20:55 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 40608-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 15 Oct 2005 13:20:51 +0000 (GMT)
Received: from fmf.vtu.lt (fmf.vtu.lt [193.219.145.206])
	by svr1.postgresql.org (Postfix) with ESMTP id A15D0D9B53
	for <pgsql-performance@postgresql.org>;
	Sat, 15 Oct 2005 10:20:53 -0300 (ADT)
Received: from fmf.vtu.lt (localhost [127.0.0.1])
	by fmf.vtu.lt (Postfix) with ESMTP id 6C18718474
	for <pgsql-performance@postgresql.org>;
	Sat, 15 Oct 2005 16:20:54 +0300 (EEST)
Received: from 81.7.89.65 (SquirrelMail authenticated user nso)
	by fmf.vtu.lt with HTTP; Sat, 15 Oct 2005 16:20:54 +0300 (EEST)
Message-ID: <17260.81.7.89.65.1129382454.squirrel@fmf.vtu.lt>
Date: Sat, 15 Oct 2005 16:20:54 +0300 (EEST)
Subject: Bytea poor performance
From: "NSO" <nso@fmf.vtu.lt>
To: pgsql-performance@postgresql.org
User-Agent: SquirrelMail/1.4.5
MIME-Version: 1.0
Content-Type: text/plain;charset=utf-8
Content-Transfer-Encoding: 8bit
X-Priority: 3 (Normal)
Importance: Normal
X-VGTU-MailScanner-OpenProtect-Information: Please contact the ISP for more
	information
X-VGTU-MailScanner-OpenProtect: Found to be clean
X-MailScanner-OpenProtect-MCPCheck: 
X-MailScanner-OpenProtect-From: nso@fmf.vtu.lt
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.262 required=5 tests=[AWL=-0.112,
	DNS_FROM_RFC_ABUSE=0.374]
X-Spam-Level: 
X-Archive-Number: 200510/238
X-Sequence-Number: 15006

Hello,

 I am trying to select form table with bytea field. And queries runs very
slow.
My table:
CREATE TABLE files (file bytea, nr serial NOT NULL) WITH OIDS;

Query:
select * from files where nr > 1450

(I have total 1500 records in it, every holds picture of 23kB size)
Query runs very long:
Total query runtime: 23625 ms.
Data retrieval runtime: 266 ms.
50 rows retrieved.

explain:
Index Scan using pk on files  (cost=0.00..3.67 rows=50 width=36)
Index Cond: (nr > 1450)

 Is it possible to do something with it? or it is normal? Our server is
fast, and all other tables work fine..



-- 
This message has been scanned for viruses and
dangerous content, and is believed to be clean.


From pgsql-performance-owner@postgresql.org  Sat Oct 15 10:40:29 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 917A5D9B13
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 15 Oct 2005 10:40:28 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 43416-03
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 15 Oct 2005 13:40:24 +0000 (GMT)
Received: from wimpy.net.nih.gov (mailfwd.nih.gov [128.231.88.106])
	by svr1.postgresql.org (Postfix) with ESMTP id E37F8D9A99
	for <pgsql-performance@postgresql.org>;
	Sat, 15 Oct 2005 10:40:26 -0300 (ADT)
Received: from wimpy.net.nih.gov (localhost [127.0.0.1])
	by wimpy.net.nih.gov (8.12.11/8.11.7) with ESMTP id j9FDeTdq023557
	for <pgsql-performance@postgresql.org>;
	Sat, 15 Oct 2005 09:40:30 -0400 (EDT)
Received: from [128.231.145.14] (holmes.nhgri.nih.gov [128.231.145.14])
	by wimpy.net.nih.gov (8.12.11/8.11.7) with ESMTP id j9FDeS8g023552;
	Sat, 15 Oct 2005 09:40:29 -0400 (EDT)
User-Agent: Microsoft-Entourage/10.1.4.030702.0
Date: Sat, 15 Oct 2005 09:40:28 -0400
Subject: Re: Bytea poor performance
From: Sean Davis <sdavis2@mail.nih.gov>
To: NSO <nso@fmf.vtu.lt>, <pgsql-performance@postgresql.org>
Message-ID: <BF767F0C.10CEA%sdavis2@mail.nih.gov>
In-Reply-To: <17260.81.7.89.65.1129382454.squirrel@fmf.vtu.lt>
Mime-version: 1.0
Content-type: text/plain; charset="US-ASCII"
Content-transfer-encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.013 required=5 tests=[AWL=0.013]
X-Spam-Level: 
X-Archive-Number: 200510/239
X-Sequence-Number: 15007

On 10/15/05 9:20 AM, "NSO" <nso@fmf.vtu.lt> wrote:

> Hello,
> 
> I am trying to select form table with bytea field. And queries runs very
> slow.
> My table:
> CREATE TABLE files (file bytea, nr serial NOT NULL) WITH OIDS;
> 
> Query:
> select * from files where nr > 1450
> 
> (I have total 1500 records in it, every holds picture of 23kB size)
> Query runs very long:
> Total query runtime: 23625 ms.
> Data retrieval runtime: 266 ms.
> 50 rows retrieved.
> 
> explain:
> Index Scan using pk on files  (cost=0.00..3.67 rows=50 width=36)
> Index Cond: (nr > 1450)
> 
> Is it possible to do something with it? or it is normal? Our server is
> fast, and all other tables work fine..

How about some explain analyze output?  Have you done a full vacuum lately?
How about reindexing?

Sean


From pgsql-performance-owner@postgresql.org  Sat Oct 15 11:00:09 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 1FC97DA240
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 15 Oct 2005 11:00:09 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 43802-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 15 Oct 2005 14:00:05 +0000 (GMT)
Received: from fmf.vtu.lt (fmf.vtu.lt [193.219.145.206])
	by svr1.postgresql.org (Postfix) with ESMTP id 7528AD9A99
	for <pgsql-performance@postgresql.org>;
	Sat, 15 Oct 2005 11:00:07 -0300 (ADT)
Received: from fmf.vtu.lt (localhost [127.0.0.1])
	by fmf.vtu.lt (Postfix) with ESMTP id 359DC18473;
	Sat, 15 Oct 2005 17:00:09 +0300 (EEST)
Received: from 81.7.89.65 (SquirrelMail authenticated user nso)
	by fmf.vtu.lt with HTTP; Sat, 15 Oct 2005 17:00:09 +0300 (EEST)
Message-ID: <17363.81.7.89.65.1129384809.squirrel@fmf.vtu.lt>
In-Reply-To: <BF767F0C.10CEA%sdavis2@mail.nih.gov>
References: <17260.81.7.89.65.1129382454.squirrel@fmf.vtu.lt>
	<BF767F0C.10CEA%sdavis2@mail.nih.gov>
Date: Sat, 15 Oct 2005 17:00:09 +0300 (EEST)
Subject: Re: Bytea poor performance
From: "NSO" <nso@fmf.vtu.lt>
To: "Sean Davis" <sdavis2@mail.nih.gov>
Cc: pgsql-performance@postgresql.org
User-Agent: SquirrelMail/1.4.5
MIME-Version: 1.0
Content-Type: text/plain;charset=utf-8
Content-Transfer-Encoding: 8bit
X-Priority: 3 (Normal)
Importance: Normal
X-VGTU-MailScanner-OpenProtect-Information: Please contact the ISP for more
	information
X-VGTU-MailScanner-OpenProtect: Found to be clean
X-MailScanner-OpenProtect-MCPCheck: 
X-MailScanner-OpenProtect-From: nso@fmf.vtu.lt
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.267 required=5 tests=[AWL=-0.107,
	DNS_FROM_RFC_ABUSE=0.374]
X-Spam-Level: 
X-Archive-Number: 200510/240
X-Sequence-Number: 15008

Hello,

How about some explain analyze output?
  Explain analyse select * from files where nr > 1450

  "Index Scan using pk on files  (cost=0.00..3.67 rows=50 width=36)
  (actual time=0.000..0.000 rows=50 loops=1)"

Have you done a full vacuum lately? How about reindexing?
  Yes, I did reindexing and vacuum full just before query..




> On 10/15/05 9:20 AM, "NSO" <nso@fmf.vtu.lt> wrote:
>
>> Hello,
>>
>> I am trying to select form table with bytea field. And queries runs very
>> slow.
>> My table:
>> CREATE TABLE files (file bytea, nr serial NOT NULL) WITH OIDS;
>>
>> Query:
>> select * from files where nr > 1450
>>
>> (I have total 1500 records in it, every holds picture of 23kB size)
>> Query runs very long:
>> Total query runtime: 23625 ms.
>> Data retrieval runtime: 266 ms.
>> 50 rows retrieved.
>>
>> explain:
>> Index Scan using pk on files  (cost=0.00..3.67 rows=50 width=36)
>> Index Cond: (nr > 1450)
>>
>> Is it possible to do something with it? or it is normal? Our server is
>> fast, and all other tables work fine..
>
> How about some explain analyze output?  Have you done a full vacuum
> lately?
> How about reindexing?
>
> Sean
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: explain analyze is your friend
>
> --
> This message has been scanned for viruses and
> dangerous content, and is believed to be clean.
>
>



-- 
This message has been scanned for viruses and
dangerous content, and is believed to be clean.


From pgsql-performance-owner@postgresql.org  Sat Oct 15 11:09:24 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 46E21DA240
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 15 Oct 2005 11:08:23 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 51564-04
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 15 Oct 2005 14:08:15 +0000 (GMT)
Received: from wimpy.net.nih.gov (mailfwd.nih.gov [128.231.88.106])
	by svr1.postgresql.org (Postfix) with ESMTP id 9F42EDA096
	for <pgsql-performance@postgresql.org>;
	Sat, 15 Oct 2005 11:08:17 -0300 (ADT)
Received: from wimpy.net.nih.gov (localhost [127.0.0.1])
	by wimpy.net.nih.gov (8.12.11/8.11.7) with ESMTP id j9FE8LKM001426
	for <pgsql-performance@postgresql.org>;
	Sat, 15 Oct 2005 10:08:21 -0400 (EDT)
Received: from [128.231.145.14] (holmes.nhgri.nih.gov [128.231.145.14])
	by wimpy.net.nih.gov (8.12.11/8.11.7) with ESMTP id j9FE8Kdq001423;
	Sat, 15 Oct 2005 10:08:20 -0400 (EDT)
User-Agent: Microsoft-Entourage/10.1.4.030702.0
Date: Sat, 15 Oct 2005 10:08:20 -0400
Subject: Re: Bytea poor performance
From: Sean Davis <sdavis2@mail.nih.gov>
To: NSO <nso@fmf.vtu.lt>
Cc: <pgsql-performance@postgresql.org>
Message-ID: <BF768594.10D2B%sdavis2@mail.nih.gov>
In-Reply-To: <17363.81.7.89.65.1129384809.squirrel@fmf.vtu.lt>
Mime-version: 1.0
Content-type: text/plain; charset="US-ASCII"
Content-transfer-encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.013 required=5 tests=[AWL=0.013]
X-Spam-Level: 
X-Archive-Number: 200510/241
X-Sequence-Number: 15009

On 10/15/05 10:00 AM, "NSO" <nso@fmf.vtu.lt> wrote:

> Hello,
> 
> How about some explain analyze output?
> Explain analyse select * from files where nr > 1450
> 
> "Index Scan using pk on files  (cost=0.00..3.67 rows=50 width=36)
> (actual time=0.000..0.000 rows=50 loops=1)"

I may not be understanding the output, but your actual time reports 0 for
the query.  And the total runtime is 23 seconds?

Sean


>> On 10/15/05 9:20 AM, "NSO" <nso@fmf.vtu.lt> wrote:
>> 
>>> Hello,
>>> 
>>> I am trying to select form table with bytea field. And queries runs very
>>> slow.
>>> My table:
>>> CREATE TABLE files (file bytea, nr serial NOT NULL) WITH OIDS;
>>> 
>>> Query:
>>> select * from files where nr > 1450
>>> 
>>> (I have total 1500 records in it, every holds picture of 23kB size)
>>> Query runs very long:
>>> Total query runtime: 23625 ms.
>>> Data retrieval runtime: 266 ms.
>>> 50 rows retrieved.
>>> 
>>> explain:
>>> Index Scan using pk on files  (cost=0.00..3.67 rows=50 width=36)
>>> Index Cond: (nr > 1450)
>>> 
>>> Is it possible to do something with it? or it is normal? Our server is
>>> fast, and all other tables work fine..
>> 
>> How about some explain analyze output?  Have you done a full vacuum
>> lately?
>> How about reindexing?
>> 
>> Sean
>> 
>> 
>> ---------------------------(end of broadcast)---------------------------
>> TIP 6: explain analyze is your friend
>> 
>> --
>> This message has been scanned for viruses and
>> dangerous content, and is believed to be clean.
>> 
>> 
> 
> 


From pgsql-performance-owner@postgresql.org  Mon Oct 17 14:09:43 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 0B4BAD9B13
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 15 Oct 2005 11:48:41 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 79845-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 15 Oct 2005 14:48:36 +0000 (GMT)
Received: from moonunit2.moonview.localnet (wsip-68-15-5-150.sd.sd.cox.net
	[68.15.5.150])
	by svr1.postgresql.org (Postfix) with ESMTP id 1E188D9A99
	for <pgsql-performance@postgresql.org>;
	Sat, 15 Oct 2005 11:48:38 -0300 (ADT)
Received: from [192.168.0.3] (moonunit3.moonview.localnet [192.168.0.3])
	by moonunit2.moonview.localnet (8.13.1/8.13.1) with ESMTP id
	j9FEr6AB016197
	for <pgsql-performance@postgresql.org>; Sat, 15 Oct 2005 07:53:06 -0700
Message-ID: <4351166C.9010102@modgraph-usa.com>
Date: Sat, 15 Oct 2005 07:47:08 -0700
From: "Craig A. James" <cjames@modgraph-usa.com>
User-Agent: Mozilla Thunderbird 1.0.6 (X11/20050716)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: pgsql-performance@postgresql.org
Subject: tsearch2/GIST performance factors?
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.05 required=5 tests=[AWL=-0.000,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/253
X-Sequence-Number: 15021

We are indexing about 5 million small documents using tsearch2/GIST.  Each "document" contains 2 to 50 words.  This is a "write once, read many" situation.  Write performance is unimportant, and the database contents are static.  (We build it offline.)

We're having problems with inconsistent performance, and it's very hard to separate the effects of various factors.  Here are the things we think may be relevant.

1. Total number of words

Our documents currently contain about 110,000 unique words.  Oleg wrote: "[The limit is] 100K, but it's very fuzzy limit." By trial and error, we've learned that 50,000 works well, and 150,000 works poorly, so Oleg's comment appears to be a good rule-of-thumb.  (With SIGLENINT enlarged, see below.)  But there may be other factors that affect this conclusion (such as shared memory, total memory, etc.).


2. Total size of the table

5 million documents is not a very big database (each document is a few to a few hundred bytes), so we don't think this is relevant.


3. Number of documents per word

There seems to be a VERY strong effect related to "common" words.  When a word occurs in more than about 1% of the documents (say 50,000 to 150,000 documents), performance goes WAY down.  Not just for that specific query, but it screws up tsearch2/GIST completely.

We have a test of 100 queries that return 382,000 documents total.  The first time we run it, it's slow, about 20 minutes (as expected).  The second time we run it, it's very fast, about 72 seconds -- very fast!!  As long as we avoid queries with common words, performance is very good.

But, if we run just one query that contains a common word (a word that's in more than about 2% of the documents, roughly 150,000 documents), then the next time we run the 100 test queries, it will take 20 minutes again.

We can't simply eliminate these common words.  First of all, they can be very significant.  Second, it doesn't seem like 2% is "common".  I can understand that a words like "the" which occur in most documents shouldn't be indexed.  But a word that occurs in 2% of the database seems like a very good word to index, yet it causes us great problems.

I've read a bit about tsearchd, and wonder if it would solve our problem.  For our application, consistent performance is VERY important.  If we could lock the GIST index into memory, I think it would fix our problem.

I tried copying the GIST indexes (which are in a separate tablespace) to a 1 GB RAM disk, and it made the initial query faster, but overall performance seemed worse, probably because the RAM disk was using memory that could have been used by the file-system cache.


4. Available RAM and Disk drives

Would more RAM help?  How would we tell Postgres to use it effectively?  The GIST indexes are currently about 2.6 GB on the disk.

Would more disks help?  I know they would make it faster -- the 20-minute initial query would be reduce with a RAID drive, etc.  But I'm not concerned about the 20-minute initial query, I'm concerned about keeping the system in that super-fast state where the GIST indexes are all in memory.


Hardware:
 Dual-CPU Xeon Dell server with 4 GB memory and a single SATA 7200 RPM 150GB disk.

tsearch2/gistidx.h
 modified as: #define SIGLENINT  120

System configuration:
 echo 2147483648 >/proc/sys/kernel/shmmax
 echo 4096      >/proc/sys/kernel/shmmni
 echo 2097152   >/proc/sys/kernel/shmall

Postgres Configuration:
 shared_buffers = 20000	
 work_mem = 32768
 effective_cache_size = 300000

I feel like I'm shooting in the dark -- Linux, Postgres and tsearch2/GIST are interacting in ways that I can't predict or analyze.  Thanks very much for any comments and advice.

Craig





From pgsql-performance-owner@postgresql.org  Sat Oct 15 11:48:58 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 83160D9B9E
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 15 Oct 2005 11:48:57 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 82518-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 15 Oct 2005 14:48:51 +0000 (GMT)
Received: from fmf.vtu.lt (fmf.vtu.lt [193.219.145.206])
	by svr1.postgresql.org (Postfix) with ESMTP id 106DDD9B85
	for <pgsql-performance@postgresql.org>;
	Sat, 15 Oct 2005 11:48:54 -0300 (ADT)
Received: from fmf.vtu.lt (localhost [127.0.0.1])
	by fmf.vtu.lt (Postfix) with ESMTP id 2F51818473;
	Sat, 15 Oct 2005 17:48:54 +0300 (EEST)
Received: from 81.7.89.65 (SquirrelMail authenticated user nso)
	by fmf.vtu.lt with HTTP; Sat, 15 Oct 2005 17:48:54 +0300 (EEST)
Message-ID: <17532.81.7.89.65.1129387734.squirrel@fmf.vtu.lt>
In-Reply-To: <BF768594.10D2B%sdavis2@mail.nih.gov>
References: <17363.81.7.89.65.1129384809.squirrel@fmf.vtu.lt>
	<BF768594.10D2B%sdavis2@mail.nih.gov>
Date: Sat, 15 Oct 2005 17:48:54 +0300 (EEST)
Subject: Re: Bytea poor performance
From: "NSO" <nso@fmf.vtu.lt>
To: "Sean Davis" <sdavis2@mail.nih.gov>
Cc: pgsql-performance@postgresql.org
User-Agent: SquirrelMail/1.4.5
MIME-Version: 1.0
Content-Type: text/plain;charset=utf-8
Content-Transfer-Encoding: 8bit
X-Priority: 3 (Normal)
Importance: Normal
X-VGTU-MailScanner-OpenProtect-Information: Please contact the ISP for more
	information
X-VGTU-MailScanner-OpenProtect: Found to be clean
X-MailScanner-OpenProtect-MCPCheck: 
X-MailScanner-OpenProtect-From: nso@fmf.vtu.lt
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.27 required=5 tests=[AWL=-0.104,
	DNS_FROM_RFC_ABUSE=0.374]
X-Spam-Level: 
X-Archive-Number: 200510/242
X-Sequence-Number: 15010


  Yes, it takes even up to 35 seconds.. I did the same query on the server
(not PC with was connected directly to server with 100mbit net), and /I
got better result it is 3.5 - 4 seconds, but it still not good.. Why it
is slow? and why the difference is so big? I mean from 4 to 35 seconds?

thx

> On 10/15/05 10:00 AM, "NSO" <nso@fmf.vtu.lt> wrote:
>
>> Hello,
>>
>> How about some explain analyze output?
>> Explain analyse select * from files where nr > 1450
>>
>> "Index Scan using pk on files  (cost=0.00..3.67 rows=50 width=36)
>> (actual time=0.000..0.000 rows=50 loops=1)"
>
> I may not be understanding the output, but your actual time reports 0 for
> the query.  And the total runtime is 23 seconds?
>
> Sean
>
>
>>> On 10/15/05 9:20 AM, "NSO" <nso@fmf.vtu.lt> wrote:
>>>
>>>> Hello,
>>>>
>>>> I am trying to select form table with bytea field. And queries runs
>>>> very
>>>> slow.
>>>> My table:
>>>> CREATE TABLE files (file bytea, nr serial NOT NULL) WITH OIDS;
>>>>
>>>> Query:
>>>> select * from files where nr > 1450
>>>>
>>>> (I have total 1500 records in it, every holds picture of 23kB size)
>>>> Query runs very long:
>>>> Total query runtime: 23625 ms.
>>>> Data retrieval runtime: 266 ms.
>>>> 50 rows retrieved.
>>>>
>>>> explain:
>>>> Index Scan using pk on files  (cost=0.00..3.67 rows=50 width=36)
>>>> Index Cond: (nr > 1450)
>>>>
>>>> Is it possible to do something with it? or it is normal? Our server is
>>>> fast, and all other tables work fine..
>>>
>>> How about some explain analyze output?  Have you done a full vacuum
>>> lately?
>>> How about reindexing?
>>>
>>> Sean
>>>
>>>
>>> ---------------------------(end of
>>> broadcast)---------------------------
>>> TIP 6: explain analyze is your friend
>>>
>>> --
>>> This message has been scanned for viruses and
>>> dangerous content, and is believed to be clean.
>>>
>>>
>>
>>
>
>
> --
> This message has been scanned for viruses and
> dangerous content, and is believed to be clean.
>
>



-- 
This message has been scanned for viruses and
dangerous content, and is believed to be clean.


From pgsql-performance-owner@postgresql.org  Sat Oct 15 12:54:25 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 3F31FD9C65
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 15 Oct 2005 12:54:24 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 91528-09
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 15 Oct 2005 15:54:21 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id A1187D8E7C
	for <pgsql-performance@postgresql.org>;
	Sat, 15 Oct 2005 12:54:21 -0300 (ADT)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j9FFs8BC029779;
	Sat, 15 Oct 2005 11:54:08 -0400 (EDT)
To: "NSO" <nso@fmf.vtu.lt>
Cc: pgsql-performance@postgresql.org
Subject: Re: Bytea poor performance 
In-reply-to: <17260.81.7.89.65.1129382454.squirrel@fmf.vtu.lt> 
References: <17260.81.7.89.65.1129382454.squirrel@fmf.vtu.lt>
Comments: In-reply-to "NSO" <nso@fmf.vtu.lt>
	message dated "Sat, 15 Oct 2005 16:20:54 +0300"
Date: Sat, 15 Oct 2005 11:54:07 -0400
Message-ID: <29778.1129391647@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/243
X-Sequence-Number: 15011

"NSO" <nso@fmf.vtu.lt> writes:
> Query runs very long:
> Total query runtime: 23625 ms.
> Data retrieval runtime: 266 ms.
> 50 rows retrieved.

Notice that the query itself took 266ms.  The rest of the time was
wasted by your client app trying to format a 23Kb by 50 row table
for display.  You need to replace your client-side code with something
less inefficient about handling wide values.

			regards, tom lane

From pgsql-performance-owner@postgresql.org  Sat Oct 15 13:16:39 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id AEEF7D857F
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 15 Oct 2005 13:16:38 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 05408-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 15 Oct 2005 16:16:33 +0000 (GMT)
Received: from fmf.vtu.lt (fmf.vtu.lt [193.219.145.206])
	by svr1.postgresql.org (Postfix) with ESMTP id EC2FFD80DD
	for <pgsql-performance@postgresql.org>;
	Sat, 15 Oct 2005 13:16:32 -0300 (ADT)
Received: from fmf.vtu.lt (localhost [127.0.0.1])
	by fmf.vtu.lt (Postfix) with ESMTP id 213B418473;
	Sat, 15 Oct 2005 19:16:30 +0300 (EEST)
Received: from 81.7.89.65 (SquirrelMail authenticated user nso)
	by fmf.vtu.lt with HTTP; Sat, 15 Oct 2005 19:16:30 +0300 (EEST)
Message-ID: <18133.81.7.89.65.1129392990.squirrel@fmf.vtu.lt>
In-Reply-To: <29778.1129391647@sss.pgh.pa.us>
References: <17260.81.7.89.65.1129382454.squirrel@fmf.vtu.lt>
	<29778.1129391647@sss.pgh.pa.us>
Date: Sat, 15 Oct 2005 19:16:30 +0300 (EEST)
Subject: Re: Bytea poor performance
From: "NSO" <nso@fmf.vtu.lt>
To: "Tom Lane" <tgl@sss.pgh.pa.us>
Cc: pgsql-performance@postgresql.org
User-Agent: SquirrelMail/1.4.5
MIME-Version: 1.0
Content-Type: text/plain;charset=utf-8
Content-Transfer-Encoding: 8bit
X-Priority: 3 (Normal)
Importance: Normal
X-VGTU-MailScanner-OpenProtect-Information: Please contact the ISP for more
	information
X-VGTU-MailScanner-OpenProtect: Found to be clean
X-MailScanner-OpenProtect-MCPCheck: 
X-MailScanner-OpenProtect-From: nso@fmf.vtu.lt
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.272 required=5 tests=[AWL=-0.102,
	DNS_FROM_RFC_ABUSE=0.374]
X-Spam-Level: 
X-Archive-Number: 200510/244
X-Sequence-Number: 15012

Hello,

 Yes, I can understand that, but then why the same app on the server
machine is done in 4 seconds? (big difference from 20-30 seconds). I
tryed to monitor network traffic and it is used only for 1-2% of total
100mbit.


> "NSO" <nso@fmf.vtu.lt> writes:
>> Query runs very long:
>> Total query runtime: 23625 ms.
>> Data retrieval runtime: 266 ms.
>> 50 rows retrieved.
>
> Notice that the query itself took 266ms.  The rest of the time was
> wasted by your client app trying to format a 23Kb by 50 row table
> for display.  You need to replace your client-side code with something
> less inefficient about handling wide values.
>
> 			regards, tom lane
>
> --
> This message has been scanned for viruses and
> dangerous content, and is believed to be clean.
>
>



-- 
This message has been scanned for viruses and
dangerous content, and is believed to be clean.


From pgsql-performance-owner@postgresql.org  Sat Oct 15 13:24:27 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 4CCB2D9E36
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 15 Oct 2005 13:24:27 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 07058-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 15 Oct 2005 16:24:25 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id 6202BD954A
	for <pgsql-performance@postgresql.org>;
	Sat, 15 Oct 2005 13:24:25 -0300 (ADT)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j9FGOOmI000137;
	Sat, 15 Oct 2005 12:24:24 -0400 (EDT)
To: "NSO" <nso@fmf.vtu.lt>
Cc: pgsql-performance@postgresql.org
Subject: Re: Bytea poor performance 
In-reply-to: <18133.81.7.89.65.1129392990.squirrel@fmf.vtu.lt> 
References: <17260.81.7.89.65.1129382454.squirrel@fmf.vtu.lt>
	<29778.1129391647@sss.pgh.pa.us>
	<18133.81.7.89.65.1129392990.squirrel@fmf.vtu.lt>
Comments: In-reply-to "NSO" <nso@fmf.vtu.lt>
	message dated "Sat, 15 Oct 2005 19:16:30 +0300"
Date: Sat, 15 Oct 2005 12:24:24 -0400
Message-ID: <136.1129393464@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/245
X-Sequence-Number: 15013

"NSO" <nso@fmf.vtu.lt> writes:
>  Yes, I can understand that, but then why the same app on the server
> machine is done in 4 seconds? (big difference from 20-30 seconds).

That would suggest a networking problem, which is a bit outside my
expertise.  If the client machine is running Windows, we have seen
problems of that sort before from (IIRC) various third-party add-ons
that fool around with networking behavior.  Try searching the archives.

			regards, tom lane

From pgsql-performance-owner@postgresql.org  Sun Oct 16 01:53:20 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 6EC27DA2AC
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 16 Oct 2005 01:53:19 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 37770-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 16 Oct 2005 04:53:15 +0000 (GMT)
Received: from linda-4.paradise.net.nz (bm-4a.paradise.net.nz
 [203.96.152.183])
	by svr1.postgresql.org (Postfix) with ESMTP id 550F3D8E8E
	for <pgsql-performance@postgresql.org>;
	Sun, 16 Oct 2005 01:53:15 -0300 (ADT)
Received: from smtp-3.paradise.net.nz ([203.96.152.177])
	by linda-4.paradise.net.nz (Paradise.net.nz)
	with ESMTP id <0IOF00A68S8QIZ@linda-4.paradise.net.nz> for
	pgsql-performance@postgresql.org; Sun, 16 Oct 2005 17:53:14 +1300 (NZDT)
Received: from [192.168.1.11] (218-101-13-49.paradise.net.nz [218.101.13.49])
	by smtp-3.paradise.net.nz (Postfix) with ESMTP id D595F13BB192; Sun,
	16 Oct 2005 17:53:13 +1300 (NZDT)
Date: Sun, 16 Oct 2005 17:53:10 +1300
From: Mark Kirkwood <markir@paradise.net.nz>
Subject: Re: Bytea poor performance
In-reply-to: <18133.81.7.89.65.1129392990.squirrel@fmf.vtu.lt>
To: NSO <nso@fmf.vtu.lt>
Cc: pgsql-performance@postgresql.org
Message-id: <4351DCB6.3040307@paradise.net.nz>
MIME-version: 1.0
Content-type: text/plain; format=flowed; charset=UTF-8
Content-transfer-encoding: 7bit
X-Accept-Language: en-us, en
User-Agent: Mozilla Thunderbird 1.0.6 (X11/20050726)
References: <17260.81.7.89.65.1129382454.squirrel@fmf.vtu.lt>
	<29778.1129391647@sss.pgh.pa.us>
	<18133.81.7.89.65.1129392990.squirrel@fmf.vtu.lt>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.124 required=5 tests=[AWL=0.124]
X-Spam-Level: 
X-Archive-Number: 200510/246
X-Sequence-Number: 15014

NSO wrote:
> Hello,
> 
>  Yes, I can understand that, but then why the same app on the server
> machine is done in 4 seconds? (big difference from 20-30 seconds). I
> tryed to monitor network traffic and it is used only for 1-2% of total
> 100mbit.
>  

Is this a web app? If so, then check you are using the same browser 
settings on the server and client (or the same browser for that matter).

Note that some browsers really suck for large (wide or long) table display!

cheers

Mark


From pgsql-performance-owner@postgresql.org  Sun Oct 16 08:01:52 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id C1005DA440
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 16 Oct 2005 08:01:51 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 31893-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 16 Oct 2005 11:01:45 +0000 (GMT)
Received: from fmf.vtu.lt (fmf.vtu.lt [193.219.145.206])
	by svr1.postgresql.org (Postfix) with ESMTP id 93B1FDA43E
	for <pgsql-performance@postgresql.org>;
	Sun, 16 Oct 2005 08:01:46 -0300 (ADT)
Received: from fmf.vtu.lt (localhost [127.0.0.1])
	by fmf.vtu.lt (Postfix) with ESMTP id 852A018473;
	Sun, 16 Oct 2005 14:01:46 +0300 (EEST)
Received: from 81.7.89.65 (SquirrelMail authenticated user nso)
	by fmf.vtu.lt with HTTP; Sun, 16 Oct 2005 14:01:46 +0300 (EEST)
Message-ID: <23627.81.7.89.65.1129460506.squirrel@fmf.vtu.lt>
In-Reply-To: <4351DCB6.3040307@paradise.net.nz>
References: <17260.81.7.89.65.1129382454.squirrel@fmf.vtu.lt>
	<29778.1129391647@sss.pgh.pa.us>
	<18133.81.7.89.65.1129392990.squirrel@fmf.vtu.lt>
	<4351DCB6.3040307@paradise.net.nz>
Date: Sun, 16 Oct 2005 14:01:46 +0300 (EEST)
Subject: Re: Bytea poor performance
From: "NSO" <nso@fmf.vtu.lt>
To: "Mark Kirkwood" <markir@paradise.net.nz>
Cc: pgsql-performance@postgresql.org
User-Agent: SquirrelMail/1.4.5
MIME-Version: 1.0
Content-Type: text/plain;charset=utf-8
Content-Transfer-Encoding: 8bit
X-Priority: 3 (Normal)
Importance: Normal
X-VGTU-MailScanner-OpenProtect-Information: Please contact the ISP for more
	information
X-VGTU-MailScanner-OpenProtect: Found to be clean
X-MailScanner-OpenProtect-MCPCheck: 
X-MailScanner-OpenProtect-From: nso@fmf.vtu.lt
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.273 required=5 tests=[AWL=-0.101,
	DNS_FROM_RFC_ABUSE=0.374]
X-Spam-Level: 
X-Archive-Number: 200510/247
X-Sequence-Number: 15015

Hello,

 No it is not web app, I tested on simple delphi app and with PGAdmin
III.. same results.. Query from PGAdmin takes up to 30seconds...

> NSO wrote:
>> Hello,
>>
>>  Yes, I can understand that, but then why the same app on the server
>> machine is done in 4 seconds? (big difference from 20-30 seconds). I
>> tryed to monitor network traffic and it is used only for 1-2% of total
>> 100mbit.
>>
>
> Is this a web app? If so, then check you are using the same browser
> settings on the server and client (or the same browser for that matter).
>
> Note that some browsers really suck for large (wide or long) table
> display!
>
> cheers
>
> Mark
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
>                http://www.postgresql.org/docs/faq
>
> --
> This message has been scanned for viruses and
> dangerous content, and is believed to be clean.
>
>



-- 
This message has been scanned for viruses and
dangerous content, and is believed to be clean.


From pgsql-performance-owner@postgresql.org  Sun Oct 16 18:12:46 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 24FF3DA254
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 16 Oct 2005 18:12:45 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 60028-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 16 Oct 2005 21:12:41 +0000 (GMT)
Received: from moutng.kundenserver.de (moutng.kundenserver.de
	[212.227.126.177])
	by svr1.postgresql.org (Postfix) with ESMTP id CB237D7057
	for <pgsql-performance@postgresql.org>;
	Sun, 16 Oct 2005 18:12:42 -0300 (ADT)
Received: from p548F1258.dip0.t-ipconnect.de [84.143.18.88]
	(helo=pse.dyndns.org)
	by mrelayeu.kundenserver.de with ESMTP (Nemesis),
	id 0ML25U-1ERFo32zCj-0000Og; Sun, 16 Oct 2005 23:12:35 +0200
Received: from p548f1258.dip0.t-ipconnect.de ([84.143.18.88]
	helo=[192.168.0.101])
	by pse.dyndns.org with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.44)
	id 1ERFo2-0007lU-7w; Sun, 16 Oct 2005 23:12:34 +0200
Message-ID: <4352C113.80104@pse-consulting.de>
Date: Sun, 16 Oct 2005 23:07:31 +0200
From: Andreas Pflug <pgadmin@pse-consulting.de>
User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: NSO <nso@fmf.vtu.lt>
Cc: Mark Kirkwood <markir@paradise.net.nz>,
	pgsql-performance@postgresql.org
Subject: Re: Bytea poor performance
References: <17260.81.7.89.65.1129382454.squirrel@fmf.vtu.lt>
	<29778.1129391647@sss.pgh.pa.us>
	<18133.81.7.89.65.1129392990.squirrel@fmf.vtu.lt>
	<4351DCB6.3040307@paradise.net.nz>
	<23627.81.7.89.65.1129460506.squirrel@fmf.vtu.lt>
In-Reply-To: <23627.81.7.89.65.1129460506.squirrel@fmf.vtu.lt>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Provags-ID: kundenserver.de abuse@kundenserver.de
	login:0ce7ee5c3478b8d72edd8e05ccd40b70
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.163 required=5 tests=[AWL=0.113,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/248
X-Sequence-Number: 15016

NSO wrote:

>Hello,
>
> No it is not web app, I tested on simple delphi app and with PGAdmin
>III.. same results.. Query from PGAdmin takes up to 30seconds...
>  
>
Displaying the data can take a long time on several platforms for 
pgAdmin; complex controls tend to be dead slow on larger data sets. 
We're waiting for a better wxWidgets solution, I doubt delphi is better...

Regards,
Andreas


From pgsql-performance-owner@postgresql.org  Sun Oct 16 19:02:06 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id D0F4BDA4DF
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 16 Oct 2005 19:02:05 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 59723-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 16 Oct 2005 22:02:01 +0000 (GMT)
Received: from fmf.vtu.lt (fmf.vtu.lt [193.219.145.206])
	by svr1.postgresql.org (Postfix) with ESMTP id C4AF5DA682
	for <pgsql-performance@postgresql.org>;
	Sun, 16 Oct 2005 19:02:02 -0300 (ADT)
Received: from fmf.vtu.lt (localhost [127.0.0.1])
	by fmf.vtu.lt (Postfix) with ESMTP id 98C9918473;
	Mon, 17 Oct 2005 01:02:00 +0300 (EEST)
Received: from 85.206.197.88 (SquirrelMail authenticated user nso)
	by fmf.vtu.lt with HTTP; Mon, 17 Oct 2005 01:02:00 +0300 (EEST)
Message-ID: <3311.85.206.197.88.1129500120.squirrel@fmf.vtu.lt>
In-Reply-To: <4352C113.80104@pse-consulting.de>
References: <17260.81.7.89.65.1129382454.squirrel@fmf.vtu.lt>   
	<29778.1129391647@sss.pgh.pa.us>   
	<18133.81.7.89.65.1129392990.squirrel@fmf.vtu.lt>   
	<4351DCB6.3040307@paradise.net.nz>
	<23627.81.7.89.65.1129460506.squirrel@fmf.vtu.lt>
	<4352C113.80104@pse-consulting.de>
Date: Mon, 17 Oct 2005 01:02:00 +0300 (EEST)
Subject: Re: Bytea poor performance
From: "NSO" <nso@fmf.vtu.lt>
To: "Andreas Pflug" <pgadmin@pse-consulting.de>
Cc: pgsql-performance@postgresql.org
User-Agent: SquirrelMail/1.4.5
MIME-Version: 1.0
Content-Type: text/plain;charset=utf-8
Content-Transfer-Encoding: 8bit
X-Priority: 3 (Normal)
Importance: Normal
X-VGTU-MailScanner-OpenProtect-Information: Please contact the ISP for more
	information
X-VGTU-MailScanner-OpenProtect: Found to be clean
X-MailScanner-OpenProtect-MCPCheck: 
X-MailScanner-OpenProtect-From: nso@fmf.vtu.lt
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.274 required=5 tests=[AWL=-0.100,
	DNS_FROM_RFC_ABUSE=0.374]
X-Spam-Level: 
X-Archive-Number: 200510/249
X-Sequence-Number: 15017



Well, no. Delphi isn't better, same time just for downloading data... But
as I told before, if for ex. pgAdminIII is running on server machine it is
a lot faster, I do not know why, I was monitoring network connection
between client and server and it is using only up to 2% of full speed.. is
server can't send faster? or client is not accepting data faster?

> NSO wrote:
>
>>Hello,
>>
>> No it is not web app, I tested on simple delphi app and with PGAdmin
>>III.. same results.. Query from PGAdmin takes up to 30seconds...
>>
>>
> Displaying the data can take a long time on several platforms for
> pgAdmin; complex controls tend to be dead slow on larger data sets.
> We're waiting for a better wxWidgets solution, I doubt delphi is better...
>
> Regards,
> Andreas
>
>
> --
> This message has been scanned for viruses and
> dangerous content, and is believed to be clean.
>
>



-- 
This message has been scanned for viruses and
dangerous content, and is believed to be clean.


From pgsql-performance-owner@postgresql.org  Mon Oct 17 08:17:50 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 21A23DA735
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 17 Oct 2005 05:36:19 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 94557-10
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 17 Oct 2005 08:36:12 +0000 (GMT)
Received: from moutng.kundenserver.de (moutng.kundenserver.de
	[212.227.126.183])
	by svr1.postgresql.org (Postfix) with ESMTP id 1B874D9EF7
	for <pgsql-performance@postgresql.org>;
	Mon, 17 Oct 2005 05:36:12 -0300 (ADT)
Received: from p548F1E2F.dip0.t-ipconnect.de [84.143.30.47]
	(helo=pse.dyndns.org)
	by mrelayeu.kundenserver.de with ESMTP (Nemesis),
	id 0ML2ov-1ERQTd0srO-0000j8; Mon, 17 Oct 2005 10:36:13 +0200
Received: from p548f2989.dip0.t-ipconnect.de ([84.143.41.137]
	helo=[10.10.11.120])
	by pse.dyndns.org with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.44)
	id 1ERQTb-0007u3-FM; Mon, 17 Oct 2005 10:36:11 +0200
Message-ID: <43536167.1010305@pse-consulting.de>
Date: Mon, 17 Oct 2005 10:31:35 +0200
From: Andreas Pflug <pgadmin@pse-consulting.de>
User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: NSO <nso@fmf.vtu.lt>
Cc: pgsql-performance@postgresql.org
Subject: Re: Bytea poor performance
References: <17260.81.7.89.65.1129382454.squirrel@fmf.vtu.lt>
	<29778.1129391647@sss.pgh.pa.us>
	<18133.81.7.89.65.1129392990.squirrel@fmf.vtu.lt>
	<4351DCB6.3040307@paradise.net.nz>
	<23627.81.7.89.65.1129460506.squirrel@fmf.vtu.lt>
	<4352C113.80104@pse-consulting.de>
	<3311.85.206.197.88.1129500120.squirrel@fmf.vtu.lt>
In-Reply-To: <3311.85.206.197.88.1129500120.squirrel@fmf.vtu.lt>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Provags-ID: kundenserver.de abuse@kundenserver.de
	login:0ce7ee5c3478b8d72edd8e05ccd40b70
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=1.058 required=5 tests=[AWL=-0.784,
	FORGED_RCVD_HELO=0.05, RCVD_IN_NJABL_DUL=1.655, RCVD_IN_SORBS_DUL=0.137]
X-Spam-Level: *
X-Archive-Number: 200510/251
X-Sequence-Number: 15019

NSO wrote:

>Well, no. Delphi isn't better, same time just for downloading data... But
>as I told before, if for ex. pgAdminIII is running on server machine it is
>a lot faster, I do not know why, I was monitoring network connection
>between client and server and it is using only up to 2% of full speed.. is
>server can't send faster? or client is not accepting data faster?
>  
>

Only the first number is relevant and subject to network/db/server 
issues. The second is GUI only.

Regards,
Andreas


From pgsql-performance-owner@postgresql.org  Mon Oct 17 08:06:45 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 8772FDA6B0
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 17 Oct 2005 05:45:25 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 95750-04
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 17 Oct 2005 08:45:22 +0000 (GMT)
Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75])
	by svr1.postgresql.org (Postfix) with ESMTP id A7073D77A8
	for <pgsql-performance@postgresql.org>;
	Mon, 17 Oct 2005 05:45:23 -0300 (ADT)
Received: from mainbox.archonet.com
	(84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99])
	by smtp.metronet.co.uk (MetroNet Mail) with ESMTP
	id 25120407D81; Mon, 17 Oct 2005 09:45:20 +0100 (BST)
Received: from localhost (localhost.localdomain [127.0.0.1])
	by mainbox.archonet.com (Postfix) with ESMTP id B7F0C15ED9;
	Mon, 17 Oct 2005 09:45:05 +0100 (BST)
Received: from mainbox.archonet.com ([127.0.0.1])
	by localhost (mainbox [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 13151-09; Mon, 17 Oct 2005 09:45:01 +0100 (BST)
Received: from [192.168.1.17] (client17.office.archonet.com [192.168.1.17])
	by mainbox.archonet.com (Postfix) with ESMTP id 1928D15ED5;
	Mon, 17 Oct 2005 09:45:01 +0100 (BST)
Message-ID: <4353648C.8040507@archonet.com>
Date: Mon, 17 Oct 2005 09:45:00 +0100
From: Richard Huxton <dev@archonet.com>
User-Agent: Mozilla Thunderbird 1.0.7 (X11/20051010)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: Martin Nickel <martin@portant.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Sequential scan on FK join
References: <pan.2005.10.12.20.40.22.703085@portant.com>
In-Reply-To: <pan.2005.10.12.20.40.22.703085@portant.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.059 required=5 tests=[AWL=0.009,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/250
X-Sequence-Number: 15018

Martin Nickel wrote:
> EXPLAIN SELECT m.mailcode, l.lead_id
>   FROM mailing m 
>  INNER JOIN lead l ON m.mailing_id = l.mailing_id 
>  WHERE (m.maildate >= '2005-7-01'::date 
>          AND m.maildate < '2005-8-01'::date) 
> 
> Hash Join  (cost=62.13..2001702.55 rows=2711552 width=20)
>   Hash Cond: ("outer".mailing_id = "inner".mailing_id)
>   ->  Seq Scan on lead l  (cost=0.00..1804198.60 rows=34065260 width=8)
>   ->  Hash  (cost=61.22..61.22 rows=362 width=20)
>         ->  Index Scan using mailing_maildate_idx on mailing m  (cost=0.00..61.22 rows=362 width=20)
>               Index Cond: ((maildate >= '2005-07-01'::date) AND (maildate < '2005-08-01'::date))

Well the reason *why* is that the planner expects 2.71 million rows to 
be matched. If that was the case, then a seq-scan of 34 million rows 
might well make sense. The output from EXPLAIN ANALYSE would show us 
whether that estimate is correct - is it?

-- 
   Richard Huxton
   Archonet Ltd

From pgsql-performance-owner@postgresql.org  Mon Oct 17 14:09:40 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 51085D6DB0
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 17 Oct 2005 09:58:09 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 70220-07
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 17 Oct 2005 12:58:05 +0000 (GMT)
Received: from floppy.pyrenet.fr (news.pyrenet.fr [194.116.145.2])
	by svr1.postgresql.org (Postfix) with ESMTP id DBB1ED6FB5
	for <pgsql-performance@postgresql.org>;
	Mon, 17 Oct 2005 09:58:06 -0300 (ADT)
Received: by floppy.pyrenet.fr (Postfix, from userid 106)
	id 9C02B31058; Mon, 17 Oct 2005 14:58:10 +0200 (MET DST)
From: Martin Nickel <martin@portant.com>
X-Newsgroups: pgsql.performance
Subject: Re: Sequential scan on FK join
Date: Mon, 17 Oct 2005 08:07:54 -0500
Organization: Hub.Org Networking Services
Lines: 21
Message-ID: <pan.2005.10.17.13.07.53.915839@portant.com>
References: <pan.2005.10.12.20.40.22.703085@portant.com>
	<4353648C.8040507@archonet.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Complaints-To: usenet@news.hub.org
User-Agent: Pan/0.14.2 (This is not a psychotic episode. It's a cleansing
	moment of clarity.)
To: pgsql-performance@postgresql.org
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0 required=5 tests=[none]
X-Spam-Level: 
X-Archive-Number: 200510/252
X-Sequence-Number: 15020

Subject:      Re: Sequential scan on FK join
From:         Martin Nickel <martin@portant.com>
Newsgroups:   pgsql.performance
Date:         Wed, 12 Oct 2005 15:53:35 -0500

Richard, here's the EXPLAIN ANALYZE.  I see your point re: the 2.7M
expected vs the 2 actual, but I've run ANALYZE on the lead table and it
hasn't changed the plan.  Suggestions?

"Hash Join  (cost=62.13..2001702.55 rows=2711552 width=20) (actual
time=40.659..244709.315 rows=2	125270 loops=1)" "  Hash Cond:
("outer".mailing_id = "inner".mailing_id)" "  ->  Seq Scan on lead l
(cost=0.00..1804198.60 rows=34065260 width=8) (actual
time=8.621..180281.094 rows=34060373 loops=1)" "  ->  Hash
(cost=61.22..61.22 rows=362 width=20) (actual time=28.718..28.718 rows=0
loops=1)" "        ->  Index Scan using mailing_maildate_idx on mailing m
(cost=0.00..61.22 rows=362 width=20) (actual time=16.571..27.793 rows=430
loops=1)" "              Index Cond: ((maildate >= '2005-07-01'::date) AND
(maildate < '2005-08-01'::date))" "Total runtime: 248104.339 ms"



From pgsql-performance-owner@postgresql.org  Mon Oct 17 15:01:23 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id D3718D7A13
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 17 Oct 2005 14:43:35 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 59635-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 17 Oct 2005 17:43:32 +0000 (GMT)
Received: from ra.sai.msu.su (ra.sai.msu.su [158.250.29.2])
	by svr1.postgresql.org (Postfix) with ESMTP id 5A6DCD7A2C
	for <pgsql-performance@postgresql.org>;
	Mon, 17 Oct 2005 14:43:24 -0300 (ADT)
Received: from ra (ra [158.250.29.2])
	by ra.sai.msu.su (8.13.4/8.13.4) with ESMTP id j9HHhD19017871;
	Mon, 17 Oct 2005 21:43:13 +0400 (MSD)
Date: Mon, 17 Oct 2005 21:43:13 +0400 (MSD)
From: Oleg Bartunov <oleg@sai.msu.su>
X-X-Sender: megera@ra.sai.msu.su
To: "Craig A. James" <cjames@modgraph-usa.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: tsearch2/GIST performance factors?
In-Reply-To: <4351166C.9010102@modgraph-usa.com>
Message-ID: <Pine.GSO.4.63.0510172127510.10366@ra.sai.msu.su>
References: <4351166C.9010102@modgraph-usa.com>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.322 required=5 tests=[AWL=-0.052,
	DNS_FROM_RFC_ABUSE=0.374]
X-Spam-Level: 
X-Archive-Number: 200510/256
X-Sequence-Number: 15024

On Sat, 15 Oct 2005, Craig A. James wrote:

> We are indexing about 5 million small documents using tsearch2/GIST.  Each 
> "document" contains 2 to 50 words.  This is a "write once, read many" 
> situation.  Write performance is unimportant, and the database contents are 
> static.  (We build it offline.)
>
> We're having problems with inconsistent performance, and it's very hard to 
> separate the effects of various factors.  Here are the things we think may be 
> relevant.
>
> 1. Total number of words
>
> Our documents currently contain about 110,000 unique words.  Oleg wrote: 
> "[The limit is] 100K, but it's very fuzzy limit." By trial and error, we've 
> learned that 50,000 works well, and 150,000 works poorly, so Oleg's comment 
> appears to be a good rule-of-thumb.  (With SIGLENINT enlarged, see below.) 
> But there may be other factors that affect this conclusion (such as shared 
> memory, total memory, etc.).
>

Did you consider *decreasing* SIGLENINT ? Size of index will diminish
and performance could be increased. I use in current project SIGLENINT=15

>
> 2. Total size of the table
>
> 5 million documents is not a very big database (each document is a few to a 
> few hundred bytes), so we don't think this is relevant.
>
>
> 3. Number of documents per word
>
> There seems to be a VERY strong effect related to "common" words.  When a 
> word occurs in more than about 1% of the documents (say 50,000 to 150,000 
> documents), performance goes WAY down.  Not just for that specific query, but 
> it screws up tsearch2/GIST completely.
>
> We have a test of 100 queries that return 382,000 documents total.  The first 
> time we run it, it's slow, about 20 minutes (as expected).  The second time 
> we run it, it's very fast, about 72 seconds -- very fast!!  As long as we 
> avoid queries with common words, performance is very good.
>
> But, if we run just one query that contains a common word (a word that's in 
> more than about 2% of the documents, roughly 150,000 documents), then the 
> next time we run the 100 test queries, it will take 20 minutes again.
>

> We can't simply eliminate these common words.  First of all, they can be very 
> significant.  Second, it doesn't seem like 2% is "common".  I can understand 
> that a words like "the" which occur in most documents shouldn't be indexed. 
> But a word that occurs in 2% of the database seems like a very good word to 
> index, yet it causes us great problems.
>

tsearch2's index is a lossy index, read http://www.sai.msu.su/~megera/oddmuse/index.cgi/Tsearch_V2_internals
so search results  should be rechecked !


> I've read a bit about tsearchd, and wonder if it would solve our problem. 
> For our application, consistent performance is VERY important.  If we could 
> lock the GIST index into memory, I think it would fix our problem.

I think so, tsearchd was designed for static contents in mind and it's
index doesn't require rechecking !

>
> I tried copying the GIST indexes (which are in a separate tablespace) to a 1 
> GB RAM disk, and it made the initial query faster, but overall performance 
> seemed worse, probably because the RAM disk was using memory that could have 
> been used by the file-system cache.
>
>
> 4. Available RAM and Disk drives
>
> Would more RAM help?  How would we tell Postgres to use it effectively?  The 
> GIST indexes are currently about 2.6 GB on the disk.

try to decrease signature size, say, 
#define SIGLENINT  15


> I feel like I'm shooting in the dark -- Linux, Postgres and tsearch2/GIST are 
> interacting in ways that I can't predict or analyze.  Thanks very much for 
> any comments and advice.

We have our TODO http://www.sai.msu.su/~megera/oddmuse/index.cgi/todo
and hope to find sponsorhips for fts project for 8.2 release.
Unfortunately, I didn't find spare time to package tsearchd for you,
it should certainly help you.


 	Regards,
 		Oleg
_____________________________________________________________
Oleg Bartunov, sci.researcher, hostmaster of AstroNet,
Sternberg Astronomical Institute, Moscow University (Russia)
Internet: oleg@sai.msu.su, http://www.sai.msu.su/~megera/
phone: +007(095)939-16-83, +007(095)939-23-83

From pgsql-performance-owner@postgresql.org  Mon Oct 17 14:58:14 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id B396BD72D2
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 17 Oct 2005 14:51:19 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 61661-04
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 17 Oct 2005 17:51:13 +0000 (GMT)
Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75])
	by svr1.postgresql.org (Postfix) with ESMTP id C4925D70B4
	for <pgsql-performance@postgresql.org>;
	Mon, 17 Oct 2005 14:51:13 -0300 (ADT)
Received: from mainbox.archonet.com
	(84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99])
	by smtp.metronet.co.uk (MetroNet Mail) with ESMTP
	id B5CBC417ED7; Mon, 17 Oct 2005 18:50:21 +0100 (BST)
Received: from localhost (localhost.localdomain [127.0.0.1])
	by mainbox.archonet.com (Postfix) with ESMTP id 72E6315EDE;
	Mon, 17 Oct 2005 18:46:03 +0100 (BST)
Received: from mainbox.archonet.com ([127.0.0.1])
	by localhost (mainbox [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 28736-03; Mon, 17 Oct 2005 18:45:58 +0100 (BST)
Received: from [192.168.1.17] (client17.office.archonet.com [192.168.1.17])
	by mainbox.archonet.com (Postfix) with ESMTP id D2F7515EDA;
	Mon, 17 Oct 2005 18:45:38 +0100 (BST)
Message-ID: <4353E342.2060708@archonet.com>
Date: Mon, 17 Oct 2005 18:45:38 +0100
From: Richard Huxton <dev@archonet.com>
User-Agent: Mozilla Thunderbird 1.0.7 (X11/20051013)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: Martin Nickel <martin@portant.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Sequential scan on FK join
References: <pan.2005.10.12.20.40.22.703085@portant.com>
	<4353648C.8040507@archonet.com>
	<pan.2005.10.17.13.07.53.915839@portant.com>
In-Reply-To: <pan.2005.10.17.13.07.53.915839@portant.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.059 required=5 tests=[AWL=0.009,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/255
X-Sequence-Number: 15023

Martin Nickel wrote:
> Subject:      Re: Sequential scan on FK join
> From:         Martin Nickel <martin@portant.com>
> Newsgroups:   pgsql.performance
> Date:         Wed, 12 Oct 2005 15:53:35 -0500
> 
> Richard, here's the EXPLAIN ANALYZE.  I see your point re: the 2.7M
> expected vs the 2 actual, but I've run ANALYZE on the lead table and it
> hasn't changed the plan.  Suggestions?
> 
> Hash Join  (cost=62.13..2001702.55 rows=2711552 width=20) 
> (actual time=40.659..244709.315 rows=2 125270 loops=1)
                                        ^^^
Hmm - is that not just a formatting gap there? Is it not 2,125,270 rows 
matching which would suggest PG is getting it more right than wrong.

Try issuing "SET enable_seqscan=false" before running the explain 
analyse - that will force the planner to use any indexes it can find and 
should show us whether the index would help.
--
   Richard Huxton
   Archonet Ltd

From pgsql-performance-owner@postgresql.org  Mon Oct 17 17:02:56 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 19B01D77A5
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 17 Oct 2005 16:46:59 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 89631-07
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 17 Oct 2005 19:46:56 +0000 (GMT)
Received: from floppy.pyrenet.fr (news.pyrenet.fr [194.116.145.2])
	by svr1.postgresql.org (Postfix) with ESMTP id 9AF54D7357
	for <pgsql-performance@postgresql.org>;
	Mon, 17 Oct 2005 16:46:56 -0300 (ADT)
Received: by floppy.pyrenet.fr (Postfix, from userid 106)
	id 9E86631058; Mon, 17 Oct 2005 21:46:57 +0200 (MET DST)
From: Martin Nickel <martin@portant.com>
X-Newsgroups: pgsql.performance
Subject: Re: Sequential scan on FK join
Date: Mon, 17 Oct 2005 14:56:43 -0500
Organization: Hub.Org Networking Services
Lines: 34
Message-ID: <pan.2005.10.17.19.56.36.629275@portant.com>
References: <pan.2005.10.12.20.40.22.703085@portant.com>
	<4353648C.8040507@archonet.com>
	<pan.2005.10.17.13.07.53.915839@portant.com>
	<4353E342.2060708@archonet.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Complaints-To: usenet@news.hub.org
User-Agent: Pan/0.14.2 (This is not a psychotic episode. It's a cleansing
	moment of clarity.)
To: pgsql-performance@postgresql.org
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0 required=5 tests=[none]
X-Spam-Level: 
X-Archive-Number: 200510/257
X-Sequence-Number: 15025

When I turn of seqscan it does use the index - and it runs 20 to 30%
longer.  Based on that, the planner is correctly choosing a sequential
scan - but that's just hard for me to comprehend.  I'm joining on an int4
key, 2048 per index page - I guess that's a lot of reads - then the data
-page reads.  Still, the 8-minute query time seems excessive.  

On Mon, 17 Oct 2005 18:45:38 +0100, Richard Huxton wrote:

> Martin Nickel wrote:
>> Subject:      Re: Sequential scan on FK join From:         Martin Nickel
>> <martin@portant.com> Newsgroups:   pgsql.performance
>> Date:         Wed, 12 Oct 2005 15:53:35 -0500
>> 
>> Richard, here's the EXPLAIN ANALYZE.  I see your point re: the 2.7M
>> expected vs the 2 actual, but I've run ANALYZE on the lead table and it
>> hasn't changed the plan.  Suggestions?
>> 
>> Hash Join  (cost=62.13..2001702.55 rows=2711552 width=20) (actual
>> time=40.659..244709.315 rows=2 125270 loops=1)
>                                         ^^^
> Hmm - is that not just a formatting gap there? Is it not 2,125,270 rows
> matching which would suggest PG is getting it more right than wrong.
> 
> Try issuing "SET enable_seqscan=false" before running the explain analyse
> - that will force the planner to use any indexes it can find and should
> show us whether the index would help. --
>    Richard Huxton
>    Archonet Ltd
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
> 
>                http://archives.postgresql.org


From pgsql-performance-owner@postgresql.org  Mon Oct 17 22:58:54 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 61412D818C
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 17 Oct 2005 22:58:53 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 35791-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 18 Oct 2005 01:58:49 +0000 (GMT)
Received: from linda-5.paradise.net.nz (bm-5a.paradise.net.nz
 [203.96.152.184])
	by svr1.postgresql.org (Postfix) with ESMTP id 56DD5D7AC5
	for <pgsql-performance@postgresql.org>;
	Mon, 17 Oct 2005 22:58:51 -0300 (ADT)
Received: from smtp-3.paradise.net.nz
	(tclsnelb2-src-1.paradise.net.nz [203.96.152.177]) by
	linda-5.paradise.net.nz (Paradise.net.nz) with ESMTP id
	<0IOJ009F39I3DA@linda-5.paradise.net.nz> for
	pgsql-performance@postgresql.org; Tue, 18 Oct 2005 14:58:51 +1300 (NZDT)
Received: from [192.168.1.11] (218-101-13-34.paradise.net.nz [218.101.13.34])
	by smtp-3.paradise.net.nz (Postfix) with ESMTP id AE9612DF3B5; Tue,
	18 Oct 2005 14:58:50 +1300 (NZDT)
Date: Tue, 18 Oct 2005 14:58:48 +1300
From: Mark Kirkwood <markir@paradise.net.nz>
Subject: Re: Bytea poor performance
In-reply-to: <3311.85.206.197.88.1129500120.squirrel@fmf.vtu.lt>
To: NSO <nso@fmf.vtu.lt>
Cc: Andreas Pflug <pgadmin@pse-consulting.de>,
 pgsql-performance@postgresql.org
Message-id: <435456D8.8070303@paradise.net.nz>
MIME-version: 1.0
Content-type: text/plain; format=flowed; charset=UTF-8
Content-transfer-encoding: 7bit
X-Accept-Language: en-us, en
User-Agent: Mozilla Thunderbird 1.0.6 (X11/20050726)
References: <17260.81.7.89.65.1129382454.squirrel@fmf.vtu.lt>
	<29778.1129391647@sss.pgh.pa.us>
	<18133.81.7.89.65.1129392990.squirrel@fmf.vtu.lt>
	<4351DCB6.3040307@paradise.net.nz>
	<23627.81.7.89.65.1129460506.squirrel@fmf.vtu.lt>
	<4352C113.80104@pse-consulting.de>
	<3311.85.206.197.88.1129500120.squirrel@fmf.vtu.lt>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=1.038 required=5 tests=[AWL=-0.794,
	RCVD_IN_BL_SPAMCOP_NET=1.832]
X-Spam-Level: *
X-Archive-Number: 200510/258
X-Sequence-Number: 15026

NSO wrote:
> 
> Well, no. Delphi isn't better, same time just for downloading data... But
> as I told before, if for ex. pgAdminIII is running on server machine it is
> a lot faster, I do not know why, I was monitoring network connection
> between client and server and it is using only up to 2% of full speed.. is
> server can't send faster? or client is not accepting data faster?
> 
>  

That difference is suspiciously high - you need to get one of your 
network boys to check that the NIC in your client box is operating at 
full speed (and/or does not clash with whatever network device it is 
plugged into). The other thing to check that that your client box is 
reasonably spec'ed : e.g. not running out of ram or disk in particular - 
or suffering from massively fragmented disk (the latter if its win32).

With respect to the Delphi, you can probably narrow where it has issues 
by running test versions of your app that have bits of functionality 
removed:

- retrieves the bytea but does not display it
- retrieves the bytea but displays it unformatted, or truncated
- does not retrieve the bytea at all

The difference between these should tell you where your issue is!

By way of comparison, I have a Php page (no Delphi sorry) that 
essentially shows 50 rows from your files table over a 100Mbit network. 
Some experiments with that show:

- takes 2 seconds to display in Firefox
- takes 0.2 seconds to complete a request (i.e. "display") using httperf

This indicates that (in my case) most of the 2 seconds is being used by 
Firefox (not being very good at) formatting the wide output for display.

The figure of about 2-5 seconds seems about right, so your 20-30 seconds 
certainly seems high!


cheers

Mark

From pgsql-performance-owner@postgresql.org  Tue Oct 18 03:09:41 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 39C3FD837E
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 18 Oct 2005 03:09:40 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 48736-07
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 18 Oct 2005 06:09:36 +0000 (GMT)
Received: from moonunit2.moonview.localnet (wsip-68-15-5-150.sd.sd.cox.net
	[68.15.5.150])
	by svr1.postgresql.org (Postfix) with ESMTP id 57823D8378
	for <pgsql-performance@postgresql.org>;
	Tue, 18 Oct 2005 03:09:35 -0300 (ADT)
Received: from [192.168.0.3] (moonunit3.moonview.localnet [192.168.0.3])
	by moonunit2.moonview.localnet (8.13.1/8.13.1) with ESMTP id
	j9I6EHUR003368; Mon, 17 Oct 2005 23:14:18 -0700
Message-ID: <4354913B.2020001@modgraph-usa.com>
Date: Mon, 17 Oct 2005 23:07:55 -0700
From: "Craig A. James" <cjames@modgraph-usa.com>
User-Agent: Mozilla Thunderbird 1.0.6 (X11/20050716)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: Oleg Bartunov <oleg@sai.msu.su>
Cc: pgsql-performance@postgresql.org
Subject: Re: tsearch2/GIST performance factors?
References: <4351166C.9010102@modgraph-usa.com>
	<Pine.GSO.4.63.0510172127510.10366@ra.sai.msu.su>
In-Reply-To: <Pine.GSO.4.63.0510172127510.10366@ra.sai.msu.su>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.05 required=5 tests=[FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/259
X-Sequence-Number: 15027

Oleg wrote:
> Did you consider *decreasing* SIGLENINT ? Size of index will diminish
> and performance could be increased. I use in current project SIGLENINT=15

The default value for SIGLENINT actually didn't work at all.  It was only by increasing it that I got any performance at all.  An examination of the GIST indexes showed that most of the first level and many of the second level bitmaps were saturated.

> tsearch2's index is a lossy index, read 
> http://www.sai.msu.su/~megera/oddmuse/index.cgi/Tsearch_V2_internals
> so search results  should be rechecked !

Yes, thanks.  We do indeed recheck the actual results.  The tests I'm running are just on the raw index performance - how long does it take to "select ... where dockeys @@ to_tsquery(...)".

> We have our TODO http://www.sai.msu.su/~megera/oddmuse/index.cgi/todo
> and hope to find sponsorhips for fts project for 8.2 release.
> Unfortunately, I didn't find spare time to package tsearchd for you,
> it should certainly help you.

At this point we may not have time to try tsearchd, and unfortunately we're not in a position to sponsor anything yet.

My original question is still bothering me.  Is it normal for a keyword that occurs in more than about 2% of the documents to cause such inconsistent performance?  Is there any single thing I might look at that would help improve performance (like, do I need more memory?  More shared memory?  Different config parameters?)

Thanks,
Craig

From pgsql-performance-owner@postgresql.org  Tue Oct 18 03:21:03 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 55017D811E
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 18 Oct 2005 03:21:02 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 53021-07
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 18 Oct 2005 06:20:58 +0000 (GMT)
Received: from ra.sai.msu.su (ra.sai.msu.su [158.250.29.2])
	by svr1.postgresql.org (Postfix) with ESMTP id 2A852D6F2A
	for <pgsql-performance@postgresql.org>;
	Tue, 18 Oct 2005 03:20:51 -0300 (ADT)
Received: from ra (ra [158.250.29.2])
	by ra.sai.msu.su (8.13.4/8.13.4) with ESMTP id j9I6KhaA014410;
	Tue, 18 Oct 2005 10:20:43 +0400 (MSD)
Date: Tue, 18 Oct 2005 10:20:43 +0400 (MSD)
From: Oleg Bartunov <oleg@sai.msu.su>
X-X-Sender: megera@ra.sai.msu.su
To: "Craig A. James" <cjames@modgraph-usa.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: tsearch2/GIST performance factors?
In-Reply-To: <4354913B.2020001@modgraph-usa.com>
Message-ID: <Pine.GSO.4.63.0510181017230.10366@ra.sai.msu.su>
References: <4351166C.9010102@modgraph-usa.com>
	<Pine.GSO.4.63.0510172127510.10366@ra.sai.msu.su>
	<4354913B.2020001@modgraph-usa.com>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.322 required=5 tests=[AWL=-0.052,
	DNS_FROM_RFC_ABUSE=0.374]
X-Spam-Level: 
X-Archive-Number: 200510/260
X-Sequence-Number: 15028

Craig,

could you prepare excerption from your db (if possible), so I could
play myself ?

 	Oleg
On Mon, 17 Oct 2005, Craig A. James wrote:

> Oleg wrote:
>> Did you consider *decreasing* SIGLENINT ? Size of index will diminish
>> and performance could be increased. I use in current project SIGLENINT=15
>
> The default value for SIGLENINT actually didn't work at all.  It was only by 
> increasing it that I got any performance at all.  An examination of the GIST 
> indexes showed that most of the first level and many of the second level 
> bitmaps were saturated.
>
>> tsearch2's index is a lossy index, read 
>> http://www.sai.msu.su/~megera/oddmuse/index.cgi/Tsearch_V2_internals
>> so search results  should be rechecked !
>
> Yes, thanks.  We do indeed recheck the actual results.  The tests I'm running 
> are just on the raw index performance - how long does it take to "select ... 
> where dockeys @@ to_tsquery(...)".
>
>> We have our TODO http://www.sai.msu.su/~megera/oddmuse/index.cgi/todo
>> and hope to find sponsorhips for fts project for 8.2 release.
>> Unfortunately, I didn't find spare time to package tsearchd for you,
>> it should certainly help you.
>
> At this point we may not have time to try tsearchd, and unfortunately we're 
> not in a position to sponsor anything yet.
>
> My original question is still bothering me.  Is it normal for a keyword that 
> occurs in more than about 2% of the documents to cause such inconsistent 
> performance?  Is there any single thing I might look at that would help 
> improve performance (like, do I need more memory?  More shared memory? 
> Different config parameters?)
>
> Thanks,
> Craig
>

 	Regards,
 		Oleg
_____________________________________________________________
Oleg Bartunov, sci.researcher, hostmaster of AstroNet,
Sternberg Astronomical Institute, Moscow University (Russia)
Internet: oleg@sai.msu.su, http://www.sai.msu.su/~megera/
phone: +007(095)939-16-83, +007(095)939-23-83

From pgsql-performance-owner@postgresql.org  Tue Oct 18 04:55:23 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 8B1D6D877E
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 18 Oct 2005 04:55:21 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 72546-09
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 18 Oct 2005 07:55:17 +0000 (GMT)
Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75])
	by svr1.postgresql.org (Postfix) with ESMTP id 9B937D874A
	for <pgsql-performance@postgresql.org>;
	Tue, 18 Oct 2005 04:55:18 -0300 (ADT)
Received: from mainbox.archonet.com
	(84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99])
	by smtp.metronet.co.uk (MetroNet Mail) with ESMTP
	id 200FD401E16; Tue, 18 Oct 2005 08:55:14 +0100 (BST)
Received: from localhost (localhost.localdomain [127.0.0.1])
	by mainbox.archonet.com (Postfix) with ESMTP id DE7DB15ED9;
	Tue, 18 Oct 2005 08:52:19 +0100 (BST)
Received: from mainbox.archonet.com ([127.0.0.1])
	by localhost (mainbox [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 12305-08; Tue, 18 Oct 2005 08:52:16 +0100 (BST)
Received: from [192.168.1.17] (client17.office.archonet.com [192.168.1.17])
	by mainbox.archonet.com (Postfix) with ESMTP id 2616515ED5;
	Tue, 18 Oct 2005 08:52:16 +0100 (BST)
Message-ID: <4354A9AF.30300@archonet.com>
Date: Tue, 18 Oct 2005 08:52:15 +0100
From: Richard Huxton <dev@archonet.com>
User-Agent: Mozilla Thunderbird 1.0.7 (X11/20051013)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: Martin Nickel <martin@portant.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Sequential scan on FK join
References: <pan.2005.10.12.20.40.22.703085@portant.com>
	<4353648C.8040507@archonet.com>
	<pan.2005.10.17.13.07.53.915839@portant.com>
	<4353E342.2060708@archonet.com>
	<pan.2005.10.17.19.56.36.629275@portant.com>
In-Reply-To: <pan.2005.10.17.19.56.36.629275@portant.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.059 required=5 tests=[AWL=0.009,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/261
X-Sequence-Number: 15029

Martin Nickel wrote:
> When I turn of seqscan it does use the index - and it runs 20 to 30%
> longer.  Based on that, the planner is correctly choosing a sequential
> scan - but that's just hard for me to comprehend.  I'm joining on an int4
> key, 2048 per index page - I guess that's a lot of reads - then the data
> -page reads.  Still, the 8-minute query time seems excessive.  

You'll be getting (many) fewer than 2048 index entries per page. There's 
a page header and various pointers involved too, and index pages aren't 
going to be full. So - it needs to search the table on dates, fetch the 
id's and then assemble them for the hash join. Of course, if you have 
too many to join then all this will spill to disk slowing you further.

Now, you'd rather get down below 8 minutes. There are a number of options:
  1. Make sure your disk i/o is being pushed to its limit
  2. Look into increasing the sort memory for this one query "set 
work_mem..." (see the runtime configuration section of the manual)
  3. Actually - are you happy that your general configuration is OK?
  4. Perhaps use a cursor - I'm guessing you want to process these 
mailings in some way and only want them one at a time in any case.
  5. Try the query one day at a time and see if the balance tips the 
other way - you'll be dealing with substantially less data per query 
which might match your system better. Of course, this may not be 
practical for your applicaton.
  6. If your lead table is updated only rarely, you could try a CLUSTER 
on the table by mailing_id - that should speed the scan. Read the manual 
for the cluster command first though.

-- 
   Richard Huxton
   Archonet Ltd

From pgsql-performance-owner@postgresql.org  Tue Oct 18 12:19:29 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id E778DD96AD
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 18 Oct 2005 12:19:22 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 85104-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 18 Oct 2005 15:19:21 +0000 (GMT)
Received: from bramble.mmrd.com (bramble.mmrd.com [65.217.53.66])
	by svr1.postgresql.org (Postfix) with ESMTP id B73DBD96A5
	for <pgsql-performance@postgresql.org>;
	Tue, 18 Oct 2005 12:19:20 -0300 (ADT)
Received: from thorn.mmrd.com (thorn.mmrd.com [172.25.10.100])
	by bramble.mmrd.com (8.12.8/8.12.8) with ESMTP id j9IFiHoJ022967;
	Tue, 18 Oct 2005 11:44:18 -0400
Received: from gnvex001.mmrd.com (gnvex001.mmrd.com [10.225.10.110])
	by thorn.mmrd.com (8.11.6/8.11.6) with ESMTP id j9IFIid00429;
	Tue, 18 Oct 2005 11:18:44 -0400
Received: from camel.mmrd.com ([172.25.5.213]) by gnvex001.mmrd.com with SMTP
	(Microsoft Exchange Internet Mail Service Version 5.5.2657.72)
	id TWC05D66; Tue, 18 Oct 2005 11:18:41 -0400
Subject: Re: Help tuning postgres
From: Robert Treat <xzilla@users.sourceforge.net>
To: Steve Poe <spoe@sfnet.cc>
Cc: Tom Lane <tgl@sss.pgh.pa.us>, pgsql-performance@postgresql.org,
	Csaba Nagy <nagy@ecircle-ag.com>, emil@baymountain.com
In-Reply-To: <1129138325.26659.14.camel@amd64-gentoo-laptop>
References: <1129128315.2995.174.camel@coppola.muc.ecircle.de>
	<200510121112.11486.emil@baymountain.com>
	<1129130273.2995.177.camel@coppola.muc.ecircle.de>
	<200510121133.56955.emil@baymountain.com>
	<2741.1129137684@sss.pgh.pa.us>
	<1129138325.26659.14.camel@amd64-gentoo-laptop>
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
X-Mailer: Ximian Evolution 1.0.8 
Date: 18 Oct 2005 11:18:41 -0400
Message-Id: <1129648722.2022.8.camel@camel>
Mime-Version: 1.0
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.028 required=5 tests=[AWL=0.028]
X-Spam-Level: 
X-Archive-Number: 200510/262
X-Sequence-Number: 15030

reindex should be faster, since you're not dumping/reloading the table
contents on top of rebuilding the index, you're just rebuilding the
index. 


Robert Treat
emdeon Practice Services
Alachua, Florida

On Wed, 2005-10-12 at 13:32, Steve Poe wrote:
> 
> Would it not be faster to do a dump/reload of the table than reindex or
> is it about the same? 
> 
> Steve Poe
> 
> On Wed, 2005-10-12 at 13:21 -0400, Tom Lane wrote:
> > Emil Briggs <emil@baymountain.com> writes:
> > >> Not yet, the db is in production use and I have to plan for a down-time
> > >> for that... or is it not impacting the activity on the table ?
> > 
> > > It will cause some performance hit while you are doing it.
> > 
> > It'll also lock out writes on the table until the index is rebuilt,
> > so he does need to schedule downtime.
> > 
> > 			regards, tom lane
> > 
> > ---------------------------(end of broadcast)---------------------------
> > TIP 1: if posting/reading through Usenet, please send an appropriate
> >        subscribe-nomail command to majordomo@postgresql.org so that your
> >        message can get through to the mailing list cleanly
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 5: don't forget to increase your free space map settings

-- 
Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL


From pgsql-performance-owner@postgresql.org  Tue Oct 18 12:26:48 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 8FD22D934A
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 18 Oct 2005 12:22:45 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 81822-09
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 18 Oct 2005 15:22:43 +0000 (GMT)
Received: from mail.ecircle.de (mail.ecircle.de [195.140.186.200])
	by svr1.postgresql.org (Postfix) with ESMTP id 3A3D3D8EB8
	for <pgsql-performance@postgresql.org>;
	Tue, 18 Oct 2005 12:22:42 -0300 (ADT)
Received: from [192.168.1.110] (unknown [192.168.1.110])
	by mail.ecircle.de (READY) with ESMTP id E38049AC869;
	Tue, 18 Oct 2005 17:22:40 +0200 (CEST)
Subject: Re: Help tuning postgres
From: Csaba Nagy <nagy@ecircle-ag.com>
To: Andrew Sullivan <ajs@crankycanuck.ca>
Cc: postgres performance list <pgsql-performance@postgresql.org>
In-Reply-To: <20051013124007.GA15592@phlogiston.dyndns.org>
References: <1129128315.2995.174.camel@coppola.muc.ecircle.de>
	<f3c0b4080510120939x6c08feebvfad37c98df306538@mail.gmail.com>
	<1129136130.2995.188.camel@coppola.muc.ecircle.de>
	<20051012220036.GE13571@phlogiston.dyndns.org>
	<1129191303.2995.192.camel@coppola.muc.ecircle.de>
	<20051013124007.GA15592@phlogiston.dyndns.org>
Content-Type: text/plain
Message-Id: <1129648896.27587.22.camel@coppola.muc.ecircle.de>
Mime-Version: 1.0
X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) 
Date: Tue, 18 Oct 2005 17:21:37 +0200
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.012 required=5 tests=[AWL=0.012]
X-Spam-Level: 
X-Archive-Number: 200510/263
X-Sequence-Number: 15031

In the light of what you've explained below about "nonremovable" row
versions reported by vacuum, I wonder if I should worry about the
following type of report:

INFO:  vacuuming "public.some_table"
INFO:  "some_table": removed 29598 row versions in 452 pages
DETAIL:  CPU 0.01s/0.04u sec elapsed 18.77 sec.
INFO:  "some_table": found 29598 removable, 39684 nonremovable row
versions in 851 pages
DETAIL:  0 dead row versions cannot be removed yet.
There were 0 unused item pointers.
0 pages are entirely empty.
CPU 0.02s/0.07u sec elapsed 23.16 sec.
VACUUM


Does that mean that 39684 nonremovable pages are actually the active
live pages in the table (as it reports 0 dead) ? I'm sure I don't have
any long running transaction, at least according to pg_stats_activity
(backed by the linux ps too). Or I should run a vacuum full...

This table is one of which has frequently updated rows.

TIA,
Csaba.


On Thu, 2005-10-13 at 14:40, Andrew Sullivan wrote:
> On Thu, Oct 13, 2005 at 10:15:03AM +0200, Csaba Nagy wrote:
> > 
> > OK, this sounds interesting, but I don't understand: why would an update
> > "chase down a lot of dead tuples" ? Should I read up on some docs, cause
> > I obviously don't know enough about how updates work on postgres...
> 
> Right.  Here's the issue:
> 
> MVCC does not replace rows when you update.  Instead, it marks the
> old row as expired, and sets the new values.  The old row is still
> there, and it's available for other transactions who need to see it. 
> As the docs say (see
> <http://www.postgresql.org/docs/8.0/interactive/transaction-iso.html>),
> "In effect, a SELECT query sees a snapshot of the database as of the
> instant that that query begins to run."  And that can be true because
> the original data is still there, although marked as expired for
> subsequent transactions.
> 
> UPDATE works the same was as SELECT in terms of searching for rows
> (so does any command that searches for data).  
> 
> Now, when you select data, you actually have to traverse all the
> existing versions of the tuple in order to get the one that's live
> for you.  This is normally not a problem: VACUUM goes around and
> cleans out old, expired data that is not live for _anyone_.  It does
> this by looking for the oldest transaction that is open.  (As far as
> I understand it, this is actually the oldest transaction in the
> entire back end; but I've never understood why that should the the
> case, and I'm too incompetent/dumb to understand the code, so I may
> be wrong on this point.)  If you have very long-running transactions,
> then, you can end up with a lot of versions of dead tuples on the
> table, and so reading the few records you want can turn out actually
> to be a very expensive operation, even though it ought to be cheap.
> 
> You can see this by using the VERBOSE option to VACUUM:
> 
> test=# VACUUM VERBOSE eval1 ;
> INFO:  vacuuming "public.eval1"
> INFO:  "eval1": found 0 removable, 0 nonremovable row versions in 0
> pages
> DETAIL:  0 dead row versions cannot be removed yet.
> There were 0 unused item pointers.
> 0 pages are entirely empty.
> CPU 0.00s/0.00u sec elapsed 0.00 sec.
> INFO:  vacuuming "pg_toast.pg_toast_18831"
> INFO:  index "pg_toast_18831_index" now contains 0 row versions in 1
> pages
> DETAIL:  0 index pages have been deleted, 0 are currently reusable.
> CPU 0.00s/0.00u sec elapsed 0.00 sec.
> INFO:  "pg_toast_18831": found 0 removable, 0 nonremovable row
> versions in 0 pages
> DETAIL:  0 dead row versions cannot be removed yet.
> There were 0 unused item pointers.
> 0 pages are entirely empty.
> CPU 0.00s/0.00u sec elapsed 0.00 sec.
> VACUUM
> 
> Note those "removable" and "nonremovable" row versions.  It's the
> unremovable ones that can hurt.  WARNING: doing VACUUM on a big table
> on a disk that's already pegged is going to cause you performance
> pain, because it scans the whole table.  In some cases, though, you
> have no choice: if the winds are already out of your sails, and
> you're effectively stopped, anything that might get you moving again
> is an improvement.
> 
> > And how would the analyze help in finding this out ? I thought it would
> > only show me additionally the actual timings, not more detail in what
> > was done...
> 
> Yes, it shows the actual timings, and the actual number of rows.  But
> if the estimates that the planner makes are wildly different than the
> actual results, then you know your statistics are wrong, and that the
> planner is going about things the wrong way.  ANALYSE is a big help. 
> There's also a verbose option to it, but it's usually less useful in
> production situations.
> 
> A


From pgsql-performance-owner@postgresql.org  Tue Oct 18 12:50:45 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id E3182D9512
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 18 Oct 2005 12:50:43 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 92127-06
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 18 Oct 2005 15:50:41 +0000 (GMT)
Received: from mail.ecircle.de (mail.ecircle.de [195.140.186.200])
	by svr1.postgresql.org (Postfix) with ESMTP id 140C6D94E5
	for <pgsql-performance@postgresql.org>;
	Tue, 18 Oct 2005 12:50:41 -0300 (ADT)
Received: from [192.168.1.110] (unknown [192.168.1.110])
	by mail.ecircle.de (READY) with ESMTP id 907679AC7F6;
	Tue, 18 Oct 2005 17:50:40 +0200 (CEST)
Subject: Re: Help tuning postgres
From: Csaba Nagy <nagy@ecircle-ag.com>
To: Robert Treat <xzilla@users.sourceforge.net>
Cc: Steve Poe <spoe@sfnet.cc>, Tom Lane <tgl@sss.pgh.pa.us>,
	postgres performance list <pgsql-performance@postgresql.org>,
	emil@baymountain.com
In-Reply-To: <1129648722.2022.8.camel@camel>
References: <1129128315.2995.174.camel@coppola.muc.ecircle.de>
	<200510121112.11486.emil@baymountain.com>
	<1129130273.2995.177.camel@coppola.muc.ecircle.de>
	<200510121133.56955.emil@baymountain.com>
	<2741.1129137684@sss.pgh.pa.us>
	<1129138325.26659.14.camel@amd64-gentoo-laptop>
	<1129648722.2022.8.camel@camel>
Content-Type: text/plain
Message-Id: <1129650576.27587.52.camel@coppola.muc.ecircle.de>
Mime-Version: 1.0
X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) 
Date: Tue, 18 Oct 2005 17:49:36 +0200
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.012 required=5 tests=[AWL=0.012]
X-Spam-Level: 
X-Archive-Number: 200510/264
X-Sequence-Number: 15032

First of all thanks all for the input.

I probably can't afford even the reindex till Christmas, when we have
about 2 weeks of company holiday... but I guess I'll have to do
something until Christmas.

The system should at least look like working all the time. I can have
downtime, but only for short periods preferably less than 1 minute. The
tables we're talking about have ~10 million rows the smaller ones and
~150 million rows the bigger ones, and I guess reindex will take quite
some time.

I wonder if I could device a scheme like:
 
 - create a temp table exactly like the production table, including
indexes and foreign keys;
 - create triggers on the production table which log all inserts,
deletes, updates to a log table;
 - activate these triggers;
 - copy all data from the production table to a temp table (this will
take the bulk of the time needed for the whole operation);
 - replay the log on the temp table repeatedly if necessary, until the
temp table is sufficiently close to the original;
 - rename the original table to something else, and then rename the temp
table to the original name, all this in a transaction - this would be
ideally the only visible delay for the user, and if the system is not
busy, it should be quick I guess;
 - replay on more time the log;

All this should happen in a point in time when there's little traffic to
the data base.

Replaying could be as simple as a few delete triggers on the log table,
which replay the deleted record on the production table, and the replay
then consisting in a delete operation on the log table. This is so that
new log entries can be replayed later without replaying again what was
already replayed.

The big tables I should do this procedure on have low probability of
conflicting operations (like insert and immediate delete of the same
row, or multiple insert of the same row, multiple conflicting updates of
the same row, etc.), this is why I think replaying the log will work
fine... of course this whole set up will be a lot more work than just
reindex...

I wonder if somebody tried anything like this and if it has chances to
work ?

Thanks,
Csaba.

On Tue, 2005-10-18 at 17:18, Robert Treat wrote:
> reindex should be faster, since you're not dumping/reloading the table
> contents on top of rebuilding the index, you're just rebuilding the
> index. 
> 
> 
> Robert Treat
> emdeon Practice Services
> Alachua, Florida
> 
> On Wed, 2005-10-12 at 13:32, Steve Poe wrote:
> > 
> > Would it not be faster to do a dump/reload of the table than reindex or
> > is it about the same? 
> > 
> > Steve Poe
> > 
> > On Wed, 2005-10-12 at 13:21 -0400, Tom Lane wrote:
> > > Emil Briggs <emil@baymountain.com> writes:
> > > >> Not yet, the db is in production use and I have to plan for a down-time
> > > >> for that... or is it not impacting the activity on the table ?
> > > 
> > > > It will cause some performance hit while you are doing it.
> > > 
> > > It'll also lock out writes on the table until the index is rebuilt,
> > > so he does need to schedule downtime.
> > > 
> > > 			regards, tom lane
> > > 
> > > ---------------------------(end of broadcast)---------------------------
> > > TIP 1: if posting/reading through Usenet, please send an appropriate
> > >        subscribe-nomail command to majordomo@postgresql.org so that your
> > >        message can get through to the mailing list cleanly
> > 
> > 
> > ---------------------------(end of broadcast)---------------------------
> > TIP 5: don't forget to increase your free space map settings


From pgsql-performance-owner@postgresql.org  Tue Oct 18 13:48:25 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 222FBD85DC
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 18 Oct 2005 13:48:13 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 05837-09
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 18 Oct 2005 16:48:11 +0000 (GMT)
Received: from smtp102.rog.mail.re2.yahoo.com (smtp102.rog.mail.re2.yahoo.com
	[206.190.36.80])
	by svr1.postgresql.org (Postfix) with SMTP id 269F7D82C2
	for <pgsql-performance@postgresql.org>;
	Tue, 18 Oct 2005 13:48:10 -0300 (ADT)
Received: (qmail 42994 invoked from network); 18 Oct 2005 16:48:07 -0000
Received: from unknown (HELO phlogiston.dydns.org)
	(a.sullivan@rogers.com@209.222.54.227 with login)
	by smtp102.rog.mail.re2.yahoo.com with SMTP; 18 Oct 2005 16:48:07 -0000
Received: by phlogiston.dydns.org (Postfix, from userid 1000)
	id 0F4DA40E6; Tue, 18 Oct 2005 12:48:06 -0400 (EDT)
Date: Tue, 18 Oct 2005 12:48:06 -0400
From: Andrew Sullivan <ajs@crankycanuck.ca>
To: pgsql-performance@postgresql.org
Subject: Re: Help tuning postgres
Message-ID: <20051018164806.GH3441@phlogiston.dyndns.org>
References: <1129128315.2995.174.camel@coppola.muc.ecircle.de>
	<f3c0b4080510120939x6c08feebvfad37c98df306538@mail.gmail.com>
	<1129136130.2995.188.camel@coppola.muc.ecircle.de>
	<20051012220036.GE13571@phlogiston.dyndns.org>
	<1129191303.2995.192.camel@coppola.muc.ecircle.de>
	<20051013124007.GA15592@phlogiston.dyndns.org>
	<1129648896.27587.22.camel@coppola.muc.ecircle.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <1129648896.27587.22.camel@coppola.muc.ecircle.de>
User-Agent: Mutt/1.5.9i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.033 required=5 tests=[AWL=-0.017,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/265
X-Sequence-Number: 15033

On Tue, Oct 18, 2005 at 05:21:37PM +0200, Csaba Nagy wrote:
> INFO:  vacuuming "public.some_table"
> INFO:  "some_table": removed 29598 row versions in 452 pages
> DETAIL:  CPU 0.01s/0.04u sec elapsed 18.77 sec.
> INFO:  "some_table": found 29598 removable, 39684 nonremovable row
> versions in 851 pages
> DETAIL:  0 dead row versions cannot be removed yet.

> Does that mean that 39684 nonremovable pages are actually the active
> live pages in the table (as it reports 0 dead) ? I'm sure I don't have
> any long running transaction, at least according to pg_stats_activity
> (backed by the linux ps too). Or I should run a vacuum full...
> 
> This table is one of which has frequently updated rows.

No, you should be ok there.  What that should tell you is that you
have about 40,000 rows in the table.  But notice that your vacuum
process just removed about 75% of the live table rows.  Moreover,
your 39684 rows are taking 851 pages.  On a standard installation,
that's usually 8Kb/page.  So that's about 6,808 Kb of physical
storage space you're using.  Is that consistent with the size of your
data?  If it's very large compared to the data you have stored in
there, you may want to ask if you're "leaking" space from the free
space map (because of that table turnover, which seems pretty
severe).

A

-- 
Andrew Sullivan  | ajs@crankycanuck.ca
The whole tendency of modern prose is away from concreteness.
		--George Orwell

From pgsql-performance-owner@postgresql.org  Tue Oct 18 15:07:15 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id E4965D94DD
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 18 Oct 2005 15:07:14 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 33477-07
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 18 Oct 2005 18:07:11 +0000 (GMT)
Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.205])
	by svr1.postgresql.org (Postfix) with ESMTP id 086D2D934A
	for <pgsql-performance@postgresql.org>;
	Tue, 18 Oct 2005 15:07:11 -0300 (ADT)
Received: by wproxy.gmail.com with SMTP id i5so73225wra
	for <pgsql-performance@postgresql.org>;
	Tue, 18 Oct 2005 11:07:13 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:to:subject:mime-version:content-type;
	b=iKa2NqenOAZb2NJzTYKS9zRrKJKm5S1RhSMd8gTP47TkRo7dsmhizjw2gQY19Ft6u7zBiq13/8ZQN0Nm5JvpxWDuTpQJnSMO96uUh1w/OzGdzav9kicWDlys4o1l3iR5GnCMv7eE1dAmip1Vb01l4JXND64F0cCXKvW30nUlnVU=
Received: by 10.54.94.16 with SMTP id r16mr232542wrb;
	Tue, 18 Oct 2005 11:07:12 -0700 (PDT)
Received: by 10.54.95.19 with HTTP; Tue, 18 Oct 2005 11:07:12 -0700 (PDT)
Message-ID: <3cf983d0510181107sb060171je702da5fe0c29252@mail.gmail.com>
Date: Tue, 18 Oct 2005 18:07:12 +0000
From: Rodrigo Madera <rodrigo.madera@gmail.com>
To: pgsql-performance@postgresql.org
Subject: Inefficient escape codes.
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="----=_Part_15569_18150319.1129658832979"
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.137 required=5 tests=[AWL=-0.026, HTML_00_10=0.138,
	HTML_MESSAGE=0.001, RCVD_BY_IP=0.024]
X-Spam-Level: 
X-Archive-Number: 200510/266
X-Sequence-Number: 15034

------=_Part_15569_18150319.1129658832979
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Hello there,

This is my first post in the list. I have a deep low-level background on
computer programming, but I am totally newbie to sql databases. I am using
postgres because of its commercial license.

My problem is with storing large values. I have a database that stores larg=
e
ammounts of data (each row consisting of up to 5MB). After carefully readin=
g
the Postgres 8.0 manual (the version I'm using), I was told that the best
option was to create a bytea field.

Large objects are out of the line here since we have lots of tables.

As I understand it, the client needs to put the data into the server using =
a
textual-based command. This makes the 5MB data grow up-to 5x, making it 25M=
B
in the worst case. (Example: 0x01 -> \\001).

My question is:

1) Is there any way for me to send the binary field directly without needin=
g
escape codes?
2) Will this mean that the client actually wastes my network bandwidth
converting binary data to text? Or does the client transparently manage
this?

Thanks for any light on the subject,
Rodrigo

------=_Part_15569_18150319.1129658832979
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Hello there,<br>
<br>
This is my first post in the list. I have a deep low-level background
on computer programming, but I am totally newbie to sql databases. I am
using postgres because of its commercial license.<br>
<br>
My problem is with storing large values. I have a database that stores
large ammounts of data (each row consisting of up to 5MB). After
carefully reading the Postgres 8.0 manual (the version I'm using), I
was told that the best option was to create a bytea field.<br>
<br>
Large objects are out of the line here since we have lots of tables.<br>
<br>
As I understand it, the client needs to put the data into the server
using a textual-based command. This makes the 5MB data grow up-to 5x,
making it 25MB in the worst case. (Example: 0x01 -&gt; \\001).<br>
<br>
My question is:<br>
<br>
1) Is there any way for me to send the binary field directly without needin=
g escape codes?<br>
2) Will this mean that the client actually wastes my network bandwidth
converting binary data to text? Or does the client transparently manage
this?<br>
<br>
Thanks for any light on the subject,<br>
Rodrigo<br>
<br>

------=_Part_15569_18150319.1129658832979--

From pgsql-performance-owner@postgresql.org  Tue Oct 18 16:03:46 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 12FABD70A2
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 18 Oct 2005 16:03:45 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 42837-04
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 18 Oct 2005 19:03:41 +0000 (GMT)
Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158])
	by svr1.postgresql.org (Postfix) with ESMTP id 1DE1ED6ED4
	for <pgsql-performance@postgresql.org>;
	Tue, 18 Oct 2005 16:03:41 -0300 (ADT)
Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1])
	by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id j9IJ3Pub093362
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);
	Tue, 18 Oct 2005 13:03:27 -0600 (MDT)
	(envelope-from mfuhr@winnie.fuhr.org)
Received: from winnie.fuhr.org (localhost [127.0.0.1])
	by winnie.fuhr.org (8.13.4/8.13.4) with ESMTP id j9IJ3P2f092803;
	Tue, 18 Oct 2005 13:03:25 -0600 (MDT)
	(envelope-from mfuhr@winnie.fuhr.org)
Received: (from mfuhr@localhost)
	by winnie.fuhr.org (8.13.4/8.13.4/Submit) id j9IJ3OST092802;
	Tue, 18 Oct 2005 13:03:24 -0600 (MDT) (envelope-from mfuhr)
Date: Tue, 18 Oct 2005 13:03:24 -0600
From: Michael Fuhr <mike@fuhr.org>
To: Rodrigo Madera <rodrigo.madera@gmail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Inefficient escape codes.
Message-ID: <20051018190324.GA92715@winnie.fuhr.org>
References: <3cf983d0510181107sb060171je702da5fe0c29252@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <3cf983d0510181107sb060171je702da5fe0c29252@mail.gmail.com>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/267
X-Sequence-Number: 15035

On Tue, Oct 18, 2005 at 06:07:12PM +0000, Rodrigo Madera wrote:
> 1) Is there any way for me to send the binary field directly without needing
> escape codes?

In 7.4 and later the client/server protocol supports binary data
transfer.  If you're programming with libpq you can use PQexecParams()
to send and/or retrieve values in binary instead of text.

http://www.postgresql.org/docs/8.0/interactive/libpq-exec.html#LIBPQ-EXEC-MAIN

APIs built on top of libpq or that implement the protcol themselves
might provide hooks to this capability; check your documentation.
What language and API are you using?

See also COPY BINARY:

http://www.postgresql.org/docs/8.0/interactive/sql-copy.html

> 2) Will this mean that the client actually wastes my network bandwidth
> converting binary data to text? Or does the client transparently manage
> this?

Binary transfer sends data in binary, not by automatically converting
to and from text.

-- 
Michael Fuhr

From pgsql-performance-owner@postgresql.org  Tue Oct 18 18:11:01 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id D629AD8DD1
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 18 Oct 2005 17:47:34 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 06272-10
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 18 Oct 2005 20:47:31 +0000 (GMT)
Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158])
	by svr1.postgresql.org (Postfix) with ESMTP id A5216D84C6
	for <pgsql-performance@postgresql.org>;
	Tue, 18 Oct 2005 17:47:32 -0300 (ADT)
Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1])
	by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id j9IKlStN093437
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);
	Tue, 18 Oct 2005 14:47:31 -0600 (MDT)
	(envelope-from mfuhr@winnie.fuhr.org)
Received: from winnie.fuhr.org (localhost [127.0.0.1])
	by winnie.fuhr.org (8.13.4/8.13.4) with ESMTP id j9IKlSLo029348;
	Tue, 18 Oct 2005 14:47:28 -0600 (MDT)
	(envelope-from mfuhr@winnie.fuhr.org)
Received: (from mfuhr@localhost)
	by winnie.fuhr.org (8.13.4/8.13.4/Submit) id j9IKlR3Z029347;
	Tue, 18 Oct 2005 14:47:27 -0600 (MDT) (envelope-from mfuhr)
Date: Tue, 18 Oct 2005 14:47:27 -0600
From: Michael Fuhr <mike@fuhr.org>
To: Rodrigo Madera <rodrigo.madera@gmail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Inefficient escape codes.
Message-ID: <20051018204727.GA29110@winnie.fuhr.org>
Reply-To: pgsql-performance@postgresql.org
References: <3cf983d0510181107sb060171je702da5fe0c29252@mail.gmail.com>
	<20051018190324.GA92715@winnie.fuhr.org>
	<3cf983d0510181209v3070a81dw9b21d4d09cbb5022@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <3cf983d0510181209v3070a81dw9b21d4d09cbb5022@mail.gmail.com>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/268
X-Sequence-Number: 15036

[Please copy the mailing list on replies so others can participate
in and learn from the discussion.]

On Tue, Oct 18, 2005 at 07:09:08PM +0000, Rodrigo Madera wrote:
> > What language and API are you using?
> 
> I'm using libpqxx. A nice STL-style library for C++ (I am 101% C++).

I've only dabbled with libpqxx; I don't know if or how you can make
it send data in binary instead of text.  See the documentation or
ask in a mailing list like libpqxx-general or pgsql-interfaces.

> > Binary transfer sends data in binary, not by automatically converting
> > to and from text.
> 
> Uh, I'm sorry I didn't get that... If I send: insert into foo
> values('\\001\\002') will libpq send 0x01, 0x02 or "\\\\001\\\\002"??

If you do it that way libpq will send the string as text with escape
sequences; you can use a sniffer like tcpdump or ethereal to see this
for yourself.  To send the data in binary you'd call PQexecParams()
with a query like "INSERT INTO foo VALUES ($1)".  The $1 is a
placeholder; the other arguments to PQexecParams() provide the data
itself, the data type and length, and specify whether the data is in
text format or binary.  See the libpq documentation for details.

-- 
Michael Fuhr

From pgsql-performance-owner@postgresql.org  Wed Oct 19 04:19:07 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 95748DA027
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 19 Oct 2005 04:19:05 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 59843-06
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 19 Oct 2005 07:19:03 +0000 (GMT)
Received: from qproxy.gmail.com (qproxy.gmail.com [72.14.204.197])
	by svr1.postgresql.org (Postfix) with ESMTP id AFA64D9FFA
	for <pgsql-performance@postgresql.org>;
	Wed, 19 Oct 2005 04:19:03 -0300 (ADT)
Received: by qproxy.gmail.com with SMTP id v40so23300qbe
	for <pgsql-performance@postgresql.org>;
	Wed, 19 Oct 2005 00:19:05 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references;
	b=RaHJ+iokc78r4xDvoO7SMCFqAXnBzIOlTcClRGKL+H+1MUceOapKkqZZFTwpmmZoQ3ZNOP8dRPy/yLo1gB7/ANhjmYmR2qsrGhWKk2VdpqqWHY93YRumcB5+Zv9rJkT/n1/TJzrVlbub1yN8z5gmCXmOZg+/dv+FhTMdcsHx+xI=
Received: by 10.65.188.4 with SMTP id q4mr255509qbp;
	Wed, 19 Oct 2005 00:19:05 -0700 (PDT)
Received: by 10.64.232.11 with HTTP; Wed, 19 Oct 2005 00:19:04 -0700 (PDT)
Message-ID: <a2de01dd0510190019v54de5097i@mail.gmail.com>
Date: Wed, 19 Oct 2005 08:19:04 +0100
From: Peter Childs <peterachilds@gmail.com>
To: pgsql-performance@postgresql.org
Subject: Re: Inefficient escape codes.
In-Reply-To: <20051018204727.GA29110@winnie.fuhr.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
References: <3cf983d0510181107sb060171je702da5fe0c29252@mail.gmail.com>
	<20051018190324.GA92715@winnie.fuhr.org>
	<3cf983d0510181209v3070a81dw9b21d4d09cbb5022@mail.gmail.com>
	<20051018204727.GA29110@winnie.fuhr.org>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=1.856 required=5 tests=[RCVD_BY_IP=0.024,
	RCVD_IN_BL_SPAMCOP_NET=1.832]
X-Spam-Level: *
X-Archive-Number: 200510/269
X-Sequence-Number: 15037

On 18/10/05, Michael Fuhr <mike@fuhr.org> wrote:
> [Please copy the mailing list on replies so others can participate
> in and learn from the discussion.]
>
> On Tue, Oct 18, 2005 at 07:09:08PM +0000, Rodrigo Madera wrote:
> > > What language and API are you using?
> >
> > I'm using libpqxx. A nice STL-style library for C++ (I am 101% C++).
>
> I've only dabbled with libpqxx; I don't know if or how you can make
> it send data in binary instead of text.  See the documentation or
> ask in a mailing list like libpqxx-general or pgsql-interfaces.
>
> > > Binary transfer sends data in binary, not by automatically converting
> > > to and from text.
> >
> > Uh, I'm sorry I didn't get that... If I send: insert into foo
> > values('\\001\\002') will libpq send 0x01, 0x02 or "\\\\001\\\\002"??
>
> If you do it that way libpq will send the string as text with escape
> sequences; you can use a sniffer like tcpdump or ethereal to see this
> for yourself.  To send the data in binary you'd call PQexecParams()
> with a query like "INSERT INTO foo VALUES ($1)".  The $1 is a
> placeholder; the other arguments to PQexecParams() provide the data
> itself, the data type and length, and specify whether the data is in
> text format or binary.  See the libpq documentation for details.
>

You could base64 encode your data admitiaddly increasing it by 1/3 but
it does at least convert it to text which means that its more
unserstandable. base64 is also pritty standard being whats used in
EMails for mime attachments.

Peter

From pgsql-performance-owner@postgresql.org  Mon Oct 24 23:50:01 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 94CABDA127;
	Wed, 19 Oct 2005 11:52:11 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 28517-03; Wed, 19 Oct 2005 14:52:05 +0000 (GMT)
Received: from floppy.pyrenet.fr (floppy.pyrenet.fr [194.116.145.2])
	by svr1.postgresql.org (Postfix) with ESMTP id BE6F3D8379;
	Wed, 19 Oct 2005 11:52:07 -0300 (ADT)
Received: by floppy.pyrenet.fr (Postfix, from userid 106)
	id 3CB4C31059; Wed, 19 Oct 2005 16:52:12 +0200 (MET DST)
From: Katherine Stoovs <ambrosiac@nedsenta.nl>
X-Newsgroups: pgsql.hackers, pgsql.performance
Subject: tuning seqscan costs
Followup-To: pgsql.hackers
Date: Wed, 19 Oct 2005 14:51:55 +0000 (UTC)
Organization: Aioe.org NNTP Server
Lines: 29
Message-ID: <dj5gjc$q0g$1@news.host.net>
X-Complaints-To: abuse@aioe.org
User-Agent: slrn/0.9.8.1pl1 (Linux)
To: pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0 required=5 tests=[none]
X-Spam-Level: 
X-Archive-Number: 200510/343
X-Sequence-Number: 15111

I want to correlate two index rows of different tables to find an
offset so that

table1.value = table2.value AND table1.id = table2.id + offset

is true for a maximum number of rows.

To achieve this, I have the two tables and a table with possible
offset values and execute a query:

SELECT value,(SELECT COUNT(*) FROM table1,table2
                              WHERE table1.value = table2.value AND
                                    table1.id = table2.id + offset)
             AS matches FROM offsets ORDER BY matches;

The query is very inefficient, however, because the planner doesn't
use my indexes and executes seqscans instead. I can get it to execute
fast by setting ENABLE_SEQSCAN to OFF, but I have read this will make
the performance bad on other query types so I want to know how to
tweak the planner costs or possibly other stats so the planner will
plan the query correctly and use index scans. There must be something
wrong in the planning parameters after all if a plan that is slower by
a factor of tens or hundreds becomes estimated better than the fast
variant.

I have already issued ANALYZE commands on the tables.

Thanks for your help,
Katherine Stoovs

From pgsql-performance-owner@postgresql.org  Wed Oct 19 11:54:20 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 6C6BDDA2E2
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 19 Oct 2005 11:54:19 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 19682-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 19 Oct 2005 14:54:15 +0000 (GMT)
Received: from Herge.rcsinc.local (mail.rcsonline.com [70.89.208.142])
	by svr1.postgresql.org (Postfix) with ESMTP id 4DB3CDA283
	for <pgsql-performance@postgresql.org>;
	Wed, 19 Oct 2005 11:54:16 -0300 (ADT)
X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0
Content-class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Subject: Re: Inefficient escape codes.
Date: Wed, 19 Oct 2005 10:54:21 -0400
Message-ID: <6EE64EF3AB31D5448D0007DD34EEB3417DD61D@Herge.rcsinc.local>
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
Thread-Topic: [PERFORM] Inefficient escape codes.
Thread-Index: AcXUD4yTx0/swSCyRj62JFtk9nSACwAqWyWg
From: "Merlin Moncure" <merlin.moncure@rcsonline.com>
To: "Rodrigo Madera" <rodrigo.madera@gmail.com>
Cc: <pgsql-performance@postgresql.org>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.07 required=5 tests=[AWL=0.020,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/270
X-Sequence-Number: 15038

Rodrigo wrote:
$$
As I understand it, the client needs to put the data into the server
using a textual-based command. This makes the 5MB data grow up-to 5x,
making it 25MB in the worst case. (Example: 0x01 -> \\001).

My question is:

1) Is there any way for me to send the binary field directly without
needing escape codes?
2) Will this mean that the client actually wastes my network bandwidth
converting binary data to text? Or does the client transparently manage
this?
$$ [snip]

I think the fastest, most efficient binary transfer of data to
PostgreSQL via C++ is a STL wrapper to libpq.  Previously I would not
have recommended libqpxx for this purpose although this may have changed
with the later releases.  As others have commented you most certainly
want to do this with the ExecParams/ExecPrepared interface.  If you want
to exclusively use libqxx then you need to find out if it exposes/wraps
this function (IIRC libpqxx build on top of libpq).

You can of course 'roll your own' libpq wrapper via STL pretty easily.
For example, here is how I am making my SQL calls from my COBOL apps:

typedef vector<string>      stmt_param_strings;
typedef vector<int>         stmt_param_lengths;
typedef vector<const char*> stmt_param_values;
typedef vector<int>         stmt_param_formats;

[...]

res =3D PQexecPrepared(	_connection,=20
				stmt.c_str(),=20
				num_params,=20
				&param_values[0],=20
				&param_lengths[0],=20
				&param_formats[0],=20
				result_format);

Executing data this way is a direct data injection to/from the server,
no parsing/unparsing, no plan generating, etc.  Also STL vectors play
very nice with the libpq interface because it takes unterminated stings.


Merlin





From pgsql-performance-owner@postgresql.org  Wed Oct 19 14:45:52 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 85E86DA579
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 19 Oct 2005 14:45:50 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 79211-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 19 Oct 2005 17:45:46 +0000 (GMT)
Received: from cassarossa.samfundet.no (cassarossa.samfundet.no
	[129.241.93.19])
	by svr1.postgresql.org (Postfix) with ESMTP id 3EE57D9214
	for <pgsql-performance@postgresql.org>;
	Wed, 19 Oct 2005 14:45:45 -0300 (ADT)
Received: from sesse by cassarossa.samfundet.no with local (Exim 4.50)
	id 1ESI0W-0000JP-S4
	for pgsql-performance@postgresql.org; Wed, 19 Oct 2005 19:45:44 +0200
Date: Wed, 19 Oct 2005 19:45:44 +0200
From: "Steinar H. Gunderson" <sgunderson@bigfoot.com>
To: pgsql-performance@postgresql.org
Subject: Materializing a sequential scan
Message-ID: <20051019174544.GA32303@samfundet.no>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
User-Agent: Mutt/1.5.9i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.012 required=5 tests=[AWL=0.012]
X-Spam-Level: 
X-Archive-Number: 200510/271
X-Sequence-Number: 15039

Hi,

I'm using PostgreSQL 8.1 beta 3 (packages from Debian experimental), and I
have a (rather complex) query that seems to take forever -- when the database
was just installed, it took about 1200ms (which is quite good, considering
that the 7.4 system this runs on today uses about the same time, but has
twice as much CPU power and runs sequential scans up to eight times as fast),
but now I can never even get it to complete. I've tried running it for half
an hour, but it still doesn't complete, so I'm a bit unsure what's going on.

There's a _lot_ of tables and views in here, several hundres lines of SQL,
but experience tells me that posting more is better than posting less, so
here goes. (The data is unfortunately not public since it contains PIN codes
and such, but if anybody asks I can probably send it off-list. It's ~30MB in
plain pg_dump, though.) There might be a few tables that aren't referenced,
but I don't really know a good way to figure out such dependencies
automatically, and I'd guess most of them _are_ used :-) Apologies in advance
for the Norwegian in the names.

=== cut here ===

CREATE TABLE gruppetype (
    gruppetype_id integer NOT NULL PRIMARY KEY,
    gruppetype varchar
);
CREATE TABLE gruppe (
    gruppe_id serial NOT NULL PRIMARY KEY,
    gruppe varchar NOT NULL,
    beskrivelse varchar,
    gruppetype_id integer DEFAULT 1 NOT NULL REFERENCES gruppetype,
    adminacl varchar,
    aktiv boolean default 't' NOT NULL
);
CREATE TABLE adgangsskjema (
    adgangsskjema_id serial NOT NULL PRIMARY KEY,
    navn varchar NOT NULL,
    rita_navn varchar NOT NULL
);
CREATE TABLE adgangsskjema_gruppe_kobling (
    gruppe_id integer NOT NULL REFERENCES gruppe (gruppe_id),
    adgangsskjema_id integer NOT NULL REFERENCES adgangsskjema (adgangsskjema_id),
    PRIMARY KEY (adgangsskjema_id, gruppe_id)
);
CREATE TABLE kortstatus (
    kortstatus_id smallint NOT NULL PRIMARY KEY,
    kortstatus varchar
);
CREATE TABLE korttype (
    korttype_id serial NOT NULL PRIMARY KEY,
    korttype varchar NOT NULL,
    beskrivelse varchar
);
CREATE TABLE medlemstatus (
    medlemstatus_id serial NOT NULL PRIMARY KEY,
    medlemstatus varchar NOT NULL,
    beskrivelse varchar
);
CREATE TABLE oblattype (
    oblattype_id serial NOT NULL PRIMARY KEY,
    oblattype varchar NOT NULL,
    varighet interval NOT NULL
);
CREATE TABLE skole (
    skole_id serial NOT NULL PRIMARY KEY,
    skole varchar NOT NULL,
    beskrivelse varchar
);
CREATE TABLE studie (
    studie_id serial NOT NULL PRIMARY KEY,
    studie varchar NOT NULL,
    beskrivelse varchar
);
CREATE TABLE poststed (
    postnummer smallint NOT NULL PRIMARY KEY CHECK (postnummer >= 0 AND postnummer <= 9999),
    poststed varchar
);
CREATE TABLE gruppekobling (
    overgruppe_id integer NOT NULL REFERENCES gruppe (gruppe_id),
    undergruppe_id integer NOT NULL REFERENCES gruppe (gruppe_id),
    PRIMARY KEY (overgruppe_id, undergruppe_id)
);
CREATE TABLE medlem (
    medlem_id serial NOT NULL PRIMARY KEY CHECK (medlem_id > 0),
    fornavn varchar NOT NULL,
    etternavn varchar NOT NULL,
    hjemadresse varchar,
    hjem_postnummer smallint REFERENCES poststed (postnummer),
    studieadresse varchar,
    studie_postnummer smallint REFERENCES poststed (postnummer),
    fodselsdato date,
    telefon varchar,
    mail varchar UNIQUE,
    passord character(32) NOT NULL,
    registrert date DEFAULT now(),
    oppdatert date DEFAULT now(),
    skole_id integer REFERENCES skole,
    studie_id integer REFERENCES studie,
    medlemstatus_id integer DEFAULT 1 NOT NULL REFERENCES medlemstatus,
    pinkode smallint CHECK ((pinkode >= 0 AND pinkode <= 9999) OR pinkode IS NULL),
    UNIQUE ( LOWER(mail) )
);
CREATE TABLE kort (
    kortnummer integer NOT NULL PRIMARY KEY CHECK (kortnummer > 0),
    medlem_id integer REFERENCES medlem DEFERRABLE,
    korttype_id integer DEFAULT 1 NOT NULL REFERENCES korttype,
    serie_registrert date DEFAULT now() NOT NULL,
    bruker_registrert date,
    kortstatus_id integer DEFAULT 1 NOT NULL REFERENCES kortstatus
);
CREATE TABLE oblat (
    oblatnummer integer NOT NULL PRIMARY KEY CHECK (oblatnummer > 0),
    oblattype_id integer NOT NULL REFERENCES oblattype,
    "start" date NOT NULL,
    kortnummer integer REFERENCES kort,
    bruker_registrert date,
    serie_registrert date DEFAULT NOW() NOT NULL
);
CREATE TABLE verv (
    medlem_id integer NOT NULL REFERENCES medlem,
    gruppe_id integer NOT NULL REFERENCES gruppe,
    "start" date DEFAULT now() NOT NULL,
    stopp date,

    CHECK ( stopp >= start ),
    PRIMARY KEY ( medlem_id, gruppe_id, "start" )
);
CREATE TABLE nytt_passord (
    medlem_id integer NOT NULL REFERENCES medlem,
    hash varchar NOT NULL,
    tidspunkt date DEFAULT now() NOT NULL
);
CREATE VIEW gyldige_medlemskap AS
	SELECT medlem_id,MAX("start"+varighet) AS stopp
	  FROM kort
	  JOIN oblat ON kort.kortnummer=oblat.kortnummer
	  NATURAL JOIN oblattype
	WHERE kortstatus_id=1
	AND medlem_id IS NOT NULL
	GROUP BY medlem_id
	HAVING MAX("start"+varighet) >= current_date;

CREATE SCHEMA kortsys2;

CREATE FUNCTION kortsys2.effektiv_dato(date) RETURNS date
AS
	'SELECT CASE WHEN $1 < CURRENT_DATE THEN CURRENT_DATE ELSE $1 END'
LANGUAGE SQL STABLE;

CREATE VIEW kortsys2.mdb_personer AS
  SELECT * FROM (
    SELECT DISTINCT ON (medlem_id) medlem_id,fornavn,etternavn,mail,pinkode,kort.kortnummer AS kortnummer
      FROM medlem
        NATURAL JOIN kort                        -- the member must have an ID card
      WHERE
        kortstatus_id=1                          -- the card must be active
        AND korttype_id IN (2,3)                 -- the card must be an ID card or UKA ID card
        AND pinkode IS NOT NULL                  -- the member must have a PIN
        AND medlem_id IN (                       -- the member must be active in at least one group
          SELECT medlem_id
  	  FROM verv
  	  WHERE stopp IS NULL OR stopp >= current_date
        )
        AND medlem_id IN (                       -- the member must have a valid membership
          SELECT medlem_id FROM gyldige_medlemskap
        )
      ORDER BY
        medlem_id,                               -- needed for the DISTINCT
        korttype_id                              -- prioritize ID cards over UKA ID cards
  ) AS t1
  UNION ALL
  SELECT * FROM eksterne_kort.eksterne_personer;
  
CREATE TABLE kortsys2.rita_personer (
	medlem_id integer PRIMARY KEY NOT NULL,
	fornavn varchar NOT NULL,
	etternavn varchar NOT NULL,
	mail varchar NOT NULL,
	pinkode smallint NOT NULL CHECK (pinkode >= 0 AND pinkode <= 9999),
	kortnummer integer UNIQUE NOT NULL
);
CREATE TABLE kortsys2.personer_tving_sletting (
	medlem_id integer PRIMARY KEY NOT NULL
);
CREATE VIEW kortsys2.personer_skal_slettes AS
	SELECT medlem_id
	  FROM kortsys2.rita_personer
	  WHERE (medlem_id,pinkode,kortnummer) NOT IN (
	    SELECT medlem_id,pinkode,kortnummer
	      FROM kortsys2.mdb_personer
	  )
	UNION
	  SELECT medlem_id
	  FROM kortsys2.personer_tving_sletting;

CREATE TABLE kortsys2.personer_nylig_slettet (
	medlem_id integer PRIMARY KEY NOT NULL
);

CREATE VIEW kortsys2.personer_skal_eksporteres AS
        SELECT *
          FROM kortsys2.mdb_personer
          WHERE medlem_id NOT IN (
            SELECT medlem_id FROM kortsys2.rita_personer
          )
	  AND medlem_id NOT IN (
	    SELECT medlem_id FROM kortsys2.personer_nylig_slettet
	  );

CREATE TABLE kortsys2.mdb_gruppekobling_temp (
	overgruppe_id INTEGER NOT NULL,
	undergruppe_id INTEGER NOT NULL
);

CREATE OR REPLACE FUNCTION kortsys2.mdb_gruppekobling_transitiv_tillukning() RETURNS SETOF gruppekobling AS
'
DECLARE
	r RECORD;
BEGIN
	INSERT INTO kortsys2.mdb_gruppekobling_temp
	SELECT overgruppe_id,undergruppe_id FROM gruppekobling gk
		JOIN gruppe g1 ON gk.overgruppe_id=g1.gruppe_id
		JOIN gruppe g2 ON gk.overgruppe_id=g2.gruppe_id
		WHERE g1.aktiv AND g2.aktiv;
	LOOP
		INSERT INTO kortsys2.mdb_gruppekobling_temp
		SELECT g1.overgruppe_id, g2.undergruppe_id
		    FROM kortsys2.mdb_gruppekobling_temp g1
		    JOIN kortsys2.mdb_gruppekobling_temp g2
		        ON g1.undergruppe_id=g2.overgruppe_id
		WHERE (g1.overgruppe_id, g2.undergruppe_id) NOT IN (
			SELECT * FROM kortsys2.mdb_gruppekobling_temp
		);
		EXIT WHEN NOT FOUND;
	END LOOP;
	FOR r IN SELECT * from kortsys2.mdb_gruppekobling_temp LOOP
		RETURN NEXT r;
	END LOOP;
        DELETE FROM kortsys2.mdb_gruppekobling_temp;
	RETURN;
END;
' LANGUAGE plpgsql;

CREATE VIEW kortsys2.mdb_gruppetilgang AS
	SELECT DISTINCT
		gk.undergruppe_id AS gruppe_id,
		rita_navn
	FROM (
		SELECT * FROM mdb_gruppekobling_transitiv_tillukning()
		UNION SELECT gruppe_id,gruppe_id FROM gruppe WHERE aktiv 
	) gk 
	JOIN adgangsskjema_gruppe_kobling ak ON gk.overgruppe_id=ak.gruppe_id
	NATURAL JOIN adgangsskjema; 

CREATE VIEW kortsys2.mdb_tilgang AS
 SELECT
   t1.medlem_id AS medlem_id,
   rita_navn,
   "start",
   CASE WHEN m_stopp < stopp OR stopp IS NULL THEN m_stopp ELSE stopp END AS stopp 
   FROM (    
     SELECT
       medlem_id,
       gruppe_id,
       ms.stopp AS m_stopp,
       MIN("start") AS start,
       MAX(v.stopp) AS stopp
     FROM (
       SELECT * FROM verv
         UNION ALL
       SELECT * FROM eksterne_kort.vervekvivalens
     ) v
     JOIN (
       SELECT * FROM gyldige_medlemskap ms
         UNION ALL
       SELECT medlem_id,stopp FROM eksterne_kort.vervekvivalens
     ) ms
     USING (medlem_id)
        
     WHERE ( v.stopp IS NULL OR v.stopp >= current_date ) 
     GROUP BY medlem_id,gruppe_id,ms.stopp
   ) t1
   JOIN mdb_gruppetilgang gt ON t1.gruppe_id=gt.gruppe_id
   WHERE medlem_id IN (
     SELECT medlem_id FROM mdb_personer
   )
;

CREATE VIEW kortsys2.mdb_effektiv_tilgang AS
	SELECT
	  medlem_id,
	  rita_navn,
	  MIN("start") AS "start",
	  MAX(stopp) AS stopp
	FROM kortsys2.mdb_tilgang
	GROUP BY medlem_id,rita_navn
	HAVING MAX(stopp) >= current_date;

CREATE TABLE kortsys2.rita_tilgang (
	medlem_id integer NOT NULL REFERENCES kortsys2.rita_personer,
	rita_navn varchar NOT NULL,
	"start" date NOT NULL,
	stopp date NOT NULL,

	PRIMARY KEY ( medlem_id, rita_navn )
);

CREATE VIEW kortsys2.tilganger_skal_slettes AS
	SELECT * FROM kortsys2.rita_tilgang
	  WHERE medlem_id NOT IN (
	    SELECT medlem_id FROM kortsys2.personer_nylig_slettet
	  )
	  AND (medlem_id,rita_navn,kortsys2.effektiv_dato("start"),stopp) NOT IN (
	    SELECT medlem_id,rita_navn,kortsys2.effektiv_dato("start"),stopp FROM kortsys2.mdb_effektiv_tilgang
	  );

CREATE VIEW kortsys2.tilganger_skal_gis AS
	SELECT medlem_id,rita_navn,"start",stopp
	FROM kortsys2.mdb_effektiv_tilgang
	  WHERE medlem_id NOT IN (
	    SELECT medlem_id FROM kortsys2.personer_nylig_slettet
	  )
	  AND (medlem_id,rita_navn,kortsys2.effektiv_dato("start"),stopp) NOT IN (
	    SELECT medlem_id,rita_navn,kortsys2.effektiv_dato("start"),stopp FROM kortsys2.rita_tilgang
	  );

=== cut here ===

Now for the simple query:

  mdb2_jodal=# explain select * from kortsys2.tilganger_skal_gis ;

and the monster of a query plan (no EXPLAIN ANALYZE because, well, it never
finishes):
                                                                                                            QUERY PLAN                                                                                                            
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Subquery Scan mdb_effektiv_tilgang  (cost=19821.69..4920621.69 rows=10000 width=48)
   Filter: ((NOT (hashed subplan)) AND (NOT (subplan)))
   ->  HashAggregate  (cost=19238.48..20838.48 rows=40000 width=52)
         Filter: (max(CASE WHEN ((m_stopp < (stopp)::timestamp without time zone) OR (stopp IS NULL)) THEN m_stopp ELSE (stopp)::timestamp without time zone END) >= (('now'::text)::date)::timestamp without time zone)
         ->  Merge Join  (cost=12231.86..16091.27 rows=251777 width=52)
               Merge Cond: ("outer".gruppe_id = "inner".gruppe_id)
               ->  Unique  (cost=483.64..514.68 rows=4138 width=30)
                     ->  Sort  (cost=483.64..493.99 rows=4138 width=30)
                           Sort Key: gk.undergruppe_id, adgangsskjema.rita_navn
                           ->  Merge Join  (cost=149.81..235.06 rows=4138 width=30)
                                 Merge Cond: ("outer".overgruppe_id = "inner".gruppe_id)
                                 ->  Unique  (cost=92.52..101.21 rows=1159 width=8)
                                       ->  Sort  (cost=92.52..95.41 rows=1159 width=8)
                                             Sort Key: overgruppe_id, undergruppe_id
                                             ->  Append  (cost=0.00..33.53 rows=1159 width=8)
                                                   ->  Function Scan on mdb_gruppekobling_transitiv_tillukning  (cost=0.00..12.50 rows=1000 width=8)
                                                   ->  Seq Scan on gruppe  (cost=0.00..9.44 rows=159 width=4)
                                                         Filter: aktiv
                                 ->  Sort  (cost=57.29..59.08 rows=714 width=30)
                                       Sort Key: ak.gruppe_id
                                       ->  Hash Join  (cost=1.60..23.45 rows=714 width=30)
                                             Hash Cond: ("outer".adgangsskjema_id = "inner".adgangsskjema_id)
                                             ->  Seq Scan on adgangsskjema_gruppe_kobling ak  (cost=0.00..11.14 rows=714 width=8)
                                             ->  Hash  (cost=1.48..1.48 rows=48 width=30)
                                                   ->  Seq Scan on adgangsskjema  (cost=0.00..1.48 rows=48 width=30)
               ->  Sort  (cost=11748.21..11778.64 rows=12169 width=24)
                     Sort Key: t1.gruppe_id
                     ->  Hash Join  (cost=8975.45..10922.49 rows=12169 width=24)
                           Hash Cond: ("outer".medlem_id = "inner".medlem_id)
                           ->  HashAggregate  (cost=5180.87..6093.55 rows=60845 width=24)
                                 ->  Merge Join  (cost=3496.19..4420.31 rows=60845 width=24)
                                       Merge Cond: ("outer".medlem_id = "inner".medlem_id)
                                       ->  Sort  (cost=2743.39..2749.11 rows=2290 width=12)
                                             Sort Key: ms.medlem_id
                                             ->  Subquery Scan ms  (cost=2483.70..2615.60 rows=2290 width=12)
                                                   ->  Append  (cost=2483.70..2592.70 rows=2290 width=12)
                                                         ->  HashAggregate  (cost=2483.70..2545.82 rows=2259 width=24)
                                                               Filter: (max(("start" + varighet)) >= (('now'::text)::date)::timestamp without time zone)
                                                               ->  Hash Join  (cost=662.54..2427.49 rows=7494 width=24)
                                                                     Hash Cond: ("outer".oblattype_id = "inner".oblattype_id)
                                                                     ->  Hash Join  (cost=661.50..2314.03 rows=7494 width=12)
                                                                           Hash Cond: ("outer".kortnummer = "inner".kortnummer)
                                                                           ->  Seq Scan on oblat  (cost=0.00..632.17 rows=37817 width=12)
                                                                           ->  Hash  (cost=614.81..614.81 rows=18673 width=8)
                                                                                 ->  Seq Scan on kort  (cost=0.00..614.81 rows=18673 width=8)
                                                                                       Filter: ((kortstatus_id = 1) AND (medlem_id IS NOT NULL))
                                                                     ->  Hash  (cost=1.04..1.04 rows=4 width=20)
                                                                           ->  Seq Scan on oblattype  (cost=0.00..1.04 rows=4 width=20)
                                                         ->  Subquery Scan "*SELECT* 2"  (cost=0.00..1.70 rows=31 width=4)
                                                               ->  Seq Scan on eksterne_kort  (cost=0.00..1.39 rows=31 width=4)
                                       ->  Sort  (cost=752.80..766.08 rows=5314 width=16)
                                             Sort Key: v.medlem_id
                                             ->  Append  (cost=0.00..370.84 rows=5314 width=16)
                                                   ->  Seq Scan on verv  (cost=0.00..316.31 rows=5283 width=16)
                                                         Filter: ((stopp IS NULL) OR (stopp >= ('now'::text)::date))
                                                   ->  Subquery Scan "*SELECT* 2"  (cost=0.01..1.70 rows=31 width=8)
                                                         ->  Result  (cost=0.01..1.39 rows=31 width=8)
                                                               One-Time Filter: (('2030-01-01'::date IS NULL) OR ('2030-01-01'::date >= ('now'::text)::date))
                                                               ->  Seq Scan on eksterne_kort  (cost=0.00..1.31 rows=31 width=8)
                           ->  Hash  (cost=3794.48..3794.48 rows=40 width=4)
                                 ->  HashAggregate  (cost=3794.08..3794.48 rows=40 width=4)
                                       ->  Append  (cost=3791.65..3793.58 rows=40 width=106)
                                             ->  Subquery Scan t1  (cost=3791.65..3791.79 rows=9 width=106)
                                                   ->  Unique  (cost=3791.65..3791.70 rows=9 width=60)
                                                         ->  Sort  (cost=3791.65..3791.68 rows=9 width=60)
                                                               Sort Key: medlem.medlem_id, public.kort.korttype_id
                                                               ->  Nested Loop  (cost=2922.47..3791.51 rows=9 width=60)
                                                                     Join Filter: ("outer".medlem_id = "inner".medlem_id)
                                                                     ->  Hash Join  (cost=2918.46..3454.13 rows=42 width=60)
                                                                           Hash Cond: ("outer".medlem_id = "inner".medlem_id)
                                                                           ->  Hash Join  (cost=2574.06..3106.62 rows=538 width=56)
                                                                                 Hash Cond: ("outer".medlem_id = "inner".medlem_id)
                                                                                 ->  Seq Scan on medlem  (cost=0.00..500.01 rows=3623 width=52)
                                                                                       Filter: (pinkode IS NOT NULL)
                                                                                 ->  Hash  (cost=2568.41..2568.41 rows=2259 width=4)
                                                                                       ->  HashAggregate  (cost=2483.70..2545.82 rows=2259 width=24)
                                                                                             Filter: (max(("start" + varighet)) >= (('now'::text)::date)::timestamp without time zone)
                                                                                             ->  Hash Join  (cost=662.54..2427.49 rows=7494 width=24)
                                                                                                   Hash Cond: ("outer".oblattype_id = "inner".oblattype_id)
                                                                                                   ->  Hash Join  (cost=661.50..2314.03 rows=7494 width=12)
                                                                                                         Hash Cond: ("outer".kortnummer = "inner".kortnummer)
                                                                                                         ->  Seq Scan on oblat  (cost=0.00..632.17 rows=37817 width=12)
                                                                                                         ->  Hash  (cost=614.81..614.81 rows=18673 width=8)
                                                                                                               ->  Seq Scan on kort  (cost=0.00..614.81 rows=18673 width=8)
                                                                                                                     Filter: ((kortstatus_id = 1) AND (medlem_id IS NOT NULL))
                                                                                                   ->  Hash  (cost=1.04..1.04 rows=4 width=20)
                                                                                                         ->  Seq Scan on oblattype  (cost=0.00..1.04 rows=4 width=20)
                                                                           ->  Hash  (cost=341.42..341.42 rows=1191 width=4)
                                                                                 ->  HashAggregate  (cost=329.51..341.42 rows=1191 width=4)
                                                                                       ->  Seq Scan on verv  (cost=0.00..316.31 rows=5283 width=4)
                                                                                             Filter: ((stopp IS NULL) OR (stopp >= ('now'::text)::date))
                                                                     ->  Bitmap Heap Scan on kort  (cost=4.01..8.02 rows=1 width=12)
                                                                           Recheck Cond: ((("outer".medlem_id = kort.medlem_id) AND (kort.korttype_id = 2)) OR (("outer".medlem_id = kort.medlem_id) AND (kort.korttype_id = 3)))
                                                                           Filter: (kortstatus_id = 1)
                                                                           ->  BitmapOr  (cost=4.01..4.01 rows=1 width=0)
                                                                                 ->  Bitmap Index Scan on maksimalt_ett_aktivt_kort_per_medlem  (cost=0.00..2.01 rows=1 width=0)
                                                                                       Index Cond: (("outer".medlem_id = kort.medlem_id) AND (kort.korttype_id = 2))
                                                                                 ->  Bitmap Index Scan on maksimalt_ett_aktivt_kort_per_medlem  (cost=0.00..2.01 rows=1 width=0)
                                                                                       Index Cond: (("outer".medlem_id = kort.medlem_id) AND (kort.korttype_id = 3))
                                             ->  Subquery Scan "*SELECT* 2"  (cost=0.00..1.70 rows=31 width=25)
                                                   ->  Seq Scan on eksterne_kort  (cost=0.00..1.39 rows=31 width=25)
   SubPlan
     ->  Materialize  (cost=546.45..742.37 rows=19592 width=38)
           ->  Seq Scan on rita_tilgang  (cost=0.00..526.86 rows=19592 width=38)
     ->  Seq Scan on personer_nylig_slettet  (cost=0.00..31.40 rows=2140 width=4)
(105 rows)

There's two oddities here at first sight:

  1. Why does it materialize the sequential scan? What use would that have?
  2. Why does it estimate four million disk page fetches in the top node? 
     I can't find anything like that in the bottom nodes...

All the obvious things are taken care of: The tables are freshly loaded,
VACUUM ANALYZE just ran, sort_mem/shared_buffers/effective_cache_size is the
same as on the 7.4 machine with the same amount of RAM (1GB).

/* Steinar */
-- 
Homepage: http://www.sesse.net/


From pgsql-performance-owner@postgresql.org  Thu Oct 20 01:37:35 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 6667ED9C48
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 20 Oct 2005 01:37:33 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 72746-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 20 Oct 2005 04:37:31 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id 302A4DA6D5
	for <pgsql-performance@postgresql.org>;
	Thu, 20 Oct 2005 01:37:31 -0300 (ADT)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j9K4bPiH004249;
	Thu, 20 Oct 2005 00:37:25 -0400 (EDT)
To: "Steinar H. Gunderson" <sgunderson@bigfoot.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Materializing a sequential scan 
In-reply-to: <20051019174544.GA32303@samfundet.no> 
References: <20051019174544.GA32303@samfundet.no>
Comments: In-reply-to "Steinar H. Gunderson" <sgunderson@bigfoot.com>
	message dated "Wed, 19 Oct 2005 19:45:44 +0200"
Date: Thu, 20 Oct 2005 00:37:25 -0400
Message-ID: <4248.1129783045@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/272
X-Sequence-Number: 15040

"Steinar H. Gunderson" <sgunderson@bigfoot.com> writes:
> I'm using PostgreSQL 8.1 beta 3 (packages from Debian experimental), and I
> have a (rather complex) query that seems to take forever -- when the database
> was just installed, it took about 1200ms (which is quite good, considering
> that the 7.4 system this runs on today uses about the same time, but has
> twice as much CPU power and runs sequential scans up to eight times as fast),
> but now I can never even get it to complete. I've tried running it for half
> an hour, but it still doesn't complete, so I'm a bit unsure what's going on.

That mdb_gruppekobling_transitiv_tillukning function looks awfully
grotty ... how many rows does it return, and how long does it take to
run by itself?  How often does its temp table get vacuumed?  A quick
band-aid might be to use TRUNCATE instead of DELETE FROM to clean the
table ... but if I were you I'd try to rewrite the function entirely.

			regards, tom lane

From pgsql-performance-owner@postgresql.org  Thu Oct 20 01:58:57 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 8B9A5DA7E5
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 20 Oct 2005 01:58:56 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 75888-04
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 20 Oct 2005 04:58:54 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id 3D5BBDA7A3
	for <pgsql-performance@postgresql.org>;
	Thu, 20 Oct 2005 01:58:54 -0300 (ADT)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j9K4wp7w004453;
	Thu, 20 Oct 2005 00:58:51 -0400 (EDT)
To: "Steinar H. Gunderson" <sgunderson@bigfoot.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Materializing a sequential scan 
In-reply-to: <20051019174544.GA32303@samfundet.no> 
References: <20051019174544.GA32303@samfundet.no>
Comments: In-reply-to "Steinar H. Gunderson" <sgunderson@bigfoot.com>
	message dated "Wed, 19 Oct 2005 19:45:44 +0200"
Date: Thu, 20 Oct 2005 00:58:51 -0400
Message-ID: <4452.1129784331@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/273
X-Sequence-Number: 15041

"Steinar H. Gunderson" <sgunderson@bigfoot.com> writes:
> BEGIN
> 	INSERT INTO kortsys2.mdb_gruppekobling_temp
> 	SELECT overgruppe_id,undergruppe_id FROM gruppekobling gk
> 		JOIN gruppe g1 ON gk.overgruppe_id=g1.gruppe_id
> 		JOIN gruppe g2 ON gk.overgruppe_id=g2.gruppe_id
> 		WHERE g1.aktiv AND g2.aktiv;
> 	LOOP

BTW, it sure looks like that second JOIN ought to be
		JOIN gruppe g2 ON gk.undergruppe_id=g2.gruppe_id

As-is, it's not doing anything for you ... certainly not enforcing
that the undergruppe_id be aktiv.

			regards, tom lane

From pgsql-performance-owner@postgresql.org  Thu Oct 20 04:15:23 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 5B43CDA80F
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 20 Oct 2005 04:15:22 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 26238-04
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 20 Oct 2005 07:15:18 +0000 (GMT)
Received: from moutng.kundenserver.de (moutng.kundenserver.de
	[212.227.126.188])
	by svr1.postgresql.org (Postfix) with ESMTP id C2FC0DA82B
	for <pgsql-performance@postgresql.org>;
	Thu, 20 Oct 2005 04:15:17 -0300 (ADT)
Received: from p508E5E86.dip.t-dialin.net [80.142.94.134]
	(helo=swtexchange2.technology.de)
	by mrelayeu.kundenserver.de with ESMTP (Nemesis),
	id 0ML21M-1ESUdy0Ezn-0002S3; Thu, 20 Oct 2005 09:15:18 +0200
content-class: urn:content-classes:message
Subject: Re: Inefficient escape codes.
MIME-Version: 1.0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Date: Thu, 20 Oct 2005 09:15:17 +0200
X-MimeOLE: Produced By Microsoft Exchange V6.0.6556.0
Message-ID: 
 <16F953410A0F1346848DCB476A989CFE01D557@swtexchange2.technology.de>
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
Thread-Topic: [PERFORM] Inefficient escape codes.
Thread-Index: AcXUYc4J45L1KvnPROegqnDqsT3t0AA48ZRA
From: =?iso-8859-1?Q?N=F6rder-Tuitje=2C_Marcus?=
 <noerder-tuitje@technology.de>
To: <pgsql-performance@postgresql.org>
X-Provags-ID: kundenserver.de abuse@kundenserver.de
	login:24478085a861b01e05bdc3b8f80dc176
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.131 required=5 tests=[AWL=0.081,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/274
X-Sequence-Number: 15042

I guess, You should check, if a blob field and large object access is =
suitable for you - no escaping etc, just raw binary large objects.

AFAIK, PQExecParams is not the right solution for You. Refer the "Large =
object" section:

"28.3.5. Writing Data to a Large Object
The function
int lo_write(PGconn *conn, int fd, const char *buf, size_t len);writes =
len bytes from buf to large object descriptor fd. The fd argument must =
have been returned by a previous lo_open. The number of bytes actually =
written is returned. In the event of an error, the return value is =
negative."

regards,
Narcus

-----Urspr=FCngliche Nachricht-----
Von: pgsql-performance-owner@postgresql.org
[mailto:pgsql-performance-owner@postgresql.org]Im Auftrag von Michael
Fuhr
Gesendet: Dienstag, 18. Oktober 2005 22:47
An: Rodrigo Madera
Cc: pgsql-performance@postgresql.org
Betreff: Re: [PERFORM] Inefficient escape codes.


[Please copy the mailing list on replies so others can participate
in and learn from the discussion.]

On Tue, Oct 18, 2005 at 07:09:08PM +0000, Rodrigo Madera wrote:
> > What language and API are you using?
>=20
> I'm using libpqxx. A nice STL-style library for C++ (I am 101% C++).

I've only dabbled with libpqxx; I don't know if or how you can make
it send data in binary instead of text.  See the documentation or
ask in a mailing list like libpqxx-general or pgsql-interfaces.

> > Binary transfer sends data in binary, not by automatically =
converting
> > to and from text.
>=20
> Uh, I'm sorry I didn't get that... If I send: insert into foo
> values('\\001\\002') will libpq send 0x01, 0x02 or "\\\\001\\\\002"??

If you do it that way libpq will send the string as text with escape
sequences; you can use a sniffer like tcpdump or ethereal to see this
for yourself.  To send the data in binary you'd call PQexecParams()
with a query like "INSERT INTO foo VALUES ($1)".  The $1 is a
placeholder; the other arguments to PQexecParams() provide the data
itself, the data type and length, and specify whether the data is in
text format or binary.  See the libpq documentation for details.

--=20
Michael Fuhr

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

               http://archives.postgresql.org



From pgsql-performance-owner@postgresql.org  Thu Oct 20 05:39:58 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 1190ED9A85
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 20 Oct 2005 05:39:57 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 46815-03
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 20 Oct 2005 08:39:52 +0000 (GMT)
Received: from mailer.eglobalreach.net (mail.padalacentral.com
	[202.124.128.22])
	by svr1.postgresql.org (Postfix) with ESMTP id 5AFF8D6F4A
	for <pgsql-performance@postgresql.org>;
	Thu, 20 Oct 2005 05:39:52 -0300 (ADT)
Received: from ghwk02002147 (localhost [127.0.0.1] (may be forged))
	by mailer.eglobalreach.net (8.11.6p2/) with ESMTP id j9K8dPT11484
	for <pgsql-performance@postgresql.org>; Thu, 20 Oct 2005 16:39:25 +0800
From: "Christian Paul B. Cosinas" <cpc@cybees.com>
To: <pgsql-performance@postgresql.org>
Subject: Deleting Records
Date: Thu, 20 Oct 2005 08:43:34 -0000
Message-ID: <002701c5d552$5bc7ea30$1e21100a@ghwk02002147>
MIME-Version: 1.0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit
X-Mailer: Microsoft Office Outlook 11
In-Reply-To: 
 <16F953410A0F1346848DCB476A989CFE01D557@swtexchange2.technology.de>
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506
Thread-Index: AcXUYc4J45L1KvnPROegqnDqsT3t0AA48ZRAAAMDDdA=
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.679 required=5 tests=[FORGED_RCVD_HELO=0.05,
	URIBL_SBL=0.629]
X-Spam-Level: 
X-Archive-Number: 200510/275
X-Sequence-Number: 15043

Hi!

I'm experiencing a very slow deletion of records. Which I thin is not right.
I have a Dual Xeon Server with 6gig Memory.
I am only deleting about 22,000 records but it took me more than 1 hour to
finish this.

What could possibly I do so that I can make this fast?

Here is the code inside my function:

	FOR temp_rec IN SELECT * FROM item_qc_doer LOOP
		DELETE FROM qc_session WHERE item_id = temp_rec.item_id;
		DELETE FROM item_qc_doer WHERE item_id = temp_rec.item_id;
	END LOOP;

Item_qc_oder table contains 22,000 records.


I choose Polesoft Lockspam to fight spam, and you?
http://www.polesoft.com/refer.html    


From pgsql-performance-owner@postgresql.org  Thu Oct 20 05:50:29 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 82101D6F4A
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 20 Oct 2005 05:50:28 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 48799-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 20 Oct 2005 08:50:21 +0000 (GMT)
Received: from mail.ecircle.de (mail.ecircle.de [195.140.186.200])
	by svr1.postgresql.org (Postfix) with ESMTP id 7CDA1DA838
	for <pgsql-performance@postgresql.org>;
	Thu, 20 Oct 2005 05:50:22 -0300 (ADT)
Received: from [192.168.1.110] (unknown [192.168.1.110])
	by mail.ecircle.de (READY) with ESMTP id 78A5F11DE6C;
	Thu, 20 Oct 2005 10:50:24 +0200 (CEST)
Subject: Re: Deleting Records
From: Csaba Nagy <nagy@ecircle-ag.com>
To: "Christian Paul B. Cosinas" <cpc@cybees.com>
Cc: postgres performance list <pgsql-performance@postgresql.org>
In-Reply-To: <002701c5d552$5bc7ea30$1e21100a@ghwk02002147>
References: <002701c5d552$5bc7ea30$1e21100a@ghwk02002147>
Content-Type: text/plain
Message-Id: <1129798144.27587.152.camel@coppola.muc.ecircle.de>
Mime-Version: 1.0
X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) 
Date: Thu, 20 Oct 2005 10:49:04 +0200
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.325 required=5 tests=[AWL=-0.304, URIBL_SBL=0.629]
X-Spam-Level: 
X-Archive-Number: 200510/276
X-Sequence-Number: 15044

Christian,

Do you have foreign keys pointing to your table with ON CASCADE... ?
Cause in that case you're not only deleting your 22000 records, but the
whole tree of cascades. And if you don't have an index on one of those
foreign keys, then you might have a sequential scan of the child table
on each deleted row... I would check the foreign keys.

HTH,
Csaba.


On Thu, 2005-10-20 at 10:43, Christian Paul B. Cosinas wrote:
> Hi!
> 
> I'm experiencing a very slow deletion of records. Which I thin is not right.
> I have a Dual Xeon Server with 6gig Memory.
> I am only deleting about 22,000 records but it took me more than 1 hour to
> finish this.
> 
> What could possibly I do so that I can make this fast?
> 
> Here is the code inside my function:
> 
> 	FOR temp_rec IN SELECT * FROM item_qc_doer LOOP
> 		DELETE FROM qc_session WHERE item_id = temp_rec.item_id;
> 		DELETE FROM item_qc_doer WHERE item_id = temp_rec.item_id;
> 	END LOOP;
> 
> Item_qc_oder table contains 22,000 records.
> 
> 
> I choose Polesoft Lockspam to fight spam, and you?
> http://www.polesoft.com/refer.html    
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 6: explain analyze is your friend


From pgsql-performance-owner@postgresql.org  Thu Oct 20 05:51:02 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 96B2ED6F4A
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 20 Oct 2005 05:51:01 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 48356-04
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 20 Oct 2005 08:50:57 +0000 (GMT)
Received: from moutng.kundenserver.de (moutng.kundenserver.de
	[212.227.126.177])
	by svr1.postgresql.org (Postfix) with ESMTP id 0298DDA856
	for <pgsql-performance@postgresql.org>;
	Thu, 20 Oct 2005 05:50:58 -0300 (ADT)
Received: from p508E5E86.dip.t-dialin.net [80.142.94.134]
	(helo=swtexchange2.technology.de)
	by mrelayeu.kundenserver.de with ESMTP (Nemesis),
	id 0ML2ov-1ESW8R24Yf-0004bY; Thu, 20 Oct 2005 10:50:51 +0200
content-class: urn:content-classes:message
Subject: Re: Deleting Records
MIME-Version: 1.0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Date: Thu, 20 Oct 2005 10:50:50 +0200
X-MimeOLE: Produced By Microsoft Exchange V6.0.6556.0
Message-ID: 
 <16F953410A0F1346848DCB476A989CFE01D559@swtexchange2.technology.de>
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
Thread-Topic: [PERFORM] Deleting Records
Thread-Index: AcXUYc4J45L1KvnPROegqnDqsT3t0AA48ZRAAAMDDdAAAG8o4A==
From: =?iso-8859-1?Q?N=F6rder-Tuitje=2C_Marcus?=
 <noerder-tuitje@technology.de>
To: "Christian Paul B. Cosinas" <cpc@cybees.com>,
	<pgsql-performance@postgresql.org>
X-Provags-ID: kundenserver.de abuse@kundenserver.de
	login:24478085a861b01e05bdc3b8f80dc176
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.419 required=5 tests=[AWL=-0.260,
	FORGED_RCVD_HELO=0.05, URIBL_SBL=0.629]
X-Spam-Level: 
X-Archive-Number: 200510/277
X-Sequence-Number: 15045


what about firing a=20

DELETE FROM qc_session S=20
       WHERE EXISTS (SELECT *=20
                       FROM item_qc_doer i
                      WHERE i.item_id =3D s.item_id);

and=20

DELETE FROM item_qc_doer S=20
       WHERE EXISTS (SELECT *=20
                       FROM item_qc_doer i
                      WHERE i.item_id =3D s.item_id);


this might be faster.

another way to speed up deletes might be disabling foreign keys.

also a SET ENABLE_SEQSCAN=3DFALSE; can speed up queries (force use of =
indices for access)


do you have a EXPLAIN for us ? do you have a index on item_id on your =
tables ?

questions by questions ;-)



mfg


-----Urspr=FCngliche Nachricht-----
Von: pgsql-performance-owner@postgresql.org
[mailto:pgsql-performance-owner@postgresql.org]Im Auftrag von Christian
Paul B. Cosinas
Gesendet: Donnerstag, 20. Oktober 2005 10:44
An: pgsql-performance@postgresql.org
Betreff: [PERFORM] Deleting Records


Hi!

I'm experiencing a very slow deletion of records. Which I thin is not =
right.
I have a Dual Xeon Server with 6gig Memory.
I am only deleting about 22,000 records but it took me more than 1 hour =
to
finish this.

What could possibly I do so that I can make this fast?

Here is the code inside my function:

	FOR temp_rec IN SELECT * FROM item_qc_doer LOOP
		DELETE FROM qc_session WHERE item_id =3D temp_rec.item_id;
		DELETE FROM item_qc_doer WHERE item_id =3D temp_rec.item_id;
	END LOOP;

Item_qc_oder table contains 22,000 records.


I choose Polesoft Lockspam to fight spam, and you?
http://www.polesoft.com/refer.html   =20


---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend



From pgsql-performance-owner@postgresql.org  Thu Oct 20 05:52:32 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id B0B90DA828
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 20 Oct 2005 05:52:30 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 45882-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 20 Oct 2005 08:52:24 +0000 (GMT)
Received: from roast.hq.mobyt.it (194-185-112-82.f5.ngi.it [194.185.112.82])
	by svr1.postgresql.org (Postfix) with SMTP id 12A4BDA84F
	for <pgsql-performance@postgresql.org>;
	Thu, 20 Oct 2005 05:52:24 -0300 (ADT)
Received: (qmail 11544 invoked from network); 20 Oct 2005 10:51:48 +0200
Received: from webdev.hq.mobyt.it (HELO ?10.20.20.4?) (10.20.20.4)
	by 0 with SMTP; 20 Oct 2005 10:51:48 +0200
Message-ID: <43575ACD.8000206@beccati.com>
Date: Thu, 20 Oct 2005 10:52:29 +0200
From: Matteo Beccati <php@beccati.com>
User-Agent: Thunderbird 1.4 (Windows/20050908)
MIME-Version: 1.0
To: "Christian Paul B. Cosinas" <cpc@cybees.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Deleting Records
References: <002701c5d552$5bc7ea30$1e21100a@ghwk02002147>
In-Reply-To: <002701c5d552$5bc7ea30$1e21100a@ghwk02002147>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.031 required=5 tests=[AWL=-0.019,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/279
X-Sequence-Number: 15047

Hi,

> What could possibly I do so that I can make this fast?
> 
> Here is the code inside my function:
> 
> 	FOR temp_rec IN SELECT * FROM item_qc_doer LOOP
> 		DELETE FROM qc_session WHERE item_id = temp_rec.item_id;
> 		DELETE FROM item_qc_doer WHERE item_id = temp_rec.item_id;
> 	END LOOP;

Qhat about just using:

DELETE FROM gc_session WHERE item_id IN
	(SELECT item_id FROM item_qc_doer)
DELETE FROM item_qc_doer;

It doesn't make sense to run 2 x 22.000 separate delete statements 
instead that only two...

And... What about using a foreing key?


Best regards
--
Matteo Beccati
http://phpadsnew.com
http://phppgads.com

From pgsql-performance-owner@postgresql.org  Thu Oct 20 05:52:10 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 17BEBD6F4A
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 20 Oct 2005 05:52:09 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 47825-09
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 20 Oct 2005 08:52:04 +0000 (GMT)
Received: from houston.familyhealth.com.au (houston.au.fhnetwork.com
	[203.22.197.21])
	by svr1.postgresql.org (Postfix) with ESMTP id D9AD6DA841
	for <pgsql-performance@postgresql.org>;
	Thu, 20 Oct 2005 05:52:01 -0300 (ADT)
Received: from houston.familyhealth.com.au (localhost [127.0.0.1])
	by houston.familyhealth.com.au (Postfix) with ESMTP id D36F62505B;
	Thu, 20 Oct 2005 16:51:55 +0800 (WST)
Received: from [127.0.0.1] (work-40.internal [192.168.0.40])
	by houston.familyhealth.com.au (Postfix) with ESMTP id E63D024FF7;
	Thu, 20 Oct 2005 16:51:53 +0800 (WST)
Message-ID: <43575BFB.5050800@familyhealth.com.au>
Date: Thu, 20 Oct 2005 16:57:31 +0800
From: Christopher Kings-Lynne <chriskl@familyhealth.com.au>
User-Agent: Mozilla Thunderbird 1.0.7 (Windows/20050923)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: "Christian Paul B. Cosinas" <cpc@cybees.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Deleting Records
References: <002701c5d552$5bc7ea30$1e21100a@ghwk02002147>
In-Reply-To: <002701c5d552$5bc7ea30$1e21100a@ghwk02002147>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-familyhealth-MailScanner-Information: Please contact the ISP for more
	information
X-familyhealth-MailScanner: Found to be clean
X-familyhealth-MailScanner-From: chriskl@familyhealth.com.au
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.06 required=5 tests=[AWL=0.010,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/278
X-Sequence-Number: 15046

> What could possibly I do so that I can make this fast?
> 
> Here is the code inside my function:
> 
> 	FOR temp_rec IN SELECT * FROM item_qc_doer LOOP
> 		DELETE FROM qc_session WHERE item_id = temp_rec.item_id;
> 		DELETE FROM item_qc_doer WHERE item_id = temp_rec.item_id;
> 	END LOOP;
> 
> Item_qc_oder table contains 22,000 records.

I'd check to see if i have foreign keys on those tables and if the 
columns that refer to them are properly indexed.  (For cascade delete or 
even just checking restrict)

Chris


From pgsql-performance-owner@postgresql.org  Thu Oct 20 05:54:10 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 45937DA858
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 20 Oct 2005 05:53:37 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 47348-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 20 Oct 2005 08:53:33 +0000 (GMT)
Received: from houston.familyhealth.com.au (houston.au.fhnetwork.com
	[203.22.197.21])
	by svr1.postgresql.org (Postfix) with ESMTP id 5FC15DA844
	for <pgsql-performance@postgresql.org>;
	Thu, 20 Oct 2005 05:53:32 -0300 (ADT)
Received: from houston.familyhealth.com.au (localhost [127.0.0.1])
	by houston.familyhealth.com.au (Postfix) with ESMTP id 7CCBE25076;
	Thu, 20 Oct 2005 16:53:27 +0800 (WST)
Received: from [127.0.0.1] (work-40.internal [192.168.0.40])
	by houston.familyhealth.com.au (Postfix) with ESMTP id 5AE642505B;
	Thu, 20 Oct 2005 16:53:26 +0800 (WST)
Message-ID: <43575C5D.3030301@familyhealth.com.au>
Date: Thu, 20 Oct 2005 16:59:09 +0800
From: Christopher Kings-Lynne <chriskl@familyhealth.com.au>
User-Agent: Mozilla Thunderbird 1.0.7 (Windows/20050923)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: "Christian Paul B. Cosinas" <cpc@cybees.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Deleting Records
References: <002701c5d552$5bc7ea30$1e21100a@ghwk02002147>
In-Reply-To: <002701c5d552$5bc7ea30$1e21100a@ghwk02002147>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-familyhealth-MailScanner-Information: Please contact the ISP for more
	information
X-familyhealth-MailScanner: Found to be clean
X-familyhealth-MailScanner-From: chriskl@familyhealth.com.au
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.164 required=5 tests=[AWL=-0.093,
	FORGED_RCVD_HELO=0.05, UPPERCASE_25_50=0.207]
X-Spam-Level: 
X-Archive-Number: 200510/280
X-Sequence-Number: 15048

> Here is the code inside my function:
> 
> 	FOR temp_rec IN SELECT * FROM item_qc_doer LOOP
> 		DELETE FROM qc_session WHERE item_id = temp_rec.item_id;
> 		DELETE FROM item_qc_doer WHERE item_id = temp_rec.item_id;
> 	END LOOP;
> 
> Item_qc_oder table contains 22,000 records.

Also, chekc you have an index on both those item_id columns.

Also, why don't you just not use the loop and do this instead:

DELETE FROM qc_session WHERE item_id IN (SELECT item_id FROM item_qc_doer);
DELETE FROM item_qc_doer;

Chris


From pgsql-performance-owner@postgresql.org  Thu Oct 20 07:16:39 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id F28EDDA841
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 20 Oct 2005 07:16:37 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 65335-09
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 20 Oct 2005 10:16:32 +0000 (GMT)
Received: from cassarossa.samfundet.no (cassarossa.samfundet.no
	[129.241.93.19])
	by svr1.postgresql.org (Postfix) with ESMTP id 8C97ADA146
	for <pgsql-performance@postgresql.org>;
	Thu, 20 Oct 2005 07:16:33 -0300 (ADT)
Received: from sesse by cassarossa.samfundet.no with local (Exim 4.50)
	id 1ESXTO-0002zr-NU
	for pgsql-performance@postgresql.org; Thu, 20 Oct 2005 12:16:34 +0200
Date: Thu, 20 Oct 2005 12:16:34 +0200
From: "Steinar H. Gunderson" <sgunderson@bigfoot.com>
To: pgsql-performance@postgresql.org
Subject: Re: Materializing a sequential scan
Message-ID: <20051020101634.GB11055@samfundet.no>
References: <20051019174544.GA32303@samfundet.no>
	<4248.1129783045@sss.pgh.pa.us>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <4248.1129783045@sss.pgh.pa.us>
User-Agent: Mutt/1.5.9i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.012 required=5 tests=[AWL=0.012]
X-Spam-Level: 
X-Archive-Number: 200510/281
X-Sequence-Number: 15049

On Thu, Oct 20, 2005 at 12:37:25AM -0400, Tom Lane wrote:
> That mdb_gruppekobling_transitiv_tillukning function looks awfully
> grotty ... how many rows does it return, and how long does it take to
> run by itself?  How often does its temp table get vacuumed?  A quick
> band-aid might be to use TRUNCATE instead of DELETE FROM to clean the
> table ... but if I were you I'd try to rewrite the function entirely.

It returns 752 rows, and the table is autovacuumed. If I run the queries
manually, they take ~15ms in all -- for some odd reason, the function in itself
varies between 40 and 500ms, though...

I tried using TRUNCATE earlier, but if anything, it made the function slower
(might just have been zero difference, though).  I also had written the
function differently (using a series of depth-first searches), but it was
awfully slow even after a lot of tweaking, so it was not really worth it...

/* Steinar */
-- 
Homepage: http://www.sesse.net/


From pgsql-performance-owner@postgresql.org  Thu Oct 20 07:18:49 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 85D72DA83E
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 20 Oct 2005 07:18:47 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 87277-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 20 Oct 2005 10:18:43 +0000 (GMT)
Received: from cassarossa.samfundet.no (cassarossa.samfundet.no
	[129.241.93.19])
	by svr1.postgresql.org (Postfix) with ESMTP id 4CAB0DA829
	for <pgsql-performance@postgresql.org>;
	Thu, 20 Oct 2005 07:18:45 -0300 (ADT)
Received: from sesse by cassarossa.samfundet.no with local (Exim 4.50)
	id 1ESXVX-00030z-Lr
	for pgsql-performance@postgresql.org; Thu, 20 Oct 2005 12:18:47 +0200
Date: Thu, 20 Oct 2005 12:18:47 +0200
From: "Steinar H. Gunderson" <sgunderson@bigfoot.com>
To: pgsql-performance@postgresql.org
Subject: Re: Materializing a sequential scan
Message-ID: <20051020101847.GC11055@samfundet.no>
References: <20051019174544.GA32303@samfundet.no>
	<4452.1129784331@sss.pgh.pa.us>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <4452.1129784331@sss.pgh.pa.us>
User-Agent: Mutt/1.5.9i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.012 required=5 tests=[AWL=0.012]
X-Spam-Level: 
X-Archive-Number: 200510/282
X-Sequence-Number: 15050

On Thu, Oct 20, 2005 at 12:58:51AM -0400, Tom Lane wrote:
> As-is, it's not doing anything for you ... certainly not enforcing
> that the undergruppe_id be aktiv.

Oops, yes, that's a bug -- thanks for noticing. (It does not matter
particularily with the current data set, though.)

/* Steinar */
-- 
Homepage: http://www.sesse.net/


From pgsql-performance-owner@postgresql.org  Thu Oct 20 11:07:32 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id F1F56DA7FE
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 20 Oct 2005 11:07:30 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 14841-04
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 20 Oct 2005 14:07:26 +0000 (GMT)
Received: from floppy.pyrenet.fr (news.pyrenet.fr [194.116.145.2])
	by svr1.postgresql.org (Postfix) with ESMTP id 19428D99D8
	for <pgsql-performance@postgresql.org>;
	Thu, 20 Oct 2005 11:07:29 -0300 (ADT)
Received: by floppy.pyrenet.fr (Postfix, from userid 106)
	id 22C6E31058; Thu, 20 Oct 2005 16:07:32 +0200 (MET DST)
From: Kuba Ouhrabka <kuba@comgate.cz>
X-Newsgroups: pgsql.performance
Subject: cached plans in plpgsql
Date: Thu, 20 Oct 2005 16:07:22 +0200
Organization: Hub.Org Networking Services
Lines: 20
Message-ID: <dj88aq$kme$1@news.hub.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1250; format=flowed
Content-Transfer-Encoding: 7bit
X-Complaints-To: usenet@news.hub.org
User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716)
X-Accept-Language: cs, en-us, en
To: pgsql-performance@postgresql.org
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0 required=5 tests=[none]
X-Spam-Level: 
X-Archive-Number: 200510/283
X-Sequence-Number: 15051

Hi,

is there an easy way to flush all cached query plans in pl/pgsql 
functions? I've long running sessions where data are changing and the 
plans become inaccurate after a while. I can imagine something like 
recreating all pl/pgsql functions. I can recreate them from sql source 
files but I'd prefer recreating them inside the database without 
accessing files outside. I can think only of one way - reconstructing 
function source code from pg_proc and EXECUTEing it. But it's not the 
cleanest solution (there isn't saved the actual source code anywhere so 
there could be problems with quoting etc.). Can you see any other 
possibility? How do you solve this problem? [And yes, I don't want to 
re-connect...]

Thanks,

Kuba




From pgsql-performance-owner@postgresql.org  Thu Oct 20 11:15:54 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 98E7CDA881;
	Thu, 20 Oct 2005 11:15:16 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 10062-08; Thu, 20 Oct 2005 14:15:12 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id B0063DA8AB;
	Thu, 20 Oct 2005 11:15:14 -0300 (ADT)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j9KEFJo9009429;
	Thu, 20 Oct 2005 10:15:19 -0400 (EDT)
To: Katherine Stoovs <ambrosiac@nedsenta.nl>
Cc: pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org
Subject: Re: [HACKERS] tuning seqscan costs 
In-reply-to: <dj5gjc$q0g$1@news.host.net> 
References: <dj5gjc$q0g$1@news.host.net>
Comments: In-reply-to Katherine Stoovs <ambrosiac@nedsenta.nl>
	message dated "Wed, 19 Oct 2005 14:51:55 -0000"
Date: Thu, 20 Oct 2005 10:15:19 -0400
Message-ID: <9428.1129817719@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/284
X-Sequence-Number: 15052

Katherine Stoovs <ambrosiac@nedsenta.nl> writes:
> There must be something
> wrong in the planning parameters after all if a plan that is slower by
> a factor of tens or hundreds becomes estimated better than the fast
> variant.

Instead of handwaving, how about showing us EXPLAIN ANALYZE results for
both cases?  You didn't even explain how the index you expect it to use
is defined...

Specifying what PG version you are using is also minimum required
information for this sort of question.

			regards, tom lane

From pgsql-performance-owner@postgresql.org  Thu Oct 20 12:04:06 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id DA768D981F
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 20 Oct 2005 12:04:05 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 63614-07
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 20 Oct 2005 15:04:02 +0000 (GMT)
Received: from Herge.rcsinc.local (mail.rcsonline.com [70.89.208.142])
	by svr1.postgresql.org (Postfix) with ESMTP id 35981D904F
	for <pgsql-performance@postgresql.org>;
	Thu, 20 Oct 2005 12:04:01 -0300 (ADT)
X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0
Content-class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Subject: Re: cached plans in plpgsql
Date: Thu, 20 Oct 2005 11:03:58 -0400
Message-ID: <6EE64EF3AB31D5448D0007DD34EEB3417DD640@Herge.rcsinc.local>
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
Thread-Topic: [PERFORM] cached plans in plpgsql
Thread-Index: AcXVgBsHxb0qr4NgR9epi4y0cRZ7rAABpbOg
From: "Merlin Moncure" <merlin.moncure@rcsonline.com>
To: "Kuba Ouhrabka" <kuba@comgate.cz>
Cc: <pgsql-performance@postgresql.org>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.09 required=5 tests=[AWL=0.041,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/285
X-Sequence-Number: 15053

Kuba wrote:

> is there an easy way to flush all cached query plans in pl/pgsql
> functions? I've long running sessions where data are changing and the
> plans become inaccurate after a while. I can imagine something like
> recreating all pl/pgsql functions. I can recreate them from sql source
> files but I'd prefer recreating them inside the database without
> accessing files outside. I can think only of one way - reconstructing
> function source code from pg_proc and EXECUTEing it. But it's not the
> cleanest solution (there isn't saved the actual source code anywhere
so
> there could be problems with quoting etc.). Can you see any other
> possibility? How do you solve this problem? [And yes, I don't want to
> re-connect...]

Start here:
http://archives.postgresql.org/pgsql-hackers/2005-09/msg00690.php

Merlin

From pgsql-performance-owner@postgresql.org  Thu Oct 20 13:25:26 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id E8B27DA7EE
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 20 Oct 2005 13:25:25 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 29277-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 20 Oct 2005 16:25:22 +0000 (GMT)
Received: from floppy.pyrenet.fr (news.pyrenet.fr [194.116.145.2])
	by svr1.postgresql.org (Postfix) with ESMTP id 76448D6F4A
	for <pgsql-performance@postgresql.org>;
	Thu, 20 Oct 2005 13:25:22 -0300 (ADT)
Received: by floppy.pyrenet.fr (Postfix, from userid 106)
	id C943831058; Thu, 20 Oct 2005 18:25:20 +0200 (MET DST)
From: Kuba Ouhrabka <kuba@comgate.cz>
X-Newsgroups: pgsql.performance
Subject: Re: cached plans in plpgsql
Date: Thu, 20 Oct 2005 18:25:12 +0200
Organization: Hub.Org Networking Services
Lines: 110
Message-ID: <4357C4E8.6010602@comgate.cz>
References: <6EE64EF3AB31D5448D0007DD34EEB3417DD640@Herge.rcsinc.local>
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="------------060809030609060305070302"
X-Complaints-To: usenet@news.hub.org
To: Merlin Moncure <merlin.moncure@rcsonline.com>
User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716)
X-Accept-Language: cs, en-us, en
In-Reply-To: <6EE64EF3AB31D5448D0007DD34EEB3417DD640@Herge.rcsinc.local>
To: pgsql-performance@postgresql.org
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.103 required=5 tests=[AWL=-0.103,
	UPPERCASE_25_50=0.207]
X-Spam-Level: 
X-Archive-Number: 200510/286
X-Sequence-Number: 15054

This is a multi-part message in MIME format.
--------------060809030609060305070302
Content-Type: text/plain; charset=windows-1250; format=flowed
Content-Transfer-Encoding: 7bit

 > [howto recreate plpgsql functions]
> 
> Start here:
> http://archives.postgresql.org/pgsql-hackers/2005-09/msg00690.php

Great, thanks!

I slighltly modified the function - it was not working for overloaded 
functions (same name, different arguments) and for functions with named 
arguments. Modified version attached for anyone interested - not perfect 
but works for me...

Kuba

--------------060809030609060305070302
Content-Type: text/plain;
 name="recompile.sql"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="recompile.sql"

CREATE OR REPLACE FUNCTION recompile_function(a_oid oid) RETURNS INTEGER AS $func$
DECLARE
  Par_proc TEXT; 
  
  Var_datos RECORD;
  Var_codigo text;
  Var_args varchar;
  
  Var_nameArg varchar;
  Var_nameRet varchar;
  i int;
BEGIN
  
  SELECT proretset, prorettype, proargtypes, proargnames, prosrc, pronargs, proname
	INTO Var_datos
  FROM pg_proc 
  WHERE 
  	oid = a_oid
  FOR UPDATE
  ;
  
  Par_proc := Var_datos.proname;
  
  SELECT typname::varchar INTO Var_nameRet FROM pg_type WHERE oid = Var_datos.prorettype;

  Var_codigo := 'CREATE OR REPLACE FUNCTION '||Par_proc||'(';

  IF Var_datos.pronargs > 0 THEN
	Var_args := '';
	FOR i IN 0..Var_datos.pronargs-1 LOOP
		SELECT typname::varchar INTO Var_nameArg FROM pg_type WHERE oid = Var_datos.proargtypes[i];
			
		Var_args := Var_args|| COALESCE(Var_datos.proargnames[i+1], '') || ' ' || Var_nameArg||', ';
	END LOOP;
	
	Var_codigo := Var_codigo||RTRIM(Var_args,', ');
  END IF;

  if Var_datos.proretset THEN
	Var_codigo := Var_codigo||') RETURNS SETOF '||Var_nameRet||' AS''';
  ELSE
	Var_codigo := Var_codigo||') RETURNS '||Var_nameRet||' AS''';
  END IF;

  Var_codigo := Var_codigo|| replace(Var_datos.prosrc,'''' , '\'''');

  Var_codigo := Var_codigo||'''LANGUAGE ''plpgsql''';

  EXECUTE(Var_codigo);

  RETURN 0;

END;
$func$ LANGUAGE 'plpgsql';

CREATE OR REPLACE FUNCTION recompile_all_functions() RETURNS INTEGER AS $func$
DECLARE
	lr_rec RECORD;
	li_x INTEGER;
BEGIN

	FOR lr_rec IN 
	SELECT 
		p.oid as oid
	FROM 
		pg_catalog.pg_proc p
        LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace
        LEFT JOIN pg_language l ON l.oid = p.prolang
	WHERE 
	    	NOT p.proisagg
	    AND pg_catalog.pg_function_is_visible(p.oid)
    	AND n.nspname != 'pg_catalog'
	    AND NOT p.proname IN ('recompile_all_functions', 'recompile_function')
	    AND l.lanname = 'plpgsql'
	LOOP
		li_x := recompile_function(lr_rec.oid);
	END LOOP;


	RETURN 0;
END;
$func$ LANGUAGE 'plpgsql';

--------------060809030609060305070302--

From pgsql-performance-owner@postgresql.org  Thu Oct 20 13:50:59 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 0A3C9DA792
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 20 Oct 2005 13:50:59 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 55967-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 20 Oct 2005 16:50:56 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id 9BB0EDA7EE
	for <pgsql-performance@postgresql.org>;
	Thu, 20 Oct 2005 13:50:56 -0300 (ADT)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j9KGoscc011635;
	Thu, 20 Oct 2005 12:50:54 -0400 (EDT)
To: Kuba Ouhrabka <kuba@comgate.cz>
Cc: Merlin Moncure <merlin.moncure@rcsonline.com>,
	pgsql-performance@postgresql.org
Subject: Re: cached plans in plpgsql 
In-reply-to: <4357C4E8.6010602@comgate.cz> 
References: <6EE64EF3AB31D5448D0007DD34EEB3417DD640@Herge.rcsinc.local>
	<4357C4E8.6010602@comgate.cz>
Comments: In-reply-to Kuba Ouhrabka <kuba@comgate.cz>
	message dated "Thu, 20 Oct 2005 18:25:12 +0200"
Date: Thu, 20 Oct 2005 12:50:54 -0400
Message-ID: <11634.1129827054@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/287
X-Sequence-Number: 15055

Kuba Ouhrabka <kuba@comgate.cz> writes:
>   IF Var_datos.pronargs > 0 THEN
> 	Var_args := '';
> 	FOR i IN 0..Var_datos.pronargs-1 LOOP
> 		SELECT typname::varchar INTO Var_nameArg FROM pg_type WHERE oid = Var_datos.proargtypes[i];
			
> 		Var_args := Var_args|| COALESCE(Var_datos.proargnames[i+1], '') || ' ' || Var_nameArg||', ';
> 	END LOOP;

This will not work at all; it makes far too many incorrect assumptions,
like proargnames always being non-null and having subscripts that match
proargtypes.  (It'll mess things up completely for anything that has OUT
arguments, too.)

It's pretty much the hard way to form a function reference anyway ---
you can just cast the function OID to regprocedure, which aside from
avoiding a lot of subtle assumptions about the catalog contents,
will deal with schema naming issues, something the above likewise
fails at.

To avoid having to reconstruct argument names/types, I'd suggest using
an ALTER FUNCTION command instead of CREATE OR REPLACE FUNCTION, maybe

	DECLARE fullproname text := a_oid::regprocedure;
	...
	EXECUTE 'ALTER FUNCTION ' || fullproname || ' RENAME TO ' || Var_datos.proname;

			regards, tom lane

From pgsql-performance-owner@postgresql.org  Mon Oct 24 23:50:49 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id BE3B4DA944
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 20 Oct 2005 17:39:13 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 11020-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 20 Oct 2005 20:39:09 +0000 (GMT)
Received: from news.hub.org (news.hub.org [200.46.204.72])
	by svr1.postgresql.org (Postfix) with ESMTP id 22BAFDA8E8
	for <pgsql-performance@postgresql.org>;
	Thu, 20 Oct 2005 17:39:11 -0300 (ADT)
Received: from news.hub.org (news.hub.org [200.46.204.72])
	by news.hub.org (8.13.1/8.13.1) with ESMTP id j9KKd9Xi015368
	for <pgsql-performance@postgresql.org>; Thu, 20 Oct 2005 20:39:09 GMT
	(envelope-from news@news.hub.org)
Received: (from news@localhost)
	by news.hub.org (8.13.1/8.13.1/Submit) id j9KKX9fL013886
	for pgsql-performance@postgresql.org; Thu, 20 Oct 2005 20:33:09 GMT
	(envelope-from news)
From: jnevans@gmail.com
X-Newsgroups: pgsql.performance
Subject: impact of stats_command_string
Date: 20 Oct 2005 13:33:07 -0700
Organization: http://groups.google.com
Lines: 6
Message-ID: <1129840387.509093.90500@g49g2000cwa.googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
X-Complaints-To: groups-abuse@google.com
User-Agent: G2/0.2
X-HTTP-UserAgent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US;
	rv:1.7.12) Gecko/20051018 Firefox/1.0.7,gzip(gfe),gzip(gfe)
Complaints-To: groups-abuse@google.com
Injection-Info: g49g2000cwa.googlegroups.com; posting-host=216.70.236.236;
	posting-account=rb2hdw0AAAAnkqcOzZTbHWw1_mDOFv_8
To: pgsql-performance@postgresql.org
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=-2.731 required=5 tests=[ALL_TRUSTED=-2.82,
	AWL=-0.089, NO_REAL_NAME=0.178]
X-Spam-Level: 
X-Archive-Number: 200510/344
X-Sequence-Number: 15112

If I turn on stats_command_string, how much impact would it have on
PostgreSQL server's performance during a period of massive data
INSERTs?  I know that the answer to the question I'm asking will
largely depend upon different factors so I would like to know in which
situations it would be negligible or would have a signifcant impact.


From pgsql-performance-owner@postgresql.org  Fri Oct 21 00:36:44 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 1EC2BDA69D
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 21 Oct 2005 00:36:44 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 38033-09
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 21 Oct 2005 03:36:41 +0000 (GMT)
Received: from mailer.eglobalreach.net (mail.padalacentral.com
	[202.124.128.22])
	by svr1.postgresql.org (Postfix) with ESMTP id 9D607D9E93
	for <pgsql-performance@postgresql.org>;
	Fri, 21 Oct 2005 00:36:40 -0300 (ADT)
Received: from ghwk02002147 (localhost [127.0.0.1] (may be forged))
	by mailer.eglobalreach.net (8.11.6p2/) with ESMTP id j9L3acN29123
	for <pgsql-performance@postgresql.org>; Fri, 21 Oct 2005 11:36:38 +0800
From: "Christian Paul B. Cosinas" <cpc@cybees.com>
To: <pgsql-performance@postgresql.org>
Subject: Used Memory
Date: Fri, 21 Oct 2005 03:40:47 -0000
Message-ID: <00a401c5d5f1$39f661d0$1e21100a@ghwk02002147>
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="----=_NextPart_000_00A5_01C5D5F1.39F7E870"
X-Mailer: Microsoft Office Outlook 11
In-Reply-To: <3cf983d0510181107sb060171je702da5fe0c29252@mail.gmail.com>
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506
Thread-Index: AcXUD9MHSbjkud3OSMqeu5cWHK1SMQB4GQiQ
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.679 required=5 tests=[AWL=-0.001,
	FORGED_RCVD_HELO=0.05, HTML_MESSAGE=0.001, URIBL_SBL=0.629]
X-Spam-Level: 
X-Archive-Number: 200510/288
X-Sequence-Number: 15056

This is a multi-part message in MIME format.

------=_NextPart_000_00A5_01C5D5F1.39F7E870
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit

HI!

 

I am having a confusion to the memory handling of postgreSQL.

 

Here is the Scenario.

I rebooted my Server which is a PostgreSQL 8.0 Running on Redhat 9, which is
a Dual Xeon Server and 6 gig of memory.

Of course there is not much memory still used since it is just restarted.

But after a number of access to the tables the memory is being used and it
is not being free up. Actually after this access to the database and the
server is just idle

The memory is still used up. I am monitoring this using the "free" command
which gives me about 5.5 gig of used memory and the rest free.

 

Is there something that I should do to minimize and free up the used memory?

 

Thanks You.



I choose Polesoft Lockspam to fight spam, and you?
http://www.polesoft.com/refer.html

------=_NextPart_000_00A5_01C5D5F1.39F7E870
Content-Type: text/html;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

<html xmlns:o=3D"urn:schemas-microsoft-com:office:office" =
xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns=3D"http://www.w3.org/TR/REC-html40">

<head>

<meta name=3DGenerator content=3D"Microsoft Word 11 (filtered medium)">
<style>
<!--
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0pt;
	margin-bottom:.0001pt;
	font-size:12.0pt;
	font-family:"Times New Roman";}
a:link, span.MsoHyperlink
	{color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{color:purple;
	text-decoration:underline;}
span.EmailStyle17
	{mso-style-type:personal-reply;
	font-family:Arial;
	color:navy;}
@page Section1
	{size:612.0pt 792.0pt;
	margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
	{page:Section1;}
-->
</style>

</head>

<body lang=3DEN-US link=3Dblue vlink=3Dpurple>

<div class=3DSection1>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>HI!<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>I am having a confusion to the =
memory
handling of postgreSQL.<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>Here is the =
Scenario.<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>I rebooted my Server which is a =
PostgreSQL
8.0 Running on Redhat 9, which is a Dual Xeon Server and 6 gig of =
memory.<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>Of course there is not much memory =
still
used since it is just restarted.<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>But after a number of access to the =
tables
the memory is being used and it is not being free up. Actually after =
this
access to the database and the server is just =
idle<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>The memory is still used up. I am
monitoring this using the &#8220;free&#8221; command which gives me =
about 5.5
gig of used memory and the rest free.<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>Is there something that I should do =
to minimize
and free up the used memory?<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>Thanks =
You.<o:p></o:p></span></font></p>

</div>

<BR>
<BR>
I choose Polesoft Lockspam to fight spam, and you?<BR>
<A HREF=3D"http://www.polesoft.com/refer.html" =
TARGET=3D"_blank">http://www.polesoft.com/refer.html</A></body>

</html>

------=_NextPart_000_00A5_01C5D5F1.39F7E870--


From pgsql-performance-owner@postgresql.org  Fri Oct 21 04:23:43 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id CDC35DA9AD
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 21 Oct 2005 04:23:40 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 23173-06
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 21 Oct 2005 07:23:36 +0000 (GMT)
Received: from smtp1.asco.de (smtp1.asco.de [217.13.70.154])
	by svr1.postgresql.org (Postfix) with ESMTP id 9F03EDA999
	for <pgsql-performance@postgresql.org>;
	Fri, 21 Oct 2005 04:23:33 -0300 (ADT)
Received: from [192.168.1.72] (pitr.asco.de [192.168.1.72])
	(envelope-sender: <ml+pgsql-performance@asco.de>)
	(authenticated j_schicke CRAM-MD5 bits=0)
	by smtp1.asco.de (8.13.4/8.13.4/Debian-3) with ESMTP id j9L7NSdP009314
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO);
	Fri, 21 Oct 2005 09:23:28 +0200
Date: Fri, 21 Oct 2005 09:23:28 +0200
From: Jens-Wolfhard Schicke <ml+pgsql-performance@asco.de>
Reply-To: Jens-Wolfhard Schicke <j.schicke@asco.de>
To: "Christian Paul B. Cosinas" <cpc@cybees.com>,
	pgsql-performance@postgresql.org
Subject: Re: Used Memory
Message-ID: <28EE02F5BBCA481B51C4E44E@[192.168.1.72]>
In-Reply-To: <00a401c5d5f1$39f661d0$1e21100a@ghwk02002147>
References: <00a401c5d5f1$39f661d0$1e21100a@ghwk02002147>
X-Mailer: Mulberry/3.1.6 (Linux/x86)
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1; format=flowed
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.429 required=5 tests=[AWL=-0.200, URIBL_SBL=0.629]
X-Spam-Level: 
X-Archive-Number: 200510/289
X-Sequence-Number: 15057

--On Freitag, Oktober 21, 2005 03:40:47 +0000 "Christian Paul B. Cosinas"=20
<cpc@cybees.com> wrote:
> I am having a confusion to the memory handling of postgreSQL.
> I rebooted my Server which is a PostgreSQL 8.0 Running on Redhat 9, which
> is a Dual Xeon Server and 6 gig of memory.
>
> Of course there is not much memory still used since it is just restarted.
>
> But after a number of access to the tables the memory is being used and
> it is not being free up. Actually after this access to the database and
> the server is just idle
>
> The memory is still used up. I am monitoring this using the "free"
> command which gives me about 5.5 gig of used memory and the rest free.
I suppose you looked at the top row of the free output?

Because there the disk-cache is counted as "used"... Have a look at the=20
second row where buffers are counted as free, which they more or less are.

> Is there something that I should do to minimize and free up the used
> memory?
No, the buffers make your database faster because they reduce direct disk=20
access

> I choose Polesoft Lockspam to fight spam, and you?
> http://www.polesoft.com/refer.html
I don't :)

Mit freundlichem Gru=DF,
Jens Schicke
--=20
Jens Schicke		      j.schicke@asco.de
asco GmbH		      http://www.asco.de
Mittelweg 7		      Tel 0531/3906-127
38106 Braunschweig	      Fax 0531/3906-400

From pgsql-performance-owner@postgresql.org  Fri Oct 21 04:33:28 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id DE36DDA9A2
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 21 Oct 2005 04:33:26 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 25867-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 21 Oct 2005 07:33:24 +0000 (GMT)
Received: from mx.comgate.cz (mx.comgate.cz [193.165.185.50])
	by svr1.postgresql.org (Postfix) with ESMTP id C8D9BDA9A1
	for <pgsql-performance@postgresql.org>;
	Fri, 21 Oct 2005 04:33:24 -0300 (ADT)
Received: from [10.1.0.53] (helo=[10.1.0.53])
	by mx.comgate.cz with esmtp (Exim 3.35 #1 (Debian))
	id 1ESrOw-0008Dm-00; Fri, 21 Oct 2005 09:33:18 +0200
Message-ID: <435899BD.3070808@comgate.cz>
Date: Fri, 21 Oct 2005 09:33:17 +0200
From: Kuba Ouhrabka <kuba@comgate.cz>
User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716)
X-Accept-Language: cs, en-us, en
MIME-Version: 1.0
To: Tom Lane <tgl@sss.pgh.pa.us>, pgsql-performance@postgresql.org
Subject: Re: cached plans in plpgsql
References: <6EE64EF3AB31D5448D0007DD34EEB3417DD640@Herge.rcsinc.local>
	<4357C4E8.6010602@comgate.cz> <11634.1129827054@sss.pgh.pa.us>
In-Reply-To: <11634.1129827054@sss.pgh.pa.us>
Content-Type: multipart/mixed; boundary="------------030704090600010405000005"
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.103 required=5 tests=[AWL=-0.103,
	UPPERCASE_25_50=0.207]
X-Spam-Level: 
X-Archive-Number: 200510/290
X-Sequence-Number: 15058

This is a multi-part message in MIME format.
--------------030704090600010405000005
Content-Type: text/plain; charset=windows-1250; format=flowed
Content-Transfer-Encoding: 7bit

Tom,

many thanks. Perfect advice as usual...

Corrected version attached for the archives.

Kuba

Tom Lane napsal(a):
> Kuba Ouhrabka <kuba@comgate.cz> writes:
> 
>>  IF Var_datos.pronargs > 0 THEN
>>	Var_args := '';
>>	FOR i IN 0..Var_datos.pronargs-1 LOOP
>>		SELECT typname::varchar INTO Var_nameArg FROM pg_type WHERE oid = Var_datos.proargtypes[i];
> 
> 			
> 
>>		Var_args := Var_args|| COALESCE(Var_datos.proargnames[i+1], '') || ' ' || Var_nameArg||', ';
>>	END LOOP;
> 
> 
> This will not work at all; it makes far too many incorrect assumptions,
> like proargnames always being non-null and having subscripts that match
> proargtypes.  (It'll mess things up completely for anything that has OUT
> arguments, too.)
> 
> It's pretty much the hard way to form a function reference anyway ---
> you can just cast the function OID to regprocedure, which aside from
> avoiding a lot of subtle assumptions about the catalog contents,
> will deal with schema naming issues, something the above likewise
> fails at.
> 
> To avoid having to reconstruct argument names/types, I'd suggest using
> an ALTER FUNCTION command instead of CREATE OR REPLACE FUNCTION, maybe
> 
> 	DECLARE fullproname text := a_oid::regprocedure;
> 	...
> 	EXECUTE 'ALTER FUNCTION ' || fullproname || ' RENAME TO ' || Var_datos.proname;
> 
> 			regards, tom lane

--------------030704090600010405000005
Content-Type: text/plain;
 name="recompile.sql"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="recompile.sql"

CREATE OR REPLACE FUNCTION recompile_all_functions() RETURNS INTEGER AS $func$
DECLARE
	lr_rec RECORD;
	li_x INTEGER;
BEGIN

	FOR lr_rec IN 
	SELECT 
		p.oid as oid
	FROM 
		pg_catalog.pg_proc p
        LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace
        LEFT JOIN pg_language l ON l.oid = p.prolang
	WHERE 
	    	NOT p.proisagg
	    AND pg_catalog.pg_function_is_visible(p.oid)
    	AND n.nspname != 'pg_catalog'
	    AND NOT p.proname IN ('recompile_all_functions', 'recompile_function')
	    AND l.lanname = 'plpgsql'
	LOOP
		li_x := recompile_function(lr_rec.oid);
	END LOOP;


	RETURN 0;
END;
$func$ LANGUAGE 'plpgsql';

CREATE OR REPLACE FUNCTION recompile_function(a_oid oid) RETURNS INTEGER AS $func$
DECLARE
  lv_name TEXT;
  lv_fullname TEXT;
BEGIN

  SELECT INTO lv_name proname FROM pg_proc 
  WHERE 
  		oid = a_oid
  ;

  lv_fullname := a_oid::regprocedure;
  
  EXECUTE 'ALTER FUNCTION ' || lv_fullname || ' RENAME TO ugly_function_name';
  lv_fullname := a_oid::regprocedure;
  EXECUTE 'ALTER FUNCTION ' || lv_fullname || ' RENAME TO ' || lv_name;

  RETURN 0;

END;
$func$ LANGUAGE 'plpgsql';

--------------030704090600010405000005--

From pgsql-performance-owner@postgresql.org  Fri Oct 21 04:49:08 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 29CD6DA9A4
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 21 Oct 2005 04:49:07 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 28896-10
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 21 Oct 2005 07:49:02 +0000 (GMT)
Received: from floppy.pyrenet.fr (floppy.pyrenet.fr [194.116.145.2])
	by svr1.postgresql.org (Postfix) with ESMTP id 3B5F5DA986
	for <pgsql-performance@postgresql.org>;
	Fri, 21 Oct 2005 04:49:03 -0300 (ADT)
Received: by floppy.pyrenet.fr (Postfix, from userid 106)
	id 4CB8731059; Fri, 21 Oct 2005 09:49:03 +0200 (MET DST)
From: Martin Nickel <martin@portant.com>
X-Newsgroups: pgsql.performance
Subject: Re: Sequential scan on FK join
Date: Fri, 21 Oct 2005 02:59:14 -0500
Organization: Hub.Org Networking Services
Lines: 61
Message-ID: <pan.2005.10.21.07.59.13.750857@portant.com>
References: <pan.2005.10.12.20.40.22.703085@portant.com>
	<4353648C.8040507@archonet.com>
	<pan.2005.10.17.13.07.53.915839@portant.com>
	<4353E342.2060708@archonet.com>
	<pan.2005.10.17.19.56.36.629275@portant.com>
	<4354A9AF.30300@archonet.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Complaints-To: usenet@news.hub.org
User-Agent: Pan/0.14.2 (This is not a psychotic episode. It's a cleansing
	moment of clarity.)
To: pgsql-performance@postgresql.org
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0 required=5 tests=[none]
X-Spam-Level: 
X-Archive-Number: 200510/291
X-Sequence-Number: 15059

On Tue, 18 Oct 2005 08:52:15 +0100, Richard Huxton wrote:

> Martin Nickel wrote:
>> When I turn of seqscan it does use the index - and it runs 20 to 30%
>> longer.  Based on that, the planner is correctly choosing a sequential
>> scan - but that's just hard for me to comprehend.  I'm joining on an
>> int4 key, 2048 per index page - I guess that's a lot of reads - then the
>> data -page reads.  Still, the 8-minute query time seems excessive.
> 
> You'll be getting (many) fewer than 2048 index entries per page. There's a
> page header and various pointers involved too, and index pages aren't
> going to be full. So - it needs to search the table on dates, fetch the
> id's and then assemble them for the hash join. Of course, if you have too
> many to join then all this will spill to disk slowing you further.
> 
> Now, you'd rather get down below 8 minutes. There are a number of options:
>   1. Make sure your disk i/o is being pushed to its limit 
We are completely peaked out on disk io.  iostat frequently shows 60%
iowait time.  This is quite an issue for us and I don't have any
great ideas.  Data is on a 3ware sata raid at raid 10 across 4 disks.  I
can barely even run vacuums on our largest table (lead) since it runs for
a day and a half and kills our online performance while running.

> 2. Look into increasing the sort memory for this one query "set
> work_mem..." (see the runtime configuration section of the manual)
I haven't tried this, and I will.  Thanks for the idea.

>   3. Actually - are you happy that your general configuration is OK? 
I'm not at all.  Most of the configuration changes I've tried have made
almost no discernable difference.  I'll post the relevant numbers in a
different post - possibly you'll have some suggestions.

> 4. Perhaps use a cursor - I'm guessing you want to process these
> mailings in some way and only want them one at a time in any case.
Where this first came up was in trying to get aggregate totals per
mailing.  I gave up on that and created a nightly job to create a summary
table since Postgres wasn't up to the job in real time.  Still, I
frequently need to do the join and limit it by other criteria - and it is
incredibly slow - even when the result set is smallish.

>   5. Try the query one day at a time and see if the balance tips the
> other way - you'll be dealing with substantially less data per query
> which might match your system better. Of course, this may not be
> practical for your applicaton.
It is not useful.

>   6. If your lead table is updated only rarely, you could try a CLUSTER
> on the table by mailing_id - that should speed the scan. Read the manual
> for the cluster command first though.
The lead table is one of the most volatle in our system.  Each day we
insert tens or hundreds of thousands of rows, update almost that many, and
delete a few.  It is growing, and could reach 100 million rows in 8 or 9
months.  We're redesigning the data structure a little so lead is not
updated (updates are just too slow), but it will continue to have inserts
and deletes, and we'll have to join it with the associated table being
updated, which already promises to be a slow operation.

We're looking at 15K rpm scsi drives for a replacement raid array.  We are
getting the place where it may be cheaper to convert to Oracle or DB2 than
to try and make Posgres work.


From pgsql-performance-owner@postgresql.org  Fri Oct 21 04:58:32 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id B3AEDD6E78
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 21 Oct 2005 04:58:31 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 30720-10
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 21 Oct 2005 07:58:28 +0000 (GMT)
Received: from mailer.eglobalreach.net (mail.padalacentral.com
	[202.124.128.22])
	by svr1.postgresql.org (Postfix) with ESMTP id 52F59DA9BB
	for <pgsql-performance@postgresql.org>;
	Fri, 21 Oct 2005 04:58:28 -0300 (ADT)
Received: from ghwk02002147 (localhost [127.0.0.1] (may be forged))
	by mailer.eglobalreach.net (8.11.6p2/) with ESMTP id j9L7wTs26784
	for <pgsql-performance@postgresql.org>; Fri, 21 Oct 2005 15:58:29 +0800
From: "Christian Paul B. Cosinas" <cpc@cybees.com>
To: <pgsql-performance@postgresql.org>
Subject: Re: Used Memory
Date: Fri, 21 Oct 2005 08:02:40 -0000
Message-ID: <011101c5d615$cf56b2b0$1e21100a@ghwk02002147>
MIME-Version: 1.0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
X-Mailer: Microsoft Office Outlook 11
In-Reply-To: <28EE02F5BBCA481B51C4E44E@[192.168.1.72]>
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506
Thread-Index: AcXWEFcoAHG1cVOITHaHyPh019MTKAABS1XQ
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.679 required=5 tests=[AWL=0.000,
	FORGED_RCVD_HELO=0.05, URIBL_SBL=0.629]
X-Spam-Level: 
X-Archive-Number: 200510/292
X-Sequence-Number: 15060




But as long as the memory is in the cache my database became much =
slower.
What could probably be the cause of this? But When I restarted the =
database
is back to normal processing.
-----Original Message-----
From: Jens-Wolfhard Schicke [mailto:ml+pgsql-performance@asco.de]
Sent: Friday, October 21, 2005 7:23 AM
To: Christian Paul B. Cosinas; pgsql-performance@postgresql.org
Subject: Re: [PERFORM] Used Memory

--On Freitag, Oktober 21, 2005 03:40:47 +0000 "Christian Paul B. =
Cosinas"=20
<cpc@cybees.com> wrote:
> I am having a confusion to the memory handling of postgreSQL.
> I rebooted my Server which is a PostgreSQL 8.0 Running on Redhat 9,=20
> which is a Dual Xeon Server and 6 gig of memory.
>
> Of course there is not much memory still used since it is just =
restarted.
>
> But after a number of access to the tables the memory is being used=20
> and it is not being free up. Actually after this access to the=20
> database and the server is just idle
>
> The memory is still used up. I am monitoring this using the "free"
> command which gives me about 5.5 gig of used memory and the rest free.
I suppose you looked at the top row of the free output?

Because there the disk-cache is counted as "used"... Have a look at the
second row where buffers are counted as free, which they more or less =
are.

> Is there something that I should do to minimize and free up the used=20
> memory?
No, the buffers make your database faster because they reduce direct =
disk
access

> I choose Polesoft Lockspam to fight spam, and you?
> http://www.polesoft.com/refer.html
I don't :)

Mit freundlichem Gru=DF,
Jens Schicke
--=20
Jens Schicke		      j.schicke@asco.de
asco GmbH		      http://www.asco.de
Mittelweg 7		      Tel 0531/3906-127
38106 Braunschweig	      Fax 0531/3906-400


I choose Polesoft Lockspam to fight spam, and you?
http://www.polesoft.com/refer.html   =20


From pgsql-performance-owner@postgresql.org  Fri Oct 21 05:04:07 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 2C884DA983
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 21 Oct 2005 05:04:06 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 36259-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 21 Oct 2005 08:04:03 +0000 (GMT)
Received: from mailer.eglobalreach.net (mail.padalacentral.com
	[202.124.128.22])
	by svr1.postgresql.org (Postfix) with ESMTP id CD03FDA9C4
	for <pgsql-performance@postgresql.org>;
	Fri, 21 Oct 2005 05:04:03 -0300 (ADT)
Received: from ghwk02002147 (localhost [127.0.0.1] (may be forged))
	by mailer.eglobalreach.net (8.11.6p2/) with ESMTP id j9L845X25506
	for <pgsql-performance@postgresql.org>; Fri, 21 Oct 2005 16:04:05 +0800
From: "Christian Paul B. Cosinas" <cpc@cybees.com>
To: <pgsql-performance@postgresql.org>
Subject: Re: Used Memory
Date: Fri, 21 Oct 2005 08:08:16 -0000
Message-ID: <011501c5d616$97766330$1e21100a@ghwk02002147>
MIME-Version: 1.0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
X-Mailer: Microsoft Office Outlook 11
In-Reply-To: <28EE02F5BBCA481B51C4E44E@[192.168.1.72]>
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506
Thread-Index: AcXWEFcoAHG1cVOITHaHyPh019MTKAABiD4A
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.679 required=5 tests=[AWL=0.000,
	FORGED_RCVD_HELO=0.05, URIBL_SBL=0.629]
X-Spam-Level: 
X-Archive-Number: 200510/293
X-Sequence-Number: 15061


Also Does Creating Temporary table in a function and not dropping them
affects the performance of the database?


-----Original Message-----
From: Jens-Wolfhard Schicke [mailto:ml+pgsql-performance@asco.de]
Sent: Friday, October 21, 2005 7:23 AM
To: Christian Paul B. Cosinas; pgsql-performance@postgresql.org
Subject: Re: [PERFORM] Used Memory

--On Freitag, Oktober 21, 2005 03:40:47 +0000 "Christian Paul B. =
Cosinas"=20
<cpc@cybees.com> wrote:
> I am having a confusion to the memory handling of postgreSQL.
> I rebooted my Server which is a PostgreSQL 8.0 Running on Redhat 9,=20
> which is a Dual Xeon Server and 6 gig of memory.
>
> Of course there is not much memory still used since it is just =
restarted.
>
> But after a number of access to the tables the memory is being used=20
> and it is not being free up. Actually after this access to the=20
> database and the server is just idle
>
> The memory is still used up. I am monitoring this using the "free"
> command which gives me about 5.5 gig of used memory and the rest free.
I suppose you looked at the top row of the free output?

Because there the disk-cache is counted as "used"... Have a look at the
second row where buffers are counted as free, which they more or less =
are.

> Is there something that I should do to minimize and free up the used=20
> memory?
No, the buffers make your database faster because they reduce direct =
disk
access

> I choose Polesoft Lockspam to fight spam, and you?
> http://www.polesoft.com/refer.html
I don't :)

Mit freundlichem Gru=DF,
Jens Schicke
--=20
Jens Schicke		      j.schicke@asco.de
asco GmbH		      http://www.asco.de
Mittelweg 7		      Tel 0531/3906-127
38106 Braunschweig	      Fax 0531/3906-400


I choose Polesoft Lockspam to fight spam, and you?
http://www.polesoft.com/refer.html   =20


From pgsql-performance-owner@postgresql.org  Fri Oct 21 05:41:44 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 19D95D818E
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 21 Oct 2005 05:41:43 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 42565-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 21 Oct 2005 08:41:40 +0000 (GMT)
Received: from floppy.pyrenet.fr (floppy.pyrenet.fr [194.116.145.2])
	by svr1.postgresql.org (Postfix) with ESMTP id 3D462D7D4D
	for <pgsql-performance@postgresql.org>;
	Fri, 21 Oct 2005 05:41:41 -0300 (ADT)
Received: by floppy.pyrenet.fr (Postfix, from userid 106)
	id 2A6AC31059; Fri, 21 Oct 2005 10:41:43 +0200 (MET DST)
From: Martin Nickel <martin@portant.com>
X-Newsgroups: pgsql.performance
Subject: Re: Sequential scan on FK join
Date: Fri, 21 Oct 2005 03:51:56 -0500
Organization: Hub.Org Networking Services
Lines: 26
Message-ID: <pan.2005.10.21.08.51.54.741707@portant.com>
References: <pan.2005.10.12.20.40.22.703085@portant.com>
	<4353648C.8040507@archonet.com>
	<pan.2005.10.17.13.07.53.915839@portant.com>
	<4353E342.2060708@archonet.com>
	<pan.2005.10.17.19.56.36.629275@portant.com>
	<4354A9AF.30300@archonet.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Complaints-To: usenet@news.hub.org
User-Agent: Pan/0.14.2 (This is not a psychotic episode. It's a cleansing
	moment of clarity.)
To: pgsql-performance@postgresql.org
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0 required=5 tests=[none]
X-Spam-Level: 
X-Archive-Number: 200510/294
X-Sequence-Number: 15062

On Tue, 18 Oct 2005 08:52:15 +0100, Richard Huxton wrote:
>   3. Actually - are you happy that your general configuration is OK? 
We're running dual Opteron 244s with 4G of memory.  The platform is
Suse 9.3, 64 bit.  The database is on a 3ware 9500S-8 sata raid controller
configured raid 10 with 4 drives plus a hot swap.  Drives are
7400 rpm (don't remember model or size).

I'm running Postgres 8.0.3.  Here are some of the relevant conf file
parameters:
shared_buffers = 50000
sort_mem = 8192
work_mem = 256000
vacuum_mem = 32768
max_fsm_pages = 40000
max_fsm_relations = 1000

I realize shared_buffers is too high.  Not sure on the others.  Thanks for
any help you can suggest.  I've moved most of these around some and
restarted without any clear changes for the better or worse (just
seat-of-the-pants feel - I haven't tried to benchmark the result of
changes at all).

Thanks,
Martin



From pgsql-performance-owner@postgresql.org  Fri Oct 21 09:24:22 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id A7673D9CA3
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 21 Oct 2005 09:24:21 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 43196-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 21 Oct 2005 12:24:17 +0000 (GMT)
Received: from floppy.pyrenet.fr (floppy.pyrenet.fr [194.116.145.2])
	by svr1.postgresql.org (Postfix) with ESMTP id BF567D904F
	for <pgsql-performance@postgresql.org>;
	Fri, 21 Oct 2005 09:24:17 -0300 (ADT)
Received: by floppy.pyrenet.fr (Postfix, from userid 106)
	id 0D7DF31059; Fri, 21 Oct 2005 14:24:17 +0200 (MET DST)
From: Martin Nickel <martin@portant.com>
X-Newsgroups: pgsql.performance
Subject: What gets cached?
Date: Fri, 21 Oct 2005 07:34:30 -0500
Organization: Hub.Org Networking Services
Lines: 15
Message-ID: <pan.2005.10.21.12.34.29.712700@portant.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Complaints-To: usenet@news.hub.org
User-Agent: Pan/0.14.2 (This is not a psychotic episode. It's a cleansing
	moment of clarity.)
To: pgsql-performance@postgresql.org
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0 required=5 tests=[none]
X-Spam-Level: 
X-Archive-Number: 200510/295
X-Sequence-Number: 15063

I was reading a comment in another posting and it started me thinking
about this.  Let's say I startup an Oracle server.  All my queries are a
little bit (sometimes a lot bit) slow until it gets its "normal" things in
memory, then it's up to speed.  The "normal" things would include some
small lookup tables and the indexes for the most frequently used tables.

Let's say I do the same thing in Postgres.  I'm likely to have my very
fastest performance for the first few queries until memory gets filled up.
 The only time Postgres seems to take advantage of cached data is when I
 repeat the same (or substantially the same) query.  I don't know of any
 way to view what is actually cached at any point in time, but it seems
 like "most recently used" rather than "most frequently used".  

Does this seem true?
 s

From pgsql-performance-owner@postgresql.org  Fri Oct 21 09:40:40 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 3D482D9B43
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 21 Oct 2005 09:40:39 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 83355-06
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 21 Oct 2005 12:40:34 +0000 (GMT)
Received: from cassarossa.samfundet.no (cassarossa.samfundet.no
	[129.241.93.19])
	by svr1.postgresql.org (Postfix) with ESMTP id 4D4DAD904F
	for <pgsql-performance@postgresql.org>;
	Fri, 21 Oct 2005 09:40:35 -0300 (ADT)
Received: from sesse by cassarossa.samfundet.no with local (Exim 4.50)
	id 1ESwCM-0000sw-HD
	for pgsql-performance@postgresql.org; Fri, 21 Oct 2005 14:40:38 +0200
Date: Fri, 21 Oct 2005 14:40:38 +0200
From: "Steinar H. Gunderson" <sgunderson@bigfoot.com>
To: pgsql-performance@postgresql.org
Subject: Re: What gets cached?
Message-ID: <20051021124038.GA1928@samfundet.no>
References: <pan.2005.10.21.12.34.29.712700@portant.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <pan.2005.10.21.12.34.29.712700@portant.com>
User-Agent: Mutt/1.5.9i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.011 required=5 tests=[AWL=0.011]
X-Spam-Level: 
X-Archive-Number: 200510/296
X-Sequence-Number: 15064

On Fri, Oct 21, 2005 at 07:34:30AM -0500, Martin Nickel wrote:
> Let's say I do the same thing in Postgres.  I'm likely to have my very
> fastest performance for the first few queries until memory gets filled up.
>  The only time Postgres seems to take advantage of cached data is when I
>  repeat the same (or substantially the same) query.  I don't know of any
>  way to view what is actually cached at any point in time, but it seems
>  like "most recently used" rather than "most frequently used". 

What version are you using? There have been significant improvements to the
buffer manager in the last few versions. Most of the caching is done by your
OS, though, so that would probably influence the results quite a bit.

/* Steinar */
-- 
Homepage: http://www.sesse.net/


From pgsql-performance-owner@postgresql.org  Fri Oct 21 12:19:22 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 0B5FEDA990
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 21 Oct 2005 12:19:15 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 61692-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 21 Oct 2005 15:19:11 +0000 (GMT)
Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.196])
	by svr1.postgresql.org (Postfix) with ESMTP id A72E6DA93B
	for <pgsql-performance@postgresql.org>;
	Fri, 21 Oct 2005 12:19:11 -0300 (ADT)
Received: by wproxy.gmail.com with SMTP id 71so267969wra
	for <pgsql-performance@postgresql.org>;
	Fri, 21 Oct 2005 08:19:10 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references;
	b=FRSvkqtyXdQk3uBBXJ53pfRf6zNTEoKfJPQW/kmofMn73zMBmawj7JPcFZTalI+bbrtvBBZ3hSxFHS6XTtj4CP0TKKPnshUAYGsgcB64lfAIk2tF61yPbxqZWocJmjpng1LTQObNjWObYwzqDk63Ez/sX+auWY2ylvWcrLiqTFA=
Received: by 10.54.82.16 with SMTP id f16mr1569699wrb;
	Fri, 21 Oct 2005 08:19:10 -0700 (PDT)
Received: by 10.54.86.17 with HTTP; Fri, 21 Oct 2005 08:19:10 -0700 (PDT)
Message-ID: <33c6269f0510210819k1e0da6ase7009a4f561167a7@mail.gmail.com>
Date: Fri, 21 Oct 2005 11:19:10 -0400
From: Alex Turner <armtuk@gmail.com>
To: Martin Nickel <martin@portant.com>
Subject: Re: What gets cached?
Cc: pgsql-performance@postgresql.org
In-Reply-To: <pan.2005.10.21.12.34.29.712700@portant.com>
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="----=_Part_19267_11743752.1129907950471"
References: <pan.2005.10.21.12.34.29.712700@portant.com>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.137 required=5 tests=[AWL=0.056, HTML_30_40=0.056,
	HTML_MESSAGE=0.001, RCVD_BY_IP=0.024]
X-Spam-Level: 
X-Archive-Number: 200510/297
X-Sequence-Number: 15065

------=_Part_19267_11743752.1129907950471
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Oracle uses LRU caching algorithm also, not LFU.

Alex

On 10/21/05, Martin Nickel <martin@portant.com> wrote:
>
> I was reading a comment in another posting and it started me thinking
> about this. Let's say I startup an Oracle server. All my queries are a
> little bit (sometimes a lot bit) slow until it gets its "normal" things i=
n
> memory, then it's up to speed. The "normal" things would include some
> small lookup tables and the indexes for the most frequently used tables.
>
> Let's say I do the same thing in Postgres. I'm likely to have my very
> fastest performance for the first few queries until memory gets filled up=
.
> The only time Postgres seems to take advantage of cached data is when I
> repeat the same (or substantially the same) query. I don't know of any
> way to view what is actually cached at any point in time, but it seems
> like "most recently used" rather than "most frequently used".
>
> Does this seem true?
> s
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
>
> http://archives.postgresql.org
>

------=_Part_19267_11743752.1129907950471
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Oracle uses LRU caching algorithm also, not LFU.<br>
<br>
Alex<br><br><div><span class=3D"gmail_quote">On 10/21/05, <b class=3D"gmail=
_sendername">Martin Nickel</b> &lt;<a href=3D"mailto:martin@portant.com">ma=
rtin@portant.com</a>&gt; wrote:</span><blockquote class=3D"gmail_quote" sty=
le=3D"border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex;=
 padding-left: 1ex;">
I was reading a comment in another posting and it started me thinking<br>ab=
out this.&nbsp;&nbsp;Let's say I startup an Oracle server.&nbsp;&nbsp;All m=
y queries are a<br>little bit (sometimes a lot bit) slow until it gets its =
&quot;normal&quot; things in
<br>memory, then it's up to speed.&nbsp;&nbsp;The &quot;normal&quot; things=
 would include some<br>small lookup tables and the indexes for the most fre=
quently used tables.<br><br>Let's say I do the same thing in Postgres.&nbsp=
;&nbsp;I'm likely to have my very
<br>fastest performance for the first few queries until memory gets filled =
up.<br> The only time Postgres seems to take advantage of cached data is wh=
en I<br> repeat the same (or substantially the same) query.&nbsp;&nbsp;I do=
n't know of any
<br> way to view what is actually cached at any point in time, but it seems=
<br> like &quot;most recently used&quot; rather than &quot;most frequently =
used&quot;.<br><br>Does this seem true?<br> s<br><br>----------------------=
-----(end of broadcast)---------------------------
<br>TIP 4: Have you searched our list archives?<br><br>&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href=3D=
"http://archives.postgresql.org">http://archives.postgresql.org</a><br></bl=
ockquote></div><br>

------=_Part_19267_11743752.1129907950471--

From pgsql-performance-owner@postgresql.org  Fri Oct 21 12:30:08 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 9A0EDDA8A3
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 21 Oct 2005 12:29:40 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 28320-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 21 Oct 2005 15:29:37 +0000 (GMT)
Received: from mail1.npci.com (mail.npcinternational.com [63.76.154.140])
	by svr1.postgresql.org (Postfix) with ESMTP id 5E5D2DA79E
	for <pgsql-performance@postgresql.org>;
	Fri, 21 Oct 2005 12:29:37 -0300 (ADT)
Received: from localhost ([172.16.10.91]) by mail1.npci.com (MOS 3.5.9-GR)
	with ESMTP id BVU02724 (AUTH via LOGINBEFORESMTP);
	Fri, 21 Oct 2005 10:24:59 -0500 (CDT)
Date: Fri, 21 Oct 2005 10:29:35 -0500
From: Jon Brisbin <jon.brisbin@npcinternational.com>
To: pgsql-performance@postgresql.org
Subject: Re: Used Memory
Message-ID: <20051021102935.5e4b7113@localhost>
In-Reply-To: <00a401c5d5f1$39f661d0$1e21100a@ghwk02002147>
References: <3cf983d0510181107sb060171je702da5fe0c29252@mail.gmail.com>
	<00a401c5d5f1$39f661d0$1e21100a@ghwk02002147>
Organization: NPC International
X-Mailer: Sylpheed-Claws 1.9.13 (GTK+ 2.6.7; i686-pc-linux-gnu)
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.293 required=5 tests=[AWL=0.243,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/298
X-Sequence-Number: 15066

On Fri, 21 Oct 2005 03:40:47 -0000
"Christian Paul B. Cosinas" <cpc@cybees.com> wrote:

>
> But after a number of access to the tables the memory is being used
> and it is not being free up. Actually after this access to the
> database and the server is just idle

I noticed this behavior on my SUSE linux box as well. I thought it was
a memory leak in something (I think there was an actual memory leak in
the kernel shared memory stuff, which I fixed by upgrading my kernel
to 2.6.13-ck8). It turns out that some file systems are better than
others when it comes to increasing the performance of I/O on Linux.
ReiserFS was what I put on originally and by the end of the day, the
box would be using all of it's available memory in caching inodes.

I kept rebooting and trying to get the memory usage to go down, but it
never did. All but 500MB of it was disk cache. I let my apps just run
and when the application server needed more memory, it reclaimed it from
the disk cache, so there weren't side effects to the fact that top and
free always reported full memory usage.

They tell me that this is a good thing, as it reduces disk I/O and
increases performance. That's all well and good, but it's entirely
unnecessary in our situation. Despite that, I can't turn it off because
my research into the issue has shown that kernel developers don't want
users to be able to turn off disk caching. There is a value
in /proc/sys/vm/vfs_cache_pressure that can be changed, which will
affect the propensity of the kernel to cache files in RAM (google it
to find the suggestions on what value to set it to), but there isn't a
setting to turn that off on purpose.

After rolling my own CK-based kernel, switching to XFS, and tweaking
the nice and CPU affinity of my database process (I use schedtool in my
CK kernel to run it at SCHED_FIFO, nice -15, and CPU affinity confined
to the second processor in my dual Xeon eServer) has got me to the
point that the perpetually high memory usage doesn't affect my
application server.

Hope any of this helps.

Jon Brisbin
Webmaster
NPC International, Inc.

From pgsql-performance-owner@postgresql.org  Fri Oct 21 12:41:39 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 48103D9D1F
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 21 Oct 2005 12:41:38 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 71612-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 21 Oct 2005 15:41:35 +0000 (GMT)
Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.202])
	by svr1.postgresql.org (Postfix) with ESMTP id 009B1D8307
	for <pgsql-performance@postgresql.org>;
	Fri, 21 Oct 2005 12:41:34 -0300 (ADT)
Received: by wproxy.gmail.com with SMTP id 71so271027wra
	for <pgsql-performance@postgresql.org>;
	Fri, 21 Oct 2005 08:41:34 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references;
	b=RJIwPBccX+8uMwh2biDcW6B0T+2VD1w20DX6unkeLRuYLnJrkS5x5yYNlLHax9LKAMPDDGl/iAnBD0r+/fBx7itPlfIcyB+Pon3IMxqegV3EL42CLcoKlGsm9XHqKK4NHyjYWvseRkBfCaP0OiM+4qMG+tWV3lyoChsnnPj1INw=
Received: by 10.54.99.10 with SMTP id w10mr1580331wrb;
	Fri, 21 Oct 2005 08:41:34 -0700 (PDT)
Received: by 10.54.86.17 with HTTP; Fri, 21 Oct 2005 08:41:34 -0700 (PDT)
Message-ID: <33c6269f0510210841h568f173ar2fa9ea4a7d105905@mail.gmail.com>
Date: Fri, 21 Oct 2005 11:41:34 -0400
From: Alex Turner <armtuk@gmail.com>
To: Jon Brisbin <jon.brisbin@npcinternational.com>
Subject: Re: Used Memory
Cc: pgsql-performance@postgresql.org
In-Reply-To: <20051021102935.5e4b7113@localhost>
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="----=_Part_19692_24632811.1129909294744"
References: <3cf983d0510181107sb060171je702da5fe0c29252@mail.gmail.com>
	<00a401c5d5f1$39f661d0$1e21100a@ghwk02002147>
	<20051021102935.5e4b7113@localhost>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.152 required=5 tests=[AWL=0.041, HTML_40_50=0.086,
	HTML_MESSAGE=0.001, RCVD_BY_IP=0.024]
X-Spam-Level: 
X-Archive-Number: 200510/299
X-Sequence-Number: 15067

------=_Part_19692_24632811.1129909294744
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

[snip]
>
> to the second processor in my dual Xeon eServer) has got me to the
> point that the perpetually high memory usage doesn't affect my
> application server.


I'm curious - how does the high memory usage affect your application server=
?

Alex

------=_Part_19692_24632811.1129909294744
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

[snip]<div><blockquote class=3D"gmail_quote" style=3D"border-left: 1px soli=
d rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">to the=
 second processor in my dual Xeon eServer) has got me to the<br>point that =
the perpetually high memory usage doesn't affect my
<br>application server.</blockquote><div><br>
I'm curious - how does the high memory usage affect your application server=
?<br>
<br>
Alex <br>
</div><br></div><br>

------=_Part_19692_24632811.1129909294744--

From pgsql-performance-owner@postgresql.org  Fri Oct 21 12:59:59 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 1E3AEDA8F8
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 21 Oct 2005 12:59:56 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 07975-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 21 Oct 2005 15:59:54 +0000 (GMT)
Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158])
	by svr1.postgresql.org (Postfix) with ESMTP id 502E4DA89B
	for <pgsql-performance@postgresql.org>;
	Fri, 21 Oct 2005 12:59:54 -0300 (ADT)
Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1])
	by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id j9LFxivr097421
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);
	Fri, 21 Oct 2005 09:59:46 -0600 (MDT)
	(envelope-from mfuhr@winnie.fuhr.org)
Received: from winnie.fuhr.org (localhost [127.0.0.1])
	by winnie.fuhr.org (8.13.4/8.13.4) with ESMTP id j9LFxiu7053824;
	Fri, 21 Oct 2005 09:59:44 -0600 (MDT)
	(envelope-from mfuhr@winnie.fuhr.org)
Received: (from mfuhr@localhost)
	by winnie.fuhr.org (8.13.4/8.13.4/Submit) id j9LFxh0c053823;
	Fri, 21 Oct 2005 09:59:43 -0600 (MDT) (envelope-from mfuhr)
Date: Fri, 21 Oct 2005 09:59:43 -0600
From: Michael Fuhr <mike@fuhr.org>
To: Martin Nickel <martin@portant.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: What gets cached?
Message-ID: <20051021155943.GA53729@winnie.fuhr.org>
References: <pan.2005.10.21.12.34.29.712700@portant.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <pan.2005.10.21.12.34.29.712700@portant.com>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/300
X-Sequence-Number: 15068

On Fri, Oct 21, 2005 at 07:34:30AM -0500, Martin Nickel wrote:
> I don't know of any way to view what is actually cached at any point in time

In 8.1 (currently in beta) you can use contrib/pg_buffercache.  Code
for older versions is available on PgFoundry:

http://pgfoundry.org/projects/pgbuffercache/

Note that pg_buffercache shows only pages in PostgreSQL's buffer
cache; it doesn't show your operating system's cache.

-- 
Michael Fuhr

From pgsql-performance-owner@postgresql.org  Fri Oct 21 13:59:47 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 53533D82B7
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 21 Oct 2005 13:59:46 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 70072-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 21 Oct 2005 16:59:40 +0000 (GMT)
Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.203])
	by svr1.postgresql.org (Postfix) with ESMTP id 300FDD6E85
	for <pgsql-performance@postgresql.org>;
	Fri, 21 Oct 2005 13:59:38 -0300 (ADT)
Received: by wproxy.gmail.com with SMTP id i5so408770wra
	for <pgsql-performance@postgresql.org>;
	Fri, 21 Oct 2005 09:59:30 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references;
	b=HLklKjpSGTNzeiKfTun9qouBPvTG6sIoKzhrWipNgAW0ROfuwaJgboq3Tnxn8GwLPIzZxFpGhB8/E2BHWTwabiwAXQuzCMEb9N3+DMgIJupcNIqgYYq010GXWiicvnwGADq28UIDlwTkwR53Idoyr0Al1BCbZrXAOdNiMsG9QjI=
Received: by 10.54.34.19 with SMTP id h19mr1171222wrh;
	Fri, 21 Oct 2005 09:59:30 -0700 (PDT)
Received: by 10.54.103.6 with HTTP; Fri, 21 Oct 2005 09:59:30 -0700 (PDT)
Message-ID: <3cf983d0510210959y32fdb891gff11bfbaf1943ebe@mail.gmail.com>
Date: Fri, 21 Oct 2005 16:59:30 +0000
From: Rodrigo Madera <rodrigo.madera@gmail.com>
To: =?ISO-8859-1?Q?N=F6rder-Tuitje=2C_Marcus?= <noerder-tuitje@technology.de>
Subject: Re: Inefficient escape codes.
Cc: pgsql-performance@postgresql.org
In-Reply-To: 
 <16F953410A0F1346848DCB476A989CFE01D557@swtexchange2.technology.de>
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="----=_Part_23801_12446235.1129913970877"
References: 
 <16F953410A0F1346848DCB476A989CFE01D557@swtexchange2.technology.de>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.233 required=5 tests=[AWL=-0.087, HTML_10_20=0.295,
	HTML_MESSAGE=0.001, RCVD_BY_IP=0.024]
X-Spam-Level: 
X-Archive-Number: 200510/301
X-Sequence-Number: 15069

------=_Part_23801_12446235.1129913970877
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

> I guess, You should check, if a blob field and large object access is
> suitable for you - no escaping etc, just raw binary large objects.
>
> AFAIK, PQExecParams is not the right solution for You. Refer the "Large
> object" section:
>
> "28.3.5. Writing Data to a Large Object
> The function
> int lo_write(PGconn *conn, int fd, const char *buf, size_t len);writes le=
n
> bytes from buf to large object descriptor fd. The fd argument must have b=
een
> returned by a previous lo_open. The number of bytes actually written is
> returned. In the event of an error, the return value is negative."


Well, I read that large objects are kept in only ONE table. No matter what,
only the LOID would be kept. I can't affor that since I hav lots of tables
(using the image-album-app analogy, imagine that we have pictures from
several cities, each one corresponding to a city, like Memphis_Photos,
Chicago_Photos, etc.).

This is one major drawback, isn't it?

Rodrigo

------=_Part_23801_12446235.1129913970877
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

<br>
<div><blockquote class=3D"gmail_quote" style=3D"border-left: 1px solid rgb(=
204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">I
guess, You should check, if a blob field and large object access is
suitable for you - no escaping etc, just raw binary large objects.<br><br>A=
FAIK, PQExecParams is not the right solution for You. Refer the &quot;Large=
 object&quot; section:<br><br>&quot;28.3.5. Writing Data to a Large Object
<br>The function<br>int
lo_write(PGconn *conn, int fd, const char *buf, size_t len);writes len
bytes from buf to large object descriptor fd. The fd argument must have
been returned by a previous lo_open. The number of bytes actually
written is returned. In the event of an error, the return value is
negative.&quot;</blockquote><div><br>
Well, I read that large objects are kept in only ONE table. No matter
what, only the LOID would be kept. I can't affor that since I hav lots
of tables (using the image-album-app analogy, imagine that we have
pictures from several cities, each one corresponding to a city, like
Memphis_Photos, Chicago_Photos, etc.).<br>
<br>
This is one major drawback, isn't it?<br>
<br>
Rodrigo<br>
</div><br>
</div><br>

------=_Part_23801_12446235.1129913970877--

From pgsql-performance-owner@postgresql.org  Mon Oct 24 23:50:50 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 0566DDA928
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 21 Oct 2005 14:17:24 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 14648-07
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 21 Oct 2005 17:17:17 +0000 (GMT)
Received: from planae.com.br (nat.planae.com.br [200.210.129.190])
	by svr1.postgresql.org (Postfix) with SMTP id 5E400DA89B
	for <pgsql-performance@postgresql.org>;
	Fri, 21 Oct 2005 14:17:15 -0300 (ADT)
Received: (qmail 68001 invoked by uid 0); 21 Oct 2005 17:21:16 -0000
Received: from 192.168.0.126 by mercurio.planae.com.br (envelope-from
	<pgsql-performance-owner@postgresql.org>,
	uid 0) with qmail-scanner-1.23 (uvscan: v4.3.20/v4610.  
	Clear:RC:1(192.168.0.126):.
	Processed in 1.041069 secs); 21 Oct 2005 17:21:16 -0000
X-Qmail-Scanner-Mail-From: pgsql-performance-owner@postgresql.org via
	mercurio.planae.com.br
X-Qmail-Scanner: 1.23 (Clear:RC:1(192.168.0.126):. Processed in 1.041069 secs)
Received: from unknown (HELO mail.planae.com.br) (192.168.0.126)
	by 192.168.0.3 with SMTP; 21 Oct 2005 17:21:15 -0000
Received: from mail pickup service by mail.planae.com.br with Microsoft
	SMTPSVC; Fri, 21 Oct 2005 14:15:59 -0300
Content-class: urn:content-classes:message
In-Reply-To: 
 <16F953410A0F1346848DCB476A989CFE01D557@swtexchange2.technology.de>
References: 
 <16F953410A0F1346848DCB476A989CFE01D557@swtexchange2.technology.de>
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="----_=_NextPart_001_01C5D663.1AD1F180"
X-Mailer: Microsoft CDO for Exchange 2000
X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0
X-Qmail-Scanner: 1.23 (Clear:RC:0(207.173.203.130):. Processed in 1.694492
	secs)
X-Qmail-Scanner-Mail-From: 
 pgsql-performance-owner+M15069=gfnobrega=planae.com.br@postgresql.org
	via mercurio.planae.com.br
X-OriginalArrivalTime: 21 Oct 2005 17:15:59.0612 (UTC)
	FILETIME=[1B2F53C0:01C5D663]
X-Virus-Scanned: by amavisd-new at hub.org
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
X-Mailing-List: pgsql-performance
X-Virus-Status: Clean
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references;
	b=HLklKjpSGTNzeiKfTun9qouBPvTG6sIoKzhrWipNgAW0ROfuwaJgboq3Tnxn8GwLPIzZxFpGhB8/E2BHWTwabiwAXQuzCMEb9N3+DMgIJupcNIqgYYq010GXWiicvnwGADq28UIDlwTkwR53Idoyr0Al1BCbZrXAOdNiMsG9QjI=
X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-1.6
	(www.commandprompt.com [192.168.2.159]);
	Fri, 21 Oct 2005 10:04:52 -0700 (PDT)
Subject: Re: Inefficient escape codes.
Date: Fri, 21 Oct 2005 14:15:58 -0300
Message-ID: <000501c5d663$1a907bb0$7e00a8c0@Planae2004.local>
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
Thread-Topic: [PERFORM] Inefficient escape codes.
thread-index: AcXWYxqQ8Th5JIAASqCrAqf+bZwYug==
From: "Rodrigo Madera" <rodrigo.madera@gmail.com>
To: <N�rder-Tuitje@svr1.postgresql.org>,
	"Marcus" <noerder-tuitje@technology.de>,
	"IMB Recipient 1" <mspop3connector.gfnobrega@planae2004.local>
Cc: <pgsql-performance@postgresql.org>
X-Virus-Scanned: by amavisd-new at hub.org
X-Amavis-Alert: BAD HEADER Non-encoded 8-bit data (char F6 hex) in message
	header 'To': To: <N\366rder-Tuitje@svr...
X-Spam-Status: No, hits=0.32 required=5 tests=[HTML_10_20=0.295,
	HTML_MESSAGE=0.001, RCVD_BY_IP=0.024]
X-Spam-Level: 
X-Archive-Number: 200510/345
X-Sequence-Number: 15113

This is a multi-part message in MIME format.

------_=_NextPart_001_01C5D663.1AD1F180
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable


	I guess, You should check, if a blob field and large object access is =
suitable for you - no escaping etc, just raw binary large objects.
=09
	AFAIK, PQExecParams is not the right solution for You. Refer the "Large =
object" section:
=09
	"28.3.5. Writing Data to a Large Object=20
	The function
	int lo_write(PGconn *conn, int fd, const char *buf, size_t len);writes =
len bytes from buf to large object descriptor fd. The fd argument must =
have been returned by a previous lo_open. The number of bytes actually =
written is returned. In the event of an error, the return value is =
negative."


Well, I read that large objects are kept in only ONE table. No matter =
what, only the LOID would be kept. I can't affor that since I hav lots =
of tables (using the image-album-app analogy, imagine that we have =
pictures from several cities, each one corresponding to a city, like =
Memphis_Photos, Chicago_Photos, etc.).

This is one major drawback, isn't it?

Rodrigo




------_=_NextPart_001_01C5D663.1AD1F180
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<br>
<div><blockquote class=3D"gmail_quote" style=3D"border-left: 1px solid =
rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">I
guess, You should check, if a blob field and large object access is
suitable for you - no escaping etc, just raw binary large =
objects.<br><br>AFAIK, PQExecParams is not the right solution for You. =
Refer the &quot;Large object&quot; section:<br><br>&quot;28.3.5. Writing =
Data to a Large Object
<br>The function<br>int
lo_write(PGconn *conn, int fd, const char *buf, size_t len);writes len
bytes from buf to large object descriptor fd. The fd argument must have
been returned by a previous lo_open. The number of bytes actually
written is returned. In the event of an error, the return value is
negative.&quot;</blockquote><div><br>
Well, I read that large objects are kept in only ONE table. No matter
what, only the LOID would be kept. I can't affor that since I hav lots
of tables (using the image-album-app analogy, imagine that we have
pictures from several cities, each one corresponding to a city, like
Memphis_Photos, Chicago_Photos, etc.).<br>
<br>
This is one major drawback, isn't it?<br>
<br>
Rodrigo<br>
</div><br>
</div><br>

------_=_NextPart_001_01C5D663.1AD1F180--

From pgsql-performance-owner@postgresql.org  Fri Oct 21 18:44:43 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id EDC93DA9E6
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 21 Oct 2005 18:44:41 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 02134-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 21 Oct 2005 21:44:38 +0000 (GMT)
Received: from mailbox.samurai.com (mailbox.samurai.com [205.207.28.82])
	by svr1.postgresql.org (Postfix) with ESMTP id 2AAAEDA9E9
	for <pgsql-performance@postgresql.org>;
	Fri, 21 Oct 2005 18:44:40 -0300 (ADT)
Received: from localhost (mailbox.samurai.com [205.207.28.82])
	by mailbox.samurai.com (Postfix) with ESMTP id DDD5923989E;
	Fri, 21 Oct 2005 17:44:42 -0400 (EDT)
Received: from mailbox.samurai.com ([205.207.28.82])
	by localhost (mailbox.samurai.com [205.207.28.82]) (amavisd-new,
	port 10024)
	with LMTP id 67140-01-8; Fri, 21 Oct 2005 17:44:41 -0400 (EDT)
Received: from [192.168.1.103] (d226-86-55.home.cgocable.net [24.226.86.55])
	by mailbox.samurai.com (Postfix) with ESMTP id 8E3BB239893;
	Fri, 21 Oct 2005 17:44:41 -0400 (EDT)
Subject: Re: What gets cached?
From: Neil Conway <neilc@samurai.com>
To: Martin Nickel <martin@portant.com>
Cc: pgsql-performance@postgresql.org
In-Reply-To: <pan.2005.10.21.12.34.29.712700@portant.com>
References: <pan.2005.10.21.12.34.29.712700@portant.com>
Content-Type: text/plain
Date: Fri, 21 Oct 2005 17:44:47 -0400
Message-Id: <1129931087.19971.12.camel@localhost.localdomain>
Mime-Version: 1.0
X-Mailer: Evolution 2.4.1 
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at mailbox.samurai.com
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0 required=5 tests=[none]
X-Spam-Level: 
X-Archive-Number: 200510/302
X-Sequence-Number: 15070

On Fri, 2005-21-10 at 07:34 -0500, Martin Nickel wrote:
> Let's say I do the same thing in Postgres.  I'm likely to have my very
> fastest performance for the first few queries until memory gets filled up.

No, you're not: if a query doesn't hit the cache (both the OS cache and
the Postgres userspace cache), it will run slower. If the caches are
empty when Postgres starts up (which is true for the userspace cache and
might be true of the OS cache), the first queries that are run should be
slower, not faster.

>  The only time Postgres seems to take advantage of cached data is when I
>  repeat the same (or substantially the same) query.

Caching is done on a page-by-page basis -- the source text of the query
itself is not relevant. If two different queries happen to hit a similar
set of pages, they will probably both benefit from the same set of
cached pages.

> I don't know of any way to view what is actually cached at any point
> in time, but it seems like "most recently used" rather than "most
> frequently used".

The cache replacement policy in 7.4 and older releases is simple LRU.
The policy in 8.0 is ARC (essentially a version of LRU modified to try
to retain hot pages more accurately). The policy in 8.1 is a clock-based
algorithm.

-Neil



From pgsql-performance-owner@postgresql.org  Sat Oct 22 01:55:12 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 47BDCDAA43
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 22 Oct 2005 01:55:11 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 49248-07
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 22 Oct 2005 04:55:09 +0000 (GMT)
Received: from mail22.sea5.speakeasy.net (mail22.sea5.speakeasy.net
	[69.17.117.24])
	by svr1.postgresql.org (Postfix) with ESMTP id 77E67DAA34
	for <pgsql-performance@postgresql.org>;
	Sat, 22 Oct 2005 01:55:09 -0300 (ADT)
Received: (qmail 28381 invoked from network); 22 Oct 2005 04:55:09 -0000
Received: from dsl017-073-250.chi4.dsl.speakeasy.net (HELO mofo.meme.com)
	([69.17.73.250]) (envelope-sender <kop@meme.com>)
	by mail22.sea5.speakeasy.net (qmail-ldap-1.03) with SMTP
	for <pgsql-performance@postgresql.org>; 22 Oct 2005 04:55:09 -0000
Received: from mofo (localhost.localdomain [127.0.0.1])
	by mofo.meme.com (Postfix) with ESMTP id 258E66E422
	for <pgsql-performance@postgresql.org>;
	Sat, 22 Oct 2005 00:05:21 -0500 (CDT)
Date: Sat, 22 Oct 2005 05:05:21 +0000
From: "Karl O. Pinc" <kop@meme.com>
Subject: Using LIMIT 1 in plpgsql PERFORM statements
To: pgsql-performance@postgresql.org
X-Mailer: Balsa 2.3.0
Message-Id: <1129957521l.27845l.2l@mofo>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii; DelSp=Yes; Format=Flowed
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.05 required=5 tests=[FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/303
X-Sequence-Number: 15071

Hi,

I'm wondering if the plpgsql code:

PERFORM 1 FROM foo;
IF FOUND THEN ...

is any slower than:

PERFORM 1 FROM foo LIMIT 1;
IF FOUND THEN ...

Seems like it _could_ be smart enough to know that

1) It's selecting from a real table and not a function

2) GET DIAGNOSTICS is not used

and therefore it does not have to do more than set
FOUND, and need find only one row/plan the query
to find only one row.  I'm particularly interested
in the query plan optimization aspect.

Would it be considered poor practice to rely on
such an optimization?

Thanks.

Karl <kop@meme.com>
Free Software:  "You don't pay back, you pay forward."
                  -- Robert A. Heinlein


From pgsql-performance-owner@postgresql.org  Sat Oct 22 10:24:46 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 6A942DAAE6
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 22 Oct 2005 10:24:45 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 08846-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 22 Oct 2005 13:24:41 +0000 (GMT)
Received: from mx1.surnet.cl (mx1.surnet.cl [216.155.73.180])
	by svr1.postgresql.org (Postfix) with ESMTP id E1B33DAABF
	for <pgsql-performance@postgresql.org>;
	Sat, 22 Oct 2005 10:24:42 -0300 (ADT)
Received: from unknown (HELO cluster.surnet.cl) ([216.155.73.165])
	by mx1.surnet.cl with ESMTP; 22 Oct 2005 10:26:48 -0300
X-IronPort-AV: i="3.97,240,1125892800";
	d="scan'208"; a="19080171:sNHT17954832"
Received: from alvh.no-ip.org (200.85.219.78) by cluster.surnet.cl (7.0.043)
	(authenticated as alvherre@surnet.cl)
	id 43501597000FBECD; Sat, 22 Oct 2005 10:24:47 -0300
Received: by alvh.no-ip.org (Postfix, from userid 1000)
	id 3C7D7C2D469; Sat, 22 Oct 2005 10:25:12 -0300 (CLST)
Date: Sat, 22 Oct 2005 10:25:12 -0300
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
To: Martin Nickel <martin@portant.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Sequential scan on FK join
Message-ID: <20051022132512.GE18064@surnet.cl>
Mail-Followup-To: Martin Nickel <martin@portant.com>,
	pgsql-performance@postgresql.org
References: <pan.2005.10.12.20.40.22.703085@portant.com>
	<4353648C.8040507@archonet.com>
	<pan.2005.10.17.13.07.53.915839@portant.com>
	<4353E342.2060708@archonet.com>
	<pan.2005.10.17.19.56.36.629275@portant.com>
	<4354A9AF.30300@archonet.com>
	<pan.2005.10.21.08.51.54.741707@portant.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
In-Reply-To: <pan.2005.10.21.08.51.54.741707@portant.com>
User-Agent: Mutt/1.5.10i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=2.042 required=5 tests=[AWL=-0.734,
	DNS_FROM_RFC_ABUSE=0.374, DNS_FROM_RFC_POST=1.376,
	RCVD_IN_NJABL_PROXY=1.026]
X-Spam-Level: **
X-Archive-Number: 200510/304
X-Sequence-Number: 15072

Martin Nickel wrote:
> On Tue, 18 Oct 2005 08:52:15 +0100, Richard Huxton wrote:
> >   3. Actually - are you happy that your general configuration is OK? 
> We're running dual Opteron 244s with 4G of memory.  The platform is
> Suse 9.3, 64 bit.  The database is on a 3ware 9500S-8 sata raid controller
> configured raid 10 with 4 drives plus a hot swap.  Drives are
> 7400 rpm (don't remember model or size).
> 
> I'm running Postgres 8.0.3.  Here are some of the relevant conf file
> parameters:
> shared_buffers = 50000
> sort_mem = 8192
> work_mem = 256000

Interesting that you set both sort_mem and work_mem.  Do you realize
that the former is an obsolete name, and currently a synonym for the
latter?  Maybe the problem is that you are using too much memory for
sorts, forcing swap usage, etc.

-- 
Alvaro Herrera                 http://www.amazon.com/gp/registry/DXLWNGRJD34J
"La persona que no quer�a pecar / estaba obligada a sentarse
 en duras y empinadas sillas    / desprovistas, por cierto
 de blandos atenuantes"                          (Patricio Vogel)

From pgsql-performance-owner@postgresql.org  Mon Oct 24 23:51:08 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id DB8DEDA573
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 22 Oct 2005 18:12:07 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 99600-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 22 Oct 2005 21:12:03 +0000 (GMT)
Received: from web32902.mail.mud.yahoo.com (web32902.mail.mud.yahoo.com
	[68.142.206.49])
	by svr1.postgresql.org (Postfix) with SMTP id BE3CBD7797
	for <pgsql-performance@postgresql.org>;
	Sat, 22 Oct 2005 18:12:03 -0300 (ADT)
Received: (qmail 97793 invoked by uid 60001); 22 Oct 2005 21:12:05 -0000
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com;
	h=Message-ID:Received:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding;
	b=Yv48ovXuIgNS99q+cnTC/1vWznDm3SvWMytctP0sgriK9F5woW39MG25gwbtQrAIFj/Ozj5/o1wy+nBzTVl+63oFDbZTcMrgy9c3uAaSP8UPQX2uYC6defxODzFTB3U4eBhr4ygToUk3cgKyvdmbkcdCCODs79iDzhbYqSCnzPM=
	;
Message-ID: <20051022211205.97791.qmail@web32902.mail.mud.yahoo.com>
Received: from [202.65.136.134] by web32902.mail.mud.yahoo.com via HTTP;
	Sat, 22 Oct 2005 14:12:05 PDT
Date: Sat, 22 Oct 2005 14:12:05 -0700 (PDT)
From: Kishore B <bkishorevarma@yahoo.com>
Subject: Need help in setting optimal configuration for a huge database.
To: pgsql-performance@postgresql.org
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="0-267068631-1130015525=:97706"
Content-Transfer-Encoding: 8bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.402 required=5 tests=[DNS_FROM_RFC_ABUSE=0.374,
	HTML_60_70=0.027, HTML_MESSAGE=0.001]
X-Spam-Level: 
X-Archive-Number: 200510/346
X-Sequence-Number: 15114

--0-267068631-1130015525=:97706
Content-Type: multipart/alternative; boundary="0-2134442436-1130015525=:97706"

--0-2134442436-1130015525=:97706
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit


Hi All,

 

I am Kishore doing freelance development of J2EE applications. 

 

We switched to use Postgresql recently because of the advantages it has over other commercial databases. All went well untill recently, untill we began working on an application that needs to maintain  a huge database. 

 

I am describing the problem we are facing below. Can you please take a look at the case, and help me in configuring the PostgreSQL.

 

We have only two tables, one of which contains 97% of the data and the other table which contains 2.8% of the data. All other contain only the remaining 0.2% of data and are designed to support these two big tables. Currently we have 9 million of records in the first table and 0.2 million of records in the second table.

We need to insert into the bigger table almost for every second , through out the life time. In addition, we receive at least 200,000 records a day at a fixed time.

We are facing a critical situation because of the performance of the database. Even a basic query like select count(*) from bigger_table is taking about 4 minutes to return.

The following is the system configuration.

Database : Postgresql 7.3
OS : Redhat Linux
Processor : Athlon,
Memory : 2 GB

We are expecting that at least 200 active connections need to be maintained through out the day.


 

I am also attaching the configuration file that we are currently using.



Can any you please suggest the best configuration to satisfy the above requirements?

Thanks in advance. 

 

Thank  you,

Kishore.

 


		
---------------------------------
 Yahoo! FareChase - Search multiple travel sites in one click.  
--0-2134442436-1130015525=:97706
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: 8bit

<DIV>
<DIV>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Hi All,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">I am Kishore doing freelance development of J2EE applications. <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">We switched to use Postgresql recently because of the advantages it has over other commercial databases. All went well untill recently, untill we began working on an application that needs to maintain&nbsp; a huge database. <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">I am describing the problem we are facing below. Can you please take a look at the case, and help me in configuring the PostgreSQL.<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">We have only two tables, one of which contains 97% of the data and the other table which contains 2.8% of the data. All other contain only the remaining 0.2% of data and are designed to support these two big tables. Currently we have 9 million of records in the first table and 0.2 million of records in the second table.<BR><BR>We need to insert into the bigger table almost for every second , through out the life time. In addition, we receive at least 200,000 records a day at a fixed time.<BR><BR>We are facing a<STRONG><SPAN style="FONT-FAMILY: Arial"> critical situation because of the performance of the </SPAN></STRONG><SPAN class=highlight><B>database</B></SPAN><STRONG><SPAN style="FONT-FAMILY: Arial">.</SPAN></STRONG> Even a basic query like select count(*) from bigger_table is taking about 4 minutes to return.<BR><BR>The following is the system configuration.<BR><BR><SPAN
 class=highlight>Database</SPAN> <STRONG><SPAN style="FONT-FAMILY: Arial">:</SPAN></STRONG> Postgresql 7.3<BR>OS : Redhat Linux<BR>Processor : Athlon,<BR>Memory : 2 GB<BR><BR>We are expecting that at least 200 active connections need to be maintained&nbsp;through out the day.</SPAN></P><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"></SPAN></DIV>
<P><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"></SPAN>&nbsp;</P>
<P><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">I am also attaching the configuration file that we are currently using.</P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><BR><BR>Can any&nbsp;you please suggest the best configuration to satisfy the above requirements?<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Thanks in advance. <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Thank&nbsp; you,<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Kishore.<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p><FONT face="Times New Roman" size=3>&nbsp;</FONT></o:p></P></DIV><p>
		<hr size=1> <a href="http://us.lrd.yahoo.com/_ylc=X3oDMTFqODRtdXQ4BF9TAzMyOTc1MDIEX3MDOTY2ODgxNjkEcG9zAzEEc2VjA21haWwtZm9vdGVyBHNsawNmYw--/SIG=110oav78o/**http%3a//farechase.yahoo.com/">Yahoo! FareChase - Search multiple travel sites in one click.</a>

 

 
--0-2134442436-1130015525=:97706--

--0-267068631-1130015525=:97706
Content-Type: application/octet-stream; name="postgresql.conf"
Content-Transfer-Encoding: base64
Content-Description: 3963038301-postgresql.conf
Content-Disposition: attachment; filename="postgresql.conf"

Iw0KIyBQb3N0Z3JlU1FMIGNvbmZpZ3VyYXRpb24gZmlsZQ0KIyAtLS0tLS0t
LS0tLS0tLS0tLS0tLS0tLS0tLS0tLQ0KIw0KIyBUaGlzIGZpbGUgY29uc2lz
dHMgb2YgbGluZXMgb2YgdGhlIGZvcm06DQojDQojICAgbmFtZSA9IHZhbHVl
DQojDQojIChUaGUgJz0nIGlzIG9wdGlvbmFsLikgV2hpdGUgc3BhY2UgbWF5
IGJlIHVzZWQuIENvbW1lbnRzIGFyZSBpbnRyb2R1Y2VkDQojIHdpdGggJyMn
IGFueXdoZXJlIG9uIGEgbGluZS4gVGhlIGNvbXBsZXRlIGxpc3Qgb2Ygb3B0
aW9uIG5hbWVzIGFuZA0KIyBhbGxvd2VkIHZhbHVlcyBjYW4gYmUgZm91bmQg
aW4gdGhlIFBvc3RncmVTUUwgZG9jdW1lbnRhdGlvbi4gVGhlDQojIGNvbW1l
bnRlZC1vdXQgc2V0dGluZ3Mgc2hvd24gaW4gdGhpcyBmaWxlIHJlcHJlc2Vu
dCB0aGUgZGVmYXVsdCB2YWx1ZXMuDQojDQojIEFueSBvcHRpb24gY2FuIGFs
c28gYmUgZ2l2ZW4gYXMgYSBjb21tYW5kIGxpbmUgc3dpdGNoIHRvIHRoZQ0K
IyBwb3N0bWFzdGVyLCBlLmcuICdwb3N0bWFzdGVyIC1jIGxvZ19jb25uZWN0
aW9ucz1vbicuIFNvbWUgb3B0aW9ucw0KIyBjYW4gYmUgY2hhbmdlZCBhdCBy
dW4tdGltZSB3aXRoIHRoZSAnU0VUJyBTUUwgY29tbWFuZC4NCiMNCiMgVGhp
cyBmaWxlIGlzIHJlYWQgb24gcG9zdG1hc3RlciBzdGFydHVwIGFuZCB3aGVu
IHRoZSBwb3N0bWFzdGVyDQojIHJlY2VpdmVzIGEgU0lHSFVQLiBJZiB5b3Ug
ZWRpdCB0aGUgZmlsZSBvbiBhIHJ1bm5pbmcgc3lzdGVtLCB5b3UgaGF2ZSAN
CiMgdG8gU0lHSFVQIHRoZSBwb3N0bWFzdGVyIGZvciB0aGUgY2hhbmdlcyB0
byB0YWtlIGVmZmVjdCwgb3IgdXNlIA0KIyAicGdfY3RsIHJlbG9hZCIuDQoN
Cg0KIz09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PQ0KDQoNCiMNCiMJQ29u
bmVjdGlvbiBQYXJhbWV0ZXJzDQojDQp0Y3BpcF9zb2NrZXQgPXRydWUNCiNz
c2wgPSBmYWxzZQ0KDQptYXhfY29ubmVjdGlvbnMgPTUwMA0KI3N1cGVydXNl
cl9yZXNlcnZlZF9jb25uZWN0aW9ucyA9IDINCg0KcG9ydCA9NTIyMyANCiNo
b3N0bmFtZV9sb29rdXAgPSBmYWxzZQ0KI3Nob3dfc291cmNlX3BvcnQgPSBm
YWxzZQ0KDQojdW5peF9zb2NrZXRfZGlyZWN0b3J5ID0gJycNCiN1bml4X3Nv
Y2tldF9ncm91cCA9ICcnDQojdW5peF9zb2NrZXRfcGVybWlzc2lvbnMgPSAw
Nzc3CSMgb2N0YWwNCg0KI3ZpcnR1YWxfaG9zdCA9ICcnDQoNCiNrcmJfc2Vy
dmVyX2tleWZpbGUgPSAnJw0KDQoNCiMNCiMJU2hhcmVkIE1lbW9yeSBTaXpl
DQojDQpzaGFyZWRfYnVmZmVycyA9NDgwMDAgICAgICAjIG1pbiBtYXhfY29u
bmVjdGlvbnMqMiBvciAxNiwgOEtCIGVhY2gNCiNtYXhfZnNtX3JlbGF0aW9u
cyA9IDEwMDAJIyBtaW4gMTAsIGZzbSBpcyBmcmVlIHNwYWNlIG1hcCwgfjQw
IGJ5dGVzDQojbWF4X2ZzbV9wYWdlcyA9IDEwMDAwCQkjIG1pbiAxMDAwLCBm
c20gaXMgZnJlZSBzcGFjZSBtYXAsIH42IGJ5dGVzDQojbWF4X2xvY2tzX3Bl
cl90cmFuc2FjdGlvbiA9IDY0CSMgbWluIDEwDQojd2FsX2J1ZmZlcnMgPSA4
CQkjIG1pbiA0LCB0eXBpY2FsbHkgOEtCIGVhY2gNCg0KIw0KIwlOb24tc2hh
cmVkIE1lbW9yeSBTaXplcw0KIw0Kc29ydF9tZW0gPTIwNDgJCSMgbWluIDY0
LCBzaXplIGluIEtCDQojdmFjdXVtX21lbSA9IDgxOTIJCSMgbWluIDEwMjQs
IHNpemUgaW4gS0INCg0KDQojDQojCVdyaXRlLWFoZWFkIGxvZyAoV0FMKQ0K
Iw0KI2NoZWNrcG9pbnRfc2VnbWVudHMgPSAzCSMgaW4gbG9nZmlsZSBzZWdt
ZW50cywgbWluIDEsIDE2TUIgZWFjaA0KI2NoZWNrcG9pbnRfdGltZW91dCA9
IDMwMAkjIHJhbmdlIDMwLTM2MDAsIGluIHNlY29uZHMNCiMNCiNjb21taXRf
ZGVsYXkgPSAwCQkjIHJhbmdlIDAtMTAwMDAwLCBpbiBtaWNyb3NlY29uZHMN
CiNjb21taXRfc2libGluZ3MgPSA1CQkjIHJhbmdlIDEtMTAwMA0KIw0KZnN5
bmMgPWZhbHNlDQojd2FsX3N5bmNfbWV0aG9kID0gZnN5bmMJIyB0aGUgZGVm
YXVsdCB2YXJpZXMgYWNyb3NzIHBsYXRmb3JtczoNCiMJCQkJIyBmc3luYywg
ZmRhdGFzeW5jLCBvcGVuX3N5bmMsIG9yIG9wZW5fZGF0YXN5bmMNCiN3YWxf
ZGVidWcgPSAwCQkJIyByYW5nZSAwLTE2DQoNCg0KIw0KIwlPcHRpbWl6ZXIg
UGFyYW1ldGVycw0KIw0KI2VuYWJsZV9zZXFzY2FuID0gdHJ1ZQ0KI2VuYWJs
ZV9pbmRleHNjYW4gPSB0cnVlDQojZW5hYmxlX3RpZHNjYW4gPSB0cnVlDQoj
ZW5hYmxlX3NvcnQgPSB0cnVlDQojZW5hYmxlX25lc3Rsb29wID0gdHJ1ZQ0K
I2VuYWJsZV9tZXJnZWpvaW4gPSB0cnVlDQojZW5hYmxlX2hhc2hqb2luID0g
dHJ1ZQ0KDQplZmZlY3RpdmVfY2FjaGVfc2l6ZSA9MTAwMDAwCSMgdHlwaWNh
bGx5IDhLQiBlYWNoDQpyYW5kb21fcGFnZV9jb3N0ID0gMwkJIyB1bml0cyBh
cmUgb25lIHNlcXVlbnRpYWwgcGFnZSBmZXRjaCBjb3N0DQojcmFuZG9tX3Bh
Z2VfY29zdCA9IDQJCSMgdW5pdHMgYXJlIG9uZSBzZXF1ZW50aWFsIHBhZ2Ug
ZmV0Y2ggY29zdA0KI2NwdV90dXBsZV9jb3N0ID0gMC4wMQkJIyAoc2FtZSkN
CiNjcHVfaW5kZXhfdHVwbGVfY29zdCA9IDAuMDAxCSMgKHNhbWUpDQojY3B1
X29wZXJhdG9yX2Nvc3QgPSAwLjAwMjUJIyAoc2FtZSkNCg0KI2Zyb21fY29s
bGFwc2VfbGltaXQgPSA4DQojam9pbl9jb2xsYXBzZV9saW1pdCA9IDgJIyAx
IGRpc2FibGVzIGNvbGxhcHNpbmcgb2YgZXhwbGljaXQgSk9JTnMNCg0KI2Rl
ZmF1bHRfc3RhdGlzdGljc190YXJnZXQgPSAxMAkjIHJhbmdlIDEtMTAwMA0K
DQojDQojCUdFUU8gT3B0aW1pemVyIFBhcmFtZXRlcnMNCiMNCiNnZXFvID0g
dHJ1ZQ0KI2dlcW9fc2VsZWN0aW9uX2JpYXMgPSAyLjAJIyByYW5nZSAxLjUt
Mi4wDQojZ2Vxb190aHJlc2hvbGQgPSAxMQ0KI2dlcW9fcG9vbF9zaXplID0g
MAkJIyBkZWZhdWx0IGJhc2VkIG9uIHRhYmxlcyBpbiBzdGF0ZW1lbnQsIA0K
CQkJCSMgcmFuZ2UgMTI4LTEwMjQNCiNnZXFvX2VmZm9ydCA9IDENCiNnZXFv
X2dlbmVyYXRpb25zID0gMA0KI2dlcW9fcmFuZG9tX3NlZWQgPSAtMQkJIyBh
dXRvLWNvbXB1dGUgc2VlZA0KDQoNCiMNCiMJTWVzc2FnZSBkaXNwbGF5DQoj
DQojc2VydmVyX21pbl9tZXNzYWdlcyA9IG5vdGljZQkjIFZhbHVlcywgaW4g
b3JkZXIgb2YgZGVjcmVhc2luZyBkZXRhaWw6DQoJCQkJIyAgIGRlYnVnNSwg
ZGVidWc0LCBkZWJ1ZzMsIGRlYnVnMiwgZGVidWcxLA0KCQkJCSMgICBpbmZv
LCBub3RpY2UsIHdhcm5pbmcsIGVycm9yLCBsb2csIGZhdGFsLA0KCQkJCSMg
ICBwYW5pYw0KI2NsaWVudF9taW5fbWVzc2FnZXMgPSBub3RpY2UJIyBWYWx1
ZXMsIGluIG9yZGVyIG9mIGRlY3JlYXNpbmcgZGV0YWlsOg0KCQkJCSMgICBk
ZWJ1ZzUsIGRlYnVnNCwgZGVidWczLCBkZWJ1ZzIsIGRlYnVnMSwNCgkJCQkj
ICAgbG9nLCBpbmZvLCBub3RpY2UsIHdhcm5pbmcsIGVycm9yDQojc2lsZW50
X21vZGUgPSBmYWxzZQ0KDQojbG9nX2Nvbm5lY3Rpb25zID0gZmFsc2UNCiNs
b2dfcGlkID0gZmFsc2UNCiNsb2dfc3RhdGVtZW50ID0gZmFsc2UNCiNsb2df
ZHVyYXRpb24gPSBmYWxzZQ0KI2xvZ190aW1lc3RhbXAgPSBmYWxzZQ0KDQoj
bG9nX21pbl9lcnJvcl9zdGF0ZW1lbnQgPSBwYW5pYyAjIFZhbHVlcyBpbiBv
cmRlciBvZiBpbmNyZWFzaW5nIHNldmVyaXR5Og0KCQkJCSAjICAgZGVidWc1
LCBkZWJ1ZzQsIGRlYnVnMywgZGVidWcyLCBkZWJ1ZzEsDQoJCQkJICMgICBp
bmZvLCBub3RpY2UsIHdhcm5pbmcsIGVycm9yLCBwYW5pYyhvZmYpDQoNCiNk
ZWJ1Z19wcmludF9wYXJzZSA9IGZhbHNlDQojZGVidWdfcHJpbnRfcmV3cml0
dGVuID0gZmFsc2UNCiNkZWJ1Z19wcmludF9wbGFuID0gZmFsc2UNCiNkZWJ1
Z19wcmV0dHlfcHJpbnQgPSBmYWxzZQ0KDQojZXhwbGFpbl9wcmV0dHlfcHJp
bnQgPSB0cnVlDQoNCiMgcmVxdWlyZXMgVVNFX0FTU0VSVF9DSEVDS0lORw0K
I2RlYnVnX2Fzc2VydGlvbnMgPSB0cnVlDQoNCg0KIw0KIwlTeXNsb2cNCiMN
CiNzeXNsb2cgPSAwCQkJIyByYW5nZSAwLTINCiNzeXNsb2dfZmFjaWxpdHkg
PSAnTE9DQUwwJw0KI3N5c2xvZ19pZGVudCA9ICdwb3N0Z3JlcycNCg0KDQoj
DQojCVN0YXRpc3RpY3MNCiMNCiNzaG93X3BhcnNlcl9zdGF0cyA9IGZhbHNl
DQojc2hvd19wbGFubmVyX3N0YXRzID0gZmFsc2UNCiNzaG93X2V4ZWN1dG9y
X3N0YXRzID0gZmFsc2UNCiNzaG93X3N0YXRlbWVudF9zdGF0cyA9IGZhbHNl
DQoNCiMgcmVxdWlyZXMgQlRSRUVfQlVJTERfU1RBVFMNCiNzaG93X2J0cmVl
X2J1aWxkX3N0YXRzID0gZmFsc2UNCg0KDQojDQojCUFjY2VzcyBzdGF0aXN0
aWNzIGNvbGxlY3Rpb24NCiMNCiNzdGF0c19zdGFydF9jb2xsZWN0b3IgPSB0
cnVlDQojc3RhdHNfcmVzZXRfb25fc2VydmVyX3N0YXJ0ID0gdHJ1ZQ0KI3N0
YXRzX2NvbW1hbmRfc3RyaW5nID0gZmFsc2UNCiNzdGF0c19yb3dfbGV2ZWwg
PSBmYWxzZQ0KI3N0YXRzX2Jsb2NrX2xldmVsID0gZmFsc2UNCg0KDQojDQoj
CUxvY2sgVHJhY2luZw0KIw0KI3RyYWNlX25vdGlmeSA9IGZhbHNlDQoNCiMg
cmVxdWlyZXMgTE9DS19ERUJVRw0KI3RyYWNlX2xvY2tzID0gZmFsc2UNCiN0
cmFjZV91c2VybG9ja3MgPSBmYWxzZQ0KI3RyYWNlX2x3bG9ja3MgPSBmYWxz
ZQ0KI2RlYnVnX2RlYWRsb2NrcyA9IGZhbHNlDQojdHJhY2VfbG9ja19vaWRt
aW4gPSAxNjM4NA0KI3RyYWNlX2xvY2tfdGFibGUgPSAwDQoNCg0KIw0KIwlN
aXNjDQojDQojYXV0b2NvbW1pdCA9IHRydWUNCiNkeW5hbWljX2xpYnJhcnlf
cGF0aCA9ICckbGliZGlyJw0KI3NlYXJjaF9wYXRoID0gJyR1c2VyLHB1Ymxp
YycNCiNkYXRlc3R5bGUgPSAnaXNvLCB1cycNCiN0aW1lem9uZSA9IHVua25v
d24JCSMgYWN0dWFsbHksIGRlZmF1bHRzIHRvIFRaIGVudmlyb25tZW50IHNl
dHRpbmcNCiNhdXN0cmFsaWFuX3RpbWV6b25lcyA9IGZhbHNlDQojY2xpZW50
X2VuY29kaW5nID0gc3FsX2FzY2lpCSMgYWN0dWFsbHksIGRlZmF1bHRzIHRv
IGRhdGFiYXNlIGVuY29kaW5nDQojYXV0aGVudGljYXRpb25fdGltZW91dCA9
IDYwCSMgMS02MDAsIGluIHNlY29uZHMNCiNkZWFkbG9ja190aW1lb3V0ID0g
MTAwMAkjIGluIG1pbGxpc2Vjb25kcw0KI2RlZmF1bHRfdHJhbnNhY3Rpb25f
aXNvbGF0aW9uID0gJ3JlYWQgY29tbWl0dGVkJw0KI21heF9leHByX2RlcHRo
ID0gMTAwMDAJCSMgbWluIDEwDQojbWF4X2ZpbGVzX3Blcl9wcm9jZXNzID0g
MTAwMAkjIG1pbiAyNQ0KI3Bhc3N3b3JkX2VuY3J5cHRpb24gPSB0cnVlDQoj
c3FsX2luaGVyaXRhbmNlID0gdHJ1ZQ0KI3RyYW5zZm9ybV9udWxsX2VxdWFs
cyA9IGZhbHNlDQojc3RhdGVtZW50X3RpbWVvdXQgPSAwCQkjIDAgaXMgZGlz
YWJsZWQsIGluIG1pbGxpc2Vjb25kcw0KI2RiX3VzZXJfbmFtZXNwYWNlID0g
ZmFsc2UNCiANCg0KDQojDQojCUxvY2FsZSBzZXR0aW5ncw0KIw0KIyAoaW5p
dGlhbGl6ZWQgYnkgaW5pdGRiIC0tIG1heSBiZSBjaGFuZ2VkKQ0KTENfTUVT
U0FHRVMgPSAnZW5fVVMnDQpMQ19NT05FVEFSWSA9ICdlbl9VUycNCkxDX05V
TUVSSUMgPSAnZW5fVVMnDQpMQ19USU1FID0gJ2VuX1VTJw0K

--0-267068631-1130015525=:97706--

From pgsql-performance-owner@postgresql.org  Sat Oct 22 18:15:25 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 18409DA97D
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 22 Oct 2005 18:15:25 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 94450-07
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 22 Oct 2005 21:15:22 +0000 (GMT)
Received: from zproxy.gmail.com (zproxy.gmail.com [64.233.162.192])
	by svr1.postgresql.org (Postfix) with ESMTP id 140FADAA68
	for <pgsql-performance@postgresql.org>;
	Sat, 22 Oct 2005 18:15:22 -0300 (ADT)
Received: by zproxy.gmail.com with SMTP id 8so412989nzo
	for <pgsql-performance@postgresql.org>;
	Sat, 22 Oct 2005 14:15:25 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:to:subject:mime-version:content-type;
	b=qmjPTTtJWE3Ouye540qkamDyi6hNGIn1nOZBK3c0LY0SV3J6hN248PpCVAdR8Taq97acscqJm9g0cczT9P3FQ/E7AsnMkcNcsCNmijkMJNZ7AFRdEoc1HdL4F5+cCCkelpSZZXTJkWTTLAd0FM3Kd03HhyMu4NY5ICV4N/9ijvc=
Received: by 10.36.140.13 with SMTP id n13mr1929083nzd;
	Sat, 22 Oct 2005 14:15:25 -0700 (PDT)
Received: by 10.36.61.1 with HTTP; Sat, 22 Oct 2005 14:15:25 -0700 (PDT)
Message-ID: <42567e060510221415r2516523l4c3f9b42dee91a09@mail.gmail.com>
Date: Sun, 23 Oct 2005 02:45:25 +0530
From: Kishore B <kishorebh@gmail.com>
To: pgsql-performance@postgresql.org
Subject: Need help in setting optimal configuration for a huge database.
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="----=_Part_20960_98211.1130015725464"
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.307 required=5 tests=[AWL=0.187, HTML_50_60=0.095,
	HTML_MESSAGE=0.001, RCVD_BY_IP=0.024]
X-Spam-Level: 
X-Archive-Number: 200510/305
X-Sequence-Number: 15073

------=_Part_20960_98211.1130015725464
Content-Type: multipart/alternative;
	boundary="----=_Part_20961_6465372.1130015725464"

------=_Part_20961_6465372.1130015725464
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Hi All,

 I am Kishore doing freelance development of J2EE applications.

 We switched to use Postgresql recently because of the advantages it has
over other commercial databases. All went well untill recently, untill we
began working on an application that needs to maintain a huge database.

 I am describing the problem we are facing below. Can you please take a loo=
k
at the case, and help me in configuring the PostgreSQL.

 We have only two tables, one of which contains 97% of the data and the
other table which contains 2.8% of the data. All other contain only the
remaining 0.2% of data and are designed to support these two big tables.
Currently we have 9 million of records in the first table and 0.2 million o=
f
records in the second table.

We need to insert into the bigger table almost for every second , through
out the life time. In addition, we receive at least 200,000 records a day a=
t
a fixed time.

We are facing a* critical situation because of the performance of the **
database**.* Even a basic query like select count(*) from bigger_table is
taking about 4 minutes to return.

The following is the system configuration.

Database *:* Postgresql 7.3
OS : Redhat Linux
Processor : Athlon,
Memory : 2 GB

We are expecting that at least 200 active connections need to be maintained
through out the day.

Can any you please suggest the best configuration to satisfy the above
requirements?

Thanks in advance.

 Thank you,

Kishore.

------=_Part_20961_6465372.1130015725464
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

<p class=3D"MsoNormal" style=3D"MARGIN: 0in 0in 0pt"><span style=3D"FONT-SI=
ZE: 10pt; FONT-FAMILY: Arial">Hi All,</span></p>
<p class=3D"MsoNormal" style=3D"MARGIN: 0in 0in 0pt"><span style=3D"FONT-SI=
ZE: 10pt; FONT-FAMILY: Arial">&nbsp;</span></p>
<p class=3D"MsoNormal" style=3D"MARGIN: 0in 0in 0pt"><span style=3D"FONT-SI=
ZE: 10pt; FONT-FAMILY: Arial">I am Kishore doing freelance development of J=
2EE applications. </span></p>
<p class=3D"MsoNormal" style=3D"MARGIN: 0in 0in 0pt"><span style=3D"FONT-SI=
ZE: 10pt; FONT-FAMILY: Arial">&nbsp;</span></p>
<p class=3D"MsoNormal" style=3D"MARGIN: 0in 0in 0pt"><span style=3D"FONT-SI=
ZE: 10pt; FONT-FAMILY: Arial">We switched to use Postgresql recently becaus=
e of the advantages it has over other commercial databases. All went well u=
ntill recently, untill we began working on an application that needs to mai=
ntain&nbsp; a huge database.=20
</span></p>
<p class=3D"MsoNormal" style=3D"MARGIN: 0in 0in 0pt"><span style=3D"FONT-SI=
ZE: 10pt; FONT-FAMILY: Arial">&nbsp;</span></p>
<p class=3D"MsoNormal" style=3D"MARGIN: 0in 0in 0pt"><span style=3D"FONT-SI=
ZE: 10pt; FONT-FAMILY: Arial">I am describing the problem we are facing bel=
ow. Can you please take a look at the case, and help me in configuring the =
PostgreSQL.
</span></p>
<p class=3D"MsoNormal" style=3D"MARGIN: 0in 0in 0pt"><span style=3D"FONT-SI=
ZE: 10pt; FONT-FAMILY: Arial">&nbsp;</span></p>
<p class=3D"MsoNormal" style=3D"MARGIN: 0in 0in 0pt"><span style=3D"FONT-SI=
ZE: 10pt; FONT-FAMILY: Arial">We have only two tables, one of which contain=
s 97% of the data and the other table which contains 2.8% of the data. All =
other contain only the remaining=20
0.2% of data and are designed to support these two big tables. Currently we=
 have 9 million of records in the first table and 0.2 million of records in=
 the second table.<br><br>We need to insert into the bigger table almost fo=
r every second , through out the life time. In addition, we receive at leas=
t 200,000 records a day at a fixed time.
<br><br>We are facing a<strong><span style=3D"FONT-FAMILY: Arial"> critical=
 situation because of the performance of the </span></strong><span class=3D=
"highlight"><b>database</b></span><strong><span style=3D"FONT-FAMILY: Arial=
">
.</span></strong> Even a basic query like select count(*) from bigger_table=
 is taking about 4 minutes to return.<br><br>The following is the system co=
nfiguration.<br><br><span class=3D"highlight">Database</span> <strong><span=
 style=3D"FONT-FAMILY: Arial">
:</span></strong> Postgresql 7.3<br>OS : Redhat Linux<br>Processor : Athlon=
,<br>Memory : 2 GB<br><br>We are expecting that at least 200 active connect=
ions need to be maintained&nbsp;through out the day.<br><br>Can any&nbsp;yo=
u please suggest the best configuration to satisfy the above requirements?
</span></p>
<p class=3D"MsoNormal" style=3D"MARGIN: 0in 0in 0pt"><span style=3D"FONT-SI=
ZE: 10pt; FONT-FAMILY: Arial">Thanks in advance. </span></p>
<p class=3D"MsoNormal" style=3D"MARGIN: 0in 0in 0pt"><span style=3D"FONT-SI=
ZE: 10pt; FONT-FAMILY: Arial">&nbsp;</span></p>
<p class=3D"MsoNormal" style=3D"MARGIN: 0in 0in 0pt"><span style=3D"FONT-SI=
ZE: 10pt; FONT-FAMILY: Arial">Thank&nbsp; you,</span></p>
<p class=3D"MsoNormal" style=3D"MARGIN: 0in 0in 0pt"><span style=3D"FONT-SI=
ZE: 10pt; FONT-FAMILY: Arial">Kishore.</span></p>
<p class=3D"MsoNormal" style=3D"MARGIN: 0in 0in 0pt"><font face=3D"Times Ne=
w Roman">&nbsp;</font></p>

------=_Part_20961_6465372.1130015725464--

------=_Part_20960_98211.1130015725464
Content-Type: application/octet-stream; name="postgresql.conf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="postgresql.conf"

Iw0KIyBQb3N0Z3JlU1FMIGNvbmZpZ3VyYXRpb24gZmlsZQ0KIyAtLS0tLS0tLS0tLS0tLS0tLS0t
LS0tLS0tLS0tLQ0KIw0KIyBUaGlzIGZpbGUgY29uc2lzdHMgb2YgbGluZXMgb2YgdGhlIGZvcm06
DQojDQojICAgbmFtZSA9IHZhbHVlDQojDQojIChUaGUgJz0nIGlzIG9wdGlvbmFsLikgV2hpdGUg
c3BhY2UgbWF5IGJlIHVzZWQuIENvbW1lbnRzIGFyZSBpbnRyb2R1Y2VkDQojIHdpdGggJyMnIGFu
eXdoZXJlIG9uIGEgbGluZS4gVGhlIGNvbXBsZXRlIGxpc3Qgb2Ygb3B0aW9uIG5hbWVzIGFuZA0K
IyBhbGxvd2VkIHZhbHVlcyBjYW4gYmUgZm91bmQgaW4gdGhlIFBvc3RncmVTUUwgZG9jdW1lbnRh
dGlvbi4gVGhlDQojIGNvbW1lbnRlZC1vdXQgc2V0dGluZ3Mgc2hvd24gaW4gdGhpcyBmaWxlIHJl
cHJlc2VudCB0aGUgZGVmYXVsdCB2YWx1ZXMuDQojDQojIEFueSBvcHRpb24gY2FuIGFsc28gYmUg
Z2l2ZW4gYXMgYSBjb21tYW5kIGxpbmUgc3dpdGNoIHRvIHRoZQ0KIyBwb3N0bWFzdGVyLCBlLmcu
ICdwb3N0bWFzdGVyIC1jIGxvZ19jb25uZWN0aW9ucz1vbicuIFNvbWUgb3B0aW9ucw0KIyBjYW4g
YmUgY2hhbmdlZCBhdCBydW4tdGltZSB3aXRoIHRoZSAnU0VUJyBTUUwgY29tbWFuZC4NCiMNCiMg
VGhpcyBmaWxlIGlzIHJlYWQgb24gcG9zdG1hc3RlciBzdGFydHVwIGFuZCB3aGVuIHRoZSBwb3N0
bWFzdGVyDQojIHJlY2VpdmVzIGEgU0lHSFVQLiBJZiB5b3UgZWRpdCB0aGUgZmlsZSBvbiBhIHJ1
bm5pbmcgc3lzdGVtLCB5b3UgaGF2ZSANCiMgdG8gU0lHSFVQIHRoZSBwb3N0bWFzdGVyIGZvciB0
aGUgY2hhbmdlcyB0byB0YWtlIGVmZmVjdCwgb3IgdXNlIA0KIyAicGdfY3RsIHJlbG9hZCIuDQoN
Cg0KIz09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PQ0KDQoNCiMNCiMJQ29ubmVjdGlvbiBQYXJhbWV0ZXJzDQojDQp0
Y3BpcF9zb2NrZXQgPXRydWUNCiNzc2wgPSBmYWxzZQ0KDQptYXhfY29ubmVjdGlvbnMgPTUwMA0K
I3N1cGVydXNlcl9yZXNlcnZlZF9jb25uZWN0aW9ucyA9IDINCg0KcG9ydCA9NTIyMyANCiNob3N0
bmFtZV9sb29rdXAgPSBmYWxzZQ0KI3Nob3dfc291cmNlX3BvcnQgPSBmYWxzZQ0KDQojdW5peF9z
b2NrZXRfZGlyZWN0b3J5ID0gJycNCiN1bml4X3NvY2tldF9ncm91cCA9ICcnDQojdW5peF9zb2Nr
ZXRfcGVybWlzc2lvbnMgPSAwNzc3CSMgb2N0YWwNCg0KI3ZpcnR1YWxfaG9zdCA9ICcnDQoNCiNr
cmJfc2VydmVyX2tleWZpbGUgPSAnJw0KDQoNCiMNCiMJU2hhcmVkIE1lbW9yeSBTaXplDQojDQpz
aGFyZWRfYnVmZmVycyA9NDgwMDAgICAgICAjIG1pbiBtYXhfY29ubmVjdGlvbnMqMiBvciAxNiwg
OEtCIGVhY2gNCiNtYXhfZnNtX3JlbGF0aW9ucyA9IDEwMDAJIyBtaW4gMTAsIGZzbSBpcyBmcmVl
IHNwYWNlIG1hcCwgfjQwIGJ5dGVzDQojbWF4X2ZzbV9wYWdlcyA9IDEwMDAwCQkjIG1pbiAxMDAw
LCBmc20gaXMgZnJlZSBzcGFjZSBtYXAsIH42IGJ5dGVzDQojbWF4X2xvY2tzX3Blcl90cmFuc2Fj
dGlvbiA9IDY0CSMgbWluIDEwDQojd2FsX2J1ZmZlcnMgPSA4CQkjIG1pbiA0LCB0eXBpY2FsbHkg
OEtCIGVhY2gNCg0KIw0KIwlOb24tc2hhcmVkIE1lbW9yeSBTaXplcw0KIw0Kc29ydF9tZW0gPTIw
NDgJCSMgbWluIDY0LCBzaXplIGluIEtCDQojdmFjdXVtX21lbSA9IDgxOTIJCSMgbWluIDEwMjQs
IHNpemUgaW4gS0INCg0KDQojDQojCVdyaXRlLWFoZWFkIGxvZyAoV0FMKQ0KIw0KI2NoZWNrcG9p
bnRfc2VnbWVudHMgPSAzCSMgaW4gbG9nZmlsZSBzZWdtZW50cywgbWluIDEsIDE2TUIgZWFjaA0K
I2NoZWNrcG9pbnRfdGltZW91dCA9IDMwMAkjIHJhbmdlIDMwLTM2MDAsIGluIHNlY29uZHMNCiMN
CiNjb21taXRfZGVsYXkgPSAwCQkjIHJhbmdlIDAtMTAwMDAwLCBpbiBtaWNyb3NlY29uZHMNCiNj
b21taXRfc2libGluZ3MgPSA1CQkjIHJhbmdlIDEtMTAwMA0KIw0KZnN5bmMgPWZhbHNlDQojd2Fs
X3N5bmNfbWV0aG9kID0gZnN5bmMJIyB0aGUgZGVmYXVsdCB2YXJpZXMgYWNyb3NzIHBsYXRmb3Jt
czoNCiMJCQkJIyBmc3luYywgZmRhdGFzeW5jLCBvcGVuX3N5bmMsIG9yIG9wZW5fZGF0YXN5bmMN
CiN3YWxfZGVidWcgPSAwCQkJIyByYW5nZSAwLTE2DQoNCg0KIw0KIwlPcHRpbWl6ZXIgUGFyYW1l
dGVycw0KIw0KI2VuYWJsZV9zZXFzY2FuID0gdHJ1ZQ0KI2VuYWJsZV9pbmRleHNjYW4gPSB0cnVl
DQojZW5hYmxlX3RpZHNjYW4gPSB0cnVlDQojZW5hYmxlX3NvcnQgPSB0cnVlDQojZW5hYmxlX25l
c3Rsb29wID0gdHJ1ZQ0KI2VuYWJsZV9tZXJnZWpvaW4gPSB0cnVlDQojZW5hYmxlX2hhc2hqb2lu
ID0gdHJ1ZQ0KDQplZmZlY3RpdmVfY2FjaGVfc2l6ZSA9MTAwMDAwCSMgdHlwaWNhbGx5IDhLQiBl
YWNoDQpyYW5kb21fcGFnZV9jb3N0ID0gMwkJIyB1bml0cyBhcmUgb25lIHNlcXVlbnRpYWwgcGFn
ZSBmZXRjaCBjb3N0DQojcmFuZG9tX3BhZ2VfY29zdCA9IDQJCSMgdW5pdHMgYXJlIG9uZSBzZXF1
ZW50aWFsIHBhZ2UgZmV0Y2ggY29zdA0KI2NwdV90dXBsZV9jb3N0ID0gMC4wMQkJIyAoc2FtZSkN
CiNjcHVfaW5kZXhfdHVwbGVfY29zdCA9IDAuMDAxCSMgKHNhbWUpDQojY3B1X29wZXJhdG9yX2Nv
c3QgPSAwLjAwMjUJIyAoc2FtZSkNCg0KI2Zyb21fY29sbGFwc2VfbGltaXQgPSA4DQojam9pbl9j
b2xsYXBzZV9saW1pdCA9IDgJIyAxIGRpc2FibGVzIGNvbGxhcHNpbmcgb2YgZXhwbGljaXQgSk9J
TnMNCg0KI2RlZmF1bHRfc3RhdGlzdGljc190YXJnZXQgPSAxMAkjIHJhbmdlIDEtMTAwMA0KDQoj
DQojCUdFUU8gT3B0aW1pemVyIFBhcmFtZXRlcnMNCiMNCiNnZXFvID0gdHJ1ZQ0KI2dlcW9fc2Vs
ZWN0aW9uX2JpYXMgPSAyLjAJIyByYW5nZSAxLjUtMi4wDQojZ2Vxb190aHJlc2hvbGQgPSAxMQ0K
I2dlcW9fcG9vbF9zaXplID0gMAkJIyBkZWZhdWx0IGJhc2VkIG9uIHRhYmxlcyBpbiBzdGF0ZW1l
bnQsIA0KCQkJCSMgcmFuZ2UgMTI4LTEwMjQNCiNnZXFvX2VmZm9ydCA9IDENCiNnZXFvX2dlbmVy
YXRpb25zID0gMA0KI2dlcW9fcmFuZG9tX3NlZWQgPSAtMQkJIyBhdXRvLWNvbXB1dGUgc2VlZA0K
DQoNCiMNCiMJTWVzc2FnZSBkaXNwbGF5DQojDQojc2VydmVyX21pbl9tZXNzYWdlcyA9IG5vdGlj
ZQkjIFZhbHVlcywgaW4gb3JkZXIgb2YgZGVjcmVhc2luZyBkZXRhaWw6DQoJCQkJIyAgIGRlYnVn
NSwgZGVidWc0LCBkZWJ1ZzMsIGRlYnVnMiwgZGVidWcxLA0KCQkJCSMgICBpbmZvLCBub3RpY2Us
IHdhcm5pbmcsIGVycm9yLCBsb2csIGZhdGFsLA0KCQkJCSMgICBwYW5pYw0KI2NsaWVudF9taW5f
bWVzc2FnZXMgPSBub3RpY2UJIyBWYWx1ZXMsIGluIG9yZGVyIG9mIGRlY3JlYXNpbmcgZGV0YWls
Og0KCQkJCSMgICBkZWJ1ZzUsIGRlYnVnNCwgZGVidWczLCBkZWJ1ZzIsIGRlYnVnMSwNCgkJCQkj
ICAgbG9nLCBpbmZvLCBub3RpY2UsIHdhcm5pbmcsIGVycm9yDQojc2lsZW50X21vZGUgPSBmYWxz
ZQ0KDQojbG9nX2Nvbm5lY3Rpb25zID0gZmFsc2UNCiNsb2dfcGlkID0gZmFsc2UNCiNsb2dfc3Rh
dGVtZW50ID0gZmFsc2UNCiNsb2dfZHVyYXRpb24gPSBmYWxzZQ0KI2xvZ190aW1lc3RhbXAgPSBm
YWxzZQ0KDQojbG9nX21pbl9lcnJvcl9zdGF0ZW1lbnQgPSBwYW5pYyAjIFZhbHVlcyBpbiBvcmRl
ciBvZiBpbmNyZWFzaW5nIHNldmVyaXR5Og0KCQkJCSAjICAgZGVidWc1LCBkZWJ1ZzQsIGRlYnVn
MywgZGVidWcyLCBkZWJ1ZzEsDQoJCQkJICMgICBpbmZvLCBub3RpY2UsIHdhcm5pbmcsIGVycm9y
LCBwYW5pYyhvZmYpDQoNCiNkZWJ1Z19wcmludF9wYXJzZSA9IGZhbHNlDQojZGVidWdfcHJpbnRf
cmV3cml0dGVuID0gZmFsc2UNCiNkZWJ1Z19wcmludF9wbGFuID0gZmFsc2UNCiNkZWJ1Z19wcmV0
dHlfcHJpbnQgPSBmYWxzZQ0KDQojZXhwbGFpbl9wcmV0dHlfcHJpbnQgPSB0cnVlDQoNCiMgcmVx
dWlyZXMgVVNFX0FTU0VSVF9DSEVDS0lORw0KI2RlYnVnX2Fzc2VydGlvbnMgPSB0cnVlDQoNCg0K
Iw0KIwlTeXNsb2cNCiMNCiNzeXNsb2cgPSAwCQkJIyByYW5nZSAwLTINCiNzeXNsb2dfZmFjaWxp
dHkgPSAnTE9DQUwwJw0KI3N5c2xvZ19pZGVudCA9ICdwb3N0Z3JlcycNCg0KDQojDQojCVN0YXRp
c3RpY3MNCiMNCiNzaG93X3BhcnNlcl9zdGF0cyA9IGZhbHNlDQojc2hvd19wbGFubmVyX3N0YXRz
ID0gZmFsc2UNCiNzaG93X2V4ZWN1dG9yX3N0YXRzID0gZmFsc2UNCiNzaG93X3N0YXRlbWVudF9z
dGF0cyA9IGZhbHNlDQoNCiMgcmVxdWlyZXMgQlRSRUVfQlVJTERfU1RBVFMNCiNzaG93X2J0cmVl
X2J1aWxkX3N0YXRzID0gZmFsc2UNCg0KDQojDQojCUFjY2VzcyBzdGF0aXN0aWNzIGNvbGxlY3Rp
b24NCiMNCiNzdGF0c19zdGFydF9jb2xsZWN0b3IgPSB0cnVlDQojc3RhdHNfcmVzZXRfb25fc2Vy
dmVyX3N0YXJ0ID0gdHJ1ZQ0KI3N0YXRzX2NvbW1hbmRfc3RyaW5nID0gZmFsc2UNCiNzdGF0c19y
b3dfbGV2ZWwgPSBmYWxzZQ0KI3N0YXRzX2Jsb2NrX2xldmVsID0gZmFsc2UNCg0KDQojDQojCUxv
Y2sgVHJhY2luZw0KIw0KI3RyYWNlX25vdGlmeSA9IGZhbHNlDQoNCiMgcmVxdWlyZXMgTE9DS19E
RUJVRw0KI3RyYWNlX2xvY2tzID0gZmFsc2UNCiN0cmFjZV91c2VybG9ja3MgPSBmYWxzZQ0KI3Ry
YWNlX2x3bG9ja3MgPSBmYWxzZQ0KI2RlYnVnX2RlYWRsb2NrcyA9IGZhbHNlDQojdHJhY2VfbG9j
a19vaWRtaW4gPSAxNjM4NA0KI3RyYWNlX2xvY2tfdGFibGUgPSAwDQoNCg0KIw0KIwlNaXNjDQoj
DQojYXV0b2NvbW1pdCA9IHRydWUNCiNkeW5hbWljX2xpYnJhcnlfcGF0aCA9ICckbGliZGlyJw0K
I3NlYXJjaF9wYXRoID0gJyR1c2VyLHB1YmxpYycNCiNkYXRlc3R5bGUgPSAnaXNvLCB1cycNCiN0
aW1lem9uZSA9IHVua25vd24JCSMgYWN0dWFsbHksIGRlZmF1bHRzIHRvIFRaIGVudmlyb25tZW50
IHNldHRpbmcNCiNhdXN0cmFsaWFuX3RpbWV6b25lcyA9IGZhbHNlDQojY2xpZW50X2VuY29kaW5n
ID0gc3FsX2FzY2lpCSMgYWN0dWFsbHksIGRlZmF1bHRzIHRvIGRhdGFiYXNlIGVuY29kaW5nDQoj
YXV0aGVudGljYXRpb25fdGltZW91dCA9IDYwCSMgMS02MDAsIGluIHNlY29uZHMNCiNkZWFkbG9j
a190aW1lb3V0ID0gMTAwMAkjIGluIG1pbGxpc2Vjb25kcw0KI2RlZmF1bHRfdHJhbnNhY3Rpb25f
aXNvbGF0aW9uID0gJ3JlYWQgY29tbWl0dGVkJw0KI21heF9leHByX2RlcHRoID0gMTAwMDAJCSMg
bWluIDEwDQojbWF4X2ZpbGVzX3Blcl9wcm9jZXNzID0gMTAwMAkjIG1pbiAyNQ0KI3Bhc3N3b3Jk
X2VuY3J5cHRpb24gPSB0cnVlDQojc3FsX2luaGVyaXRhbmNlID0gdHJ1ZQ0KI3RyYW5zZm9ybV9u
dWxsX2VxdWFscyA9IGZhbHNlDQojc3RhdGVtZW50X3RpbWVvdXQgPSAwCQkjIDAgaXMgZGlzYWJs
ZWQsIGluIG1pbGxpc2Vjb25kcw0KI2RiX3VzZXJfbmFtZXNwYWNlID0gZmFsc2UNCiANCg0KDQoj
DQojCUxvY2FsZSBzZXR0aW5ncw0KIw0KIyAoaW5pdGlhbGl6ZWQgYnkgaW5pdGRiIC0tIG1heSBi
ZSBjaGFuZ2VkKQ0KTENfTUVTU0FHRVMgPSAnZW5fVVMnDQpMQ19NT05FVEFSWSA9ICdlbl9VUycN
CkxDX05VTUVSSUMgPSAnZW5fVVMnDQpMQ19USU1FID0gJ2VuX1VTJw0K
------=_Part_20960_98211.1130015725464--

From pgsql-performance-owner@postgresql.org  Sat Oct 22 18:43:01 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 3617FD7938
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 22 Oct 2005 18:43:01 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 99758-09
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 22 Oct 2005 21:42:57 +0000 (GMT)
Received: from cassarossa.samfundet.no (cassarossa.samfundet.no
	[129.241.93.19])
	by svr1.postgresql.org (Postfix) with ESMTP id 776ECD77F1
	for <pgsql-performance@postgresql.org>;
	Sat, 22 Oct 2005 18:42:58 -0300 (ADT)
Received: from sesse by cassarossa.samfundet.no with local (Exim 4.50)
	id 1ETR8l-0005y2-7d; Sat, 22 Oct 2005 23:42:59 +0200
Date: Sat, 22 Oct 2005 23:42:59 +0200
From: "Steinar H. Gunderson" <sgunderson@bigfoot.com>
To: Kishore B <kishorebh@gmail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Need help in setting optimal configuration for a huge database.
Message-ID: <20051022214259.GA22328@samfundet.no>
References: <42567e060510221415r2516523l4c3f9b42dee91a09@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <42567e060510221415r2516523l4c3f9b42dee91a09@mail.gmail.com>
User-Agent: Mutt/1.5.9i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.011 required=5 tests=[AWL=0.011]
X-Spam-Level: 
X-Archive-Number: 200510/306
X-Sequence-Number: 15074

On Sun, Oct 23, 2005 at 02:45:25AM +0530, Kishore B wrote:
> Database *:* Postgresql 7.3

You definitely want to upgrade this if you can.

> Memory : 2 GB

For 2GB of RAM, your effective_cache_size (100000) is a bit low (try doubling
it), and sort_mem (2048) is probably a bit too low as well.

/* Steinar */
-- 
Homepage: http://www.sesse.net/


From pgsql-performance-owner@postgresql.org  Sat Oct 22 18:57:50 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 7304CDA9AD
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 22 Oct 2005 18:57:49 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 08282-04
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 22 Oct 2005 21:57:46 +0000 (GMT)
Received: from cassarossa.samfundet.no (cassarossa.samfundet.no
	[129.241.93.19])
	by svr1.postgresql.org (Postfix) with ESMTP id AD9ABDA25D
	for <pgsql-performance@postgresql.org>;
	Sat, 22 Oct 2005 18:57:47 -0300 (ADT)
Received: from sesse by cassarossa.samfundet.no with local (Exim 4.50)
	id 1ETRN7-00063Q-P5; Sat, 22 Oct 2005 23:57:49 +0200
Date: Sat, 22 Oct 2005 23:57:49 +0200
From: "Steinar H. Gunderson" <sgunderson@bigfoot.com>
To: Kishore B <kishorebh@gmail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Need help in setting optimal configuration for a huge database.
Message-ID: <20051022215749.GB22328@samfundet.no>
References: <42567e060510221415r2516523l4c3f9b42dee91a09@mail.gmail.com>
	<20051022214259.GA22328@samfundet.no>
	<42567e060510221449j636538c7sae78a4d05fc77760@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
In-Reply-To: <42567e060510221449j636538c7sae78a4d05fc77760@mail.gmail.com>
User-Agent: Mutt/1.5.9i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.011 required=5 tests=[AWL=0.011]
X-Spam-Level: 
X-Archive-Number: 200510/308
X-Sequence-Number: 15076

[please send replies to the list, not to me directly]

On Sun, Oct 23, 2005 at 03:19:39AM +0530, Kishore B wrote:
>  *You definitely want to upgrade this if you can.
> 
> > Memory : 2 GB
> *
> We can move upto 12 GB if need to be.

I was referring to your PostgreSQL version, not your RAM. More RAM is almost
always an improvement, but for your data set, 2GB sounds quite good. (700k
rows is not really a “huge database”, BTW -- I've seen people here have
several billion rows a _day_.)

>  For now, let us set the configuraiton parameters for 2GB.
> I failed to mention earlier, that we have a dedicated server for database.
>  Can I set the effective_cache_size to 200000?

Yes, that should work fine.

> Can I set the sort_mem size to 4096?

This depends a bit on the queries you're running. Remember that for each and
every sort you do, one of these (measured in 8kB buffers) will get allocated.
Some tuning of your queries against this would probably be useful.

>   Will the performance suffer, if I set these parameters too high?

Yes, you can easily run into allocating too much RAM with too high sort_mem,
which could kill your performance. Overestimating effective_cache_size is
AFAIK not half as bad, though -- it is merely a hint to the planner, it does
not actually allocate memory.

/* Steinar */
-- 
Homepage: http://www.sesse.net/


From pgsql-performance-owner@postgresql.org  Sat Oct 22 18:52:54 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id D0429DA9D0
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 22 Oct 2005 18:52:44 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 09359-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 22 Oct 2005 21:52:41 +0000 (GMT)
Received: from mail21.sea5.speakeasy.net (mail21.sea5.speakeasy.net
	[69.17.117.23])
	by svr1.postgresql.org (Postfix) with ESMTP id CE4A4DA9C1
	for <pgsql-performance@postgresql.org>;
	Sat, 22 Oct 2005 18:52:42 -0300 (ADT)
Received: (qmail 17307 invoked from network); 22 Oct 2005 21:52:44 -0000
Received: from dsl017-073-250.chi4.dsl.speakeasy.net (HELO mofo.meme.com)
	([69.17.73.250]) (envelope-sender <kop@meme.com>)
	by mail21.sea5.speakeasy.net (qmail-ldap-1.03) with SMTP
	for <kishorebh@gmail.com>; 22 Oct 2005 21:52:44 -0000
Received: from mofo (localhost.localdomain [127.0.0.1])
	by mofo.meme.com (Postfix) with ESMTP id ED3CA6E422;
	Sat, 22 Oct 2005 17:03:03 -0500 (CDT)
Date: Sat, 22 Oct 2005 22:03:03 +0000
From: "Karl O. Pinc" <kop@meme.com>
Subject: Re: Need help in setting optimal configuration for a huge
To: Kishore B <kishorebh@gmail.com>
Cc: pgsql-performance@postgresql.org
References: <42567e060510221415r2516523l4c3f9b42dee91a09@mail.gmail.com>
In-Reply-To: <42567e060510221415r2516523l4c3f9b42dee91a09@mail.gmail.com>
	(from kishorebh@gmail.com on Sat Oct 22 16:15:25 2005)
X-Mailer: Balsa 2.3.0
Message-Id: <1130018583l.27845l.10l@mofo>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii; DelSp=Yes; Format=Flowed
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.05 required=5 tests=[FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/307
X-Sequence-Number: 15075


On 10/22/2005 04:15:25 PM, Kishore B wrote:

> Can any you please suggest the best configuration to satisfy the above
> requirements?

You've increased shared memory buffers, told the kernel
to allow more shared memory (lots), and otherwise increased
the parameters associated with memory?

If so you might want to post the relevant configs
here.

If the basic tuning does not help enough you may
want to upgrade to 8.0 as it has significant
performance improvements.

Karl <kop@meme.com>
Free Software:  "You don't pay back, you pay forward."
                  -- Robert A. Heinlein


From pgsql-performance-owner@postgresql.org  Sat Oct 22 19:15:49 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 0E8B4DAA36
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 22 Oct 2005 19:15:49 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 11823-07
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 22 Oct 2005 22:15:45 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id D67B3DAA6C
	for <pgsql-performance@postgresql.org>;
	Sat, 22 Oct 2005 19:15:46 -0300 (ADT)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j9MMFhhO003995;
	Sat, 22 Oct 2005 18:15:43 -0400 (EDT)
To: Kishore B <kishorebh@gmail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Need help in setting optimal configuration for a huge database. 
In-reply-to: <42567e060510221415r2516523l4c3f9b42dee91a09@mail.gmail.com> 
References: <42567e060510221415r2516523l4c3f9b42dee91a09@mail.gmail.com>
Comments: In-reply-to Kishore B <kishorebh@gmail.com>
	message dated "Sun, 23 Oct 2005 02:45:25 +0530"
Date: Sat, 22 Oct 2005 18:15:43 -0400
Message-ID: <3994.1130019343@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/309
X-Sequence-Number: 15077

Kishore B <kishorebh@gmail.com> writes:
> Even a basic query like select count(*) from bigger_table is
> taking about 4 minutes to return.

You do realize that "select count(*)" requires a full table scan in
Postgres?  It's never going to be fast.

If that's not where your performance problem really is, you need to
show us some of the actual problem queries.  If it is, you should
rethink why your application needs an exact row count.

			regards, tom lane

From pgsql-performance-owner@postgresql.org  Sat Oct 22 23:05:49 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id C01B3DA8AB
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 22 Oct 2005 23:05:48 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 66422-03
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 23 Oct 2005 02:05:43 +0000 (GMT)
Received: from zproxy.gmail.com (zproxy.gmail.com [64.233.162.197])
	by svr1.postgresql.org (Postfix) with ESMTP id A61C7D6E34
	for <pgsql-performance@postgresql.org>;
	Sat, 22 Oct 2005 23:05:45 -0300 (ADT)
Received: by zproxy.gmail.com with SMTP id 8so429197nzo
	for <pgsql-performance@postgresql.org>;
	Sat, 22 Oct 2005 19:05:50 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references;
	b=ALZlQXvFmpEWNZuyjdWin0LN87zVXQFz7KLCczWq2nu7fUk6zlFJbwb2obZjX4RfMnps1kxy7MEzUW343j/6xS2s4l8+B9+36nSlr9xEdkCYIOCvc3cS5XJexdgQiz/uyJMII4sZUv5x1ynnRXfxc6WvSbIVm4dm+UMX0g9DOQo=
Received: by 10.36.158.11 with SMTP id g11mr4455843nze;
	Sat, 22 Oct 2005 19:05:50 -0700 (PDT)
Received: by 10.36.61.1 with HTTP; Sat, 22 Oct 2005 19:05:50 -0700 (PDT)
Message-ID: <42567e060510221905t54baa7d4u81cb83a8616a5a99@mail.gmail.com>
Date: Sun, 23 Oct 2005 07:35:50 +0530
From: Kishore B <kishorebh@gmail.com>
To: pgsql-performance@postgresql.org
Subject: Re: Need help in setting optimal configuration for a huge database.
In-Reply-To: <20051022215749.GB22328@samfundet.no>
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="----=_Part_22561_26022568.1130033150191"
References: <42567e060510221415r2516523l4c3f9b42dee91a09@mail.gmail.com>
	<20051022214259.GA22328@samfundet.no>
	<42567e060510221449j636538c7sae78a4d05fc77760@mail.gmail.com>
	<20051022215749.GB22328@samfundet.no>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.418 required=5 tests=[AWL=-0.111, HTML_20_30=0.504,
	HTML_MESSAGE=0.001, RCVD_BY_IP=0.024]
X-Spam-Level: 
X-Archive-Number: 200510/310
X-Sequence-Number: 15078

------=_Part_22561_26022568.1130033150191
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Hi Gunderson,
 * Can I set the effective_cache_size to 200000?*
* Yes, that should work fine.

* Do you mean that I can set the effective_cache_size to 1.5 GB out of 2GB
Memory that I have in the current system?
 Can I set the sort_memory to 3072? We need to generate reports which make
heavy use of group by and order by clauses.
 Based on the 2GB available memory, how do you want me to Please note
further that we need to execute upto 10 data centric queries at any
instance. Based on these specifications, how do you want me to allocate
memory to the following configuration parameters?
 shared_buffers, (Current Setting : 48000 (375MB))
sort_memory, (Current setting 2048 kb (2MB))
effective_cache_size (Current setting: 100000 (1GB))


 On 10/23/05, Steinar H. Gunderson <sgunderson@bigfoot.com> wrote:
>
> [please send replies to the list, not to me directly]
>
> On Sun, Oct 23, 2005 at 03:19:39AM +0530, Kishore B wrote:
> > *You definitely want to upgrade this if you can.
> >
> > > Memory : 2 GB
> > *
> > We can move upto 12 GB if need to be.
>
> I was referring to your PostgreSQL version, not your RAM. More RAM is
> almost
> always an improvement, but for your data set, 2GB sounds quite good. (700=
k
> rows is not really a "huge database", BTW -- I've seen people here have
> several billion rows a _day_.)
>
> > For now, let us set the configuraiton parameters for 2GB.
> > I failed to mention earlier, that we have a dedicated server for
> database.
> > Can I set the effective_cache_size to 200000?
>
> Yes, that should work fine.
>
> > Can I set the sort_mem size to 4096?
>
> This depends a bit on the queries you're running. Remember that for each
> and
> every sort you do, one of these (measured in 8kB buffers) will get
> allocated.
> Some tuning of your queries against this would probably be useful.
>
> > Will the performance suffer, if I set these parameters too high?
>
> Yes, you can easily run into allocating too much RAM with too high
> sort_mem,
> which could kill your performance. Overestimating effective_cache_size is
> AFAIK not half as bad, though -- it is merely a hint to the planner, it
> does
> not actually allocate memory.
>
> /* Steinar */
> --
> Homepage: http://www.sesse.net/
>
>

------=_Part_22561_26022568.1130033150191
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

<div>Hi Gunderson, </div>
<div>&nbsp;</div>
<div><strong><font color=3D"#3366ff">&nbsp;Can I set the effective_cache_si=
ze to 200000?</font></strong></div>
<div><strong><font color=3D"#3366ff">&nbsp;Yes, that should work fine.<br><=
br>&nbsp;</font></strong></div>
<div>Do you mean that I can set the effective_cache_size to 1.5 GB out of 2=
GB Memory that I have in the current system?</div>
<div>&nbsp;</div>
<div>Can I set the sort_memory to 3072? We need to generate reports which m=
ake&nbsp;heavy use of group by and order by clauses.</div>
<div>&nbsp;</div>
<div>Based on the 2GB available memory, how do you want me to Please note f=
urther that we need to execute upto 10 data centric queries at any instance=
. Based on these specifications, how do you&nbsp; want me to allocate memor=
y to&nbsp;the following configuration parameters?
</div>
<div>&nbsp;</div>
<div>shared_buffers, (Current Setting : 48000 (375MB))</div>
<div>sort_memory,&nbsp;&nbsp;&nbsp; (Current setting 2048 kb (2MB))</div>
<div>effective_cache_size (Current setting: 100000 (1GB))</div>
<div>&nbsp;</div>
<div><br><br>&nbsp;</div>
<div><span class=3D"gmail_quote">On 10/23/05, <b class=3D"gmail_sendername"=
>Steinar H. Gunderson</b> &lt;<a href=3D"mailto:sgunderson@bigfoot.com">sgu=
nderson@bigfoot.com</a>&gt; wrote:</span>
<blockquote class=3D"gmail_quote" style=3D"PADDING-LEFT: 1ex; MARGIN: 0px 0=
px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">[please send replies to the list=
, not to me directly]<br><br>On Sun, Oct 23, 2005 at 03:19:39AM +0530, Kish=
ore B wrote:
<br>&gt;&nbsp;&nbsp;*You definitely want to upgrade this if you can.<br>&gt=
;<br>&gt; &gt; Memory : 2 GB<br>&gt; *<br>&gt; We can move upto 12 GB if ne=
ed to be.<br><br>I was referring to your PostgreSQL version, not your RAM. =
More RAM is almost
<br>always an improvement, but for your data set, 2GB sounds quite good. (7=
00k<br>rows is not really a "huge database", BTW -- I've seen people here h=
ave<br>several billion rows a _day_.)<br><br>&gt;&nbsp;&nbsp;For now, let u=
s set the configuraiton parameters for 2GB.
<br>&gt; I failed to mention earlier, that we have a dedicated server for d=
atabase.<br>&gt;&nbsp;&nbsp;Can I set the effective_cache_size to 200000?<b=
r><br>Yes, that should work fine.<br><br>&gt; Can I set the sort_mem size t=
o 4096?
<br><br>This depends a bit on the queries you're running. Remember that for=
 each and<br>every sort you do, one of these (measured in 8kB buffers) will=
 get allocated.<br>Some tuning of your queries against this would probably =
be useful.
<br><br>&gt;&nbsp;&nbsp; Will the performance suffer, if I set these parame=
ters too high?<br><br>Yes, you can easily run into allocating too much RAM =
with too high sort_mem,<br>which could kill your performance. Overestimatin=
g effective_cache_size is
<br>AFAIK not half as bad, though -- it is merely a hint to the planner, it=
 does<br>not actually allocate memory.<br><br>/* Steinar */<br>--<br>Homepa=
ge: <a href=3D"http://www.sesse.net/">http://www.sesse.net/</a><br><br></bl=
ockquote>
</div><br>

------=_Part_22561_26022568.1130033150191--

From pgsql-performance-owner@postgresql.org  Sun Oct 23 01:31:33 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 5AA36D8452
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 23 Oct 2005 01:31:30 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 02743-03
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 23 Oct 2005 04:31:25 +0000 (GMT)
Received: from mail.envyfinancial.com (unknown [206.248.142.186])
	by svr1.postgresql.org (Postfix) with ESMTP id 28006D7797
	for <pgsql-performance@postgresql.org>;
	Sun, 23 Oct 2005 01:31:24 -0300 (ADT)
Received: from localhost (localhost.localdomain [127.0.0.1])
	by mail.envyfinancial.com (Postfix) with ESMTP id B6B1C23436
	for <pgsql-performance@postgresql.org>;
	Sun, 23 Oct 2005 00:14:23 -0400 (EDT)
Received: from mail.envyfinancial.com ([127.0.0.1])
	by localhost (mark.mielke.cc [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 10970-04 for <pgsql-performance@postgresql.org>;
	Sun, 23 Oct 2005 00:14:23 -0400 (EDT)
Received: by mail.envyfinancial.com (Postfix, from userid 500)
	id 75DC423434; Sun, 23 Oct 2005 00:14:23 -0400 (EDT)
Date: Sun, 23 Oct 2005 00:14:23 -0400
From: mark@mark.mielke.cc
To: pgsql-performance@postgresql.org
Subject: prepared transactions that persist across sessions?
Message-ID: <20051023041423.GA11639@mark.mielke.cc>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
User-Agent: Mutt/1.4.2.1i
X-Virus-Scanned: amavisd-new at mail.envyfinancial.com
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.189 required=5 tests=[AWL=0.011, NO_REAL_NAME=0.178]
X-Spam-Level: 
X-Archive-Number: 200510/311
X-Sequence-Number: 15079

Hey all.

Please point me to a place I should be looking if this is a common
question that has been debated periodically and at great length
already. :-)

I have a complex query. It's a few Kbytes large, and yes, I've already
worked on reducing it to be efficient in terms of database design, and
minimizing the expressions used to join the tables. Running some timing
tests, I've finding that the query itself, when issued in full, takes
around 60 milliseconds to complete on modest hardware. If prepared, and
then executed, however, it appears to take around 60 milliseconds to
prepare, and 20 milliseconds to execute. I'm not surprised. PostgreSQL
is very likely calculating the costs of many, many query plans.

This is telling me that the quickest method of me to accelerate these
queries, is to have them pre-select a query plan, and to use it.
Unfortunately, I'll only be executing this query once per session,
so "PREPARE" seems to be out of the question.

I am using PHP's PDO PGSQL interface - I haven't read up enough on it
to determine whether a persistent connection can re-use server-side
prepared queries as an option. Anybody know?

My read of the PLPGSQL documentation seems to suggest that it will do
some sort of query plan caching. Is there better documentation on this
that would explain exactly how it works? What is the best way to define
a PLPGSQL function that will return a set of records? Is RETURNS SETOF
the only option in this regard? It seems inefficient to me. Am I doing
it wrong? Not understanding it? For very simple queries, it seems that
using PLPGSQL and SELECT INTO, RETURN, and then SELECT * FROM F(arg)"
actually slows down the query slightly. It wasn't giving me much faith,
and I wanted to pick up some people's opinions befor egoing further.

What is the reason that SQL and/or PostgreSQL have not added
server-defined prepared statements? As in, one defines a
server-defined prepared statement, and all sessions that have
permission can execute the prepared statement. Is this just an issue
of nobody implementing it? Or was there some deeper explanation as
to why this would be a bad thing?

My reading of views, are that views would not accelerate the queries.
Perhaps the bytes sent to the server would reduce, however, the cost
to prepare, and execute the statement would be similar, or possibly
even longer?

I'm thinking I need some way of defined a server side query, that
takes arguments, that will infrequently prepare the query, such that
the majority of the time that it is executed, it will not have to
choose a query plan.

Am I missing something obvious? :-)

Thanks,
mark

-- 
mark@mielke.cc / markm@ncf.ca / markm@nortel.com     __________________________
.  .  _  ._  . .   .__    .  . ._. .__ .   . . .__  | Neighbourhood Coder
|\/| |_| |_| |/    |_     |\/|  |  |_  |   |/  |_   | 
|  | | | | \ | \   |__ .  |  | .|. |__ |__ | \ |__  | Ottawa, Ontario, Canada

  One ring to rule them all, one ring to find them, one ring to bring them all
                       and in the darkness bind them...

                           http://mark.mielke.cc/


From pgsql-performance-owner@postgresql.org  Sun Oct 23 03:50:11 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 7678ADAB8A
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 23 Oct 2005 03:50:10 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 25042-10
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 23 Oct 2005 06:50:07 +0000 (GMT)
Received: from wolff.to (wolff.to [66.93.197.194])
	by svr1.postgresql.org (Postfix) with SMTP id 5F17DDAB9D
	for <pgsql-performance@postgresql.org>;
	Sun, 23 Oct 2005 03:50:07 -0300 (ADT)
Received: (qmail 13577 invoked by uid 500); 23 Oct 2005 06:51:36 -0000
Date: Sun, 23 Oct 2005 01:51:36 -0500
From: Bruno Wolff III <bruno@wolff.to>
To: mark@mark.mielke.cc
Cc: pgsql-performance@postgresql.org
Subject: Re: prepared transactions that persist across sessions?
Message-ID: <20051023065136.GA12238@wolff.to>
Mail-Followup-To: Bruno Wolff III <bruno@wolff.to>,
	mark@mark.mielke.cc, pgsql-performance@postgresql.org
References: <20051023041423.GA11639@mark.mielke.cc>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20051023041423.GA11639@mark.mielke.cc>
User-Agent: Mutt/1.4.2.1i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.007 required=5 tests=[AWL=0.007]
X-Spam-Level: 
X-Archive-Number: 200510/312
X-Sequence-Number: 15080

On Sun, Oct 23, 2005 at 00:14:23 -0400,
  mark@mark.mielke.cc wrote:
> Hey all.
> 
> Please point me to a place I should be looking if this is a common
> question that has been debated periodically and at great length
> already. :-)

You probably want to read:
http://candle.pha.pa.us/main/writings/pgsql/sgml/runtime-config-query.html

Connection pooling might be another approach, since it should be possible
to reuse prepared statements when reusing a connection.

> I have a complex query. It's a few Kbytes large, and yes, I've already
> worked on reducing it to be efficient in terms of database design, and
> minimizing the expressions used to join the tables. Running some timing
> tests, I've finding that the query itself, when issued in full, takes
> around 60 milliseconds to complete on modest hardware. If prepared, and
> then executed, however, it appears to take around 60 milliseconds to
> prepare, and 20 milliseconds to execute. I'm not surprised. PostgreSQL
> is very likely calculating the costs of many, many query plans.

From pgsql-performance-owner@postgresql.org  Sun Oct 23 07:04:10 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 72BFDD8697
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 23 Oct 2005 07:04:08 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 76372-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 23 Oct 2005 10:04:05 +0000 (GMT)
Received: from zigo.dhs.org (ua-83-227-204-174.cust.bredbandsbolaget.se
	[83.227.204.174])
	by svr1.postgresql.org (Postfix) with ESMTP id B24A1D7028
	for <pgsql-performance@postgresql.org>;
	Sun, 23 Oct 2005 07:04:06 -0300 (ADT)
Received: from zigo.zigo.dhs.org (zigo.zigo.dhs.org [192.168.0.1])
	by zigo.dhs.org (Postfix) with ESMTP
	id 78A268467; Sun, 23 Oct 2005 12:04:07 +0200 (CEST)
Date: Sun, 23 Oct 2005 12:04:07 +0200 (CEST)
From: Dennis Bjorklund <db@zigo.dhs.org>
To: Kishore B <kishorebh@gmail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Need help in setting optimal configuration for a huge
In-Reply-To: <42567e060510221415r2516523l4c3f9b42dee91a09@mail.gmail.com>
Message-ID: <Pine.LNX.4.44.0510231200490.11189-100000@zigo.dhs.org>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=ISO-8859-1
Content-Transfer-Encoding: 8BIT
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.324 required=5 tests=[AWL=-0.100,
	DNS_FROM_RFC_ABUSE=0.374, FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/313
X-Sequence-Number: 15081

On Sun, 23 Oct 2005, Kishore B wrote:

> We need to insert into the bigger table almost for every second , through
> out the life time. In addition, we receive at least 200,000 records a day at
> a fixed time.
> 
> We are facing a* critical situation because of the performance of the **
> database**.* Even a basic query like select count(*) from bigger_table is
> taking about 4 minutes to return.

Count(*) like that always scans the full table, but 4 minutes still sound
like a lot.  How often do you vacuum? Could it be that the disk is full of
garbage due to not enough vacuum?

A query like this can help find bloat:

 SELECT oid::regclass, reltuples, relpages FROM pg_class ORDER BY 3 DESC;

I assume to do updates and deletes as well, and not just inserts?

-- 
/Dennis Bj�rklund


From pgsql-performance-owner@postgresql.org  Sun Oct 23 07:23:35 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 99145D8A1B
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 23 Oct 2005 07:23:34 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 82224-10
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 23 Oct 2005 10:23:30 +0000 (GMT)
Received: from cassarossa.samfundet.no (cassarossa.samfundet.no
	[129.241.93.19])
	by svr1.postgresql.org (Postfix) with ESMTP id 0585FD8637
	for <pgsql-performance@postgresql.org>;
	Sun, 23 Oct 2005 07:23:31 -0300 (ADT)
Received: from sesse by cassarossa.samfundet.no with local (Exim 4.50)
	id 1ETd0n-0002Wy-SB
	for pgsql-performance@postgresql.org; Sun, 23 Oct 2005 12:23:33 +0200
Date: Sun, 23 Oct 2005 12:23:33 +0200
From: "Steinar H. Gunderson" <sgunderson@bigfoot.com>
To: pgsql-performance@postgresql.org
Subject: Re: Materializing a sequential scan
Message-ID: <20051023102333.GA9356@samfundet.no>
References: <20051019174544.GA32303@samfundet.no>
	<4248.1129783045@sss.pgh.pa.us>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <4248.1129783045@sss.pgh.pa.us>
User-Agent: Mutt/1.5.9i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.011 required=5 tests=[AWL=0.011]
X-Spam-Level: 
X-Archive-Number: 200510/314
X-Sequence-Number: 15082

On Thu, Oct 20, 2005 at 12:37:25AM -0400, Tom Lane wrote:
> That mdb_gruppekobling_transitiv_tillukning function looks awfully
> grotty ... how many rows does it return, and how long does it take to
> run by itself?  How often does its temp table get vacuumed?  A quick
> band-aid might be to use TRUNCATE instead of DELETE FROM to clean the
> table ... but if I were you I'd try to rewrite the function entirely.

I've verified that it indeed does use 20ms more for every run without a
VACUUM, but it shouldn't really matter -- and I guess it will go away once
somebody teaches plpgsql about not caching OIDs for CREATE TEMPORARY TABLE.
:-)

In any case, I still can't understand why it picks the plan it does; what's
up with the materialized seqscan, and where do the four million rows come
from? 7.4 estimates ~52000 disk page fetches for the same query, so surely
there must be a better plan than four million :-)

/* Steinar */
-- 
Homepage: http://www.sesse.net/


From pgsql-performance-owner@postgresql.org  Sun Oct 23 13:33:50 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 85A77DAA03
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 23 Oct 2005 13:33:49 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 56240-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 23 Oct 2005 16:33:46 +0000 (GMT)
Received: from moonunit2.moonview.localnet (wsip-68-15-5-150.sd.sd.cox.net
	[68.15.5.150])
	by svr1.postgresql.org (Postfix) with ESMTP id 7DC4ADAA2D
	for <pgsql-performance@postgresql.org>;
	Sun, 23 Oct 2005 13:33:45 -0300 (ADT)
Received: from [192.168.0.3] (moonunit3.moonview.localnet [192.168.0.3])
	by moonunit2.moonview.localnet (8.13.1/8.13.1) with ESMTP id
	j9NGctqK009815; Sun, 23 Oct 2005 09:38:56 -0700
Message-ID: <435BBAF0.8080500@modgraph-usa.com>
Date: Sun, 23 Oct 2005 09:31:44 -0700
From: "Craig A. James" <cjames@modgraph-usa.com>
User-Agent: Mozilla Thunderbird 1.0.6 (X11/20050716)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: Kishore B <kishorebh@gmail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Need help in setting optimal configuration for a huge
References: <42567e060510221415r2516523l4c3f9b42dee91a09@mail.gmail.com>
In-Reply-To: <42567e060510221415r2516523l4c3f9b42dee91a09@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.05 required=5 tests=[FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/315
X-Sequence-Number: 15083


> We are facing a* critical situation because of the performance of the 
> **database** .* Even a basic query like select count(*) from 
> bigger_table is taking about 4 minutes to return.

Several other replies have mentioned that COUNT() requires a full table scan, but this point can't be emphasized enough: Don't do it!  People who are migrating from other environments (Oracle or MySQL) are used to COUNT(), MIN() and MAX() returning almost instantaneously, certainly on indexed columns.  But for reasons that have something to do with transactions, these operations are unbelievably slow in PostgreSQL.  

Here are the alternatives that I've learned.

COUNT() -- There is no good substitute.  What I do is create a new column, "ROW_NUM" with an auto-incrementing sequence.  Every time I insert a row, it gets a new value.  Unfortunately, this doesn't work if you ever delete a row.  The alternative is a more complex pair of triggers, one for insert and one for delete, that maintains the count in a separate one-row table.  It's a nuisance, but it's a lot faster than doing a full table scan for every COUNT().

MIN() and MAX() -- These are surprisingly slow, because they seem to do a full table scan EVEN ON AN INDEXED COLUMN!  I don't understand why, but happily there is an effective substitute:

   select mycolumn from mytable order by mycolumn limit 1;  -- same as MIN()

   select mycolumn from mytable order by mycolumn desc limit 1;  -- same as MAX()

For a large table, MIN or MAX can take 5-10 minutes, where the above "select..." replacements can return in one millisecond.

You should carefully examine your entire application for COUNT, MIN, and MAX, and get rid of them EVERYWHERE.  This may be the entire source of your problem.  It was in my case.  

This is, in my humble opinion, the only serious flaw in PostgreSQL.  I've been totally happy with it in every other way, and once I understood these shortcomings, my application is runs faster than ever on PostgreSQL.

Craig

From pgsql-performance-owner@postgresql.org  Sun Oct 23 13:55:08 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 63734D868B
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 23 Oct 2005 13:55:06 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 63828-07
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 23 Oct 2005 16:55:03 +0000 (GMT)
Received: from cassarossa.samfundet.no (cassarossa.samfundet.no
	[129.241.93.19])
	by svr1.postgresql.org (Postfix) with ESMTP id 91778DAA5C
	for <pgsql-performance@postgresql.org>;
	Sun, 23 Oct 2005 13:55:03 -0300 (ADT)
Received: from sesse by cassarossa.samfundet.no with local (Exim 4.50)
	id 1ETj7c-0006vE-4T; Sun, 23 Oct 2005 18:55:00 +0200
Date: Sun, 23 Oct 2005 18:55:00 +0200
From: "Steinar H. Gunderson" <sgunderson@bigfoot.com>
To: Kishore B <kishorebh@gmail.com>, pgsql-performance@postgresql.org
Subject: Re: Need help in setting optimal configuration for a huge
Message-ID: <20051023165500.GA15053@samfundet.no>
References: <42567e060510221415r2516523l4c3f9b42dee91a09@mail.gmail.com>
	<435BBAF0.8080500@modgraph-usa.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <435BBAF0.8080500@modgraph-usa.com>
User-Agent: Mutt/1.5.9i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.011 required=5 tests=[AWL=0.011]
X-Spam-Level: 
X-Archive-Number: 200510/316
X-Sequence-Number: 15084

On Sun, Oct 23, 2005 at 09:31:44AM -0700, Craig A. James wrote:
> COUNT() -- There is no good substitute.  What I do is create a new column, 
> "ROW_NUM" with an auto-incrementing sequence.  Every time I insert a row, 
> it gets a new value.  Unfortunately, this doesn't work if you ever delete a 
> row.  The alternative is a more complex pair of triggers, one for insert 
> and one for delete, that maintains the count in a separate one-row table.  
> It's a nuisance, but it's a lot faster than doing a full table scan for 
> every COUNT().

This will sometimes give you wrong results if your transactions ever roll
back, for instance. The correct way to do it is to maintain a table of
deltas, and insert a new positive record every time you insert rows, and a
negative one every time you delete them (using a trigger, of course). Then
you can query it for SUM(). (To keep the table small, run a SUM() in a cron
job or such to combine the deltas.)

There has, IIRC, been talks of supporting fast (index-only) scans on
read-only (ie. archived) partitions of tables, but it doesn't look like this
is coming in the immediate future. I guess others know more than me here :-)

> MIN() and MAX() -- These are surprisingly slow, because they seem to do a 
> full table scan EVEN ON AN INDEXED COLUMN!  I don't understand why, but 
> happily there is an effective substitute:

They are slow because PostgreSQL has generalized aggregates, ie. MAX() gets
fed exactly the same data as SUM() would. PostgreSQL 8.1 (soon-to-be
released) can rewrite a MAX() or MIN() to an appropriate LIMIT form, though,
which solves the problem.

/* Steinar */
-- 
Homepage: http://www.sesse.net/


From pgsql-performance-owner@postgresql.org  Sun Oct 23 14:06:18 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 17EFED8416
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 23 Oct 2005 14:06:12 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 67421-04
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 23 Oct 2005 17:06:10 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id 3864BD6F13
	for <pgsql-performance@postgresql.org>;
	Sun, 23 Oct 2005 14:06:10 -0300 (ADT)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j9NH67dn020904;
	Sun, 23 Oct 2005 13:06:07 -0400 (EDT)
To: "Craig A. James" <cjames@modgraph-usa.com>
Cc: Kishore B <kishorebh@gmail.com>, pgsql-performance@postgresql.org
Subject: Re: Need help in setting optimal configuration for a huge 
In-reply-to: <435BBAF0.8080500@modgraph-usa.com> 
References: <42567e060510221415r2516523l4c3f9b42dee91a09@mail.gmail.com>
	<435BBAF0.8080500@modgraph-usa.com>
Comments: In-reply-to "Craig A. James" <cjames@modgraph-usa.com>
	message dated "Sun, 23 Oct 2005 09:31:44 -0700"
Date: Sun, 23 Oct 2005 13:06:07 -0400
Message-ID: <20903.1130087167@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/318
X-Sequence-Number: 15086

"Craig A. James" <cjames@modgraph-usa.com> writes:
> MIN() and MAX() -- These are surprisingly slow, because they seem to do a full table scan EVEN ON AN INDEXED COLUMN!  I don't understand why, but happily there is an effective substitute:

>    select mycolumn from mytable order by mycolumn limit 1;  -- same as MIN()

>    select mycolumn from mytable order by mycolumn desc limit 1;  -- same as MAX()

BTW, Postgres does know to do that for itself as of 8.1.

			regards, tom lane

From pgsql-performance-owner@postgresql.org  Sun Oct 23 13:58:12 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id C8853D6EDE
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 23 Oct 2005 13:58:10 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 61637-06
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 23 Oct 2005 16:58:08 +0000 (GMT)
Received: from v00051.home.net.pl (post.pl [212.85.96.51])
	by svr1.postgresql.org (Postfix) with SMTP id 80710DA948
	for <pgsql-performance@postgresql.org>;
	Sun, 23 Oct 2005 13:58:08 -0300 (ADT)
Received: from localhost (HELO ?10.16.0.65?) (bogomips.post@home@127.0.0.1)
	by matrix01b.home.net.pl with SMTP; Sun, 23 Oct 2005 16:58:04 -0000
Subject: Re: Need help in setting optimal configuration for a huge
From: Tomasz Rybak <bogomips@post.pl>
To: "Craig A. James" <cjames@modgraph-usa.com>
Cc: Kishore B <kishorebh@gmail.com>, pgsql-performance@postgresql.org
In-Reply-To: <435BBAF0.8080500@modgraph-usa.com>
References: <42567e060510221415r2516523l4c3f9b42dee91a09@mail.gmail.com>
	<435BBAF0.8080500@modgraph-usa.com>
Content-Type: text/plain; charset=ISO-8859-2
Date: Sun, 23 Oct 2005 19:17:56 +0200
Message-Id: <1130087877.6708.16.camel@localhost.localdomain>
Mime-Version: 1.0
X-Mailer: Evolution 2.2.3 
Content-Transfer-Encoding: 8bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=-0.061 required=5 tests=[AWL=-0.111,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/317
X-Sequence-Number: 15085

Dnia 23-10-2005, nie o godzinie 09:31 -0700, Craig A. James napisa�(a):
<cut>
> MIN() and MAX() -- These are surprisingly slow, because they seem to do a full table scan EVEN ON AN INDEXED COLUMN!
In 8.1 this is no true, see the changelog.

> I don't understand why, but happily there is an effective substitute:
> 
>    select mycolumn from mytable order by mycolumn limit 1;  -- same as MIN()
> 
>    select mycolumn from mytable order by mycolumn desc limit 1;  -- same as MAX()

In 8.1 these queries are equivalent:

select mycolumn from mytable order by mycolumn limit 1;
select min(mycolumn) from mytable;

-- 
Tomasz Rybak <bogomips@post.pl>


From pgsql-performance-owner@postgresql.org  Sun Oct 23 18:01:06 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 99698DAAA7
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 23 Oct 2005 18:01:05 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 62665-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 23 Oct 2005 21:01:02 +0000 (GMT)
Received: from davinci.ethosmedia.com (server227.ethosmedia.com
	[209.128.84.227])
	by svr1.postgresql.org (Postfix) with ESMTP id EE2F4DAA87
	for <pgsql-performance@postgresql.org>;
	Sun, 23 Oct 2005 18:01:03 -0300 (ADT)
X-EthosMedia-Virus-Scanned: no infections found
Received: from [63.195.55.98] (account josh@agliodbs.com HELO spooky)
	by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.1.8)
	with ESMTP id 8334110; Sun, 23 Oct 2005 14:03:34 -0700
From: Josh Berkus <josh@agliodbs.com>
Organization: Aglio Database Solutions
To: pgsql-performance@postgresql.org
Subject: Re: Using LIMIT 1 in plpgsql PERFORM statements
Date: Sun, 23 Oct 2005 14:02:35 -0700
User-Agent: KMail/1.8
Cc: "Karl O. Pinc" <kop@meme.com>
References: <1129957521l.27845l.2l@mofo>
In-Reply-To: <1129957521l.27845l.2l@mofo>
MIME-Version: 1.0
Content-Type: text/plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Message-Id: <200510231402.35612.josh@agliodbs.com>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.114 required=5 tests=[AWL=-0.093,
	UPPERCASE_25_50=0.207]
X-Spam-Level: 
X-Archive-Number: 200510/319
X-Sequence-Number: 15087

Karl,

> PERFORM 1 FROM foo;
> IF FOUND THEN ...
>
> is any slower than:
>
> PERFORM 1 FROM foo LIMIT 1;
> IF FOUND THEN ...

I'm wondering in what context it makes sense to call PERFORM on a constant.

-- 
Josh Berkus
Aglio Database Solutions
San Francisco

From pgsql-performance-owner@postgresql.org  Sun Oct 23 18:35:39 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 46624D8FA0
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 23 Oct 2005 18:35:38 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 70442-09
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 23 Oct 2005 21:35:35 +0000 (GMT)
Received: from zproxy.gmail.com (zproxy.gmail.com [64.233.162.206])
	by svr1.postgresql.org (Postfix) with ESMTP id 4208BD8978
	for <pgsql-performance@postgresql.org>;
	Sun, 23 Oct 2005 18:35:36 -0300 (ADT)
Received: by zproxy.gmail.com with SMTP id 8so503930nzo
	for <pgsql-performance@postgresql.org>;
	Sun, 23 Oct 2005 14:35:38 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references;
	b=eEQPZO56gmmGxIh58QFugliss9a1RtASPZVoOBNKSM38ii7UOVqFyEcxR200fHw7P754Ur0aJsrvKbDIuryZiJr6pcc/+snF3VMd/8zXpF7nmkRq0YBKJDoVK7Ghfx784Mi5ofGybcWYRbSESPhiE06abUwSQZt4MNbp+642vWY=
Received: by 10.37.20.35 with SMTP id x35mr5214365nzi;
	Sun, 23 Oct 2005 14:35:38 -0700 (PDT)
Received: by 10.36.61.1 with HTTP; Sun, 23 Oct 2005 14:35:38 -0700 (PDT)
Message-ID: <42567e060510231435g113273edidc97207a71abf5f@mail.gmail.com>
Date: Mon, 24 Oct 2005 03:05:38 +0530
From: Kishore B <kishorebh@gmail.com>
To: pgsql-performance@postgresql.org
Subject: Re: Need help in setting optimal configuration for a huge database.
In-Reply-To: <435BBAF0.8080500@modgraph-usa.com>
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="----=_Part_26465_15359058.1130103338838"
References: <42567e060510221415r2516523l4c3f9b42dee91a09@mail.gmail.com>
	<435BBAF0.8080500@modgraph-usa.com>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.455 required=5 tests=[AWL=-0.074, HTML_20_30=0.504,
	HTML_MESSAGE=0.001, RCVD_BY_IP=0.024]
X-Spam-Level: 
X-Archive-Number: 200510/320
X-Sequence-Number: 15088

------=_Part_26465_15359058.1130103338838
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Hi Craig,
 Thank you very much for your response.
 It really covered a great point.
 Thank you,
Kishore.

 On 10/23/05, Craig A. James <cjames@modgraph-usa.com> wrote:
>
>
> > We are facing a* critical situation because of the performance of the
> > **database** .* Even a basic query like select count(*) from
> > bigger_table is taking about 4 minutes to return.
>
> Several other replies have mentioned that COUNT() requires a full table
> scan, but this point can't be emphasized enough: Don't do it! People who =
are
> migrating from other environments (Oracle or MySQL) are used to COUNT(),
> MIN() and MAX() returning almost instantaneously, certainly on indexed
> columns. But for reasons that have something to do with transactions, the=
se
> operations are unbelievably slow in PostgreSQL.
>
> Here are the alternatives that I've learned.
>
> COUNT() -- There is no good substitute. What I do is create a new column,
> "ROW_NUM" with an auto-incrementing sequence. Every time I insert a row, =
it
> gets a new value. Unfortunately, this doesn't work if you ever delete a r=
ow.
> The alternative is a more complex pair of triggers, one for insert and on=
e
> for delete, that maintains the count in a separate one-row table. It's a
> nuisance, but it's a lot faster than doing a full table scan for every
> COUNT().
>
> MIN() and MAX() -- These are surprisingly slow, because they seem to do a
> full table scan EVEN ON AN INDEXED COLUMN! I don't understand why, but
> happily there is an effective substitute:
>
> select mycolumn from mytable order by mycolumn limit 1; -- same as MIN()
>
> select mycolumn from mytable order by mycolumn desc limit 1; -- same as
> MAX()
>
> For a large table, MIN or MAX can take 5-10 minutes, where the above
> "select..." replacements can return in one millisecond.
>
> You should carefully examine your entire application for COUNT, MIN, and
> MAX, and get rid of them EVERYWHERE. This may be the entire source of you=
r
> problem. It was in my case.
>
> This is, in my humble opinion, the only serious flaw in PostgreSQL. I've
> been totally happy with it in every other way, and once I understood thes=
e
> shortcomings, my application is runs faster than ever on PostgreSQL.
>
> Craig
>

------=_Part_26465_15359058.1130103338838
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

<div>Hi Craig,</div>
<div>&nbsp;</div>
<div>Thank you very much for your response. </div>
<div>&nbsp;</div>
<div>It really covered a great point. </div>
<div>&nbsp;</div>
<div>Thank you,</div>
<div>Kishore.<br><br>&nbsp;</div>
<div><span class=3D"gmail_quote">On 10/23/05, <b class=3D"gmail_sendername"=
>Craig A. James</b> &lt;<a href=3D"mailto:cjames@modgraph-usa.com">cjames@m=
odgraph-usa.com</a>&gt; wrote:</span>
<blockquote class=3D"gmail_quote" style=3D"PADDING-LEFT: 1ex; MARGIN: 0px 0=
px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid"><br>&gt; We are facing a* critic=
al situation because of the performance of the<br>&gt; **database** .* Even=
 a basic query like select count(*) from
<br>&gt; bigger_table is taking about 4 minutes to return.<br><br>Several o=
ther replies have mentioned that COUNT() requires a full table scan, but th=
is point can't be emphasized enough: Don't do it!&nbsp;&nbsp;People who are=
 migrating from other environments (Oracle or MySQL) are used to COUNT(), M=
IN() and MAX() returning almost instantaneously, certainly on indexed colum=
ns.&nbsp;&nbsp;But for reasons that have something to do with transactions,=
 these operations are unbelievably slow in PostgreSQL.
<br><br>Here are the alternatives that I've learned.<br><br>COUNT() -- Ther=
e is no good substitute.&nbsp;&nbsp;What I do is create a new column, &quot=
;ROW_NUM&quot; with an auto-incrementing sequence.&nbsp;&nbsp;Every time I =
insert a row, it gets a new value.&nbsp;&nbsp;Unfortunately, this doesn't w=
ork if you ever delete a row.&nbsp;&nbsp;The alternative is a more complex =
pair of triggers, one for insert and one for delete, that maintains the cou=
nt in a separate one-row table.&nbsp;&nbsp;It's a nuisance, but it's a lot =
faster than doing a full table scan for every COUNT().
<br><br>MIN() and MAX() -- These are surprisingly slow, because they seem t=
o do a full table scan EVEN ON AN INDEXED COLUMN!&nbsp;&nbsp;I don't unders=
tand why, but happily there is an effective substitute:<br><br>&nbsp;&nbsp;=
select mycolumn from mytable order by mycolumn limit 1;&nbsp;&nbsp;-- same =
as MIN()
<br><br>&nbsp;&nbsp;select mycolumn from mytable order by mycolumn desc lim=
it 1;&nbsp;&nbsp;-- same as MAX()<br><br>For a large table, MIN or MAX can =
take 5-10 minutes, where the above &quot;select...&quot; replacements can r=
eturn in one millisecond.
<br><br>You should carefully examine your entire application for COUNT, MIN=
, and MAX, and get rid of them EVERYWHERE.&nbsp;&nbsp;This may be the entir=
e source of your problem.&nbsp;&nbsp;It was in my case.<br><br>This is, in =
my humble opinion, the only serious flaw in PostgreSQL.&nbsp;&nbsp;I've bee=
n totally happy with it in every other way, and once I understood these sho=
rtcomings, my application is runs faster than ever on PostgreSQL.
<br><br>Craig<br></blockquote></div><br>

------=_Part_26465_15359058.1130103338838--

From pgsql-admin-owner@postgresql.org  Sun Oct 23 18:55:50 2005
X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 4AA93DAAEB
	for <pgsql-admin-postgresql.org@localhost.postgresql.org>;
	Sun, 23 Oct 2005 18:55:49 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 74304-07
	for <pgsql-admin-postgresql.org@localhost.postgresql.org>;
	Sun, 23 Oct 2005 21:55:46 +0000 (GMT)
Received: from zproxy.gmail.com (zproxy.gmail.com [64.233.162.204])
	by svr1.postgresql.org (Postfix) with ESMTP id 6985ADAAAC
	for <pgsql-admin@postgresql.org>; Sun, 23 Oct 2005 18:55:47 -0300 (ADT)
Received: by zproxy.gmail.com with SMTP id 8so505340nzo
	for <pgsql-admin@postgresql.org>; Sun, 23 Oct 2005 14:55:50 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references;
	b=LuSGTdARHK1RwkJa5XbsBR2NeJ+Vw/Dl/guJkmC4F+H9VO3wNpn3RhgFdz5seF3wxUJZDMK7VEXblJUDl4LNKvCuSHmfiW4fS4V/I+32XcziQxgc49oYaPqsAL8Oo92vzVHY1fN+eQvo1fj7kouOHoAxDcsgCwoIJ881Mv//Wkg=
Received: by 10.36.220.69 with SMTP id s69mr5187815nzg;
	Sun, 23 Oct 2005 14:55:50 -0700 (PDT)
Received: by 10.36.61.1 with HTTP; Sun, 23 Oct 2005 14:55:50 -0700 (PDT)
Message-ID: <42567e060510231455l6a6721cdtc52ad1b4d254aa64@mail.gmail.com>
Date: Mon, 24 Oct 2005 03:25:50 +0530
From: Kishore B <kishorebh@gmail.com>
To: "pgsql-admin@postgresql.org" <pgsql-admin@postgresql.org>
Subject: Re: [PERFORM] Need help in setting optimal configuration for a huge
	database.
In-Reply-To: <435BBAF0.8080500@modgraph-usa.com>
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="----=_Part_26561_3347224.1130104550168"
References: <42567e060510221415r2516523l4c3f9b42dee91a09@mail.gmail.com>
	<435BBAF0.8080500@modgraph-usa.com>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.709 required=5 tests=[AWL=-0.290, HTML_20_30=0.504,
	HTML_MESSAGE=0.001, RCVD_BY_IP=0.024, TO_ADDRESS_EQ_REAL=0.47]
X-Spam-Level: 
X-Archive-Number: 200510/251
X-Sequence-Number: 19323

------=_Part_26561_3347224.1130104550168
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Hi Craig,
 Does the no of tables and the size of each table affect the performance of
a join operation?
 When we are trying to join the two big tables that I described above, pg i=
s
taking so long to execute?
 Thank you,
Kishore.

 On 10/23/05, Craig A. James <cjames@modgraph-usa.com> wrote:
>
>
> > We are facing a* critical situation because of the performance of the
> > **database** .* Even a basic query like select count(*) from
> > bigger_table is taking about 4 minutes to return.
>
> Several other replies have mentioned that COUNT() requires a full table
> scan, but this point can't be emphasized enough: Don't do it! People who =
are
> migrating from other environments (Oracle or MySQL) are used to COUNT(),
> MIN() and MAX() returning almost instantaneously, certainly on indexed
> columns. But for reasons that have something to do with transactions, the=
se
> operations are unbelievably slow in PostgreSQL.
>
> Here are the alternatives that I've learned.
>
> COUNT() -- There is no good substitute. What I do is create a new column,
> "ROW_NUM" with an auto-incrementing sequence. Every time I insert a row, =
it
> gets a new value. Unfortunately, this doesn't work if you ever delete a r=
ow.
> The alternative is a more complex pair of triggers, one for insert and on=
e
> for delete, that maintains the count in a separate one-row table. It's a
> nuisance, but it's a lot faster than doing a full table scan for every
> COUNT().
>
> MIN() and MAX() -- These are surprisingly slow, because they seem to do a
> full table scan EVEN ON AN INDEXED COLUMN! I don't understand why, but
> happily there is an effective substitute:
>
> select mycolumn from mytable order by mycolumn limit 1; -- same as MIN()
>
> select mycolumn from mytable order by mycolumn desc limit 1; -- same as
> MAX()
>
> For a large table, MIN or MAX can take 5-10 minutes, where the above
> "select..." replacements can return in one millisecond.
>
> You should carefully examine your entire application for COUNT, MIN, and
> MAX, and get rid of them EVERYWHERE. This may be the entire source of you=
r
> problem. It was in my case.
>
> This is, in my humble opinion, the only serious flaw in PostgreSQL. I've
> been totally happy with it in every other way, and once I understood thes=
e
> shortcomings, my application is runs faster than ever on PostgreSQL.
>
> Craig
>

------=_Part_26561_3347224.1130104550168
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

<div>Hi Craig, </div>
<div>&nbsp;</div>
<div>Does the no of tables and the size of each table affect the performanc=
e of a join operation? </div>
<div>&nbsp;</div>
<div>When we are trying to join the two big tables that I described above, =
pg is taking so long to execute?</div>
<div>&nbsp;</div>
<div>Thank you,</div>
<div>Kishore.<br><br>&nbsp;</div>
<div><span class=3D"gmail_quote">On 10/23/05, <b class=3D"gmail_sendername"=
>Craig A. James</b> &lt;<a href=3D"mailto:cjames@modgraph-usa.com">cjames@m=
odgraph-usa.com</a>&gt; wrote:</span>
<blockquote class=3D"gmail_quote" style=3D"PADDING-LEFT: 1ex; MARGIN: 0px 0=
px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid"><br>&gt; We are facing a* critic=
al situation because of the performance of the<br>&gt; **database** .* Even=
 a basic query like select count(*) from
<br>&gt; bigger_table is taking about 4 minutes to return.<br><br>Several o=
ther replies have mentioned that COUNT() requires a full table scan, but th=
is point can't be emphasized enough: Don't do it!&nbsp;&nbsp;People who are=
 migrating from other environments (Oracle or MySQL) are used to COUNT(), M=
IN() and MAX() returning almost instantaneously, certainly on indexed colum=
ns.&nbsp;&nbsp;But for reasons that have something to do with transactions,=
 these operations are unbelievably slow in PostgreSQL.
<br><br>Here are the alternatives that I've learned.<br><br>COUNT() -- Ther=
e is no good substitute.&nbsp;&nbsp;What I do is create a new column, &quot=
;ROW_NUM&quot; with an auto-incrementing sequence.&nbsp;&nbsp;Every time I =
insert a row, it gets a new value.&nbsp;&nbsp;Unfortunately, this doesn't w=
ork if you ever delete a row.&nbsp;&nbsp;The alternative is a more complex =
pair of triggers, one for insert and one for delete, that maintains the cou=
nt in a separate one-row table.&nbsp;&nbsp;It's a nuisance, but it's a lot =
faster than doing a full table scan for every COUNT().
<br><br>MIN() and MAX() -- These are surprisingly slow, because they seem t=
o do a full table scan EVEN ON AN INDEXED COLUMN!&nbsp;&nbsp;I don't unders=
tand why, but happily there is an effective substitute:<br><br>&nbsp;&nbsp;=
select mycolumn from mytable order by mycolumn limit 1;&nbsp;&nbsp;-- same =
as MIN()
<br><br>&nbsp;&nbsp;select mycolumn from mytable order by mycolumn desc lim=
it 1;&nbsp;&nbsp;-- same as MAX()<br><br>For a large table, MIN or MAX can =
take 5-10 minutes, where the above &quot;select...&quot; replacements can r=
eturn in one millisecond.
<br><br>You should carefully examine your entire application for COUNT, MIN=
, and MAX, and get rid of them EVERYWHERE.&nbsp;&nbsp;This may be the entir=
e source of your problem.&nbsp;&nbsp;It was in my case.<br><br>This is, in =
my humble opinion, the only serious flaw in PostgreSQL.&nbsp;&nbsp;I've bee=
n totally happy with it in every other way, and once I understood these sho=
rtcomings, my application is runs faster than ever on PostgreSQL.
<br><br>Craig<br></blockquote></div><br>

------=_Part_26561_3347224.1130104550168--

From pgsql-performance-owner@postgresql.org  Sun Oct 23 20:54:06 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 33845DABB4
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 23 Oct 2005 20:54:06 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 94760-10
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 23 Oct 2005 23:54:01 +0000 (GMT)
Received: from soufre.accelance.net (soufre.accelance.net [213.162.48.15])
	by svr1.postgresql.org (Postfix) with ESMTP id 24B9CDABB2
	for <pgsql-performance@postgresql.org>;
	Sun, 23 Oct 2005 20:54:02 -0300 (ADT)
Received: from [86.193.131.216] (ALyon-254-1-24-216.w86-193.abo.wanadoo.fr
	[86.193.131.216])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by soufre.accelance.net (Postfix) with ESMTP id B95D35CFC
	for <pgsql-performance@postgresql.org>;
	Mon, 24 Oct 2005 01:54:01 +0200 (CEST)
Message-ID: <435C2297.5050207@openwide.fr>
Date: Mon, 24 Oct 2005 01:53:59 +0200
From: Guillaume Smet <guillaume.smet@openwide.fr>
User-Agent: Mozilla Thunderbird 1.0.6-1.1.fc3 (X11/20050720)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: pgsql-performance@postgresql.org
Subject: Problem analyzing explain analyze output
X-Enigmail-Version: 0.89.6.0
X-Enigmail-Supports: pgp-inline, pgp-mime
Content-Type: multipart/mixed; boundary="------------020900030500030903050602"
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0 required=5 tests=[none]
X-Spam-Level: 
X-Archive-Number: 200510/321
X-Sequence-Number: 15089

This is a multi-part message in MIME format.
--------------020900030500030903050602
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Hi all,

I'm currently testing PostgreSQL 8.1 beta3 and I have a problem with a 
EXPLAIN ANALYZE output. You can find it attached.

I don't understand why I have the Nested Loop at line 19 with an actual 
time of 254.292..257.328 because I can't find anywhere the line taking 
this 254 ms. Is it a problem with 8.1b3 or can anyone explain me where I 
can find the part of the query taking this time? I'm not sure to 
understand the new bitmap scan stuff.

Thanks for your help

Regards,

--
Guillaume

--------------020900030500030903050602
Content-Type: text/plain;
 name="explain_analyze.txt"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="explain_analyze.txt"

                                                                                              QUERY PLAN                                                                                              
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Limit  (cost=4351.26..4351.28 rows=10 width=20) (actual time=314.658..314.686 rows=10 loops=1)
   ->  Sort  (cost=4351.26..4351.32 rows=26 width=20) (actual time=314.651..314.660 rows=10 loops=1)
         Sort Key: count(*)
         ->  HashAggregate  (cost=4350.32..4350.65 rows=26 width=20) (actual time=314.003..314.174 rows=54 loops=1)
               ->  Nested Loop  (cost=4234.34..4350.06 rows=26 width=20) (actual time=304.894..312.847 rows=110 loops=1)
                     ->  Hash Join  (cost=4234.34..4253.25 rows=26 width=4) (actual time=304.788..308.011 rows=110 loops=1)
                           Hash Cond: (("outer".codetylieu)::text = ("inner".codetylieu)::text)
                           ->  Hash Join  (cost=4232.18..4250.09 rows=43 width=11) (actual time=304.269..306.780 rows=115 loops=1)
                                 Hash Cond: (("outer".codegelieu)::text = ("inner".codegelieu)::text)
                                 ->  Seq Scan on genrelieu gl  (cost=0.00..8.84 rows=384 width=14) (actual time=0.013..1.024 rows=384 loops=1)
                                 ->  Hash  (cost=4232.07..4232.07 rows=43 width=11) (actual time=304.162..304.162 rows=115 loops=1)
                                       ->  Nested Loop  (cost=4096.51..4232.07 rows=43 width=11) (actual time=293.711..303.521 rows=115 loops=1)
                                             ->  Merge Join  (cost=4096.51..4100.10 rows=33 width=12) (actual time=293.588..295.843 rows=114 loops=1)
                                                   Merge Cond: ("outer"."?column5?" = "inner"."?column2?")
                                                   ->  Sort  (cost=4058.09..4059.55 rows=587 width=20) (actual time=291.107..291.605 rows=514 loops=1)
                                                         Sort Key: (l.codequar)::text
                                                         ->  Nested Loop  (cost=887.45..4031.09 rows=587 width=20) (actual time=254.424..280.794 rows=514 loops=1)
                                                               ->  Bitmap Heap Scan on contcrilieu ccl  (cost=887.45..1668.96 rows=587 width=8) (actual time=254.292..257.328 rows=514 loops=1)
                                                                     Recheck Cond: ((dcrilieu >= (now() - '60 days'::interval)) AND ((flagcriaccepteelieu)::text = 'O'::text))
                                                                     ->  Bitmap Index Scan on idx_contcrilieu_4  (cost=0.00..887.45 rows=587 width=0) (actual time=254.143..254.143 rows=514 loops=1)
                                                                           Index Cond: ((dcrilieu >= (now() - '60 days'::interval)) AND ((flagcriaccepteelieu)::text = 'O'::text))
                                                               ->  Index Scan using pk_lieu on lieu l  (cost=0.00..4.01 rows=1 width=12) (actual time=0.034..0.036 rows=1 loops=514)
                                                                     Index Cond: ("outer".numlieu = l.numlieu)
                                                   ->  Sort  (cost=38.43..38.61 rows=73 width=8) (actual time=1.539..1.731 rows=163 loops=1)
                                                         Sort Key: (vq.codequar)::text
                                                         ->  Bitmap Heap Scan on vilquartier vq  (cost=2.26..36.17 rows=73 width=8) (actual time=0.408..0.788 rows=73 loops=1)
                                                               Recheck Cond: ((codevil)::text = 'PAR'::text)
                                                               ->  Bitmap Index Scan on idx_vilquartier_codevil  (cost=0.00..2.26 rows=73 width=0) (actual time=0.376..0.376 rows=73 loops=1)
                                                                     Index Cond: ((codevil)::text = 'PAR'::text)
                                             ->  Index Scan using idx_lieugelieu_numlieu_principal on lieugelieu lgl  (cost=0.00..3.99 rows=1 width=11) (actual time=0.055..0.060 rows=1 loops=114)
                                                   Index Cond: (("outer".numlieu = lgl.numlieu) AND (lgl.principal = 1::numeric))
                           ->  Hash  (cost=2.11..2.11 rows=17 width=7) (actual time=0.450..0.450 rows=17 loops=1)
                                 ->  Seq Scan on rubtylieu rtl  (cost=0.00..2.11 rows=17 width=7) (actual time=0.127..0.352 rows=17 loops=1)
                                       Filter: ((codeth)::text = 'BAD'::text)
                     ->  Index Scan using pk_contact on contact c  (cost=0.00..3.71 rows=1 width=20) (actual time=0.034..0.037 rows=1 loops=110)
                           Index Cond: (c.numcont = "outer".numcont)
 Total runtime: 317.250 ms
(37 rows)


--------------020900030500030903050602--

From pgsql-performance-owner@postgresql.org  Sun Oct 23 21:08:31 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 4D972DAB27
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 23 Oct 2005 21:08:30 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 09509-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 24 Oct 2005 00:08:23 +0000 (GMT)
Received: from cassarossa.samfundet.no (cassarossa.samfundet.no
	[129.241.93.19])
	by svr1.postgresql.org (Postfix) with ESMTP id 548D1DAB13
	for <pgsql-performance@postgresql.org>;
	Sun, 23 Oct 2005 21:08:25 -0300 (ADT)
Received: from sesse by cassarossa.samfundet.no with local (Exim 4.50)
	id 1ETpt2-000392-FS; Mon, 24 Oct 2005 02:08:24 +0200
Date: Mon, 24 Oct 2005 02:08:24 +0200
From: "Steinar H. Gunderson" <sgunderson@bigfoot.com>
To: Guillaume Smet <guillaume.smet@openwide.fr>
Cc: pgsql-performance@postgresql.org
Subject: Re: Problem analyzing explain analyze output
Message-ID: <20051024000824.GA11800@samfundet.no>
References: <435C2297.5050207@openwide.fr>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <435C2297.5050207@openwide.fr>
User-Agent: Mutt/1.5.9i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.011 required=5 tests=[AWL=0.011]
X-Spam-Level: 
X-Archive-Number: 200510/322
X-Sequence-Number: 15090

On Mon, Oct 24, 2005 at 01:53:59AM +0200, Guillaume Smet wrote:
> I don't understand why I have the Nested Loop at line 19 with an actual 
> time of 254.292..257.328 because I can't find anywhere the line taking 
> this 254 ms.

You don't have a nested loop with that time; however, you have

>   ->  Nested Loop  (cost=887.45..4031.09 rows=587 width=20) (actual time=254.424..280.794 rows=514 loops=1)
>         ->  Bitmap Heap Scan on contcrilieu ccl  (cost=887.45..1668.96 rows=587 width=8) (actual time=254.292..257.328 rows=514 loops=1)
>               Recheck Cond: ((dcrilieu >= (now() - '60 days'::interval)) AND ((flagcriaccepteelieu)::text = 'O'::text))
>               ->  Bitmap Index Scan on idx_contcrilieu_4  (cost=0.00..887.45 rows=587 width=0) (actual time=254.143..254.143 rows=514 loops=1)
>                     Index Cond: ((dcrilieu >= (now() - '60 days'::interval)) AND ((flagcriaccepteelieu)::text = 'O'::text))
>         ->  Index Scan using pk_lieu on lieu l  (cost=0.00..4.01 rows=1 width=12) (actual time=0.034..0.036 rows=1 loops=514)
>               Index Cond: ("outer".numlieu = l.numlieu)


which seems to make sense; you have one run of about 257ms, plus 514 runs
taking about 0.035ms each (ie. about 18ms), which should add up to become
about 275ms (which is close enough to the reality of 281ms).

/* Steinar */
-- 
Homepage: http://www.sesse.net/


From pgsql-performance-owner@postgresql.org  Sun Oct 23 21:14:37 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 881E8DABC4
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 23 Oct 2005 21:14:36 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 13039-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 24 Oct 2005 00:14:33 +0000 (GMT)
Received: from mail25.sea5.speakeasy.net (mail25.sea5.speakeasy.net
	[69.17.117.27])
	by svr1.postgresql.org (Postfix) with ESMTP id B4F50DABA0
	for <pgsql-performance@postgresql.org>;
	Sun, 23 Oct 2005 21:14:34 -0300 (ADT)
Received: (qmail 27340 invoked from network); 24 Oct 2005 00:14:37 -0000
Received: from dsl017-073-250.chi4.dsl.speakeasy.net (HELO mofo.meme.com)
	([69.17.73.250]) (envelope-sender <kop@meme.com>)
	by mail25.sea5.speakeasy.net (qmail-ldap-1.03) with SMTP
	for <josh@agliodbs.com>; 24 Oct 2005 00:14:37 -0000
Received: from mofo (localhost.localdomain [127.0.0.1])
	by mofo.meme.com (Postfix) with ESMTP id A2EF86E422;
	Sun, 23 Oct 2005 19:25:09 -0500 (CDT)
Date: Mon, 24 Oct 2005 00:25:09 +0000
From: "Karl O. Pinc" <kop@meme.com>
Subject: Re: Using LIMIT 1 in plpgsql PERFORM statements
To: Josh Berkus <josh@agliodbs.com>
Cc: pgsql-performance@postgresql.org
References: <1129957521l.27845l.2l@mofo>
 <200510231402.35612.josh@agliodbs.com>
In-Reply-To: <200510231402.35612.josh@agliodbs.com> (from josh@agliodbs.com
	on Sun Oct 23 16:02:35 2005)
X-Mailer: Balsa 2.3.0
Message-Id: <1130113509l.8670l.1l@mofo>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii; DelSp=Yes; Format=Flowed
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.05 required=5 tests=[AWL=-0.000,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/323
X-Sequence-Number: 15091


On 10/23/2005 04:02:35 PM, Josh Berkus wrote:
> Karl,
> 
> > PERFORM 1 FROM foo;
> > IF FOUND THEN ...
> >
> > is any slower than:
> >
> > PERFORM 1 FROM foo LIMIT 1;
> > IF FOUND THEN ...
> 
> I'm wondering in what context it makes sense to call PERFORM on a
> constant.

If you want to find out if the table has any rows.
I'm really interested in what happens when
there's a WHERE qualification.  I want to find
out if there's any of some particular sort of row.
But I figured it wasn't worth putting that into
the example because I didn't have anything
specific to put in the WHERE clause.  I suppose
I should have put it in anyway and followed with ....

Karl <kop@meme.com>
Free Software:  "You don't pay back, you pay forward."
                  -- Robert A. Heinlein


From pgsql-performance-owner@postgresql.org  Sun Oct 23 21:29:47 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id BC778DABC2
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 23 Oct 2005 21:29:46 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 10836-09
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 24 Oct 2005 00:29:41 +0000 (GMT)
Received: from mail27.sea5.speakeasy.net (mail27.sea5.speakeasy.net
	[69.17.117.29])
	by svr1.postgresql.org (Postfix) with ESMTP id F0F01DABDC
	for <pgsql-performance@postgresql.org>;
	Sun, 23 Oct 2005 21:29:42 -0300 (ADT)
Received: (qmail 7173 invoked from network); 24 Oct 2005 00:29:46 -0000
Received: from dsl017-073-250.chi4.dsl.speakeasy.net (HELO mofo.meme.com)
	([69.17.73.250]) (envelope-sender <kop@meme.com>)
	by mail27.sea5.speakeasy.net (qmail-ldap-1.03) with SMTP
	for <josh@agliodbs.com>; 24 Oct 2005 00:29:46 -0000
Received: from mofo (localhost.localdomain [127.0.0.1])
	by mofo.meme.com (Postfix) with ESMTP id 77BCD6E422;
	Sun, 23 Oct 2005 19:40:18 -0500 (CDT)
Date: Mon, 24 Oct 2005 00:40:18 +0000
From: "Karl O. Pinc" <kop@meme.com>
Subject: Re: Using LIMIT 1 in plpgsql PERFORM statements
To: Josh Berkus <josh@agliodbs.com>
Cc: pgsql-performance@postgresql.org
References: <1129957521l.27845l.2l@mofo>
 <200510231402.35612.josh@agliodbs.com>
In-Reply-To: <200510231402.35612.josh@agliodbs.com> (from josh@agliodbs.com
	on Sun Oct 23 16:02:35 2005)
X-Mailer: Balsa 2.3.0
Message-Id: <1130114418l.8670l.2l@mofo>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii; DelSp=Yes; Format=Flowed
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.05 required=5 tests=[AWL=-0.000,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/324
X-Sequence-Number: 15092


On 10/23/2005 04:02:35 PM, Josh Berkus wrote:

> I'm wondering in what context it makes sense to call PERFORM on a
> constant.

I like to write PERFORMs that return a constant when
selecting from a table.  It emphasizes that the
selection is being done for its side effects.

(Programs should be written for people to read
and only incidentally for computers to execute.
Programs that people can't read quickly
become useless whereas programs that can't run
quickly can be fixed.  Computers are easy.
People are difficult.)

Karl <kop@meme.com>
Free Software:  "You don't pay back, you pay forward."
                  -- Robert A. Heinlein


From pgsql-performance-owner@postgresql.org  Mon Nov  7 01:58:47 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 6D7E4D682C
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon,  7 Nov 2005 01:58:46 -0400 (AST)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 00654-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon,  7 Nov 2005 05:58:43 +0000 (GMT)
X-Greylist: delayed 00:20:23.699001 by SQLgrey-
Received: from mailer.eglobalreach.net (mail.heliustech.net [202.124.128.22])
	by svr1.postgresql.org (Postfix) with ESMTP id 1BD8DD6805
	for <pgsql-performance@postgresql.org>;
	Mon,  7 Nov 2005 01:58:42 -0400 (AST)
Received: from ghwk02002147 (localhost [127.0.0.1] (may be forged))
	by mailer.eglobalreach.net (8.11.6p2/) with ESMTP id j9O1cNK03726
	for <pgsql-performance@postgresql.org>; Mon, 24 Oct 2005 09:38:23 +0800
From: "Christian Paul B. Cosinas" <cpc@cybees.com>
To: <pgsql-performance@postgresql.org>
Subject: Re: Used Memory
Date: Mon, 24 Oct 2005 01:42:33 -0000
Message-ID: <02b001c5d83c$34acbba0$1e21100a@ghwk02002147>
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="----=_NextPart_000_02B1_01C5D83C.34AFC8E0"
X-Mailer: Microsoft Office Outlook 11
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506
In-Reply-To: <33c6269f0510210841h568f173ar2fa9ea4a7d105905@mail.gmail.com>
Thread-Index: AcXWVwx9TKFORE3pS6yM9N43/8G7SwB5OJ9w
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.958 required=5 tests=[AWL=-0.137,
	HTML_MESSAGE=0.001, URIBL_SBL=1.094]
X-Spam-Score: 0.958
X-Spam-Level: 
X-Archive-Number: 200511/110
X-Sequence-Number: 15367

This is a multi-part message in MIME format.

------=_NextPart_000_02B1_01C5D83C.34AFC8E0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit

 

It affect my application since the database server starts to slow down.
Hence a very slow in return of functions.

 

Any more ideas about this everyone?

 

Please..

  _____  

From: pgsql-performance-owner@postgresql.org
[mailto:pgsql-performance-owner@postgresql.org] On Behalf Of Alex Turner
Sent: Friday, October 21, 2005 3:42 PM
To: Jon Brisbin
Cc: pgsql-performance@postgresql.org
Subject: Re: [PERFORM] Used Memory

 

[snip]

to the second processor in my dual Xeon eServer) has got me to the
point that the perpetually high memory usage doesn't affect my 
application server.


I'm curious - how does the high memory usage affect your application server?

Alex 

 

 



I choose Polesoft Lockspam to fight spam, and you?
http://www.polesoft.com/refer.html

------=_NextPart_000_02B1_01C5D83C.34AFC8E0
Content-Type: text/html;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

<html xmlns:v=3D"urn:schemas-microsoft-com:vml" =
xmlns:o=3D"urn:schemas-microsoft-com:office:office" =
xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns=3D"http://www.w3.org/TR/REC-html40">

<head>

<meta name=3DGenerator content=3D"Microsoft Word 11 (filtered medium)">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]-->
<style>
<!--
 /* Font Definitions */
 @font-face
	{font-family:Tahoma;
	panose-1:2 11 6 4 3 5 4 4 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0pt;
	margin-bottom:.0001pt;
	font-size:12.0pt;
	font-family:"Times New Roman";}
a:link, span.MsoHyperlink
	{color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{color:purple;
	text-decoration:underline;}
span.EmailStyle17
	{mso-style-type:personal-reply;
	font-family:Arial;
	color:navy;}
@page Section1
	{size:612.0pt 792.0pt;
	margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
	{page:Section1;}
-->
</style>

</head>

<body lang=3DEN-US link=3Dblue vlink=3Dpurple>

<div class=3DSection1>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>It affect my application since the
database server starts to slow down. Hence a very slow in return of =
functions.<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>Any more ideas about this =
everyone?<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>Please&#8230;.<o:p></o:p></span></fo=
nt></p>

<div>

<div class=3DMsoNormal align=3Dcenter style=3D'text-align:center'><font =
size=3D3
face=3D"Times New Roman"><span style=3D'font-size:12.0pt'>

<hr size=3D2 width=3D"100%" align=3Dcenter tabindex=3D-1>

</span></font></div>

<p class=3DMsoNormal><b><font size=3D2 face=3DTahoma><span =
style=3D'font-size:10.0pt;
font-family:Tahoma;font-weight:bold'>From:</span></font></b><font =
size=3D2
face=3DTahoma><span style=3D'font-size:10.0pt;font-family:Tahoma'>
pgsql-performance-owner@postgresql.org
[mailto:pgsql-performance-owner@postgresql.org] <b><span =
style=3D'font-weight:
bold'>On Behalf Of </span></b>Alex Turner<br>
<b><span style=3D'font-weight:bold'>Sent:</span></b> Friday, October 21, =
2005
3:42 PM<br>
<b><span style=3D'font-weight:bold'>To:</span></b> Jon Brisbin<br>
<b><span style=3D'font-weight:bold'>Cc:</span></b>
pgsql-performance@postgresql.org<br>
<b><span style=3D'font-weight:bold'>Subject:</span></b> Re: [PERFORM] =
Used Memory</span></font><o:p></o:p></p>

</div>

<p class=3DMsoNormal><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:
12.0pt'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:
12.0pt'>[snip]<o:p></o:p></span></font></p>

<div>

<blockquote style=3D'border:none;border-left:solid #CCCCCC =
1.0pt;padding:0pt 0pt 0pt 6.0pt;
margin-left:4.8pt;margin-right:0pt'>

<p class=3DMsoNormal><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:
12.0pt'>to the second processor in my dual Xeon eServer) has got me to =
the<br>
point that the perpetually high memory usage doesn't affect my <br>
application server.<o:p></o:p></span></font></p>

</blockquote>

<div>

<p class=3DMsoNormal><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:
12.0pt'><br>
I'm curious - how does the high memory usage affect your application =
server?<br>
<br>
Alex <o:p></o:p></span></font></p>

</div>

<p class=3DMsoNormal><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:
12.0pt'><o:p>&nbsp;</o:p></span></font></p>

</div>

<p class=3DMsoNormal><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:
12.0pt'><o:p>&nbsp;</o:p></span></font></p>

</div>

<BR>
<BR>
I choose Polesoft Lockspam to fight spam, and you?<BR>
<A HREF=3D"http://www.polesoft.com/refer.html" =
TARGET=3D"_blank">http://www.polesoft.com/refer.html</A></body>

</html>

------=_NextPart_000_02B1_01C5D83C.34AFC8E0--


From pgsql-performance-owner@postgresql.org  Sun Oct 23 22:42:58 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 241FADAB85
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 23 Oct 2005 22:42:58 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 53402-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 24 Oct 2005 01:42:50 +0000 (GMT)
Received: from mailer.eglobalreach.net (cybees.com [202.124.128.22])
	by svr1.postgresql.org (Postfix) with ESMTP id 5B453DAB4B
	for <pgsql-performance@postgresql.org>;
	Sun, 23 Oct 2005 22:42:50 -0300 (ADT)
Received: from ghwk02002147 (localhost [127.0.0.1] (may be forged))
	by mailer.eglobalreach.net (8.11.6p2/) with ESMTP id j9O1gt603929
	for <pgsql-performance@postgresql.org>; Mon, 24 Oct 2005 09:42:55 +0800
From: "Christian Paul B. Cosinas" <cpc@cybees.com>
To: <pgsql-performance@postgresql.org>
Subject: Re: Used Memory
Date: Mon, 24 Oct 2005 01:47:05 -0000
Message-ID: <02b501c5d83c$d6bf0f10$1e21100a@ghwk02002147>
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="----=_NextPart_000_02B6_01C5D83C.D6BF0F10"
X-Mailer: Microsoft Office Outlook 11
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506
In-Reply-To: <33c6269f0510210841h568f173ar2fa9ea4a7d105905@mail.gmail.com>
Thread-Index: AcXWVwx9TKFORE3pS6yM9N43/8G7SwB5T9QA
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.68 required=5 tests=[AWL=-0.000,
	FORGED_RCVD_HELO=0.05, HTML_MESSAGE=0.001, URIBL_SBL=0.629]
X-Spam-Level: 
X-Archive-Number: 200510/325
X-Sequence-Number: 15093

This is a multi-part message in MIME format.

------=_NextPart_000_02B6_01C5D83C.D6BF0F10
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit

 

total                  used                 free                   shared
buffers               cached

Mem:                6192460            6137424            55036
0                      85952               5828844

-/+ buffers/cache:                       222628              5969832

Swap:               2096472            0                      2096472

 

 

Here is the result of "free" command" I am talking about.

What does this result mean?

 

I just noticed that as long as the free memory in the first row (which is
55036 as of now) became low, the slower is the response of the database
server.



I choose Polesoft Lockspam to fight spam, and you?
http://www.polesoft.com/refer.html

------=_NextPart_000_02B6_01C5D83C.D6BF0F10
Content-Type: text/html;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

<html xmlns:o=3D"urn:schemas-microsoft-com:office:office" =
xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns=3D"http://www.w3.org/TR/REC-html40">

<head>

<meta name=3DGenerator content=3D"Microsoft Word 11 (filtered medium)">
<style>
<!--
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0pt;
	margin-bottom:.0001pt;
	font-size:12.0pt;
	font-family:"Times New Roman";}
a:link, span.MsoHyperlink
	{color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{color:purple;
	text-decoration:underline;}
span.EmailStyle17
	{mso-style-type:personal-reply;
	font-family:Arial;
	color:navy;}
@page Section1
	{size:612.0pt 792.0pt;
	margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
	{page:Section1;}
-->
</style>

</head>

<body lang=3DEN-US link=3Dblue vlink=3Dpurple>

<div class=3DSection1>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal =
style=3D'margin-left:36.0pt;text-indent:36.0pt'><font size=3D2
color=3Dnavy face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial;
color:navy'>total&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
used&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
free&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
shared&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
buffers&nbsp;&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
cached<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>Mem:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
6192460&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
6137424&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
55036&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp; 85952&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
5828844<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>-/+ =
buffers/cache:&nbsp;&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 222628&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
5969832<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>Swap:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
2096472&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; =
0&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2096472<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>Here is the result of =
&#8220;free&#8221;
command&#8221; I am talking about.<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>What does this result =
mean?<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>I just noticed that as long as the =
free
memory in the first row (which is 55036 as of now) became low, the =
slower is
the response of the database server.<o:p></o:p></span></font></p>

</div>

<BR>
<BR>
I choose Polesoft Lockspam to fight spam, and you?<BR>
<A HREF=3D"http://www.polesoft.com/refer.html" =
TARGET=3D"_blank">http://www.polesoft.com/refer.html</A></body>

</html>

------=_NextPart_000_02B6_01C5D83C.D6BF0F10--


From pgsql-performance-owner@postgresql.org  Mon Oct 24 01:15:52 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id BB924DABF6
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 24 Oct 2005 01:15:51 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 00373-03
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 24 Oct 2005 04:15:48 +0000 (GMT)
Received: from linda-4.paradise.net.nz (bm-4a.paradise.net.nz
 [203.96.152.183])
	by svr1.postgresql.org (Postfix) with ESMTP id 25555DABB6
	for <pgsql-performance@postgresql.org>;
	Mon, 24 Oct 2005 01:15:44 -0300 (ADT)
Received: from smtp-1.paradise.net.nz
	(tclsnelb2-src-1.paradise.net.nz [203.96.152.177]) by
	linda-4.paradise.net.nz (Paradise.net.nz) with ESMTP id
	<0IOU006A9GZYS1@linda-4.paradise.net.nz> for
	pgsql-performance@postgresql.org; Mon, 24 Oct 2005 16:14:22 +1300 (NZDT)
Received: from [192.168.1.11] (218-101-13-33.paradise.net.nz [218.101.13.33])
	by smtp-1.paradise.net.nz (Postfix) with ESMTP id 7D6B9155F718; Mon,
	24 Oct 2005 16:14:22 +1300 (NZDT)
Date: Mon, 24 Oct 2005 16:14:20 +1300
From: Mark Kirkwood <markir@paradise.net.nz>
Subject: Re: Used Memory
In-reply-to: <02b501c5d83c$d6bf0f10$1e21100a@ghwk02002147>
To: "Christian Paul B. Cosinas" <cpc@cybees.com>
Cc: pgsql-performance@postgresql.org
Message-id: <435C518C.8070505@paradise.net.nz>
MIME-version: 1.0
Content-type: text/plain; charset=windows-1252; format=flowed
Content-transfer-encoding: 8BIT
X-Accept-Language: en-us, en
User-Agent: Mozilla Thunderbird 1.0.6 (X11/20050726)
References: <02b501c5d83c$d6bf0f10$1e21100a@ghwk02002147>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=1.365 required=5 tests=[AWL=-1.096,
	RCVD_IN_BL_SPAMCOP_NET=1.832, URIBL_SBL=0.629]
X-Spam-Level: *
X-Archive-Number: 200510/327
X-Sequence-Number: 15095

Christian Paul B. Cosinas wrote:
>  
> 
> Here is the result of �free� command� I am talking about.
> 
> What does this result mean?
> 

I seem to recall the Linux man page for 'free' being most 
unenlightening, so have a look at:

http://gentoo-wiki.com/FAQ_Linux_Memory_Management

(For Gentoo, but should be applicable to RHEL).

The basic idea is that modern operating systems try to make as much use 
of the memory as possible. Postgresql depends on this behavior - e.g. a 
page that has previously been fetched from disk, will be cached, so it 
can be read from memory next time, as this is faster(!)

>  
> 
> I just noticed that as long as the free memory in the first row (which 
> is 55036 as of now) became low, the slower is the response of the 
> database server.
>  

Well, you could be swapping - what does the swap line of 'free' show then?

Also, how about posting your postgresql.conf (or just the non-default 
parameters) to this list?

Some other stuff that could be relevant:

- Is the machine just a database server, or does it run (say) Apache + Php?
- When the slowdown is noticed, does this coincide with certain 
activities - e.g, backup , daily maintenance, data load(!) etc.


regards

Mark

> 
> I choose Polesoft Lockspam to fight spam, and you?
> http://www.polesoft.com/refer.html

Nope, not me either.


From pgsql-performance-owner@postgresql.org  Mon Oct 24 00:58:27 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 601C3D84AC
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 24 Oct 2005 00:58:26 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 92854-06
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 24 Oct 2005 03:58:24 +0000 (GMT)
Received: from deliverator7.gatech.edu (deliverator7.gatech.edu
	[130.207.165.169])
	by svr1.postgresql.org (Postfix) with ESMTP id 2E5B3DAC28
	for <pgsql-performance@postgresql.org>;
	Mon, 24 Oct 2005 00:58:24 -0300 (ADT)
Received: from hormel1.gatech.edu (hormel1.prism.gatech.edu [130.207.171.11])
	(using TLSv1 with cipher EDH-RSA-DES-CBC3-SHA (168/168 bits))
	(Client CN "hormel1.prism.gatech.edu",
	Issuer "Tech Support CA" (verified OK))
	by deliverator7.gatech.edu (Postfix) with ESMTP id A5F3920DA
	for <pgsql-performance@postgresql.org>;
	Sun, 23 Oct 2005 23:58:23 -0400 (EDT)
	(envelope-from edmonds42@bellsouth.net)
Received: from ([130.207.171.121])
	by hormel1.gatech.edu with ESMTP with TLS id KP-BRAPX.30421660;
	Sun, 23 Oct 2005 23:58:11 -0400
Received: from deliverator1.gatech.edu (localhost [127.0.0.1])
	by localhost (Postfix) with ESMTP id 584021FAB84
	for <pgsql-performance@postgresql.org>;
	Sun, 23 Oct 2005 23:58:11 -0400 (EDT)
	(envelope-from edmonds42@bellsouth.net)
Received: from mailprx3.gatech.edu (mailprx3.prism.gatech.edu
 [130.207.171.17])
	(using TLSv1 with cipher EDH-RSA-DES-CBC3-SHA (168/168 bits))
	(Client CN "smtp.mail.gatech.edu",
	Issuer "RSA Data Security? Inc." (verified OK))
	by deliverator1.gatech.edu (Postfix) with ESMTP id 42CCE1FAB83
	for <pgsql-performance@postgresql.org>;
	Sun, 23 Oct 2005 23:58:11 -0400 (EDT)
	(envelope-from edmonds42@bellsouth.net)
Received: from localhost (r54h98.res.gatech.edu [128.61.54.98])
	(using TLSv1 with cipher DES-CBC3-SHA (168/168 bits))
	(No client certificate requested)
	(sasl: method=PLAIN, username=gtg698r@mailprx3.gatech.edu, sender=n/a)
	by mailprx3.gatech.edu (Postfix) with ESMTP id 0793120B8
	for <pgsql-performance@postgresql.org>;
	Sun, 23 Oct 2005 23:58:11 -0400 (EDT)
	(envelope-from edmonds42@bellsouth.net)
Date: Sun, 23 Oct 2005 23:58:09 -0400
From: Robert Edmonds <edmonds42@bellsouth.net>
To: pgsql-performance@postgresql.org
Subject: performance of implicit join vs. explicit conditions on inet queries?
Message-ID: <20051024035809.GA18261@edmonds.ath.cx>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
X-GT-Spam-Details: ESP<-39>=RBL:<-50> RDNS:<0> SHA:<11> UHA:<0> SLS:<0>
	BAYES:<0> SenderID:<0> GT_Custom:<0> NigeriaScam Dictionary
	(TRU8):<0> ReDictionary:<0> HTML Dictionary (TRU8):<0> Adult
	Dictionary (TRU8):<0> Spam Dictionary (TRU8):<0> Embed HTML
	Dictionary (TRU8):<0> Obscenities Dictionary (TRU8):<0> URL
	Dictionary (TRU8):<0> CAN-SPAM Compliance Dictionary
	(TRU8):<0>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=1.972 required=5 tests=[DNS_FROM_RFC_POST=1.376,
	FROM_ENDS_IN_NUMS=0.516, NORMAL_HTTP_TO_IP=0.08]
X-Spam-Level: *
X-Archive-Number: 200510/326
X-Sequence-Number: 15094

    The preliminaries:

    - PostgreSQL 8.1 beta 3, Debian experimental
    - database has been VACUUMed FULL ANALYZE.
    - a pg_dump -Fc exists at http://199.77.129.48/inet_test.db
    - ia32 hardware with 2 GB physical memory and the following settings:

shared_buffers = 40960
temp_buffers = 16384
work_mem = 131072
maintenance_work_mem = 262144
effective_cache_size = 65536


    I've populated a table evenly with about 2 million rows of RFC 1918
    addresses:


Table "public.inet_addresses"
 Column | Type | Modifiers
--------+------+-----------
 addr   | inet | not null
Indexes:
    "inet_addresses_pkey" PRIMARY KEY, btree (addr)


    The following query is very fast:


EXPLAIN ANALYZE
SELECT *
  FROM inet_addresses
 WHERE addr << inet('10.2.0.0/24')         
    OR addr << inet('10.4.0.0/24')
    OR addr << inet('10.8.0.0/24');

 Bitmap Heap Scan on inet_addresses  (cost=6.51..324.48 rows=1792335 width=11) (actual time=0.350..1.104 rows=381 loops=1)
   Recheck Cond: ((addr << '10.2.0.0/24'::inet) OR (addr << '10.4.0.0/24'::inet) OR (addr << '10.8.0.0/24'::inet)) 
   Filter: ((addr << '10.2.0.0/24'::inet) OR (addr << '10.4.0.0/24'::inet) OR (addr << '10.8.0.0/24'::inet))
   ->  BitmapOr  (cost=6.51..6.51 rows=85 width=0) (actual time=0.336..0.336 rows=0 loops=1)
         ->  Bitmap Index Scan on inet_addresses_pkey  (cost=0.00..2.17 rows=28 width=0) (actual time=0.127..0.127 rows=127 loops=1)
               Index Cond: ((addr > '10.2.0.0/24'::inet) AND (addr <= '10.2.0.255'::inet))
         ->  Bitmap Index Scan on inet_addresses_pkey  (cost=0.00..2.17 rows=28 width=0) (actual time=0.109..0.109 rows=127 loops=1)
               Index Cond: ((addr > '10.4.0.0/24'::inet) AND (addr <= '10.4.0.255'::inet))
         ->  Bitmap Index Scan on inet_addresses_pkey  (cost=0.00..2.17 rows=28 width=0) (actual time=0.096..0.096 rows=127 loops=1)
               Index Cond: ((addr > '10.8.0.0/24'::inet) AND (addr <= '10.8.0.255'::inet))
 Total runtime: 1.613 ms


    Instead of specifying explicit address ranges in the query, I'd like
    to store the ranges in a table:


inet_test_db=# \d inet_ranges
   Table "public.inet_ranges"
  Column  |  Type   | Modifiers
----------+---------+-----------
 range    | inet    | not null
 range_id | integer | 
Indexes:
    "inet_ranges_pkey" PRIMARY KEY, btree (range)
    "inet_ranges_range_id_idx" btree (range_id)

inet_test_db=# SELECT * FROM inet_ranges;
    range     | range_id
--------------+----------
 10.2.0.0/24  |        1
 10.4.0.0/24  |        1
 10.8.0.0/24  |        1
 10.16.0.0/24 |        2
 10.32.0.0/24 |        2
 10.64.0.0/24 |        2
(6 rows)


    This query is far slower, even though it generates the same result:


EXPLAIN ANALYZE 
SELECT * 
  FROM inet_addresses as ia, inet_ranges as ir
 WHERE ia.addr << ir.range
   AND ir.range_id=1;
    
 Nested Loop  (cost=0.00..171485.93 rows=3072574 width=26) (actual time=1465.803..16922.979 rows=381 loops=1)
   Join Filter: ("inner".addr << "outer".range)
   ->  Seq Scan on inet_ranges ir  (cost=0.00..1.07 rows=3 width=15) (actual time=0.008..0.021 rows=3 loops=1)
         Filter: (range_id = 1)
   ->  Seq Scan on inet_addresses ia  (cost=0.00..31556.83 rows=2048383 width=11) (actual time=0.003..2919.405 rows=2048383 loops=3)
 Total runtime: 16923.457 ms


    Even when disabling sequential scans, the query planner is unable to
    make use of the inet_addresses_pkey index:


 Nested Loop  (cost=100033605.21..100171874.11 rows=3072574 width=26) (actual time=2796.928..23453.585 rows=381 loops=1)
   Join Filter: ("inner".addr << "outer".range)
   ->  Index Scan using inet_ranges_range_id_idx on inet_ranges ir  (cost=0.00..3.04 rows=3 width=15) (actual time=0.069..0.095 rows=3 loops=1)
         Index Cond: (range_id = 1)
   ->  Materialize  (cost=100033605.21..100054089.04 rows=2048383 width=11) (actual time=0.016..5133.349 rows=2048383 loops=3)
         ->  Seq Scan on inet_addresses ia  (cost=100000000.00..100031556.83 rows=2048383 width=11) (actual time=0.005..2938.012 rows=2048383 loops=1)
 Total runtime: 23521.418 ms


    Is it possible to attain the speed of the first query and the
    flexibility of the second?  Or will I have to resort to generating
    queries of the first form with the range table in the application
    layer?

-- 
Robert Edmonds
edmonds42@bellsouth.net

From pgsql-performance-owner@postgresql.org  Mon Oct 24 01:35:09 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 4897EDAC49
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 24 Oct 2005 01:35:08 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 04182-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 24 Oct 2005 04:35:06 +0000 (GMT)
Received: from davinci.ethosmedia.com (server227.ethosmedia.com
	[209.128.84.227])
	by svr1.postgresql.org (Postfix) with ESMTP id 18D75DABED
	for <pgsql-performance@postgresql.org>;
	Mon, 24 Oct 2005 01:35:05 -0300 (ADT)
X-EthosMedia-Virus-Scanned: no infections found
Received: from [63.195.55.98] (account josh@agliodbs.com HELO spooky)
	by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.1.8)
	with ESMTP id 8335801; Sun, 23 Oct 2005 21:37:34 -0700
From: Josh Berkus <josh@agliodbs.com>
Organization: Aglio Database Solutions
To: "Karl O. Pinc" <kop@meme.com>
Subject: Re: Using LIMIT 1 in plpgsql PERFORM statements
Date: Sun, 23 Oct 2005 21:36:35 -0700
User-Agent: KMail/1.8
Cc: pgsql-performance@postgresql.org
References: <1129957521l.27845l.2l@mofo>
 <200510231402.35612.josh@agliodbs.com>
	<1130114418l.8670l.2l@mofo>
In-Reply-To: <1130114418l.8670l.2l@mofo>
MIME-Version: 1.0
Content-Type: text/plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Message-Id: <200510232136.35790.josh@agliodbs.com>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.01 required=5 tests=[AWL=0.010]
X-Spam-Level: 
X-Archive-Number: 200510/328
X-Sequence-Number: 15096

Karl,

> I like to write PERFORMs that return a constant when
> selecting from a table.  It emphasizes that the
> selection is being done for its side effects.

Well, there's always the destruction test: run each version of the function 
10,000 times and see if there's an execution time difference.

> (Programs should be written for people to read
> and only incidentally for computers to execute.
> Programs that people can't read quickly
> become useless whereas programs that can't run
> quickly can be fixed.  Computers are easy.
> People are difficult.)

That's a nice sentiment, but I don't see how it applies.  For example, if I 
do:

SELECT id INTO v_check
FROM some_table ORDER BY id LIMIT 1;

IF id > 0 THEN ....

... that says pretty clearly to code maintainers that I'm only interested in 
finding out whether there's any rows in the table, while making sure I use 
the index on ID.  If I want to make it more clear, I do:

-- check whether the table is populated

Not that there's anything wrong with your IF FOUND approach, but let's not mix 
up optimizations and making your code pretty ... especially for a SQL 
scripting language.

-- 
Josh Berkus
Aglio Database Solutions
San Francisco

From pgsql-performance-owner@postgresql.org  Mon Oct 24 01:40:10 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 619DBDAC31
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 24 Oct 2005 01:40:09 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 07486-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 24 Oct 2005 04:40:07 +0000 (GMT)
Received: from mailbox.samurai.com (mailbox.samurai.com [205.207.28.82])
	by svr1.postgresql.org (Postfix) with ESMTP id A86C7D6F13
	for <pgsql-performance@postgresql.org>;
	Mon, 24 Oct 2005 01:40:07 -0300 (ADT)
Received: from localhost (mailbox.samurai.com [205.207.28.82])
	by mailbox.samurai.com (Postfix) with ESMTP id D33B82395FC;
	Mon, 24 Oct 2005 00:40:07 -0400 (EDT)
Received: from mailbox.samurai.com ([205.207.28.82])
	by localhost (mailbox.samurai.com [205.207.28.82]) (amavisd-new,
	port 10024)
	with LMTP id 81309-01-10; Mon, 24 Oct 2005 00:40:06 -0400 (EDT)
Received: from [192.168.1.103] (d226-86-55.home.cgocable.net [24.226.86.55])
	by mailbox.samurai.com (Postfix) with ESMTP id 7701023946D;
	Mon, 24 Oct 2005 00:40:06 -0400 (EDT)
Subject: Re: Using LIMIT 1 in plpgsql PERFORM statements
From: Neil Conway <neilc@samurai.com>
To: Josh Berkus <josh@agliodbs.com>
Cc: "Karl O. Pinc" <kop@meme.com>, pgsql-performance@postgresql.org
In-Reply-To: <200510232136.35790.josh@agliodbs.com>
References: <1129957521l.27845l.2l@mofo>
	<200510231402.35612.josh@agliodbs.com> <1130114418l.8670l.2l@mofo>
	<200510232136.35790.josh@agliodbs.com>
Content-Type: text/plain
Date: Mon, 24 Oct 2005 00:40:10 -0400
Message-Id: <1130128810.8506.25.camel@localhost.localdomain>
Mime-Version: 1.0
X-Mailer: Evolution 2.4.1 
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at mailbox.samurai.com
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0 required=5 tests=[none]
X-Spam-Level: 
X-Archive-Number: 200510/329
X-Sequence-Number: 15097

On Sun, 2005-23-10 at 21:36 -0700, Josh Berkus wrote:
> SELECT id INTO v_check
> FROM some_table ORDER BY id LIMIT 1;
> 
> IF id > 0 THEN ....
> 
> ... that says pretty clearly to code maintainers that I'm only interested in 
> finding out whether there's any rows in the table, while making sure I use 
> the index on ID.

Why would you want to use the index on ID?

-Neil



From pgsql-performance-owner@postgresql.org  Mon Oct 24 02:03:12 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 7AA39DAC32
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 24 Oct 2005 02:03:11 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 12066-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 24 Oct 2005 05:03:09 +0000 (GMT)
Received: from houston.familyhealth.com.au (houston.au.fhnetwork.com
	[203.22.197.21])
	by svr1.postgresql.org (Postfix) with ESMTP id 03E21DAC38
	for <pgsql-performance@postgresql.org>;
	Mon, 24 Oct 2005 02:03:08 -0300 (ADT)
Received: from houston.familyhealth.com.au (localhost [127.0.0.1])
	by houston.familyhealth.com.au (Postfix) with ESMTP id 64F6D24FFA;
	Mon, 24 Oct 2005 13:03:04 +0800 (WST)
Received: from [127.0.0.1] (work-40.internal [192.168.0.40])
	by houston.familyhealth.com.au (Postfix) with ESMTP id 447432505B;
	Mon, 24 Oct 2005 13:03:02 +0800 (WST)
Message-ID: <435C6B07.7070402@familyhealth.com.au>
Date: Mon, 24 Oct 2005 13:03:03 +0800
From: Christopher Kings-Lynne <chriskl@familyhealth.com.au>
User-Agent: Mozilla Thunderbird 1.0.7 (Windows/20050923)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: mark@mark.mielke.cc
Cc: pgsql-performance@postgresql.org
Subject: Re: prepared transactions that persist across sessions?
References: <20051023041423.GA11639@mark.mielke.cc>
In-Reply-To: <20051023041423.GA11639@mark.mielke.cc>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-familyhealth-MailScanner-Information: Please contact the ISP for more
	information
X-familyhealth-MailScanner: Found to be clean
X-familyhealth-MailScanner-From: chriskl@familyhealth.com.au
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.06 required=5 tests=[AWL=0.010,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/330
X-Sequence-Number: 15098

> I am using PHP's PDO PGSQL interface - I haven't read up enough on it
> to determine whether a persistent connection can re-use server-side
> prepared queries as an option. Anybody know?

It re-uses server-side prepared queries by default, if you are using the 
  PDOPrepare/PDOExecute stuff.

Chris


From pgsql-performance-owner@postgresql.org  Mon Oct 24 03:33:09 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 263EEDAC9F
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 24 Oct 2005 03:33:08 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 29958-07
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 24 Oct 2005 06:33:05 +0000 (GMT)
Received: from soufre.accelance.net (soufre.accelance.net [213.162.48.15])
	by svr1.postgresql.org (Postfix) with ESMTP id 1A909DAC89
	for <pgsql-performance@postgresql.org>;
	Mon, 24 Oct 2005 03:33:05 -0300 (ADT)
Received: from [86.193.131.216] (ALyon-254-1-24-216.w86-193.abo.wanadoo.fr
	[86.193.131.216])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by soufre.accelance.net (Postfix) with ESMTP id 3CD875D65;
	Mon, 24 Oct 2005 08:33:05 +0200 (CEST)
Message-ID: <435C801F.1030709@openwide.fr>
Date: Mon, 24 Oct 2005 08:33:03 +0200
From: Guillaume Smet <guillaume.smet@openwide.fr>
User-Agent: Mozilla Thunderbird 1.0.6-1.1.fc3 (X11/20050720)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: "Steinar H. Gunderson" <sgunderson@bigfoot.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Problem analyzing explain analyze output
References: <435C2297.5050207@openwide.fr>
	<20051024000824.GA11800@samfundet.no>
In-Reply-To: <20051024000824.GA11800@samfundet.no>
X-Enigmail-Version: 0.89.6.0
X-Enigmail-Supports: pgp-inline, pgp-mime
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0 required=5 tests=[none]
X-Spam-Level: 
X-Archive-Number: 200510/331
X-Sequence-Number: 15099

Steinar,

> which seems to make sense; you have one run of about 257ms, plus 514 runs
> taking about 0.035ms each (ie. about 18ms), which should add up to become
> about 275ms (which is close enough to the reality of 281ms).

Yep. The line that disturbed me was the bitmap index scan with a cost of 
"actual time=254.143..254.143". I was more looking for something like 
"actual time=0..254.143" which is what I usually have for an index scan. 
So I suppose that the bitmap index scan returns rows only when it's 
totally computed.

Thanks for your help.

Regards.

--
Guillaume

From pgsql-performance-owner@postgresql.org  Mon Oct 24 12:09:58 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 2272CDACEA
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 24 Oct 2005 12:09:58 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 52045-03
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 24 Oct 2005 15:09:56 +0000 (GMT)
Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.195])
	by svr1.postgresql.org (Postfix) with ESMTP id 0A496DACF4
	for <pgsql-performance@postgresql.org>;
	Mon, 24 Oct 2005 12:09:55 -0300 (ADT)
Received: by wproxy.gmail.com with SMTP id 71so498833wra
	for <pgsql-performance@postgresql.org>;
	Mon, 24 Oct 2005 08:09:55 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references;
	b=QQfQmex45J/TldnqVsds03ZEuUansP8+ptNic5oXJq0CCkIHnE82oLSlvKGL7yUerS4x5x9XmR/aFthgAJTx5IzNpDDpXEXerFWYrSUnKH7Y0lyEMtlTElAZsUjRTeiWp3IelB7+2esqLDJjxY1x9Vayc6Eph+lDa3/Wy7QPHoE=
Received: by 10.54.77.5 with SMTP id z5mr1891516wra;
	Mon, 24 Oct 2005 08:09:55 -0700 (PDT)
Received: by 10.54.84.8 with HTTP; Mon, 24 Oct 2005 08:09:55 -0700 (PDT)
Message-ID: <33c6269f0510240809k47f91a71t387a0b5ab0339f4c@mail.gmail.com>
Date: Mon, 24 Oct 2005 11:09:55 -0400
From: Alex Turner <armtuk@gmail.com>
To: Neil Conway <neilc@samurai.com>
Subject: Re: What gets cached?
Cc: Martin Nickel <martin@portant.com>,
	pgsql-performance@postgresql.org
In-Reply-To: <1129931087.19971.12.camel@localhost.localdomain>
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="----=_Part_161_18481999.1130166595111"
References: <pan.2005.10.21.12.34.29.712700@portant.com>
	<1129931087.19971.12.camel@localhost.localdomain>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.36 required=5 tests=[AWL=-0.169, HTML_20_30=0.504,
	HTML_MESSAGE=0.001, RCVD_BY_IP=0.024]
X-Spam-Level: 
X-Archive-Number: 200510/332
X-Sequence-Number: 15100

------=_Part_161_18481999.1130166595111
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Just to play devils advocate here for as second, but if we have an algorith=
m
that is substational better than just plain old LRU, which is what I believ=
e
the kernel is going to use to cache pages (I'm no kernel hacker), then why
don't we apply that and have a significantly larger page cache a la Oracle?

Alex

On 10/21/05, Neil Conway <neilc@samurai.com> wrote:
>
> On Fri, 2005-21-10 at 07:34 -0500, Martin Nickel wrote:
> > Let's say I do the same thing in Postgres. I'm likely to have my very
> > fastest performance for the first few queries until memory gets filled
> up.
>
> No, you're not: if a query doesn't hit the cache (both the OS cache and
> the Postgres userspace cache), it will run slower. If the caches are
> empty when Postgres starts up (which is true for the userspace cache and
> might be true of the OS cache), the first queries that are run should be
> slower, not faster.
>
> > The only time Postgres seems to take advantage of cached data is when I
> > repeat the same (or substantially the same) query.
>
> Caching is done on a page-by-page basis -- the source text of the query
> itself is not relevant. If two different queries happen to hit a similar
> set of pages, they will probably both benefit from the same set of
> cached pages.
>
> > I don't know of any way to view what is actually cached at any point
> > in time, but it seems like "most recently used" rather than "most
> > frequently used".
>
> The cache replacement policy in 7.4 and older releases is simple LRU.
> The policy in 8.0 is ARC (essentially a version of LRU modified to try
> to retain hot pages more accurately). The policy in 8.1 is a clock-based
> algorithm.
>
> -Neil
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: explain analyze is your friend
>

------=_Part_161_18481999.1130166595111
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Just to play devils advocate here for as second, but if we have an
algorithm that is substational better than just plain old LRU, which is
what I believe the kernel is going to use to cache pages (I'm no kernel
hacker), then why don't we apply that and have a significantly larger
page cache a la Oracle?<br>
<br>
Alex<br><br><div><span class=3D"gmail_quote">On 10/21/05, <b class=3D"gmail=
_sendername">Neil Conway</b> &lt;<a href=3D"mailto:neilc@samurai.com">neilc=
@samurai.com</a>&gt; wrote:</span><blockquote class=3D"gmail_quote" style=
=3D"border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; p=
adding-left: 1ex;">
On Fri, 2005-21-10 at 07:34 -0500, Martin Nickel wrote:<br>&gt; Let's say I=
 do the same thing in Postgres.&nbsp;&nbsp;I'm likely to have my very<br>&g=
t; fastest performance for the first few queries until memory gets filled u=
p.<br>
<br>No, you're not: if a query doesn't hit the cache (both the OS cache and=
<br>the Postgres userspace cache), it will run slower. If the caches are<br=
>empty when Postgres starts up (which is true for the userspace cache and
<br>might be true of the OS cache), the first queries that are run should b=
e<br>slower, not faster.<br><br>&gt;&nbsp;&nbsp;The only time Postgres seem=
s to take advantage of cached data is when I<br>&gt;&nbsp;&nbsp;repeat the =
same (or substantially the same) query.
<br><br>Caching is done on a page-by-page basis -- the source text of the q=
uery<br>itself is not relevant. If two different queries happen to hit a si=
milar<br>set of pages, they will probably both benefit from the same set of
<br>cached pages.<br><br>&gt; I don't know of any way to view what is actua=
lly cached at any point<br>&gt; in time, but it seems like &quot;most recen=
tly used&quot; rather than &quot;most<br>&gt; frequently used&quot;.<br>
<br>The cache replacement policy in 7.4 and older releases is simple LRU.<b=
r>The policy in 8.0 is ARC (essentially a version of LRU modified to try<br=
>to retain hot pages more accurately). The policy in 8.1 is a clock-based
<br>algorithm.<br><br>-Neil<br><br><br><br>---------------------------(end =
of broadcast)---------------------------<br>TIP 6: explain analyze is your =
friend<br></blockquote></div><br>

------=_Part_161_18481999.1130166595111--

From pgsql-admin-owner@postgresql.org  Mon Oct 24 12:28:07 2005
X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 09E60DACA3
	for <pgsql-admin-postgresql.org@localhost.postgresql.org>;
	Mon, 24 Oct 2005 12:28:06 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 61944-04
	for <pgsql-admin-postgresql.org@localhost.postgresql.org>;
	Mon, 24 Oct 2005 15:28:03 +0000 (GMT)
Received: from koolancexeon.g2switchworks.com (mail.g2switchworks.com
	[63.87.162.25])
	by svr1.postgresql.org (Postfix) with ESMTP id 461FADACC9
	for <pgsql-admin@postgresql.org>; Mon, 24 Oct 2005 12:28:03 -0300 (ADT)
Received: mail.g2switchworks.com 10.10.1.8 from 10.10.1.37 10.10.1.37 via HTTP
	with MS-WebStorage 6.5.6944
Received: from state.g2switchworks.com by mail.g2switchworks.com;
	24 Oct 2005 10:28:02 -0500
Subject: Re: [PERFORM] Need help in setting optimal configuration
From: Scott Marlowe <smarlowe@g2switchworks.com>
To: Kishore B <kishorebh@gmail.com>
Cc: "pgsql-admin@postgresql.org" <pgsql-admin@postgresql.org>
In-Reply-To: <42567e060510231455l6a6721cdtc52ad1b4d254aa64@mail.gmail.com>
References: <42567e060510221415r2516523l4c3f9b42dee91a09@mail.gmail.com>
	<435BBAF0.8080500@modgraph-usa.com>
	<42567e060510231455l6a6721cdtc52ad1b4d254aa64@mail.gmail.com>
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Message-Id: <1130167682.15546.114.camel@state.g2switchworks.com>
Mime-Version: 1.0
X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) 
Date: Mon, 24 Oct 2005 10:28:02 -0500
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.007 required=5 tests=[AWL=0.007]
X-Spam-Level: 
X-Archive-Number: 200510/253
X-Sequence-Number: 19325

(Please don't top reply... your response has been moved to the bottom)

On Sun, 2005-10-23 at 16:55, Kishore B wrote:
>  
> On 10/23/05, Craig A. James <cjames@modgraph-usa.com> wrote: 
>         > We are facing a* critical situation because of the
>         performance of the
>         > **database** .* Even a basic query like select count(*) from
>         > bigger_table is taking about 4 minutes to return.
>         
>         Several other replies have mentioned that COUNT() requires a
>         full table scan,

This isn't wholly correct.  A query like this:

select count(*) from locatorcodes where locatorcode like 'ZZZ%';

can use an index.  However, since tuple visibility info is NOT stored in
indexes, ALL these tuples must be looked up in the actual table.

>          but this point can't be emphasized enough: Don't do it! 
>         People who are migrating from other environments (Oracle or
>         MySQL) are used to COUNT(), MIN() and MAX() returning almost
>         instantaneously, certainly on indexed columns.

While I'll admit that min and max are a bit faster in Oracle than in
postgresql, count doesn't seem much faster in my testing.  Of course, on
a wider table Oracle probably is faster, but I'm used to normalizing out
my tables so that there's no advantage for Oracle there.

>           But for reasons that have something to do with transactions,
>         these operations are unbelievably slow in PostgreSQL. 

It's because of visibility in the MVCC system PostgreSQL uses.

>         MIN() and MAX() -- These are surprisingly slow, because they
>         seem to do a full table scan EVEN ON AN INDEXED COLUMN!  I
>         don't understand why, but happily there is an effective
>         substitute:

It's because aggregate in PostgreSQL are abstract things.  To make these
two faster would require short circuiting the query planner to use
something other than the abstracted methods PostgreSQL was built around.

On the other hand, select with limit and order by can use the indexes
because they are not aggregates.

>         You should carefully examine your entire application for
>         COUNT, MIN, and MAX, and get rid of them EVERYWHERE.  This may
>         be the entire source of your problem.  It was in my case.

You're right on here.  The problem is that people often use aggregates
where they shouldn't.  Aggregates really are meant to operate across a
whole set of data.  An aggregate like sum() or avg() seems obviously
designed to hit every tuple.  Well, while min, max, and count may not
look like they should, they, in fact, do hit every table covered by the
where clause.

>         This is, in my humble opinion, the only serious flaw in
>         PostgreSQL.  I've been totally happy with it in every other
>         way, and once I understood these shortcomings, my application
>         is runs faster than ever on PostgreSQL. 

I wouldn't fully qualify it as a flaw.  It's a design quirk, caused by
the extensible model PostgreSQL is built under.  While it costs you in
one way, like slower min / max / count in some circumstances, it
benefits you others, like the ability make your own aggregate functions.

> Hi Craig, 
>  
> Does the no of tables and the size of each table affect the
> performance of a join operation? 

Of course they do.  The more information your query has to process, the
slower it will run.  It's usually a pretty much a linear increase in
time required, unless you go from everything fitting into buffers to
spilling to disk.  Then things will slow down noticeably.

>  
> When we are trying to join the two big tables that I described above,
> pg is taking so long to execute?

Hard to say.  There are many ways to tune PostgreSQL.  I strongly
suggest you take this thread to the performance list, and post your
postgresql.conf file, and the output of "explain analyze <your query
here>" and ask for help.  That list is much better equipped to help with
these things.

From pgsql-performance-owner@postgresql.org  Mon Oct 24 12:33:55 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id B0B09DAC68
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 24 Oct 2005 12:32:59 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 63329-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 24 Oct 2005 15:32:57 +0000 (GMT)
Received: from cassarossa.samfundet.no (cassarossa.samfundet.no
	[129.241.93.19])
	by svr1.postgresql.org (Postfix) with ESMTP id 336F3DAC38
	for <pgsql-performance@postgresql.org>;
	Mon, 24 Oct 2005 12:32:55 -0300 (ADT)
Received: from sesse by cassarossa.samfundet.no with local (Exim 4.50)
	id 1EU4Jc-0006Pj-MR; Mon, 24 Oct 2005 17:32:48 +0200
Date: Mon, 24 Oct 2005 17:32:48 +0200
From: "Steinar H. Gunderson" <sgunderson@bigfoot.com>
To: Alex Turner <armtuk@gmail.com>
Cc: Neil Conway <neilc@samurai.com>,
	Martin Nickel <martin@portant.com>, pgsql-performance@postgresql.org
Subject: Re: What gets cached?
Message-ID: <20051024153248.GA24601@samfundet.no>
References: <pan.2005.10.21.12.34.29.712700@portant.com>
	<1129931087.19971.12.camel@localhost.localdomain>
	<33c6269f0510240809k47f91a71t387a0b5ab0339f4c@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <33c6269f0510240809k47f91a71t387a0b5ab0339f4c@mail.gmail.com>
User-Agent: Mutt/1.5.9i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.01 required=5 tests=[AWL=0.010]
X-Spam-Level: 
X-Archive-Number: 200510/333
X-Sequence-Number: 15101

On Mon, Oct 24, 2005 at 11:09:55AM -0400, Alex Turner wrote:
> Just to play devils advocate here for as second, but if we have an algorithm
> that is substational better than just plain old LRU, which is what I believe
> the kernel is going to use to cache pages (I'm no kernel hacker), then why
> don't we apply that and have a significantly larger page cache a la Oracle?

There have (AFAIK) been reports of setting huge amounts of shared_buffers
(close to the total amount of RAM) performing much better in 8.1 than in
earlier versions, so this might actually be okay these days.

I haven't heard of anybody reporting increase setting such values, though.

/* Steinar */
-- 
Homepage: http://www.sesse.net/


From pgsql-performance-owner@postgresql.org  Mon Oct 24 12:51:20 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 3D847DACAA
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 24 Oct 2005 12:51:19 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 67530-04
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 24 Oct 2005 15:51:16 +0000 (GMT)
Received: from gwmta.wicourts.gov (gwmta.wicourts.gov [165.219.244.99])
	by svr1.postgresql.org (Postfix) with ESMTP id B1AFBDACA3
	for <pgsql-performance@postgresql.org>;
	Mon, 24 Oct 2005 12:51:15 -0300 (ADT)
Received: from Courts-MTA by gwmta.wicourts.gov
	with Novell_GroupWise; Mon, 24 Oct 2005 10:51:07 -0500
Message-Id: <435CBC9202000025000001AB@gwmta.wicourts.gov>
X-Mailer: Novell GroupWise Internet Agent 7.0 
Date: Mon, 24 Oct 2005 10:50:57 -0500
From: "Kevin Grittner" <Kevin.Grittner@wicourts.gov>
To: <cpc@cybees.com>
Cc: <pgsql-performance@postgresql.org>
Subject: Re: Used Memory
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.003 required=5 tests=[AWL=0.003]
X-Spam-Level: 
X-Archive-Number: 200510/334
X-Sequence-Number: 15102

In addition to what Mark pointed out, there is the possibility that a
query
is running which is scanning a large table or otherwise bringing in a
large number of pages from disk.  That would first use up all available
unused cache space, and then may start replacing some of your
frequently used data.  This can cause slowness for some time after the
process which flushed the cache, as pages are reread and recached.

Keep in mind that the cache could be flushed by some external process,
such as copying disk files.

The use of free memory for caching is not slowing you down; but if it
coincides with slowness, it could be a useful clue.

-Kevin


From pgsql-performance-owner@postgresql.org  Mon Oct 24 14:01:59 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 5BAACDACB5
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 24 Oct 2005 14:01:58 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 80990-10
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 24 Oct 2005 17:01:56 +0000 (GMT)
Received: from moonunit2.moonview.localnet (wsip-68-15-5-150.sd.sd.cox.net
	[68.15.5.150])
	by svr1.postgresql.org (Postfix) with ESMTP id 67243DACB7
	for <pgsql-performance@postgresql.org>;
	Mon, 24 Oct 2005 14:01:55 -0300 (ADT)
Received: from [192.168.0.3] (moonunit3.moonview.localnet [192.168.0.3])
	by moonunit2.moonview.localnet (8.13.1/8.13.1) with ESMTP id
	j9OH7Pc9011174
	for <pgsql-performance@postgresql.org>; Mon, 24 Oct 2005 10:07:25 -0700
Message-ID: <435D1314.5040807@modgraph-usa.com>
Date: Mon, 24 Oct 2005 10:00:04 -0700
From: "Craig A. James" <cjames@modgraph-usa.com>
User-Agent: Mozilla Thunderbird 1.0.6 (X11/20050716)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: pgsql-performance@postgresql.org
Subject: Re: Used Memory
References: <435CBC9202000025000001AB@gwmta.wicourts.gov>
In-Reply-To: <435CBC9202000025000001AB@gwmta.wicourts.gov>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.05 required=5 tests=[AWL=-0.000,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/335
X-Sequence-Number: 15103

Kevin Grittner wrote:
> In addition to what Mark pointed out, there is the possibility that a
> query
> is running which is scanning a large table or otherwise bringing in a
> large number of pages from disk.  That would first use up all available
> unused cache space, and then may start replacing some of your
> frequently used data.  

An LRU cache is often a bad strategy for database applications.  There are two illustrations that show why.

1. You have an index that's used for EVERY search, but each search returns a large and unique set of rows.  If it happens that the rows returned exceed the systems cache size, the part or all of your index will be flushed with EVERY query.

2. You do a sequential scan of a table that's one block bigger than the file system cache, then you do it again.  At the beginning of the second scan, the first block of the table will have just been swapped out because it was the oldest, so the file system brings it back in, replacing the second block, which is now the oldest.  As you scan the table, each block of the table is swapped out JUST BEFORE you get to it.  At the start of your query, the file system might have had 99.9% of the relevant data in memory, but it swaps out 100% of it as your query progresses.

Scenario 2 above is interesting because a system that is performing very well can suddenly experience a catastrophic performance decline when the size of the data exceeds a critical limit - the file system's avaliable cache.

LRU works well if your frequently-used data is used often enough to keep it in memory.  But many applications don't have that luxury.  It's often the case that a single query will exceed the file system's cache size.  The file system cache is "dumb" -- it's strategy is too simple for a relational database.

What's needed is a way for the application developer to explicitely say, "This object is frequenly used, and I want it kept in memory."

Craig

From pgsql-performance-owner@postgresql.org  Mon Oct 24 16:11:55 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 44267DABF4
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 24 Oct 2005 16:11:54 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 12609-10
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 24 Oct 2005 19:11:51 +0000 (GMT)
Received: from qproxy.gmail.com (qproxy.gmail.com [72.14.204.200])
	by svr1.postgresql.org (Postfix) with ESMTP id 30C26DAD38
	for <pgsql-performance@postgresql.org>;
	Mon, 24 Oct 2005 16:11:51 -0300 (ADT)
Received: by qproxy.gmail.com with SMTP id e12so295284qbe
	for <pgsql-performance@postgresql.org>;
	Mon, 24 Oct 2005 12:11:53 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references;
	b=Xs5nE40jFS5PimiRBxr52d2CVPR9Fc9iQnItx4w+teSxXIUtyTONLl3mTjW9kLoELm+82irqHBUxglFiueRBA3om/p0AjhCowYJhQNYpQ8JVrQCNygxEiMtt464ipLVDDpVuGq4ehLU9MVe7PJbk0MOuS5f5R+Z4BVrjFiURkzk=
Received: by 10.65.105.20 with SMTP id h20mr662394qbm;
	Mon, 24 Oct 2005 12:11:53 -0700 (PDT)
Received: by 10.65.240.20 with HTTP; Mon, 24 Oct 2005 12:11:53 -0700 (PDT)
Message-ID: <3cf983d0510241211w4f577241v33aab8feda4f604f@mail.gmail.com>
Date: Mon, 24 Oct 2005 19:11:53 +0000
From: Rodrigo Madera <rodrigo.madera@gmail.com>
To: pgsql-performance@postgresql.org
Subject: Re: Inefficient escape codes.
In-Reply-To: <3cf983d0510241208se3076fo2f1fa0b8d88f2714@mail.gmail.com>
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="----=_Part_18628_15991171.1130181113540"
References: <16F953410A0F1346848DCB476A989CFE34B8@swtexchange2.technology.de>
	<3cf983d0510241208se3076fo2f1fa0b8d88f2714@mail.gmail.com>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.529 required=5 tests=[HTML_20_30=0.504,
	HTML_MESSAGE=0.001, RCVD_BY_IP=0.024]
X-Spam-Level: 
X-Archive-Number: 200510/336
X-Sequence-Number: 15104

------=_Part_18628_15991171.1130181113540
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Now this interests me a lot.

Please clarify this:

I have 5000 tables, one for each city:

City1_Photos, City2_Photos, ... City5000_Photos.

Each of these tables are: CREATE TABLE CityN_Photos (location text, lo_id
largeobectypeiforgot)

So, what's the limit for these large objects? I heard I could only have 4
billion records for the whole database (not for each table). Is this true?
If this isn't true, then would postgres manage to create all the large
objects I ask him to?

Also, this would be a performance penalty, wouldn't it?

Much thanks for the knowledge shared,
Rodrigo

------=_Part_18628_15991171.1130181113540
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Now this interests me a lot.<br>
<br>
Please clarify this:<br>
<br>
I have 5000 tables, one for each city:<br>
<br>
City1_Photos, City2_Photos, ... City5000_Photos.<br>
<br>
Each of these tables are: CREATE TABLE CityN_Photos (location text, lo_id l=
argeobectypeiforgot)<br>
<br>
So, what's the limit for these large objects? I heard I could only have
4 billion records for the whole database (not for each table). Is this
true? If this isn't true, then would postgres manage to create all the
large objects I ask him to?<br>
<br>
Also, this would be a performance penalty, wouldn't it?<br>
<br>
Much thanks for the knowledge shared,<br><span class=3D"sg">
Rodrigo</span><div><span class=3D"e" id=3D"q_10724086ca7e0d29_2"><br>
<br><br>

</span></div>

------=_Part_18628_15991171.1130181113540--

From pgsql-performance-owner@postgresql.org  Mon Oct 24 17:25:05 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id E4CE5D850D
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 24 Oct 2005 17:25:03 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 45423-06
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 24 Oct 2005 20:24:59 +0000 (GMT)
Received: from koolancexeon.g2switchworks.com (mail.g2switchworks.com
	[63.87.162.25])
	by svr1.postgresql.org (Postfix) with ESMTP id 47C33D6EE1
	for <pgsql-performance@postgresql.org>;
	Mon, 24 Oct 2005 17:24:58 -0300 (ADT)
Received: mail.g2switchworks.com 10.10.1.8 from 10.10.1.37 10.10.1.37 via HTTP
	with MS-WebStorage 6.5.6944
Received: from state.g2switchworks.com by mail.g2switchworks.com;
	24 Oct 2005 15:24:59 -0500
Subject: Re: Used Memory
From: Scott Marlowe <smarlowe@g2switchworks.com>
To: "Craig A. James" <cjames@modgraph-usa.com>
Cc: pgsql-performance@postgresql.org
In-Reply-To: <435D1314.5040807@modgraph-usa.com>
References: <435CBC9202000025000001AB@gwmta.wicourts.gov>
	<435D1314.5040807@modgraph-usa.com>
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Message-Id: <1130185499.15546.120.camel@state.g2switchworks.com>
Mime-Version: 1.0
X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) 
Date: Mon, 24 Oct 2005 15:24:59 -0500
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.007 required=5 tests=[AWL=0.007]
X-Spam-Level: 
X-Archive-Number: 200510/337
X-Sequence-Number: 15105

On Mon, 2005-10-24 at 12:00, Craig A. James wrote:
> Kevin Grittner wrote:
> > In addition to what Mark pointed out, there is the possibility that a
> > query
> > is running which is scanning a large table or otherwise bringing in a
> > large number of pages from disk.  That would first use up all available
> > unused cache space, and then may start replacing some of your
> > frequently used data.  
> 
> An LRU cache is often a bad strategy for database applications.  There are two illustrations that show why.
> 
> 1. You have an index that's used for EVERY search, but each search returns a large and unique set of rows.  If it happens that the rows returned exceed the systems cache size, the part or all of your index will be flushed with EVERY query.
> 
> 2. You do a sequential scan of a table that's one block bigger than the file system cache, then you do it again.  At the beginning of the second scan, the first block of the table will have just been swapped out because it was the oldest, so the file system brings it back in, replacing the second block, which is now the oldest.  As you scan the table, each block of the table is swapped out JUST BEFORE you get to it.  At the start of your query, the file system might have had 99.9% of the relevant data in memory, but it swaps out 100% of it as your query progresses.
> 
> Scenario 2 above is interesting because a system that is performing very well can suddenly experience a catastrophic performance decline when the size of the data exceeds a critical limit - the file system's avaliable cache.
> 
> LRU works well if your frequently-used data is used often enough to keep it in memory.  But many applications don't have that luxury.  It's often the case that a single query will exceed the file system's cache size.  The file system cache is "dumb" -- it's strategy is too simple for a relational database.
> 
> What's needed is a way for the application developer to explicitely say, "This object is frequenly used, and I want it kept in memory."

There's an interesting conversation happening on the linux kernel
hackers mailing list right about now that applies:

http://www.gossamer-threads.com/lists/linux/kernel/580789

From pgsql-performance-owner@postgresql.org  Mon Oct 24 18:50:58 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 998ACDAD29
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 24 Oct 2005 18:48:57 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 67100-03
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 24 Oct 2005 21:48:52 +0000 (GMT)
Received: from moonunit2.moonview.localnet (wsip-68-15-5-150.sd.sd.cox.net
	[68.15.5.150])
	by svr1.postgresql.org (Postfix) with ESMTP id B1169DAD63
	for <pgsql-performance@postgresql.org>;
	Mon, 24 Oct 2005 18:48:53 -0300 (ADT)
Received: from [192.168.0.3] (moonunit3.moonview.localnet [192.168.0.3])
	by moonunit2.moonview.localnet (8.13.1/8.13.1) with ESMTP id
	j9OLsNG2011306; Mon, 24 Oct 2005 14:54:23 -0700
Message-ID: <435D5654.2080209@modgraph-usa.com>
Date: Mon, 24 Oct 2005 14:47:00 -0700
From: "Craig A. James" <cjames@modgraph-usa.com>
User-Agent: Mozilla Thunderbird 1.0.6 (X11/20050716)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: Scott Marlowe <smarlowe@g2switchworks.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Used Memory
References: <435CBC9202000025000001AB@gwmta.wicourts.gov>	
	<435D1314.5040807@modgraph-usa.com>
	<1130185499.15546.120.camel@state.g2switchworks.com>
In-Reply-To: <1130185499.15546.120.camel@state.g2switchworks.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.05 required=5 tests=[AWL=-0.000,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/338
X-Sequence-Number: 15106

Scott Marlowe wrote:
>>What's needed is a way for the application developer to explicitely say,
>> "This object is frequenly used, and I want it kept in memory."
>  
> There's an interesting conversation happening on the linux kernel
> hackers mailing list right about now that applies:
> 
> http://www.gossamer-threads.com/lists/linux/kernel/580789

Thanks for the pointer.  If you're a participant in that mailing list, maybe you could forward this comment...

A fundamental flaw in the kernel, which goes WAY back to early UNIX implementations, is that the nice(1) setting of a program only applies to CPU usage, not to other resources.  In this case, the file-system cache has no priority, so even if I set postmaster's nice(1) value to a very high priority, any pissant process with the lowest priority possible can come along with a "cat some-big-file >/dev/null" and trash my cached file-system pages.  It's essentially a denial-of-service mechanism that's built in to the kernel.

The kernel group's discussion on the heuristics of how and when to toss stale cache pages should have a strong nice(1) component to it.  A process with a low priority should not be allowed to toss memory from a higher-priority process unless there is no other source of memory.

Getting back to Postgres, the same points that the linux kernel group are discussing apply to Postgres.  There is simply no way to devise a heuristic that comes even close to what the app developer can tell you.  A mechanism that allowed an application to say, "Keep this table in memory" is the only way.  App developers should be advised to use it sparingly, because most of the time the system is pretty good at memory management, and such a mechanism hobbles the system's ability to manage.  But when it's needed, there is no substitute.

Craig


From pgsql-performance-owner@postgresql.org  Mon Oct 24 19:20:06 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id D3C03DAD3B
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 24 Oct 2005 19:20:05 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 74560-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 24 Oct 2005 22:20:02 +0000 (GMT)
Received: from moonunit2.moonview.localnet (wsip-68-15-5-150.sd.sd.cox.net
	[68.15.5.150])
	by svr1.postgresql.org (Postfix) with ESMTP id 6B4C4DAD67
	for <pgsql-performance@postgresql.org>;
	Mon, 24 Oct 2005 19:20:03 -0300 (ADT)
Received: from [192.168.0.3] (moonunit3.moonview.localnet [192.168.0.3])
	by moonunit2.moonview.localnet (8.13.1/8.13.1) with ESMTP id
	j9OMPbcw011370
	for <pgsql-performance@postgresql.org>; Mon, 24 Oct 2005 15:25:37 -0700
Message-ID: <435D5DA6.9090405@moonviewscientific.com>
Date: Mon, 24 Oct 2005 15:18:14 -0700
From: "Craig A. James" <cjames@modgraph-usa.com>
User-Agent: Mozilla Thunderbird 1.0.6 (X11/20050716)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: pgsql-performance@postgresql.org
Subject: Re: Is There Any Way ....
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.05 required=5 tests=[FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/339
X-Sequence-Number: 15107

Jim C. Nasby" <jnasby ( at ) pervasive ( dot ) com> wrote:
> > Stefan Weiss wrote:
> > ... IMO it would be useful to have a way to tell
> > PG that some tables were needed frequently, and should be cached if
> > possible. This would allow application developers to consider joins with
> > these tables as "cheap", even when querying on columns that are 
> > not indexed.
>
> Why do you think you'll know better than the database how frequently
> something is used? At best, your guess will be correct and PostgreSQL
> (or the kernel) will keep the table in memory. Or, your guess is wrong
> and you end up wasting memory that could have been used for something
> else.
> 
> It would probably be better if you describe why you want to force this
> table (or tables) into memory, so we can point you at more appropriate
> solutions.

Or perhaps we could explain why we NEED to force these tables into memory, so we can point you at a more appropriate implementation.  ;-)

Ok, wittiness aside, here's a concrete example.  I have an application with one critical index that MUST remain in memory at all times.  The index's tablespace is about 2 GB.  As long as it's in memory, performance is excellent - a user's query takes a fraction of a second.  But if it gets swapped out, the user's query might take up to five minutes as the index is re-read from memory.

Now here's the rub.  The only performance I care about is response to queries from the web application.  Everything else is low priority.  But there is other activity going on.  Suppose, for example, that I'm updating tables, performing queries, doing administration, etc., etc., for a period of an hour, during which no customer visits the site.  The another customer comes along and performs a query.

At this point, no heuristic in the world could have guessed that I DON'T CARE ABOUT PERFORMANCE for anything except my web application.  The performance of all the other stuff, the administration, the updates, etc., is utterly irrelevant compared to the performance of the customer's query.

What actually happens is that the other activities have swapped out the critical index, and my customer waits, and waits, and waits... and goes away after a minute or two.  To solve this, we've been forced to purchase two computers, and mirror the database on both.  All administration and modification happens on the "offline" database, and the web application only uses the "online" database.  At some point, we swap the two servers, sync the two databases, and carry on.  It's a very unsatisfactory solution.

There is ONLY one way to convey this sort of information to Postgres, which is to provide the application developer a mechanism to explicitely name the tables that should be locked in memory.

Look at tsearchd that Oleg is working on.  It's a direct response to this problem.

It's been recognized for decades that, as kernel developers (whether a Linux kernel or a database kernel), our ability to predict the behavior of an application is woefully inadequate compared with the application developer's knowledge of the application.  Computer Science simply isn't a match for the human brain yet, not even close.

To give you perspective, since I posted a question about this problem (regarding tsearch2/GIST indexes), half of the responses I received told me that they encountered this problem, and their solution was to use an external full-text engine.  They all confirmed that Postgres can't deal with this problem yet, primarily for the reasons outlined above.

Craig

From pgsql-performance-owner@postgresql.org  Mon Oct 24 20:11:14 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id A89D4DAD78
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 24 Oct 2005 20:11:13 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 80488-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 24 Oct 2005 23:11:10 +0000 (GMT)
Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.204])
	by svr1.postgresql.org (Postfix) with ESMTP id E6942DAD75
	for <pgsql-performance@postgresql.org>;
	Mon, 24 Oct 2005 20:11:11 -0300 (ADT)
Received: by wproxy.gmail.com with SMTP id 71so541076wra
	for <pgsql-performance@postgresql.org>;
	Mon, 24 Oct 2005 16:11:15 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references;
	b=RU0BWk7TPMQRiPnY9dgAV4nArtDfkqOKhw3m+PVBer3HgMPrDMgOFldbTFXxeIdvvTAIpvVdGkQMEPvbOoYs0CJgxkzDH76iX/pcBpILg5k45bgid2wUkDTfyUowHa6vRhS4i65MokaiF24ufhlaxhcRF6CLWOcbaZQT6kKQcGc=
Received: by 10.54.16.77 with SMTP id 77mr3414454wrp;
	Mon, 24 Oct 2005 16:11:15 -0700 (PDT)
Received: by 10.54.84.8 with HTTP; Mon, 24 Oct 2005 16:11:15 -0700 (PDT)
Message-ID: <33c6269f0510241611r1c6568fbg17ed2d059f46fbbb@mail.gmail.com>
Date: Mon, 24 Oct 2005 19:11:15 -0400
From: Alex Turner <armtuk@gmail.com>
To: "Craig A. James" <cjames@modgraph-usa.com>
Subject: Re: Is There Any Way ....
Cc: pgsql-performance@postgresql.org
In-Reply-To: <435D5DA6.9090405@moonviewscientific.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
References: <435D5DA6.9090405@moonviewscientific.com>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.112 required=5 tests=[AWL=0.088, RCVD_BY_IP=0.024]
X-Spam-Level: 
X-Archive-Number: 200510/340
X-Sequence-Number: 15108

This is possible with Oracle utilizing the keep pool

alter table t_name storage ( buffer_pool keep);

If Postgres were to implement it's own caching system, this seems like
it would be easily to implement (beyond the initial caching effort).

Alex


On 10/24/05, Craig A. James <cjames@modgraph-usa.com> wrote:
> Jim C. Nasby" <jnasby ( at ) pervasive ( dot ) com> wrote:
> > > Stefan Weiss wrote:
> > > ... IMO it would be useful to have a way to tell
> > > PG that some tables were needed frequently, and should be cached if
> > > possible. This would allow application developers to consider joins w=
ith
> > > these tables as "cheap", even when querying on columns that are
> > > not indexed.
> >
> > Why do you think you'll know better than the database how frequently
> > something is used? At best, your guess will be correct and PostgreSQL
> > (or the kernel) will keep the table in memory. Or, your guess is wrong
> > and you end up wasting memory that could have been used for something
> > else.
> >
> > It would probably be better if you describe why you want to force this
> > table (or tables) into memory, so we can point you at more appropriate
> > solutions.
>
> Or perhaps we could explain why we NEED to force these tables into memory=
, so we can point you at a more appropriate implementation.  ;-)
>
> Ok, wittiness aside, here's a concrete example.  I have an application wi=
th one critical index that MUST remain in memory at all times.  The index's=
 tablespace is about 2 GB.  As long as it's in memory, performance is excel=
lent - a user's query takes a fraction of a second.  But if it gets swapped=
 out, the user's query might take up to five minutes as the index is re-rea=
d from memory.
>
> Now here's the rub.  The only performance I care about is response to que=
ries from the web application.  Everything else is low priority.  But there=
 is other activity going on.  Suppose, for example, that I'm updating table=
s, performing queries, doing administration, etc., etc., for a period of an=
 hour, during which no customer visits the site.  The another customer come=
s along and performs a query.
>
> At this point, no heuristic in the world could have guessed that I DON'T =
CARE ABOUT PERFORMANCE for anything except my web application.  The perform=
ance of all the other stuff, the administration, the updates, etc., is utte=
rly irrelevant compared to the performance of the customer's query.
>
> What actually happens is that the other activities have swapped out the c=
ritical index, and my customer waits, and waits, and waits... and goes away=
 after a minute or two.  To solve this, we've been forced to purchase two c=
omputers, and mirror the database on both.  All administration and modifica=
tion happens on the "offline" database, and the web application only uses t=
he "online" database.  At some point, we swap the two servers, sync the two=
 databases, and carry on.  It's a very unsatisfactory solution.
>
> There is ONLY one way to convey this sort of information to Postgres, whi=
ch is to provide the application developer a mechanism to explicitely name =
the tables that should be locked in memory.
>
> Look at tsearchd that Oleg is working on.  It's a direct response to this=
 problem.
>
> It's been recognized for decades that, as kernel developers (whether a Li=
nux kernel or a database kernel), our ability to predict the behavior of an=
 application is woefully inadequate compared with the application developer=
's knowledge of the application.  Computer Science simply isn't a match for=
 the human brain yet, not even close.
>
> To give you perspective, since I posted a question about this problem (re=
garding tsearch2/GIST indexes), half of the responses I received told me th=
at they encountered this problem, and their solution was to use an external=
 full-text engine.  They all confirmed that Postgres can't deal with this p=
roblem yet, primarily for the reasons outlined above.
>
> Craig
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: don't forget to increase your free space map settings
>

From pgsql-performance-owner@postgresql.org  Mon Oct 24 21:50:43 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 88DC6DAD85
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 24 Oct 2005 21:50:42 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 08435-07
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 00:50:37 +0000 (GMT)
Received: from unicorn.rentec.com (unicorn.rentec.com [216.223.240.9])
	by svr1.postgresql.org (Postfix) with ESMTP id 4D03DDAD80
	for <pgsql-performance@postgresql.org>;
	Mon, 24 Oct 2005 21:50:38 -0300 (ADT)
Received: from ram.rentec.com (mailhost [192.5.35.66])
	by unicorn.rentec.com (8.13.1/8.12.1) with ESMTP id j9P0oeNT008593
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO)
	for <pgsql-performance@postgresql.org>;
	Mon, 24 Oct 2005 20:50:41 -0400 (EDT)
X-Source: non-mednet
Received: from [172.16.160.106] (stangesun.rentec.com [172.16.160.106])
	by ram.rentec.com (8.13.1/8.12.1) with ESMTP id j9P0oS3P005828
	for <pgsql-performance@postgresql.org>;
	Mon, 24 Oct 2005 20:50:28 -0400 (EDT)
Message-ID: <435D8151.8000200@rentec.com>
Date: Mon, 24 Oct 2005 20:50:25 -0400
From: Alan Stange <stange@rentec.com>
User-Agent: Thunderbird 1.4.1 (X11/20051006)
MIME-Version: 1.0
Cc: pgsql-performance@postgresql.org
Subject: Re: Is There Any Way ....
References: <435D5DA6.9090405@moonviewscientific.com>
	<33c6269f0510241611r1c6568fbg17ed2d059f46fbbb@mail.gmail.com>
In-Reply-To: <33c6269f0510241611r1c6568fbg17ed2d059f46fbbb@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Logged: Logged by unicorn.rentec.com as j9P0oeNT008593 at Mon Oct 24
	20:50:41 2005
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.013 required=5 tests=[AWL=0.013]
X-Spam-Level: 
X-Archive-Number: 200510/341
X-Sequence-Number: 15109

Alex Turner wrote:
> This is possible with Oracle utilizing the keep pool
>
> alter table t_name storage ( buffer_pool keep);
>
> If Postgres were to implement it's own caching system, this seems like
> it would be easily to implement (beyond the initial caching effort).
>
> Alex
>
>
> On 10/24/05, Craig A. James <cjames@modgraph-usa.com> wrote:
>   
>> Jim C. Nasby" <jnasby ( at ) pervasive ( dot ) com> wrote:
>>     
>>>> Stefan Weiss wrote:
>>>> ... IMO it would be useful to have a way to tell
>>>> PG that some tables were needed frequently, and should be cached if
>>>> possible. This would allow application developers to consider joins with
>>>> these tables as "cheap", even when querying on columns that are
>>>> not indexed.
>>>>         
>>> Why do you think you'll know better than the database how frequently
>>> something is used? At best, your guess will be correct and PostgreSQL
>>> (or the kernel) will keep the table in memory. Or, your guess is wrong
>>> and you end up wasting memory that could have been used for something
>>> else.
>>>
>>> It would probably be better if you describe why you want to force this
>>> table (or tables) into memory, so we can point you at more appropriate
>>> solutions.
>>>       
>> Or perhaps we could explain why we NEED to force these tables into memory, so we can point you at a more appropriate implementation.  ;-)
>>
>> Ok, wittiness aside, here's a concrete example.  I have an application with one critical index that MUST remain in memory at all times.  The index's tablespace is about 2 GB.  As long as it's in memory, performance is excellent - a user's query takes a fraction of a second.  But if it gets swapped out, the user's query might take up to five minutes as the index is re-read from memory.
>>
>> Now here's the rub.  The only performance I care about is response to queries from the web application.  Everything else is low priority.  But there is other activity going on.  Suppose, for example, that I'm updating tables, performing queries, doing administration, etc., etc., for a period of an hour, during which no customer visits the site.  The another customer comes along and performs a query.
>>
>> At this point, no heuristic in the world could have guessed that I DON'T CARE ABOUT PERFORMANCE for anything except my web application.  The performance of all the other stuff, the administration, the updates, etc., is utterly irrelevant compared to the performance of the customer's query.
>>
>> What actually happens is that the other activities have swapped out the critical index, and my customer waits, and waits, and waits... and goes away after a minute or two.  To solve this, we've been forced to purchase two computers, and mirror the database on both.  All administration and modification happens on the "offline" database, and the web application only uses the "online" database.  At some point, we swap the two servers, sync the two databases, and carry on.  It's a very unsatisfactory solution.
We have a similar problem with vacuum being the equivalent of 
"continuously flush all system caches for a long time".  Our database is 
about 200GB in size and vacuums take hours and hours.   The performance 
is acceptable still, but only because we've hidden the latency in our 
application.

I've occasionally thought it would be good to have the backend doing a 
vacuum or analyze also call priocntl() prior to doing any real work to 
lower its priority.   We'll be switching to the 8.1 release ASAP just 
because the direct IO capabilities are appearing to be a win on our 
development system.

-- Alan


From pgsql-performance-owner@postgresql.org  Mon Oct 24 23:41:34 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 86EDCDAE83
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 24 Oct 2005 23:39:44 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 45476-09
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 02:39:33 +0000 (GMT)
Received: from mailer.eglobalreach.net (cybees.com [202.124.128.22])
	by svr1.postgresql.org (Postfix) with ESMTP id 3CC83DAF62
	for <pgsql-performance@postgresql.org>;
	Mon, 24 Oct 2005 23:35:36 -0300 (ADT)
Received: from ghwk02002147 (localhost [127.0.0.1] (may be forged))
	by mailer.eglobalreach.net (8.11.6p2/) with ESMTP id j9P2ZeL27307
	for <pgsql-performance@postgresql.org>; Tue, 25 Oct 2005 10:35:40 +0800
From: "Christian Paul B. Cosinas" <cpc@cybees.com>
To: <pgsql-performance@postgresql.org>
Subject: Re: Used Memory
Date: Tue, 25 Oct 2005 02:39:51 -0000
Message-ID: <004e01c5d90d$5ffdadb0$1e21100a@ghwk02002147>
MIME-Version: 1.0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit
X-Mailer: Microsoft Office Outlook 11
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506
In-Reply-To: <435D5654.2080209@modgraph-usa.com>
thread-index: AcXY5Zw4tiI7/6KVSPu3LTb7x7fgKAAJsZ5w
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.679 required=5 tests=[AWL=0.000,
	FORGED_RCVD_HELO=0.05, URIBL_SBL=0.629]
X-Spam-Level: 
X-Archive-Number: 200510/342
X-Sequence-Number: 15110

Hi To all those who replied. Thank You.

I monitor my database server a while ago and found out that memory is used
extensively when I am fetching records from the database. I use the command
"fetch all" in my VB Code and put it in a recordset.Also in this command the
CPU utilization is used extensively.

Is there something wrong with my code or is it just the way postgresql is
behaving which I cannot do something about it?

I just monitor one workstation connecting to the database server and it is
already eating up about 20 % of the CPU of database server.

Which I think will not be applicable to our system since we have a target of
25 PC connecting to the database server most of the time.

-----Original Message-----
From: pgsql-performance-owner@postgresql.org
[mailto:pgsql-performance-owner@postgresql.org] On Behalf Of Craig A. James
Sent: Monday, October 24, 2005 9:47 PM
To: Scott Marlowe
Cc: pgsql-performance@postgresql.org
Subject: Re: [PERFORM] Used Memory

Scott Marlowe wrote:
>>What's needed is a way for the application developer to explicitely 
>>say,  "This object is frequenly used, and I want it kept in memory."
>  
> There's an interesting conversation happening on the linux kernel 
> hackers mailing list right about now that applies:
> 
> http://www.gossamer-threads.com/lists/linux/kernel/580789

Thanks for the pointer.  If you're a participant in that mailing list, maybe
you could forward this comment...

A fundamental flaw in the kernel, which goes WAY back to early UNIX
implementations, is that the nice(1) setting of a program only applies to
CPU usage, not to other resources.  In this case, the file-system cache has
no priority, so even if I set postmaster's nice(1) value to a very high
priority, any pissant process with the lowest priority possible can come
along with a "cat some-big-file >/dev/null" and trash my cached file-system
pages.  It's essentially a denial-of-service mechanism that's built in to
the kernel.

The kernel group's discussion on the heuristics of how and when to toss
stale cache pages should have a strong nice(1) component to it.  A process
with a low priority should not be allowed to toss memory from a
higher-priority process unless there is no other source of memory.

Getting back to Postgres, the same points that the linux kernel group are
discussing apply to Postgres.  There is simply no way to devise a heuristic
that comes even close to what the app developer can tell you.  A mechanism
that allowed an application to say, "Keep this table in memory" is the only
way.  App developers should be advised to use it sparingly, because most of
the time the system is pretty good at memory management, and such a
mechanism hobbles the system's ability to manage.  But when it's needed,
there is no substitute.

Craig


---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faq


I choose Polesoft Lockspam to fight spam, and you?
http://www.polesoft.com/refer.html    


From pgsql-performance-owner@postgresql.org  Tue Oct 25 00:06:51 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 7F38FDADBD
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 00:06:50 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 64553-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 03:06:48 +0000 (GMT)
Received: from linda-4.paradise.net.nz (bm-4a.paradise.net.nz
 [203.96.152.183])
	by svr1.postgresql.org (Postfix) with ESMTP id 01E65DAD9D
	for <pgsql-performance@postgresql.org>;
	Tue, 25 Oct 2005 00:06:48 -0300 (ADT)
Received: from smtp-3.paradise.net.nz
	(tclsnelb2-src-1.paradise.net.nz [203.96.152.177]) by
	linda-4.paradise.net.nz (Paradise.net.nz) with ESMTP id
	<0IOW0064JBBADJ@linda-4.paradise.net.nz> for
	pgsql-performance@postgresql.org; Tue, 25 Oct 2005 16:06:46 +1300 (NZDT)
Received: from [192.168.1.11] (218-101-13-43.paradise.net.nz [218.101.13.43])
	by smtp-3.paradise.net.nz (Postfix) with ESMTP id C49DE7F39F1; Tue,
	25 Oct 2005 16:06:45 +1300 (NZDT)
Date: Tue, 25 Oct 2005 16:06:43 +1300
From: Mark Kirkwood <markir@paradise.net.nz>
Subject: Re: Used Memory
In-reply-to: <004e01c5d90d$5ffdadb0$1e21100a@ghwk02002147>
To: "Christian Paul B. Cosinas" <cpc@cybees.com>
Cc: pgsql-performance@postgresql.org
Message-id: <435DA143.3050100@paradise.net.nz>
MIME-version: 1.0
Content-type: text/plain; format=flowed; charset=ISO-8859-1
Content-transfer-encoding: 7bit
X-Accept-Language: en-us, en
User-Agent: Mozilla Thunderbird 1.0.6 (X11/20050726)
References: <004e01c5d90d$5ffdadb0$1e21100a@ghwk02002147>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.146 required=5 tests=[AWL=0.146]
X-Spam-Level: 
X-Archive-Number: 200510/347
X-Sequence-Number: 15115

Christian Paul B. Cosinas wrote:
> Hi To all those who replied. Thank You.
> 
> I monitor my database server a while ago and found out that memory is used
> extensively when I am fetching records from the database. I use the command
> "fetch all" in my VB Code and put it in a recordset.Also in this command the
> CPU utilization is used extensively.
> 
> Is there something wrong with my code or is it just the way postgresql is
> behaving which I cannot do something about it?
> 
> I just monitor one workstation connecting to the database server and it is
> already eating up about 20 % of the CPU of database server.
> 
> Which I think will not be applicable to our system since we have a target of
> 25 PC connecting to the database server most of the time.
> 

Could you post the query and the output of EXPLAIN ANALYZE?

In addition, have you run ANALYZE on all the tables in that database ? 
(sorry, have to ask :-) ....).

cheers

Mark

From pgsql-performance-owner@postgresql.org  Tue Oct 25 00:16:11 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id D00E7DA78F
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 00:16:10 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 66818-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 03:16:05 +0000 (GMT)
Received: from mailer.eglobalreach.net (cybees.com [202.124.128.22])
	by svr1.postgresql.org (Postfix) with ESMTP id 5BA85DADE6
	for <pgsql-performance@postgresql.org>;
	Tue, 25 Oct 2005 00:16:04 -0300 (ADT)
Received: from ghwk02002147 (localhost [127.0.0.1] (may be forged))
	by mailer.eglobalreach.net (8.11.6p2/) with ESMTP id j9P3FwP29153;
	Tue, 25 Oct 2005 11:15:58 +0800
From: "Christian Paul B. Cosinas" <cpc@cybees.com>
To: "'Mark Kirkwood'" <markir@paradise.net.nz>,
	<pgsql-performance@postgresql.org>
Subject: Re: Used Memory
Date: Tue, 25 Oct 2005 03:20:09 -0000
Message-ID: <007801c5d913$018d2340$1e21100a@ghwk02002147>
MIME-Version: 1.0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit
X-Mailer: Microsoft Office Outlook 11
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506
In-Reply-To: <435DA143.3050100@paradise.net.nz>
thread-index: AcXZESPnDPtb0QZ8QoylE3m0wHj/cQAAWFXA
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.679 required=5 tests=[AWL=0.000,
	FORGED_RCVD_HELO=0.05, URIBL_SBL=0.629]
X-Spam-Level: 
X-Archive-Number: 200510/348
X-Sequence-Number: 15116

Hi mark

I have so many functions, more than 100 functions in the database :) And I
am dealing about 3 million of records in one database.
And about 100 databases :)


-----Original Message-----
From: Mark Kirkwood [mailto:markir@paradise.net.nz]
Sent: Tuesday, October 25, 2005 3:07 AM
To: Christian Paul B. Cosinas
Cc: pgsql-performance@postgresql.org
Subject: Re: [PERFORM] Used Memory

Christian Paul B. Cosinas wrote:
> Hi To all those who replied. Thank You.
> 
> I monitor my database server a while ago and found out that memory is 
> used extensively when I am fetching records from the database. I use 
> the command "fetch all" in my VB Code and put it in a recordset.Also 
> in this command the CPU utilization is used extensively.
> 
> Is there something wrong with my code or is it just the way postgresql 
> is behaving which I cannot do something about it?
> 
> I just monitor one workstation connecting to the database server and 
> it is already eating up about 20 % of the CPU of database server.
> 
> Which I think will not be applicable to our system since we have a 
> target of
> 25 PC connecting to the database server most of the time.
> 

Could you post the query and the output of EXPLAIN ANALYZE?

In addition, have you run ANALYZE on all the tables in that database ? 
(sorry, have to ask :-) ....).

cheers

Mark


I choose Polesoft Lockspam to fight spam, and you?
http://www.polesoft.com/refer.html    


From pgsql-performance-owner@postgresql.org  Tue Oct 25 01:14:43 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id C6FABDAD10
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 01:14:42 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 83128-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 04:14:40 +0000 (GMT)
Received: from linda-5.paradise.net.nz (bm-5a.paradise.net.nz
 [203.96.152.184])
	by svr1.postgresql.org (Postfix) with ESMTP id 3CC05DA8B4
	for <pgsql-performance@postgresql.org>;
	Tue, 25 Oct 2005 01:14:39 -0300 (ADT)
Received: from smtp-3.paradise.net.nz
	(tclsnelb2-src-1.paradise.net.nz [203.96.152.177]) by
	linda-5.paradise.net.nz (Paradise.net.nz) with ESMTP id
	<0IOW00CRUEGE34@linda-5.paradise.net.nz> for
	pgsql-performance@postgresql.org; Tue, 25 Oct 2005 17:14:38 +1300 (NZDT)
Received: from [192.168.1.11] (218-101-13-43.paradise.net.nz [218.101.13.43])
	by smtp-3.paradise.net.nz (Postfix) with ESMTP id 122FFFA50AE; Tue,
	25 Oct 2005 17:14:38 +1300 (NZDT)
Date: Tue, 25 Oct 2005 17:14:35 +1300
From: Mark Kirkwood <markir@paradise.net.nz>
Subject: Re: Used Memory
In-reply-to: <007801c5d913$018d2340$1e21100a@ghwk02002147>
To: "Christian Paul B. Cosinas" <cpc@cybees.com>
Cc: pgsql-performance@postgresql.org
Message-id: <435DB12B.5030901@paradise.net.nz>
MIME-version: 1.0
Content-type: text/plain; format=flowed; charset=ISO-8859-1
Content-transfer-encoding: 7bit
X-Accept-Language: en-us, en
User-Agent: Mozilla Thunderbird 1.0.6 (X11/20050726)
References: <007801c5d913$018d2340$1e21100a@ghwk02002147>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.144 required=5 tests=[AWL=0.144]
X-Spam-Level: 
X-Archive-Number: 200510/349
X-Sequence-Number: 15117

Christian Paul B. Cosinas wrote:
> Hi mark
> 
> I have so many functions, more than 100 functions in the database :) And I
> am dealing about 3 million of records in one database.
> And about 100 databases :)
> 

LOL - sorry, mis-understood your previous message to mean you had 
identified *one* query where 'fetch all' was causing the problem!

Having said that, to make much more progress, you probably want to 
identify those queries that are consuming your resource, pick one of two 
of the particularly bad ones and post 'em.

There are a number of ways to perform said identification, enabling 
stats collection might be worth a try.

regards

Mark


From pgsql-performance-owner@postgresql.org  Tue Oct 25 04:24:07 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 83349DADCB
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 04:24:06 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 26255-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 07:24:02 +0000 (GMT)
Received: from mailer.eglobalreach.net (cybees.com [202.124.128.22])
	by svr1.postgresql.org (Postfix) with ESMTP id E55AFDADC3
	for <pgsql-performance@postgresql.org>;
	Tue, 25 Oct 2005 04:24:02 -0300 (ADT)
Received: from ghwk02002147 (localhost [127.0.0.1] (may be forged))
	by mailer.eglobalreach.net (8.11.6p2/) with ESMTP id j9P7O3U31211
	for <pgsql-performance@postgresql.org>; Tue, 25 Oct 2005 15:24:03 +0800
From: "Christian Paul B. Cosinas" <cpc@cybees.com>
To: <pgsql-performance@postgresql.org>
Subject: Temporary Table
Date: Tue, 25 Oct 2005 07:28:15 -0000
Message-ID: <001201c5d935$aa544270$1e21100a@ghwk02002147>
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="----=_NextPart_000_0013_01C5D935.AA55C910"
X-Mailer: Microsoft Office Outlook 11
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506
Thread-Index: AcXWVwx9TKFORE3pS6yM9N43/8G7SwB5T9QAAAEl7OAAPS8/0A==
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.68 required=5 tests=[AWL=-0.000,
	FORGED_RCVD_HELO=0.05, HTML_MESSAGE=0.001, URIBL_SBL=0.629]
X-Spam-Level: 
X-Archive-Number: 200510/350
X-Sequence-Number: 15118

This is a multi-part message in MIME format.

------=_NextPart_000_0013_01C5D935.AA55C910
Content-Type: text/plain;
	charset="US-ASCII"
Content-Transfer-Encoding: 7bit

Does Creating Temporary table in a function and NOT dropping them affects
the performance of the database?

 



I choose Polesoft Lockspam to fight spam, and you?
http://www.polesoft.com/refer.html

------=_NextPart_000_0013_01C5D935.AA55C910
Content-Type: text/html;
	charset="US-ASCII"
Content-Transfer-Encoding: quoted-printable

<html xmlns:o=3D"urn:schemas-microsoft-com:office:office" =
xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns=3D"http://www.w3.org/TR/REC-html40">

<head>

<meta name=3DGenerator content=3D"Microsoft Word 11 (filtered medium)">
<style>
<!--
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0pt;
	margin-bottom:.0001pt;
	font-size:12.0pt;
	font-family:"Times New Roman";}
a:link, span.MsoHyperlink
	{color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{color:purple;
	text-decoration:underline;}
span.EmailStyle17
	{mso-style-type:personal;
	font-family:Arial;
	color:navy;}
span.EmailStyle18
	{mso-style-type:personal;
	font-family:Arial;
	color:navy;}
span.EmailStyle19
	{mso-style-type:personal-reply;
	font-family:Arial;
	color:navy;}
@page Section1
	{size:612.0pt 792.0pt;
	margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
	{page:Section1;}
-->
</style>

</head>

<body lang=3DEN-US link=3Dblue vlink=3Dpurple>

<div class=3DSection1>

<p class=3DMsoNormal style=3D'text-autospace:none'><font size=3D2 =
face=3D"Courier New"><span
style=3D'font-size:10.0pt;font-family:"Courier New"'>Does Creating =
Temporary table
in a function and NOT dropping them affects the performance of the =
database?<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

</div>

<BR>
<BR>
I choose Polesoft Lockspam to fight spam, and you?<BR>
<A HREF=3D"http://www.polesoft.com/refer.html" =
TARGET=3D"_blank">http://www.polesoft.com/refer.html</A></body>

</html>

------=_NextPart_000_0013_01C5D935.AA55C910--


From pgsql-performance-owner@postgresql.org  Tue Oct 25 04:24:42 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 4D008DADA7
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 04:24:41 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 27693-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 07:24:38 +0000 (GMT)
Received: from mailer.eglobalreach.net (cybees.com [202.124.128.22])
	by svr1.postgresql.org (Postfix) with ESMTP id CD3C4DADC8
	for <pgsql-performance@postgresql.org>;
	Tue, 25 Oct 2005 04:24:38 -0300 (ADT)
Received: from ghwk02002147 (localhost [127.0.0.1] (may be forged))
	by mailer.eglobalreach.net (8.11.6p2/) with ESMTP id j9P7OdO25014
	for <pgsql-performance@postgresql.org>; Tue, 25 Oct 2005 15:24:39 +0800
From: "Christian Paul B. Cosinas" <cpc@cybees.com>
To: <pgsql-performance@postgresql.org>
Subject: FW: Used Memory
Date: Tue, 25 Oct 2005 07:28:51 -0000
Message-ID: <001701c5d935$bfc21970$1e21100a@ghwk02002147>
MIME-Version: 1.0
Content-Type: text/plain;
	charset="US-ASCII"
Content-Transfer-Encoding: 7bit
X-Mailer: Microsoft Office Outlook 11
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506
Thread-Index: AcXYSRQEEzZVhwc+RZSn0P4xxglPcQAA3w8wADpH21A=
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.679 required=5 tests=[AWL=0.000,
	FORGED_RCVD_HELO=0.05, URIBL_SBL=0.629]
X-Spam-Level: 
X-Archive-Number: 200510/351
X-Sequence-Number: 15119


Here are the configuration of our database server:
	port = 5432
	max_connections = 300
	superuser_reserved_connections = 10
	authentication_timeout = 60	
	shared_buffers = 48000   
	sort_mem = 32168
	sync = false

Do you think this is enough? Or can you recommend a better configuration for
my server?

The server is also running PHP and Apache but wer'e not using it
extensively. For development purpose only. 

The database slow down is occurring most of the time (when the memory free
is low) I don't think it has something to do with vacuum. We only have a
full server vacuum once a day.



I choose Polesoft Lockspam to fight spam, and you?
http://www.polesoft.com/refer.html    


From pgsql-performance-owner@postgresql.org  Tue Oct 25 05:47:59 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 12CDDDA9FF
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 05:47:58 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 44602-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 08:47:54 +0000 (GMT)
Received: from zproxy.gmail.com (zproxy.gmail.com [64.233.162.206])
	by svr1.postgresql.org (Postfix) with ESMTP id CF446DA9F0
	for <pgsql-performance@postgresql.org>;
	Tue, 25 Oct 2005 05:47:55 -0300 (ADT)
Received: by zproxy.gmail.com with SMTP id x7so208267nzc
	for <pgsql-performance@postgresql.org>;
	Tue, 25 Oct 2005 01:47:57 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:to:subject:mime-version:content-type;
	b=JNZ3TY7anDsYIheNKtyO0Ip0k0xPnYuLNg9YSwQRGSU7v810FnUpYQ/2FIwXaHPHjRGBdlUlkoUCXay/dW0Sj7JbhpmNqjFGyxNNeG1LBv+gmsrbFjVT0fG7fOaIy0PWbRaemERR2M1ubOKoyXEiI4X5wCBRPVFj9tCZoU8ewDg=
Received: by 10.36.65.7 with SMTP id n7mr4613937nza;
	Tue, 25 Oct 2005 01:47:57 -0700 (PDT)
Received: by 10.36.61.1 with HTTP; Tue, 25 Oct 2005 01:47:57 -0700 (PDT)
Message-ID: <42567e060510250147j582ce648p3ceef8e4376975be@mail.gmail.com>
Date: Tue, 25 Oct 2005 14:17:57 +0530
From: Kishore B <kishorebh@gmail.com>
To: pgsql-performance@postgresql.org
Subject: Why Index is not working on date columns.
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="----=_Part_3017_160846.1130230077720"
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.308 required=5 tests=[AWL=0.227, HTML_30_40=0.056,
	HTML_MESSAGE=0.001, RCVD_BY_IP=0.024]
X-Spam-Level: 
X-Archive-Number: 200510/352
X-Sequence-Number: 15120

------=_Part_3017_160846.1130230077720
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Hi All,
 Thank you very much for your help in configuring the database.
 Can you guys please take a look at the following query and let me know why
the index is not considered in the plan?
 Here is the extract of the condition string of the query that is taking th=
e
transaction_date in index condition:
 *where (account.id <http://account.id> =3D search_engine.account_fk) and (
account.status =3D 't' and account.id <http://account.id> =3D
'40288a820726362f0107263c55d00003') and ( search_engine.id =3D
conversion.search_engine_fk and conversion.event_type =3D'daily_spend' and
conversion.tactic =3D 'PPC' and conversion.transaction_date between
'2005-01-01 00:00:00' and '2005-10-31 23:59:59') group by
account.id<http://account.id>
;
*
Plan:
*" -> Index Scan using conversion_all on "conversion"
(cost=3D0.00..6.02rows=3D1 width=3D98)"
" Index Cond: (((tactic)::text =3D 'PPC'::text) AND ((event_type)::text =3D
'daily_spend'::text) AND (transaction_date >=3D '2005-01-01
00:00:00'::timestamp without time zone) AND (transaction_date <=3D '2005-10=
-31
23:59:59'::timestamp without time zon (..)"
*
 Here is the extract of the condition string of the query that is not takin=
g
the transaction_date in index condition:
**
where ( account.status =3D 't' and account.id <http://account.id> =3D
search_engine.account_fk and account.id <http://account.id> =3D
'40288a820726362f0107263c55d00003' ) and ( search_engine.id =3D
conversion.search_engine_fk and conversion.tactic =3D 'PPC' and
conversion.transaction_date >=3D '2005-01-01 00:00:00' and
conversion.transaction_date <=3D '2005-10-31 23:59:59' ) group by
account.id<http://account.id>
;
 *Plan:*
*" -> Index Scan using conv_evnt_tact_trans_date_sefk on "conversion" (cost=
=3D
0.00..6.02 rows=3D1 width=3D132)"
" Index Cond: ((("outer".id)::text =3D ("conversion".search_engine_fk)::tex=
t)
AND (("conversion".tactic)::text =3D 'PPC'::text))"
" Filter: ((transaction_date >=3D '2005-01-01 00:00:00'::timestamp without
time zone) AND (transaction_date <=3D '2005-10-31 23:59:59'::timestamp with=
out
time zone))"
*
**
I have the following indexes defined on the columns.
*conv_evnt_tact_trans_date_sefk : (search_engine_fk, tactic, event_type,
transaction_date);*
*conv_all : (tactic, event_type, transaction_date);*
**
I am really confused when I saw this plan. In both queries, I am using the
same columns in the where condition, but the optimizer is taking different
indexes in these two cases.
Second, even though, I have the transaction_date column specified in the
second instance, why is it not taking the constraint as index condition?
 Thanks in advance.
 Thank you,
Kishore.

------=_Part_3017_160846.1130230077720
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

<div>Hi All, </div>
<div>&nbsp;</div>
<div>Thank you very much for your help in configuring the database.</div>
<div>&nbsp;</div>
<div>Can you guys please take a look at the following query and&nbsp;let me=
&nbsp;know why the index is not considered in the plan?</div>
<div>&nbsp;</div>
<div>Here is the extract of the condition string of the query that is takin=
g the transaction_date in index condition:</div>
<div>&nbsp;</div>
<div><em>where (<a href=3D"http://account.id">account.id</a> =3D search_eng=
ine.account_fk) and ( account.status =3D 't' and <a href=3D"http://account.=
id">account.id</a> =3D '40288a820726362f0107263c55d00003') and (&nbsp; sear=
ch_engine.id =3D=20
conversion.search_engine_fk&nbsp;&nbsp; and conversion.event_type =3D'daily=
_spend' and conversion.tactic =3D 'PPC' and conversion.transaction_date bet=
ween '2005-01-01 00:00:00' and '2005-10-31 23:59:59') group by <a href=3D"h=
ttp://account.id">
account.id</a>;<br></em></div>
<div>Plan:</div>
<div><em>&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&gt;&nbsp; Index=
 Scan using conversion_all on &quot;conversion&quot;&nbsp; (cost=3D0.00..6.=
02 rows=3D1 width=3D98)&quot;<br>&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Index Cond: (((tactic)::text =3D=
 'PPC'::text) AND ((event_type)::text =3D 'daily_spend'::text) AND (transac=
tion_date &gt;=3D '2005-01-01 00:00:00'::timestamp without time zone) AND (=
transaction_date &lt;=3D '2005-10-31 23:59:59'::timestamp without time zon =
(..)&quot;
<br></em></div>
<div>
<div>Here is the extract of the condition string of the query that is not &=
nbsp;taking the transaction_date in index condition:</div></div>
<div><strong></strong>&nbsp;</div>
<div>where ( account.status =3D 't' and <a href=3D"http://account.id">accou=
nt.id</a>&nbsp; =3D search_engine.account_fk and <a href=3D"http://account.=
id">account.id</a> =3D '40288a820726362f0107263c55d00003' ) and (&nbsp; sea=
rch_engine.id =3D=20
conversion.search_engine_fk&nbsp;&nbsp; and conversion.tactic =3D 'PPC' and=
 conversion.transaction_date &gt;=3D '2005-01-01 00:00:00' and conversion.t=
ransaction_date &lt;=3D '2005-10-31 23:59:59'&nbsp; ) group by <a href=3D"h=
ttp://account.id">account.id
</a>;<br>&nbsp;</div>
<div><strong>Plan:</strong></div>
<div><em>&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&gt;&nbsp; Index=
 Scan using conv_evnt_tact_trans_date_sefk on &quot;conversion&quot;&nbsp; =
(cost=3D0.00..6.02 rows=3D1 width=3D132)&quot;<br>&quot;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Index Cond: (((=
&quot;outer&quot;.id)::text =3D (&quot;conversion&quot;.search_engine_fk)::=
text) AND ((&quot;conversion&quot;.tactic)::text =3D 'PPC'::text))&quot;
<br>&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp; Filter: ((transaction_date &gt;=3D '2005-01-01 00:00:00'::tim=
estamp without time zone) AND (transaction_date &lt;=3D '2005-10-31 23:59:5=
9'::timestamp without time zone))&quot;<br></em></div>
<div><em></em>&nbsp;</div>
<div>I have the following indexes defined on the columns.</div>
<div><em><em>conv_evnt_tact_trans_date_sefk : </em>(search_engine_fk, tacti=
c, event_type, transaction_date);</em></div>
<div><em>conv_all : (tactic, event_type, transaction_date);</em></div>
<div><em></em>&nbsp;</div>
<div>I am really confused when I saw this plan. In both queries, I am using=
 the same columns in the where condition, but the optimizer is taking diffe=
rent indexes in these two cases.</div>
<div>Second, even though, I have the transaction_date column specified in t=
he second instance, why is it not taking the constraint as index condition?=
</div>
<div>&nbsp;</div>
<div>Thanks in advance.</div>
<div>&nbsp;</div>
<div>Thank you,</div>
<div>Kishore.</div>

------=_Part_3017_160846.1130230077720--

From pgsql-performance-owner@postgresql.org  Tue Oct 25 06:48:06 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 1FCC6DA928
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 06:48:05 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 59986-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 09:48:00 +0000 (GMT)
Received: from smtpgw.computec.de (unknown [212.123.108.8])
	by svr1.postgresql.org (Postfix) with ESMTP id 6142DDA7BD
	for <pgsql-performance@postgresql.org>;
	Tue, 25 Oct 2005 06:48:00 -0300 (ADT)
Received: from localhost (localhost.localdomain [127.0.0.1])
	by smtpgw.computec.de (Postfix) with ESMTP id 2E88E2EBD0
	for <pgsql-performance@postgresql.org>;
	Tue, 25 Oct 2005 11:48:02 +0200 (CEST)
Received: from smtpgw.computec.de ([127.0.0.1])
	by localhost (localhost [127.0.0.1]) (amavisd-new, port 10024)
	with LMTP id 28607-01-69 for <pgsql-performance@postgresql.org>;
	Tue, 25 Oct 2005 11:48:01 +0200 (CEST)
Received: from dozer.computec.de (dozer.computec.de [192.168.0.12])
	by smtpgw.computec.de (Postfix) with ESMTP id 8DE522EBCE
	for <pgsql-performance@postgresql.org>;
	Tue, 25 Oct 2005 11:48:01 +0200 (CEST)
content-class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Subject: Strange planner decision on quite simple select
X-MimeOLE: Produced By Microsoft Exchange V6.0.6487.1
Date: Tue, 25 Oct 2005 11:47:57 +0200
Message-ID: <2266D0630E43BB4290742247C891057508383E8E@dozer.computec.de>
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
Thread-Topic: Strange planner decision on quite simple select
Thread-Index: AcXZSSma/jO6RtGvSNKdIj7JoSPZIQ==
From: "Markus Wollny" <Markus.Wollny@computec.de>
To: <pgsql-performance@postgresql.org>
X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at computec.de
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=1.265 required=5 tests=[AWL=-0.485,
	DNS_FROM_RFC_ABUSE=0.374, DNS_FROM_RFC_POST=1.376]
X-Spam-Level: *
X-Archive-Number: 200510/353
X-Sequence-Number: 15121

Hello!

I've got a table BOARD_MESSAGE (message_id int8, thread_id int8, ...)
with pk on message_id and and a non_unique not_null index on thread_id.
A count(*) on BOARD_MESSAGE currently yields a total of 1231171 rows,
the planner estimated a total of 1232530 rows in this table. I've got
pg_autovacuum running on the database and run an additional nightly
VACUUM ANALYZE over it every night.

I've got a few queries of the following type:

select          *=20
                                from PUBLIC.BOARD_MESSAGE=20
                                where THREAD_ID =3D 3354253=20
                                order by        MESSAGE_ID asc=20
                                limit           20=20
                                offset          0;=20


There are currently roughly 4500 rows with this thread_id in
BOARD_MESSAGE. Explain-output is like so:

                                                      QUERY PLAN=20

------------------------------------------------------------------------
----------------------------------------------=20
 Limit  (cost=3D0.00..3927.22 rows=3D20 width=3D1148)=20
   ->  Index Scan using pk_board_message on board_message
(cost=3D0.00..1100800.55 rows=3D5606 width=3D1148)=20
         Filter: (thread_id =3D 3354253)=20
(3 rows)=20

I didn't have the patience to actually complete an explain analyze on
that one - I cancelled the query on several attempts after more than 40
minutes runtime. Now I fiddled a little with this statement and tried
nudging the planner in the right direction like so:

explain analyze select * from (select          *=20
                                from PUBLIC.BOARD_MESSAGE=20
                                where THREAD_ID =3D 3354253=20
                                order by        MESSAGE_ID asc ) as foo=20
                                limit           20=20
                                offset          0;=20
=20
QUERY PLAN


------------------------------------------------------------------------
------------------------------------------------------------------------
-------------------------

 Limit  (cost=3D8083.59..8083.84 rows=3D20 width=3D464) (actual
time=3D1497.455..1498.466 rows=3D20 loops=3D1)=20
   ->  Subquery Scan foo  (cost=3D8083.59..8153.67 rows=3D5606 =
width=3D464)
(actual time=3D1497.447..1498.408 rows=3D20 loops=3D1)=20
         ->  Sort  (cost=3D8083.59..8097.61 rows=3D5606 width=3D1148) =
(actual
time=3D1497.326..1497.353 rows=3D20 loops=3D1)=20
               Sort Key: message_id=20
               ->  Index Scan using nidx_bm_thread_id on board_message
(cost=3D0.00..7734.54 rows=3D5606 width=3D1148) (actual =
time=3D0.283..1431.752
rows=3D4215 loops=3D1)

                     Index Cond: (thread_id =3D 3354253)=20
 Total runtime: 1502.138 ms=20

Now this is much more like it. As far as I interpret the explain output,
in the former case the planner decides to just sort the whole table with
it's 1.2m rows by it's primary key on message_id and then filters out
the few thousand rows matching the requested thread_id. In the latter
case, it selects the few thousand rows with the matching thread_id
_first_ and _then_ sorts them according to their message_id. The former
attempt involves sorting of more than a million rows and then filtering
through the result, the latter just uses the index to retrieve a few
thousand rows and sorts those - which is much more efficient.

What's more puzzling is that the results vary somewhat depending on the
overall load situation. When using the first approach without the
subselect, sometimes the planner chooses exactly the same plan as it
does with the second approach - with equally satisfying results in
regard to total execution time; sometimes it does use the first plan and
does complete with a very acceptable execution time, too. But sometimes
(when overall load is sufficiently high, I presume) it just runs and
runs for minutes on end - I've had this thing running for more than one
hour on several occasions until I made some changes to my app which
limits the maximum execution time for a query to no more than 55
seconds.

With this IMHO quite ugly subselect-workaround, performance is
reproducably stable and sufficiently good under either load, so I chose
to stick with it for the time being - but I'd still like to know if I
could have done anything to have the planner choose the evidently better
plan for the first query without such a workaround?

Kind regards

   Markus

From pgsql-performance-owner@postgresql.org  Tue Oct 25 07:10:24 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id F3D37DAB20
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 07:10:23 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 63263-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 10:10:20 +0000 (GMT)
Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75])
	by svr1.postgresql.org (Postfix) with ESMTP id 92C03DA9E5
	for <pgsql-performance@postgresql.org>;
	Tue, 25 Oct 2005 07:10:21 -0300 (ADT)
Received: from mainbox.archonet.com
	(84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99])
	by smtp.metronet.co.uk (MetroNet Mail) with ESMTP
	id AE51B415C17; Tue, 25 Oct 2005 11:10:15 +0100 (BST)
Received: from localhost (localhost.localdomain [127.0.0.1])
	by mainbox.archonet.com (Postfix) with ESMTP id EC23315EDA;
	Tue, 25 Oct 2005 11:07:32 +0100 (BST)
Received: from mainbox.archonet.com ([127.0.0.1])
	by localhost (mainbox [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 05323-01; Tue, 25 Oct 2005 11:07:28 +0100 (BST)
Received: from [192.168.1.17] (client17.office.archonet.com [192.168.1.17])
	by mainbox.archonet.com (Postfix) with ESMTP id A0FB015ED5;
	Tue, 25 Oct 2005 11:07:28 +0100 (BST)
Message-ID: <435E03E0.2040107@archonet.com>
Date: Tue, 25 Oct 2005 11:07:28 +0100
From: Richard Huxton <dev@archonet.com>
User-Agent: Mozilla Thunderbird 1.0.7 (X11/20051013)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: Markus Wollny <Markus.Wollny@computec.de>
Cc: pgsql-performance@postgresql.org
Subject: Re: Strange planner decision on quite simple select
References: <2266D0630E43BB4290742247C891057508383E8E@dozer.computec.de>
In-Reply-To: <2266D0630E43BB4290742247C891057508383E8E@dozer.computec.de>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.059 required=5 tests=[AWL=0.009,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/354
X-Sequence-Number: 15122

Markus Wollny wrote:
> Hello!
> 
> I've got a table BOARD_MESSAGE (message_id int8, thread_id int8, ...)
> with pk on message_id and and a non_unique not_null index on thread_id.
> A count(*) on BOARD_MESSAGE currently yields a total of 1231171 rows,
> the planner estimated a total of 1232530 rows in this table. I've got
> pg_autovacuum running on the database and run an additional nightly
> VACUUM ANALYZE over it every night.
> 
> I've got a few queries of the following type:
> 
> select          * 
>                                 from PUBLIC.BOARD_MESSAGE 
>                                 where THREAD_ID = 3354253 
>                                 order by        MESSAGE_ID asc 
>                                 limit           20 
>                                 offset          0; 
> 
> 
> There are currently roughly 4500 rows with this thread_id in
> BOARD_MESSAGE. Explain-output is like so:
> 
>                                                       QUERY PLAN 
> 
> ------------------------------------------------------------------------
> ---------------------------------------------- 
>  Limit  (cost=0.00..3927.22 rows=20 width=1148) 
>    ->  Index Scan using pk_board_message on board_message
> (cost=0.00..1100800.55 rows=5606 width=1148) 
>          Filter: (thread_id = 3354253) 
> (3 rows) 
> 
> I didn't have the patience to actually complete an explain analyze on
> that one - I cancelled the query on several attempts after more than 40
> minutes runtime. Now I fiddled a little with this statement and tried
> nudging the planner in the right direction like so:

Hmm - it shouldn't take that long. If I'm reading this right, it's 
expecting to have to fetch 5606 rows to match thread_id=3354253 the 20 
times you've asked for. Now, what it probably doesn't know is that 
thread_id is correlated with message_id quite highly (actually, I don't 
know that, I'm guessing). So - it starts at message_id=1 and works 
along, but I'm figuring that it needs to reach message_id's in the 3-4 
million range to see any of the required thread.

Suggestions:
1. Try "ORDER BY thread_id,message_id" and see if that nudges things 
your way.
2. Keep #1 and try replacing the index on (thread_id) with 
(thread_id,message_id)

--
   Richard Huxton
   Archonet Ltd

From pgsql-performance-owner@postgresql.org  Tue Oct 25 08:35:08 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 5AEF4DAC90
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 08:35:06 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 91521-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 11:35:02 +0000 (GMT)
Received: from europa.cosmos.opusvl.com (europa.cosmos.opusvl.com
	[213.106.249.125])
	by svr1.postgresql.org (Postfix) with ESMTP id 28CB1DAC6B
	for <pgsql-performance@postgresql.org>;
	Tue, 25 Oct 2005 08:35:04 -0300 (ADT)
Received: from localhost.localdomain ([127.0.0.1])
	by europa.cosmos.opusvl.com with esmtp (Exim 4.30)
	id 1EUN58-0003xi-Eh
	for pgsql-performance@postgresql.org; Tue, 25 Oct 2005 12:35:06 +0100
Message-ID: <435E186A.3060003@opusvl.com>
Date: Tue, 25 Oct 2005 12:35:06 +0100
From: Rich Doughty <rich@opusvl.com>
Organization: Opus VL
User-Agent: Mozilla Thunderbird 1.0.2 (X11/20050317)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: pgsql-performance@postgresql.org
Subject: Outer join query plans and performance
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0 required=5 tests=[none]
X-Spam-Level: 
X-Archive-Number: 200510/355
X-Sequence-Number: 15123

I tried on pgsql-general but got no reply. re-posting here as it's
probably the best place to ask

I'm having some significant performance problems with left join. Can
anyone give me any pointers as to why the following 2 query plans are so
different?


EXPLAIN SELECT *
FROM
     tokens.ta_tokens      t  LEFT JOIN
     tokens.ta_tokenhist   h1 ON t.token_id = h1.token_id LEFT JOIN
     tokens.ta_tokenhist   h2 ON t.token_id = h2.token_id
WHERE
     h1.histdate = 'now';


  Nested Loop Left Join  (cost=0.00..68778.43 rows=2215 width=1402)
    ->  Nested Loop  (cost=0.00..55505.62 rows=2215 width=714)
          ->  Index Scan using idx_tokenhist__histdate on ta_tokenhist h1  (cost=0.00..22970.70 rows=5752 width=688)
                Index Cond: (histdate = '2005-10-24 13:28:38.411844'::timestamp without time zone)
          ->  Index Scan using ta_tokens_pkey on ta_tokens t  (cost=0.00..5.64 rows=1 width=26)
                Index Cond: ((t.token_id)::integer = ("outer".token_id)::integer)
    ->  Index Scan using fkx_tokenhist__tokens on ta_tokenhist h2  (cost=0.00..5.98 rows=1 width=688)
          Index Cond: (("outer".token_id)::integer = (h2.token_id)::integer)


Performance is fine for this one and the plan is pretty much as i'd
expect.

This is where i hit a problem.


EXPLAIN SELECT *
FROM
     tokens.ta_tokens      t  LEFT JOIN
     tokens.ta_tokenhist   h1 ON t.token_id = h1.token_id LEFT JOIN
     tokens.ta_tokenhist   h2 ON t.token_id = h2.token_id
WHERE
     h2.histdate = 'now';


  Hash Join  (cost=1249148.59..9000709.22 rows=2215 width=1402)
    Hash Cond: (("outer".token_id)::integer = ("inner".token_id)::integer)
    ->  Hash Left Join  (cost=1225660.51..8181263.40 rows=4045106 width=714)
          Hash Cond: (("outer".token_id)::integer = ("inner".token_id)::integer)
          ->  Seq Scan on ta_tokens t  (cost=0.00..71828.06 rows=4045106 width=26)
          ->  Hash  (cost=281243.21..281243.21 rows=10504921 width=688)
                ->  Seq Scan on ta_tokenhist h1  (cost=0.00..281243.21 rows=10504921 width=688)
    ->  Hash  (cost=22970.70..22970.70 rows=5752 width=688)
          ->  Index Scan using idx_tokenhist__histdate on ta_tokenhist h2  (cost=0.00..22970.70 rows=5752 width=688)
                Index Cond: (histdate = '2005-10-24 13:34:51.371905'::timestamp without time zone)


I would understand if h2 was joined on h1, but it isn't. It only joins
on t. can anyone give any tips on improving the performance of the second
query (aside from changing the join order manually)?


select version();
                                                    version
--------------------------------------------------------------------------------------------------------------
  PostgreSQL 8.0.3 on i486-pc-linux-gnu, compiled by GCC cc (GCC) 4.0.2 20050821 (prerelease) (Debian 4.0.1-6)


Thanks

-- 

   - Rich Doughty

From pgsql-performance-owner@postgresql.org  Tue Oct 25 10:38:35 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 2DA7FDADB4
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 10:38:34 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 31260-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 13:38:30 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id DB38BDADA4
	for <pgsql-performance@postgresql.org>;
	Tue, 25 Oct 2005 10:38:31 -0300 (ADT)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j9PDcZFZ013280;
	Tue, 25 Oct 2005 09:38:35 -0400 (EDT)
To: Kishore B <kishorebh@gmail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Why Index is not working on date columns. 
In-reply-to: <42567e060510250147j582ce648p3ceef8e4376975be@mail.gmail.com> 
References: <42567e060510250147j582ce648p3ceef8e4376975be@mail.gmail.com>
Comments: In-reply-to Kishore B <kishorebh@gmail.com>
	message dated "Tue, 25 Oct 2005 14:17:57 +0530"
Date: Tue, 25 Oct 2005 09:38:35 -0400
Message-ID: <13279.1130247515@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/356
X-Sequence-Number: 15124

Kishore B <kishorebh@gmail.com> writes:
>  Can you guys please take a look at the following query and let me know why
> the index is not considered in the plan?

"Considered" and "used" are two different things.

The two examples you give have the same estimated cost (within two
decimal places) so the planner sees no particular reason to choose one
over the other.

I surmise that you are testing on toy tables and extrapolating to what
will happen on larger tables.  This is an unjustified assumption.
Create a realistic test data set, ANALYZE it, and then see if the
planner chooses indexes you like.

			regards, tom lane

From pgsql-performance-owner@postgresql.org  Tue Oct 25 10:44:12 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 1EC11DAC33
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 10:44:11 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 32471-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 13:44:07 +0000 (GMT)
Received: from smtpgw.computec.de (unknown [212.123.108.8])
	by svr1.postgresql.org (Postfix) with ESMTP id 0B4ADD6EE1
	for <pgsql-performance@postgresql.org>;
	Tue, 25 Oct 2005 10:44:08 -0300 (ADT)
Received: from localhost (localhost.localdomain [127.0.0.1])
	by smtpgw.computec.de (Postfix) with ESMTP id 81EE02EBD3;
	Tue, 25 Oct 2005 15:44:12 +0200 (CEST)
Received: from smtpgw.computec.de ([127.0.0.1])
	by localhost (localhost [127.0.0.1]) (amavisd-new, port 10024)
	with LMTP id 00321-01-3; Tue, 25 Oct 2005 15:44:12 +0200 (CEST)
Received: from dozer.computec.de (dozer.computec.de [192.168.0.12])
	by smtpgw.computec.de (Postfix) with ESMTP id 18C2F2EBD1;
	Tue, 25 Oct 2005 15:44:12 +0200 (CEST)
content-class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Subject: Re: Strange planner decision on quite simple select
X-MimeOLE: Produced By Microsoft Exchange V6.0.6487.1
Date: Tue, 25 Oct 2005 15:39:42 +0200
Message-ID: <2266D0630E43BB4290742247C891057508384067@dozer.computec.de>
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
Thread-Topic: [PERFORM] Strange planner decision on quite simple select
Thread-Index: AcXZUTbjjgZt/9KXSOCcCZWVhDGz9AAFmOyA
From: "Markus Wollny" <Markus.Wollny@computec.de>
To: "Richard Huxton" <dev@archonet.com>
Cc: <pgsql-performance@postgresql.org>
X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at computec.de
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=1.267 required=5 tests=[AWL=-0.483,
	DNS_FROM_RFC_ABUSE=0.374, DNS_FROM_RFC_POST=1.376]
X-Spam-Level: *
X-Archive-Number: 200510/357
X-Sequence-Number: 15125

=20
Hi!

> -----Urspr=FCngliche Nachricht-----
> Von: pgsql-performance-owner@postgresql.org=20
> [mailto:pgsql-performance-owner@postgresql.org] Im Auftrag=20
> von Richard Huxton
> Gesendet: Dienstag, 25. Oktober 2005 12:07
> An: Markus Wollny
> Cc: pgsql-performance@postgresql.org
> Betreff: Re: [PERFORM] Strange planner decision on quite simple select
>=20
> Hmm - it shouldn't take that long. If I'm reading this right,=20
> it's expecting to have to fetch 5606 rows to match=20
> thread_id=3D3354253 the 20 times you've asked for. Now, what it=20
> probably doesn't know is that thread_id is correlated with=20
> message_id quite highly (actually, I don't know that, I'm=20
> guessing). So - it starts at message_id=3D1 and works along,=20
> but I'm figuring that it needs to reach message_id's in the=20
> 3-4 million range to see any of the required thread.

Reading this I tried with adding a "AND MESSAGE_ID >=3D THREAD_ID" to =
the WHERE-clause, as you've guessed quite correctly, both message_id and =
thread_id are derived from the same sequence and thread_id equals the =
lowest message_id in a thread. This alone did quite a lot to improve =
things - I got stable executing times down from an average 12 seconds to =
a mere 2 seconds - just about the same as with the subselect.

> Suggestions:
> 1. Try "ORDER BY thread_id,message_id" and see if that nudges=20
> things your way.
> 2. Keep #1 and try replacing the index on (thread_id) with
> (thread_id,message_id)

Did both (though adding such an index during ordinary workload took some =
time as did the VACUUM ANALYZE afterwards) and that worked like a charm =
- I've got execution times down to as little as a few milliseconds - =
wow! Thank you very much for providing such insightful hints!

Kind regards

   Markus

From pgsql-performance-owner@postgresql.org  Tue Oct 25 10:49:19 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 384B4DAE1A
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 10:49:18 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 33853-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 13:49:12 +0000 (GMT)
Received: from my.endian.it (unknown [62.146.87.34])
	by svr1.postgresql.org (Postfix) with ESMTP id 407F3DAE32
	for <pgsql-performance@postgresql.org>;
	Tue, 25 Oct 2005 10:49:13 -0300 (ADT)
Received: from 1006.org (localhost.localdomain [127.0.0.1])
	by my.endian.it (8.11.6/8.11.6) with SMTP id j9PDiac11365
	for <pgsql-performance@postgresql.org>; Tue, 25 Oct 2005 15:44:36 +0200
Received: from unibz.it ([193.206.186.101])
	(SquirrelMail authenticated user list@1006.org)
	by www.endian.it with HTTP; Tue, 25 Oct 2005 15:44:36 +0200 (CEST)
Message-ID: <54222.193.206.186.101.1130247876.squirrel@www.endian.it>
Date: Tue, 25 Oct 2005 15:44:36 +0200 (CEST)
Subject: insertion of bytea
From: "Chris Mair" <list@1006.org>
To: <pgsql-performance@postgresql.org>
X-Priority: 3
Importance: Normal
X-MSMail-Priority: Normal
X-Mailer: SquirrelMail (version 1.2.7)
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0 required=5 tests=[none]
X-Spam-Level: 
X-Archive-Number: 200510/358
X-Sequence-Number: 15126

Hi,

I have the following test setup:

* PG 8.0.4 on Linux (Centos 4) compiled from source.

* DB schema: essentially one table with a few int columns and
  one bytea column that stores blobs of 52000 bytes each, a
  primary key on one of the int columns.

* A test client was written in C using libpq to see what rate
  can be reached (inserting records). The client uses a
  prepared tatement and bundles n inserts into a single
  transaction (n is variable for testing).

* Hardware: different setups tested, in particular a
  single-opteron box with a built in SATA disk and also an
  array of SATA disks connected via FC.

 From the test run it appears that the insert rate here is
essentially CPU bound. I'm getting about 11 MB/s net transfer,
regardless if I use the built in disk or the much faster
array and regardless various settings (like n, shared_mem).

vmstat says that disk bo is about 30MB/s (the array can do much
better, I tried with dd and sync!) while the CPU is maxed out
at about 90% us and 10% sy. The client accounts for just 2% CPU,
most goes into the postmaster.

The client inserts random data. I found out that I can improve
things by 35% if I use random sequences of bytes that are
in the printable range vs. full range.


Question 1:
Am I correct in assuming that even though I'm passing my 52000
bytes as a (char *) to PQexecPrepared(), encoding/decoding is
happening (think 0 -> \000) somewhere in the transfer?


Question 2:
Is there a better, faster way to do these inserts?
I'm unsure about large objects. I'm planning to use some
custom server side functions to do computations on the bytes
in these records and the large objects API doesn't appear
to be well suited for this.


Sidequestion:
I've tried to profile the server using CFLAGS="-p -DLINUX_PROFILE".
I'm getting profiling output but when I look at it using
"gprof bin-somewhere/postgres $PGDATA/gmon.out" I'm only seeing
what I think are the calls for the server startup. How can I profile
the (forked) process that actually performs all the work on
my connection?


Sorry for the long post :)
Bye,
Chris.




From pgsql-performance-owner@postgresql.org  Tue Oct 25 10:56:06 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id BBD8CDAD8E
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 10:56:05 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 36718-04
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 13:56:01 +0000 (GMT)
Received: from web31615.mail.mud.yahoo.com (web31615.mail.mud.yahoo.com
	[68.142.198.161])
	by svr1.postgresql.org (Postfix) with SMTP id 842B4DADA0
	for <pgsql-performance@postgresql.org>;
	Tue, 25 Oct 2005 10:56:03 -0300 (ADT)
Received: (qmail 39808 invoked by uid 60001); 25 Oct 2005 13:56:07 -0000
Message-ID: <20051025135607.39805.qmail@web31615.mail.mud.yahoo.com>
Received: from [209.217.70.195] by web31615.mail.mud.yahoo.com via HTTP;
	Tue, 25 Oct 2005 06:56:07 PDT
Date: Tue, 25 Oct 2005 06:56:07 -0700 (PDT)
From: Markus Benne <thing@m-bass.com>
Reply-To: markus@m-bass.com
Subject: Reindex - Is this necessary after a vacuum?
To: pgsql-performance@postgresql.org
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0 required=5 tests=[none]
X-Spam-Level: 
X-Archive-Number: 200510/359
X-Sequence-Number: 15127

We are reindexing frequently, and I'm wondering if
this is really necessary, given that it appears to
take an exclusive lock on the table.

Our table in question is vacuumed every 4 minutes, and
we are reindexing after each one.

I'm not a fan of locking this table that frequently,
even if it is only for 5 - 10 seconds depending on
load.

The vacuum is a standard vacuum.  Nightly we do a
vacuum analyze.

Thanks for any tips,
...Markus

From pgsql-performance-owner@postgresql.org  Tue Oct 25 11:05:51 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 8DEB7DADB4
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 11:05:50 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 45901-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 14:05:44 +0000 (GMT)
Received: from vms042pub.verizon.net (vms042pub.verizon.net [206.46.252.42])
	by svr1.postgresql.org (Postfix) with ESMTP id 10419DAD93
	for <pgsql-performance@postgresql.org>;
	Tue, 25 Oct 2005 11:05:46 -0300 (ADT)
Received: from osgiliath.mathom.us ([70.108.61.78])
	by vms042.mailsrvcs.net (Sun Java System Messaging Server 6.2-4.02
	(built Sep
	9 2005)) with ESMTPA id <0IOX00LHV5TQ1DI0@vms042.mailsrvcs.net> for
	pgsql-performance@postgresql.org; Tue, 25 Oct 2005 09:05:51 -0500 (CDT)
Received: from localhost (localhost [127.0.0.1])
	by osgiliath.mathom.us (Postfix) with ESMTP id BE2586031F0; Tue,
	25 Oct 2005 10:05:49 -0400 (EDT)
Received: from osgiliath.mathom.us ([127.0.0.1])
	by localhost (osgiliath [127.0.0.1]) (amavisd-new, port 10024)
	with LMTP id 30315-01-10; Tue, 25 Oct 2005 10:05:49 -0400 (EDT)
Received: by osgiliath.mathom.us (Postfix, from userid 1000)
	id 9D09B60265F; Tue, 25 Oct 2005 10:05:49 -0400 (EDT)
Date: Tue, 25 Oct 2005 10:05:49 -0400
From: Michael Stone <mstone+postgres@mathom.us>
Subject: Re: insertion of bytea
In-reply-to: <54222.193.206.186.101.1130247876.squirrel@www.endian.it>
To: Chris Mair <list@1006.org>
Cc: pgsql-performance@postgresql.org
Mail-Followup-To: Chris Mair <list@1006.org>, pgsql-performance@postgresql.org
Message-id: <20051025140549.GC17398@mathom.us>
MIME-version: 1.0
Content-type: text/plain; charset=us-ascii; format=flowed
Content-disposition: inline
X-Pgp-Fingerprint: 53 FF 38 00 E7 DD 0A 9C  84 52 84 C5 EE DF 7C 88
X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at mathom.us
References: <54222.193.206.186.101.1130247876.squirrel@www.endian.it>
User-Agent: Mutt/1.5.11
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.003 required=5 tests=[AWL=0.003]
X-Spam-Level: 
X-Archive-Number: 200510/360
X-Sequence-Number: 15128

On Tue, Oct 25, 2005 at 03:44:36PM +0200, Chris Mair wrote:
>Is there a better, faster way to do these inserts?

COPY is generally the fastest way to do bulk inserts (see
PQputCopyData). 

Mike Stone

From pgsql-performance-owner@postgresql.org  Tue Oct 25 11:12:01 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 9981EDAC33
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 11:12:00 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 42050-09
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 14:11:56 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id 9576DDA0DE
	for <pgsql-performance@postgresql.org>;
	Tue, 25 Oct 2005 11:11:58 -0300 (ADT)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j9PEC2ER013680;
	Tue, 25 Oct 2005 10:12:02 -0400 (EDT)
To: Rich Doughty <rich@opusvl.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Outer join query plans and performance 
In-reply-to: <435E186A.3060003@opusvl.com> 
References: <435E186A.3060003@opusvl.com>
Comments: In-reply-to Rich Doughty <rich@opusvl.com>
	message dated "Tue, 25 Oct 2005 12:35:06 +0100"
Date: Tue, 25 Oct 2005 10:12:02 -0400
Message-ID: <13679.1130249522@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/361
X-Sequence-Number: 15129

Rich Doughty <rich@opusvl.com> writes:
> EXPLAIN SELECT *
> FROM
>      tokens.ta_tokens      t  LEFT JOIN
>      tokens.ta_tokenhist   h1 ON t.token_id = h1.token_id LEFT JOIN
>      tokens.ta_tokenhist   h2 ON t.token_id = h2.token_id
> WHERE
>      h1.histdate = 'now';

> EXPLAIN SELECT *
> FROM
>      tokens.ta_tokens      t  LEFT JOIN
>      tokens.ta_tokenhist   h1 ON t.token_id = h1.token_id LEFT JOIN
>      tokens.ta_tokenhist   h2 ON t.token_id = h2.token_id
> WHERE
>      h2.histdate = 'now';

The reason these are different is that the second case constrains only
the last-to-be-joined table, so the full cartesian product of t and h1
has to be formed.  If this wasn't what you had in mind, you might be
able to rearrange the order of the LEFT JOINs, but bear in mind that
in general, changing outer-join ordering changes the results.  (This
is why the planner won't fix it for you.)

			regards, tom lane

From pgsql-performance-owner@postgresql.org  Tue Oct 25 11:20:26 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 0AAD4DAD9F
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 11:20:26 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 46894-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 14:20:21 +0000 (GMT)
Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75])
	by svr1.postgresql.org (Postfix) with ESMTP id 0D8C7DACF5
	for <pgsql-performance@postgresql.org>;
	Tue, 25 Oct 2005 11:20:23 -0300 (ADT)
Received: from mainbox.archonet.com
	(84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99])
	by smtp.metronet.co.uk (MetroNet Mail) with ESMTP
	id 741FB4149E7; Tue, 25 Oct 2005 15:20:17 +0100 (BST)
Received: from localhost (localhost.localdomain [127.0.0.1])
	by mainbox.archonet.com (Postfix) with ESMTP id 8429615EDA;
	Tue, 25 Oct 2005 15:16:31 +0100 (BST)
Received: from mainbox.archonet.com ([127.0.0.1])
	by localhost (mainbox [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 11889-04; Tue, 25 Oct 2005 15:16:27 +0100 (BST)
Received: from [192.168.1.17] (client17.office.archonet.com [192.168.1.17])
	by mainbox.archonet.com (Postfix) with ESMTP id 8C1DA15ED5;
	Tue, 25 Oct 2005 15:16:27 +0100 (BST)
Message-ID: <435E3E3B.1000805@archonet.com>
Date: Tue, 25 Oct 2005 15:16:27 +0100
From: Richard Huxton <dev@archonet.com>
User-Agent: Mozilla Thunderbird 1.0.7 (X11/20051013)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: markus@m-bass.com
Cc: pgsql-performance@postgresql.org
Subject: Re: Reindex - Is this necessary after a vacuum?
References: <20051025135607.39805.qmail@web31615.mail.mud.yahoo.com>
In-Reply-To: <20051025135607.39805.qmail@web31615.mail.mud.yahoo.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.059 required=5 tests=[AWL=0.009,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/362
X-Sequence-Number: 15130

Markus Benne wrote:
> We are reindexing frequently, and I'm wondering if
> this is really necessary, given that it appears to
> take an exclusive lock on the table.
> 
> Our table in question is vacuumed every 4 minutes, and
> we are reindexing after each one.
> 
> I'm not a fan of locking this table that frequently,
> even if it is only for 5 - 10 seconds depending on
> load.
> 
> The vacuum is a standard vacuum.  Nightly we do a
> vacuum analyze.

At most I'd do a nightly reindex. And in fact, I'd probably drop the 
index, full vacuum, recreate index.

But you only need to reindex at all if you have a specific problem with 
the index bloating. Are you seeing this?

-- 
   Richard Huxton
   Archonet Ltd

From pgsql-performance-owner@postgresql.org  Tue Oct 25 11:23:33 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id AC7CDDADBE
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 11:23:32 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 58824-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 14:23:23 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id CD7AFDAD35
	for <pgsql-performance@postgresql.org>;
	Tue, 25 Oct 2005 11:23:17 -0300 (ADT)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j9PENKgp013783;
	Tue, 25 Oct 2005 10:23:20 -0400 (EDT)
To: "Chris Mair" <list@1006.org>
Cc: pgsql-performance@postgresql.org
Subject: Re: insertion of bytea 
In-reply-to: <54222.193.206.186.101.1130247876.squirrel@www.endian.it> 
References: <54222.193.206.186.101.1130247876.squirrel@www.endian.it>
Comments: In-reply-to "Chris Mair" <list@1006.org>
	message dated "Tue, 25 Oct 2005 15:44:36 +0200"
Date: Tue, 25 Oct 2005 10:23:20 -0400
Message-ID: <13782.1130250200@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/363
X-Sequence-Number: 15131

"Chris Mair" <list@1006.org> writes:
> Am I correct in assuming that even though I'm passing my 52000
> bytes as a (char *) to PQexecPrepared(), encoding/decoding is
> happening (think 0 -> \000) somewhere in the transfer?

Are you specifying it as a text or binary parameter?  Have you looked to
see if the stored data is what you expect?

			regards, tom lane

From pgsql-performance-owner@postgresql.org  Tue Oct 25 11:27:09 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id E4CFADAD6C
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 11:27:08 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 59255-07
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 14:27:03 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id 2222BDAD49
	for <pgsql-performance@postgresql.org>;
	Tue, 25 Oct 2005 11:27:04 -0300 (ADT)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j9PER8KK013828;
	Tue, 25 Oct 2005 10:27:09 -0400 (EDT)
To: markus@m-bass.com
Cc: pgsql-performance@postgresql.org
Subject: Re: Reindex - Is this necessary after a vacuum? 
In-reply-to: <20051025135607.39805.qmail@web31615.mail.mud.yahoo.com> 
References: <20051025135607.39805.qmail@web31615.mail.mud.yahoo.com>
Comments: In-reply-to Markus Benne <thing@m-bass.com>
	message dated "Tue, 25 Oct 2005 06:56:07 -0700"
Date: Tue, 25 Oct 2005 10:27:08 -0400
Message-ID: <13827.1130250428@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/364
X-Sequence-Number: 15132

Markus Benne <thing@m-bass.com> writes:
> Our table in question is vacuumed every 4 minutes, and
> we are reindexing after each one.

That's pretty silly.  You might need a reindex once in awhile, but
not every time you vacuum.

The draft 8.1 docs contain some discussion of possible reasons for
periodic reindexing:
http://developer.postgresql.org/docs/postgres/routine-reindex.html
but none of these reasons justify once-per-vacuum reindexes.

			regards, tom lane

From pgsql-performance-owner@postgresql.org  Tue Oct 25 12:04:27 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id EA98BDADE4
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 12:04:24 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 80514-06
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 15:04:23 +0000 (GMT)
Received: from zproxy.gmail.com (zproxy.gmail.com [64.233.162.195])
	by svr1.postgresql.org (Postfix) with ESMTP id B9CC5DAE03
	for <pgsql-performance@postgresql.org>;
	Tue, 25 Oct 2005 12:04:22 -0300 (ADT)
Received: by zproxy.gmail.com with SMTP id x7so258672nzc
	for <pgsql-performance@postgresql.org>;
	Tue, 25 Oct 2005 08:04:21 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references;
	b=WhWHBa1CI9Y11VnF1FPqBCLd7PzrBesu8tZ1n0i7bvfMR4fYQ9z3TyO7VLoBJIzijBF2cJJ/NPuLPqMdfckH5h7QpmXN84LgYK9O7g7LSP5GT5ti2WNoM5NtohMUHBCfsW3vo2AKepXrBXd7ySN+D92O0TjlnCXLR9aSEmUUmQM=
Received: by 10.36.74.8 with SMTP id w8mr4961503nza;
	Tue, 25 Oct 2005 08:04:21 -0700 (PDT)
Received: by 10.36.61.1 with HTTP; Tue, 25 Oct 2005 08:04:21 -0700 (PDT)
Message-ID: <42567e060510250804y3329c901l21770d887dfcde42@mail.gmail.com>
Date: Tue, 25 Oct 2005 20:34:21 +0530
From: Kishore B <kishorebh@gmail.com>
To: pgsql-performance@postgresql.org
Subject: Re: Why Index is not working on date columns.
In-Reply-To: <13279.1130247515@sss.pgh.pa.us>
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="----=_Part_5365_1464850.1130252661870"
References: <42567e060510250147j582ce648p3ceef8e4376975be@mail.gmail.com>
	<13279.1130247515@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.285 required=5 tests=[AWL=0.174, HTML_40_50=0.086,
	HTML_MESSAGE=0.001, RCVD_BY_IP=0.024]
X-Spam-Level: 
X-Archive-Number: 200510/365
X-Sequence-Number: 15133

------=_Part_5365_1464850.1130252661870
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Hi Tom,
 Thank you for your response.

> I surmise that you are testing on toy tables and extrapolating to what
> will happen on larger tables.
>
These tables participating here contain more than 8 million records as of
now, and on every day, 200K records, will add to them.
  Thank you,
Kishore.


 On 10/25/05, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> Kishore B <kishorebh@gmail.com> writes:
> > Can you guys please take a look at the following query and let me know
> why
> > the index is not considered in the plan?
>
> "Considered" and "used" are two different things.
>
> The two examples you give have the same estimated cost (within two
> decimal places) so the planner sees no particular reason to choose one
> over the other.
>
> I surmise that you are testing on toy tables and extrapolating to what
> will happen on larger tables. This is an unjustified assumption.
> Create a realistic test data set, ANALYZE it, and then see if the
> planner chooses indexes you like.
>
> regards, tom lane
>

------=_Part_5365_1464850.1130252661870
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

<div>Hi Tom,</div>
<div>&nbsp;</div>
<div>Thank you for&nbsp;your response.</div>
<div>&nbsp;</div>
<blockquote class=3D"gmail_quote" style=3D"PADDING-LEFT: 1ex; MARGIN: 0px 0=
px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">I surmise that you are testing o=
n toy tables and extrapolating to what<br>will happen on larger tables.&nbs=
p;<br>
</blockquote>
<div>These tables participating here contain more than 8 million records as=
 of now, and on every day, 200K records, will add to them.</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>Thank you,</div>
<div>Kishore.</div>
<p>&nbsp;</p>
<div><br>&nbsp;</div>
<div><span class=3D"gmail_quote">On 10/25/05, <b class=3D"gmail_sendername"=
>Tom Lane</b> &lt;<a href=3D"mailto:tgl@sss.pgh.pa.us">tgl@sss.pgh.pa.us</a=
>&gt; wrote:</span>
<blockquote class=3D"gmail_quote" style=3D"PADDING-LEFT: 1ex; MARGIN: 0px 0=
px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Kishore B &lt;<a href=3D"mailto:=
kishorebh@gmail.com">kishorebh@gmail.com</a>&gt; writes:<br>&gt;&nbsp;&nbsp=
;Can you guys please take a look at the following query and let me know why
<br>&gt; the index is not considered in the plan?<br><br>&quot;Considered&q=
uot; and &quot;used&quot; are two different things.<br><br>The two examples=
 you give have the same estimated cost (within two<br>decimal places) so th=
e planner sees no particular reason to choose one
<br>over the other.<br><br>I surmise that you are testing on toy tables and=
 extrapolating to what<br>will happen on larger tables.&nbsp;&nbsp;This is =
an unjustified assumption.<br>Create a realistic test data set, ANALYZE it,=
 and then see if the
<br>planner chooses indexes you like.<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp; regards, tom lane<br></blockquote></div><br>

------=_Part_5365_1464850.1130252661870--

From pgsql-performance-owner@postgresql.org  Tue Oct 25 13:03:53 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 15211DA7FD
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 13:03:52 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 29493-06
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 16:03:35 +0000 (GMT)
Received: from qproxy.gmail.com (qproxy.gmail.com [72.14.204.195])
	by svr1.postgresql.org (Postfix) with ESMTP id C37ADDACF5
	for <pgsql-performance@postgresql.org>;
	Tue, 25 Oct 2005 13:03:19 -0300 (ADT)
Received: by qproxy.gmail.com with SMTP id v28so521378qbe
	for <pgsql-performance@postgresql.org>;
	Tue, 25 Oct 2005 09:03:19 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references;
	b=l+aX6yYc0ey4AmrPaS8sGd0p96HgpEKWqx4GmHZfQ/YRNigfst7Hm8uMppPejL5vHJSEbflrm/1fy2jzW9QyPKnfndM/Sp3NavnBgPO4k59SLFslVYQKIoUJ+movvX/Rdcby1/+akNzWvvVsN3PbNORX2cUzs/315EDOQ8Wm1/A=
Received: by 10.64.53.20 with SMTP id b20mr1531142qba;
	Tue, 25 Oct 2005 09:03:19 -0700 (PDT)
Received: by 10.65.240.20 with HTTP; Tue, 25 Oct 2005 09:03:19 -0700 (PDT)
Message-ID: <3cf983d0510250903l6eb5b3dfsda46190f3e7fd289@mail.gmail.com>
Date: Tue, 25 Oct 2005 16:03:19 +0000
From: Rodrigo Madera <rodrigo.madera@gmail.com>
To: =?ISO-8859-1?Q?N=F6rder-Tuitje=2C_Marcus?= <noerder-tuitje@technology.de>
Subject: Re: Inefficient escape codes.
Cc: pgsql-performance@postgresql.org
In-Reply-To: 
 <16F953410A0F1346848DCB476A989CFE01D56C@swtexchange2.technology.de>
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="----=_Part_6165_8123633.1130256199753"
References: 
 <16F953410A0F1346848DCB476A989CFE01D56C@swtexchange2.technology.de>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.325 required=5 tests=[AWL=0.205, HTML_50_60=0.095,
	HTML_MESSAGE=0.001, RCVD_BY_IP=0.024]
X-Spam-Level: 
X-Archive-Number: 200510/366
X-Sequence-Number: 15134

------=_Part_6165_8123633.1130256199753
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Ok, thanks for the limits info, but I have that in the manual. Thanks.

But what I really want to know is this:

1) All large objects of all tables inside one DATABASE is kept on only one
table. True or false?

Thanks =3Do)
Rodrigo

On 10/25/05, N=F6rder-Tuitje, Marcus <noerder-tuitje@technology.de> wrote:
>
> oh, btw, no harm, but :
>  having 5000 tables only to gain access via city name is a major design
> flaw.
>  you might consider putting all into one table working with a distributed
> index over yer table (city, loc_texdt, blobfield); creating a partitioned
> index over city.
>  best regards
>
> -----Urspr=FCngliche Nachricht-----
> *Von:* pgsql-performance-owner@postgresql.org [mailto:
> pgsql-performance-owner@postgresql.org]*Im Auftrag von *Rodrigo Madera
> *Gesendet:* Montag, 24. Oktober 2005 21:12
> *An:* pgsql-performance@postgresql.org
> *Betreff:* Re: [PERFORM] Inefficient escape codes.
>
> Now this interests me a lot.
>
> Please clarify this:
>
> I have 5000 tables, one for each city:
>
> City1_Photos, City2_Photos, ... City5000_Photos.
>
> Each of these tables are: CREATE TABLE CityN_Photos (location text, lo_id
> largeobectypeiforgot)
>
> So, what's the limit for these large objects? I heard I could only have 4
> billion records for the whole database (not for each table). Is this true=
?
> If this isn't true, then would postgres manage to create all the large
> objects I ask him to?
>
> Also, this would be a performance penalty, wouldn't it?
>
> Much thanks for the knowledge shared,
> Rodrigo
>
>
>

------=_Part_6165_8123633.1130256199753
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Ok, thanks for the limits info, but I have that in the manual. Thanks.<br>
<br>
But what I really want to know is this:<br>
<br>
1) All large objects of all tables inside one DATABASE is kept on only one =
table. True or false?<br>
<br>
Thanks =3Do)<br>
Rodrigo<br><br><div><span class=3D"gmail_quote">On 10/25/05, <b class=3D"gm=
ail_sendername">N=F6rder-Tuitje, Marcus</b> &lt;<a href=3D"mailto:noerder-t=
uitje@technology.de">noerder-tuitje@technology.de</a>&gt; wrote:</span><blo=
ckquote class=3D"gmail_quote" style=3D"border-left: 1px solid rgb(204, 204,=
 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">







<div><span><font color=3D"#0000ff" face=3D"Arial" size=3D"2">oh,=20
btw, no harm, but : </font></span></div>
<div><span><font color=3D"#0000ff" face=3D"Arial" size=3D"2"></font></span>=
&nbsp;</div>
<div><span><font color=3D"#0000ff" face=3D"Arial" size=3D"2">having=20
5000 tables only to gain access via city name is a major design=20
flaw.</font></span></div>
<div><span><font color=3D"#0000ff" face=3D"Arial" size=3D"2"></font></span>=
&nbsp;</div>
<div><span><font color=3D"#0000ff" face=3D"Arial" size=3D"2">you=20
might consider putting&nbsp;all into one table working with a distributed i=
ndex=20
over yer table (city, loc_texdt, blobfield); creating a partitioned index o=
ver=20
city.</font></span></div><div><span class=3D"e" id=3D"q_10726a5410eef483_1"=
>
<div><span><font color=3D"#0000ff" face=3D"Arial" size=3D"2"></font></span>=
<span><font color=3D"#0000ff" face=3D"Arial" size=3D"2"></font></span>&nbsp=
;</div>
<div><span><font color=3D"#0000ff" face=3D"Arial" size=3D"2">best=20
regards</font></span></div>
<blockquote style=3D"margin-right: 0px;" dir=3D"ltr">
  <div align=3D"left" dir=3D"ltr"><font face=3D"Tahoma" size=3D"2">-----Urs=
pr=FCngliche Nachricht-----<br><b>Von:</b>=20
  <a href=3D"mailto:pgsql-performance-owner@postgresql.org" target=3D"_blan=
k" onclick=3D"return top.js.OpenExtLink(window,event,this)">pgsql-performan=
ce-owner@postgresql.org</a>=20
  [mailto:<a href=3D"mailto:pgsql-performance-owner@postgresql.org" target=
=3D"_blank" onclick=3D"return top.js.OpenExtLink(window,event,this)">pgsql-=
performance-owner@postgresql.org</a>]<b>Im Auftrag von </b>Rodrigo=20
  Madera<br><b>Gesendet:</b> Montag, 24. Oktober 2005 21:12<br><b>An:</b>=
=20
  <a href=3D"mailto:pgsql-performance@postgresql.org" target=3D"_blank" onc=
lick=3D"return top.js.OpenExtLink(window,event,this)">pgsql-performance@pos=
tgresql.org</a><br><b>Betreff:</b> Re: [PERFORM] Inefficient=20
  escape codes.<br><br></font></div>Now this interests me a lot.<br><br>Ple=
ase=20
  clarify this:<br><br>I have 5000 tables, one for each=20
  city:<br><br>City1_Photos, City2_Photos, ... City5000_Photos.<br><br>Each=
 of=20
  these tables are: CREATE TABLE CityN_Photos (location text, lo_id=20
  largeobectypeiforgot)<br><br>So, what's the limit for these large objects=
? I=20
  heard I could only have 4 billion records for the whole database (not for=
 each=20
  table). Is this true? If this isn't true, then would postgres manage to c=
reate=20
  all the large objects I ask him to?<br><br>Also, this would be a performa=
nce=20
  penalty, wouldn't it?<br><br>Much thanks for the knowledge shared,<br><sp=
an>Rodrigo</span>
  <div><span><br><br><br></span></div></blockquote>

</span></div></blockquote></div><br>

------=_Part_6165_8123633.1130256199753--

From pgsql-performance-owner@postgresql.org  Tue Oct 25 13:05:01 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 5D71FDAB8F
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 13:05:00 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 45593-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 16:04:48 +0000 (GMT)
Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158])
	by svr1.postgresql.org (Postfix) with ESMTP id 79B68D87C9
	for <pgsql-performance@postgresql.org>;
	Tue, 25 Oct 2005 13:04:48 -0300 (ADT)
Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1])
	by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id j9PG49sH003152
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);
	Tue, 25 Oct 2005 10:04:11 -0600 (MDT)
	(envelope-from mfuhr@winnie.fuhr.org)
Received: from winnie.fuhr.org (localhost [127.0.0.1])
	by winnie.fuhr.org (8.13.4/8.13.4) with ESMTP id j9PG497J053693;
	Tue, 25 Oct 2005 10:04:09 -0600 (MDT)
	(envelope-from mfuhr@winnie.fuhr.org)
Received: (from mfuhr@localhost)
	by winnie.fuhr.org (8.13.4/8.13.4/Submit) id j9PG489a053692;
	Tue, 25 Oct 2005 10:04:09 -0600 (MDT) (envelope-from mfuhr)
Date: Tue, 25 Oct 2005 10:04:08 -0600
From: Michael Fuhr <mike@fuhr.org>
To: jnevans@gmail.com
Cc: pgsql-performance@postgresql.org
Subject: Re: impact of stats_command_string
Message-ID: <20051025160408.GA53661@winnie.fuhr.org>
References: <1129840387.509093.90500@g49g2000cwa.googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <1129840387.509093.90500@g49g2000cwa.googlegroups.com>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/367
X-Sequence-Number: 15135

On Thu, Oct 20, 2005 at 01:33:07PM -0700, jnevans@gmail.com wrote:
> If I turn on stats_command_string, how much impact would it have on
> PostgreSQL server's performance during a period of massive data
> INSERTs?

Do you really need to be doing "massive data INSERTs"?  Can you use
COPY, which is much more efficient for bulk loads?

http://www.postgresql.org/docs/8.0/interactive/populate.html

-- 
Michael Fuhr

From pgsql-performance-owner@postgresql.org  Tue Oct 25 14:02:26 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 71443DAE30
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 14:02:25 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 68557-06
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 17:02:23 +0000 (GMT)
Received: from Herge.rcsinc.local (mail.rcsonline.com [70.89.208.142])
	by svr1.postgresql.org (Postfix) with ESMTP id 897DADAE32
	for <pgsql-performance@postgresql.org>;
	Tue, 25 Oct 2005 14:02:23 -0300 (ADT)
X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0
Content-class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Subject: Re: impact of stats_command_string
Date: Tue, 25 Oct 2005 13:02:20 -0400
Message-ID: <6EE64EF3AB31D5448D0007DD34EEB3417DD69F@Herge.rcsinc.local>
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
Thread-Topic: [PERFORM] impact of stats_command_string
Thread-Index: AcXZD1xckbrkwNFJT3Sd6gUw83HfjgAdXyKg
From: "Merlin Moncure" <merlin.moncure@rcsonline.com>
To: <jnevans@gmail.com>
Cc: <pgsql-performance@postgresql.org>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.083 required=5 tests=[AWL=0.033,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/368
X-Sequence-Number: 15136

> If I turn on stats_command_string, how much impact would it have on
> PostgreSQL server's performance during a period of massive data
> INSERTs?  I know that the answer to the question I'm asking will
> largely depend upon different factors so I would like to know in which
> situations it would be negligible or would have a signifcant impact.

First of all, we have to assume your writes are buffered in some way or
you are using transactions, or you will likely be i/o bound (or you have
a super fast disk setup).

Assuming that, I can tell you from experience on win32 that
stats_command_string can be fairly expensive for certain types of access
patterns.  What patterns?

1. If your ratio of queries to records involved is low.
2. If you are accessing data in a very quick way, for example via
prepared statements over a LAN
3. Your volume of queries is very high.

In these cases, the cost is high.  stats_command_string can add a
fractional millisecond ( ~.2  in my setup ) to statement latency and as
much as double cpu time in extreme cases...you are warned.  You may want
to turn it off before doing bulk loads or lengthy record iterations.

Merlin

From pgsql-performance-owner@postgresql.org  Tue Oct 25 15:01:07 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 043FADAD5E
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 15:01:07 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 53737-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 18:01:04 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id 1F52EDAD25
	for <pgsql-performance@postgresql.org>;
	Tue, 25 Oct 2005 15:01:04 -0300 (ADT)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j9PI14kZ018599;
	Tue, 25 Oct 2005 14:01:04 -0400 (EDT)
To: Kishore B <kishorebh@gmail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Why Index is not working on date columns. 
In-reply-to: <42567e060510250804y3329c901l21770d887dfcde42@mail.gmail.com> 
References: <42567e060510250147j582ce648p3ceef8e4376975be@mail.gmail.com>
	<13279.1130247515@sss.pgh.pa.us>
	<42567e060510250804y3329c901l21770d887dfcde42@mail.gmail.com>
Comments: In-reply-to Kishore B <kishorebh@gmail.com>
	message dated "Tue, 25 Oct 2005 20:34:21 +0530"
Date: Tue, 25 Oct 2005 14:01:04 -0400
Message-ID: <18598.1130263264@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/369
X-Sequence-Number: 15137

Kishore B <kishorebh@gmail.com> writes:
>> I surmise that you are testing on toy tables and extrapolating to what
>> will happen on larger tables.
>> 
> These tables participating here contain more than 8 million records as of
> now, and on every day, 200K records, will add to them.

In that case, have you ANALYZEd the tables lately?  The planner's cost
estimates correspond to awfully small tables ...

			regards, tom lane

From pgsql-performance-owner@postgresql.org  Tue Oct 25 15:28:42 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 1C7D0D87C9
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 15:28:41 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 62849-10
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 18:28:36 +0000 (GMT)
Received: from europa.cosmos.opusvl.com (europa.cosmos.opusvl.com
	[213.106.249.125])
	by svr1.postgresql.org (Postfix) with ESMTP id D576BD6EE1
	for <pgsql-performance@postgresql.org>;
	Tue, 25 Oct 2005 15:28:36 -0300 (ADT)
Received: from localhost.localdomain ([127.0.0.1])
	by europa.cosmos.opusvl.com with esmtp (Exim 4.30)
	id 1EUTXH-0005Lx-0y; Tue, 25 Oct 2005 19:28:35 +0100
Message-ID: <435E7952.8080403@opusvl.com>
Date: Tue, 25 Oct 2005 19:28:34 +0100
From: Rich Doughty <rich@opusvl.com>
Organization: Opus VL
User-Agent: Mozilla Thunderbird 1.0.2 (X11/20050317)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-performance@postgresql.org
Subject: Re: Outer join query plans and performance
References: <435E186A.3060003@opusvl.com> <13679.1130249522@sss.pgh.pa.us>
In-Reply-To: <13679.1130249522@sss.pgh.pa.us>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0 required=5 tests=[none]
X-Spam-Level: 
X-Archive-Number: 200510/370
X-Sequence-Number: 15138

Tom Lane wrote:
> Rich Doughty <rich@opusvl.com> writes:
> 
>>EXPLAIN SELECT *
>>FROM
>>     tokens.ta_tokens      t  LEFT JOIN
>>     tokens.ta_tokenhist   h1 ON t.token_id = h1.token_id LEFT JOIN
>>     tokens.ta_tokenhist   h2 ON t.token_id = h2.token_id
>>WHERE
>>     h1.histdate = 'now';
> 
> 
>>EXPLAIN SELECT *
>>FROM
>>     tokens.ta_tokens      t  LEFT JOIN
>>     tokens.ta_tokenhist   h1 ON t.token_id = h1.token_id LEFT JOIN
>>     tokens.ta_tokenhist   h2 ON t.token_id = h2.token_id
>>WHERE
>>     h2.histdate = 'now';
> 
> 
> The reason these are different is that the second case constrains only
> the last-to-be-joined table, so the full cartesian product of t and h1
> has to be formed.  If this wasn't what you had in mind, you might be
> able to rearrange the order of the LEFT JOINs, but bear in mind that
> in general, changing outer-join ordering changes the results.  (This
> is why the planner won't fix it for you.)

FWIW mysql 4.1 (and i'm no fan at all of mysql) completes both these queries
in approximately 3 seconds. postgres does the first in 6 seconds and the
second in a lot longer (eventually abandoned).


-- 

   - Rich Doughty

From pgsql-performance-owner@postgresql.org  Tue Oct 25 16:46:53 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 27D17DAE3F
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 16:46:53 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 99519-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 19:46:50 +0000 (GMT)
Received: from zproxy.gmail.com (zproxy.gmail.com [64.233.162.199])
	by svr1.postgresql.org (Postfix) with ESMTP id 13707DAE55
	for <pgsql-performance@postgresql.org>;
	Tue, 25 Oct 2005 16:46:50 -0300 (ADT)
Received: by zproxy.gmail.com with SMTP id 8so825935nzo
	for <pgsql-performance@postgresql.org>;
	Tue, 25 Oct 2005 12:46:52 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:to:subject:mime-version:content-type;
	b=k3nsPC5pC5mE9qyHfdEfqrAOv8SHU4yDM0GnpO/iAJjt5HVmyEeHEap+5X4iCwXZnSQP7ow3BAWf81OxxfXhHkIt/E3ZZP2JLzHcnbxcKuVOrLnPrJ0la6yrs8HdgtpMDIvuyww8OCDnPw2T1cqwLA4ip9ja/UWWKzLZQlOD+Fc=
Received: by 10.36.9.19 with SMTP id 19mr89519nzi;
	Tue, 25 Oct 2005 12:46:52 -0700 (PDT)
Received: by 10.36.61.1 with HTTP; Tue, 25 Oct 2005 12:46:52 -0700 (PDT)
Message-ID: <42567e060510251246s1b9eda40l54e73993f8bcfb34@mail.gmail.com>
Date: Wed, 26 Oct 2005 01:16:52 +0530
From: Kishore B <kishorebh@gmail.com>
To: pgsql-performance@postgresql.org
Subject: Why different execution times for different instances for the same
	query?
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="----=_Part_7717_21674086.1130269612673"
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.469 required=5 tests=[AWL=-0.060, HTML_20_30=0.504,
	HTML_MESSAGE=0.001, RCVD_BY_IP=0.024]
X-Spam-Level: 
X-Archive-Number: 200510/371
X-Sequence-Number: 15139

------=_Part_7717_21674086.1130269612673
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Hi All,
 We are executing a single query that returned very fast on the first
instance. But when I executed the same query for multiple times, it is
giving strange results. It is not coming back.
 When I checked with the processes running in the system, I observed that
multiple instances of postmaster are running and all of them are consuming
very high amounts of memory. I could also observe that they are sharing the
memory in a uniform distribution across them.
 Please let me know if any body has experienced the same and how do they
resolved it.
 Thank you,
Kishore.

------=_Part_7717_21674086.1130269612673
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

<div>Hi All, </div>
<div>&nbsp;</div>
<div>We are executing a single query that returned very&nbsp;fast on the fi=
rst instance. But&nbsp;when I executed the same query&nbsp;for&nbsp;multipl=
e times,&nbsp;it is giving strange results. It is not coming back.&nbsp;</d=
iv>
<div>&nbsp;</div>
<div>When I checked with the processes running in the system, I&nbsp;observ=
ed that multiple instances of postmaster are running and all of them are co=
nsuming very high amounts of memory. I could also observe that they are sha=
ring the memory in a uniform distribution across them.=20
</div>
<div>&nbsp;</div>
<div>Please let me know if any body has experienced the same and how do the=
y resolved it.</div>
<div>&nbsp;</div>
<div>Thank you,</div>
<div>Kishore.</div>

------=_Part_7717_21674086.1130269612673--

From pgsql-performance-owner@postgresql.org  Tue Oct 25 17:24:33 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 9460EDAE32
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 17:24:32 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 07175-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 20:24:29 +0000 (GMT)
Received: from koolancexeon.g2switchworks.com (mail.g2switchworks.com
	[63.87.162.25])
	by svr1.postgresql.org (Postfix) with ESMTP id BB760DAD24
	for <pgsql-performance@postgresql.org>;
	Tue, 25 Oct 2005 17:24:30 -0300 (ADT)
Received: mail.g2switchworks.com 10.10.1.8 from 10.10.1.37 10.10.1.37 via HTTP
	with MS-WebStorage 6.5.6944
Received: from state.g2switchworks.com by mail.g2switchworks.com;
	25 Oct 2005 15:24:32 -0500
Subject: Re: Why different execution times for different
From: Scott Marlowe <smarlowe@g2switchworks.com>
To: Kishore B <kishorebh@gmail.com>
Cc: pgsql-performance@postgresql.org
In-Reply-To: <42567e060510251246s1b9eda40l54e73993f8bcfb34@mail.gmail.com>
References: <42567e060510251246s1b9eda40l54e73993f8bcfb34@mail.gmail.com>
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Message-Id: <1130271872.2872.2.camel@state.g2switchworks.com>
Mime-Version: 1.0
X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) 
Date: Tue, 25 Oct 2005 15:24:32 -0500
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.007 required=5 tests=[AWL=0.007]
X-Spam-Level: 
X-Archive-Number: 200510/372
X-Sequence-Number: 15140

On Tue, 2005-10-25 at 14:46, Kishore B wrote:
> Hi All, 
>  
> We are executing a single query that returned very fast on the first
> instance. But when I executed the same query for multiple times, it is
> giving strange results. It is not coming back. 
>  
> When I checked with the processes running in the system, I observed
> that multiple instances of postmaster are running and all of them are
> consuming very high amounts of memory. I could also observe that they
> are sharing the memory in a uniform distribution across them. 
>  
> Please let me know if any body has experienced the same and how do
> they resolved it.

You may or may not have an actual problem.

For one, if they're each using 128 megs, but sharing 120 megs of that
then that's not too bad.  If they're each using 512 meg and sharing 100
meg of that, then you've got a problem.

What is your sort mem set to?  Going too high can cause memory
starvation and other problems.

Also, when you run top, how much memory is being used for cache and
buffer.  If you've still got a fair amount used for cache then you're
probably ok there.

What are your settings in postgresql.conf that aren't default?  How's
the behaviour as you run 1, then 2, then 3, then 4 and so on?  Where's
the "knee" with this behaviour and what are you running out of, disk IO
or memory or memory bandwidth.

Are you using iostat/vmstat/top/free/ipcs to check resource usage under
load?

From pgsql-performance-owner@postgresql.org  Tue Oct 25 18:40:45 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 1A7BDDA26A
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 18:40:45 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 35265-06
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 21:40:41 +0000 (GMT)
Received: from my.endian.it (unknown [62.146.87.34])
	by svr1.postgresql.org (Postfix) with ESMTP id E5179D6EE1
	for <pgsql-performance@postgresql.org>;
	Tue, 25 Oct 2005 18:40:41 -0300 (ADT)
Received: from 1006.org (localhost.localdomain [127.0.0.1])
	by my.endian.it (8.11.6/8.11.6) with SMTP id j9PLa2c23558;
	Tue, 25 Oct 2005 23:36:02 +0200
Received: from host118-59.pool8258.interbusiness.it ([82.58.59.118])
	(SquirrelMail authenticated user list@1006.org)
	by www.endian.it with HTTP; Tue, 25 Oct 2005 23:36:02 +0200 (CEST)
Message-ID: <19128.82.58.59.118.1130276162.squirrel@www.endian.it>
Date: Tue, 25 Oct 2005 23:36:02 +0200 (CEST)
Subject: Re: insertion of bytea
From: "Chris Mair" <list@1006.org>
To: <mstone+postgres@mathom.us>
In-Reply-To: <20051025140549.GC17398@mathom.us>
References: <54222.193.206.186.101.1130247876.squirrel@www.endian.it>
	<20051025140549.GC17398@mathom.us>
X-Priority: 3
Importance: Normal
X-MSMail-Priority: Normal
Cc: <list@1006.org>, <pgsql-performance@postgresql.org>
X-Mailer: SquirrelMail (version 1.2.7)
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0 required=5 tests=[none]
X-Spam-Level: 
X-Archive-Number: 200510/373
X-Sequence-Number: 15141

>>Is there a better, faster way to do these inserts?
>
> COPY is generally the fastest way to do bulk inserts (see
> PQputCopyData).

Thanks :)
I'll give that I try and report the results here later.

Bye, Chris.




From pgsql-performance-owner@postgresql.org  Tue Oct 25 18:46:29 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 49EA4DAE17
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 18:46:29 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 36728-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 21:46:25 +0000 (GMT)
Received: from my.endian.it (unknown [62.146.87.34])
	by svr1.postgresql.org (Postfix) with ESMTP id 9F9A2DA8EF
	for <pgsql-performance@postgresql.org>;
	Tue, 25 Oct 2005 18:46:26 -0300 (ADT)
Received: from 1006.org (localhost.localdomain [127.0.0.1])
	by my.endian.it (8.11.6/8.11.6) with SMTP id j9PLflc23738;
	Tue, 25 Oct 2005 23:41:47 +0200
Received: from host118-59.pool8258.interbusiness.it ([82.58.59.118])
	(SquirrelMail authenticated user list@1006.org)
	by www.endian.it with HTTP; Tue, 25 Oct 2005 23:41:47 +0200 (CEST)
Message-ID: <19131.82.58.59.118.1130276507.squirrel@www.endian.it>
Date: Tue, 25 Oct 2005 23:41:47 +0200 (CEST)
Subject: Re: insertion of bytea
From: "Chris Mair" <list@1006.org>
To: <tgl@sss.pgh.pa.us>
In-Reply-To: <13782.1130250200@sss.pgh.pa.us>
References: <54222.193.206.186.101.1130247876.squirrel@www.endian.it>
	<13782.1130250200@sss.pgh.pa.us>
X-Priority: 3
Importance: Normal
X-MSMail-Priority: Normal
Cc: <list@1006.org>, <pgsql-performance@postgresql.org>
X-Mailer: SquirrelMail (version 1.2.7)
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0 required=5 tests=[none]
X-Spam-Level: 
X-Archive-Number: 200510/374
X-Sequence-Number: 15142

>> Am I correct in assuming that even though I'm passing my 52000
>> bytes as a (char *) to PQexecPrepared(), encoding/decoding is
>> happening (think 0 -> \000) somewhere in the transfer?
>
> Are you specifying it as a text or binary parameter?  Have you looked to
> see if the stored data is what you expect?

I'm specifying it as binary (i.e. one's in PQexecPrepared's
format parameter). The stored data is correct.

I'll try "copy from stdin with binary" tomorrow and see what
I get...

Thanks & Bye, Chris.



From pgsql-performance-owner@postgresql.org  Tue Oct 25 19:03:02 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id D0FB4DAE04
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 19:03:00 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 43148-09
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 22:02:57 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id BEE5BDAD36
	for <pgsql-performance@postgresql.org>;
	Tue, 25 Oct 2005 19:02:58 -0300 (ADT)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j9PM30aN029459;
	Tue, 25 Oct 2005 18:03:00 -0400 (EDT)
To: Rich Doughty <rich@opusvl.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Outer join query plans and performance 
In-reply-to: <435E7952.8080403@opusvl.com> 
References: <435E186A.3060003@opusvl.com> <13679.1130249522@sss.pgh.pa.us>
	<435E7952.8080403@opusvl.com>
Comments: In-reply-to Rich Doughty <rich@opusvl.com>
	message dated "Tue, 25 Oct 2005 19:28:34 +0100"
Date: Tue, 25 Oct 2005 18:03:00 -0400
Message-ID: <29458.1130277780@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/375
X-Sequence-Number: 15143

Rich Doughty <rich@opusvl.com> writes:
> Tom Lane wrote:
>> The reason these are different is that the second case constrains only
>> the last-to-be-joined table, so the full cartesian product of t and h1
>> has to be formed.  If this wasn't what you had in mind, you might be
>> able to rearrange the order of the LEFT JOINs, but bear in mind that
>> in general, changing outer-join ordering changes the results.  (This
>> is why the planner won't fix it for you.)

> FWIW mysql 4.1 (and i'm no fan at all of mysql) completes both these queries
> in approximately 3 seconds.

Does mysql get the correct answer, though?  It's hard to see how they do
this fast unless they (a) are playing fast and loose with the semantics,
or (b) have very substantially more analysis logic for OUTER JOIN semantics
than we do.  Perhaps mysql 5.x is better about this sort of thing, but
for 4.x I'd definitely find theory (a) more plausible than (b).

The cases that would be interesting are those where rearranging the
outer join order actually does change the correct answer --- it may not
in this particular case, I haven't thought hard about it.  It seems
fairly likely to me that they are rearranging the join order here, and
I'm just wondering whether they have the logic needed to verify that
such a transformation is correct.

			regards, tom lane

From pgsql-performance-owner@postgresql.org  Tue Oct 25 19:25:12 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 4B439DAE92
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 19:25:12 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 51461-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 22:25:07 +0000 (GMT)
Received: from gwmta.wicourts.gov (gwmta.wicourts.gov [165.219.244.99])
	by svr1.postgresql.org (Postfix) with ESMTP id E340CDAE8E
	for <pgsql-performance@postgresql.org>;
	Tue, 25 Oct 2005 19:25:06 -0300 (ADT)
Received: from Courts-MTA by gwmta.wicourts.gov
	with Novell_GroupWise; Tue, 25 Oct 2005 17:25:04 -0500
Message-Id: <435E6A670200002500000224@gwmta.wicourts.gov>
X-Mailer: Novell GroupWise Internet Agent 7.0 
Date: Tue, 25 Oct 2005 17:24:54 -0500
From: "Kevin Grittner" <Kevin.Grittner@wicourts.gov>
To: <rich@opusvl.com>, <tgl@sss.pgh.pa.us>
Cc: <pgsql-performance@postgresql.org>
Subject: Re: Outer join query plans and performance
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.002 required=5 tests=[AWL=0.002]
X-Spam-Level: 
X-Archive-Number: 200510/376
X-Sequence-Number: 15144

In this particular case both outer joins are to the same table, and
the where clause is applied to one or the other, so it's pretty easy
to prove that they should generate identical results.  I'll grant that
this is not generally very useful; but then, simple test cases often
don't look very useful.

We've had mixed results with PostgreSQL and queries with
multiple outer joins when the WHERE clause limits the results
based on columns from the optional tables.  In at least one case
which performs very well, we have enough tables to cause the
"genetic" optimizer to kick in.  (So I suppose there is a chance
that sometimes it won't perform well, although we haven't seen
that happen yet.)

I can't speak to MySQL, but both Sybase and MaxDB handled
such cases accurately, and chose a plan with very fast
execution.  Sybase, however, spent 5 to 10 seconds in the
optimizer finding the sub-second plan.

-Kevin


>>> Tom Lane <tgl@sss.pgh.pa.us>  >>>
Rich Doughty <rich@opusvl.com> writes:
> Tom Lane wrote:
>> The reason these are different is that the second case constrains
only
>> the last-to-be-joined table, so the full cartesian product of t and
h1
>> has to be formed.  If this wasn't what you had in mind, you might be
>> able to rearrange the order of the LEFT JOINs, but bear in mind that
>> in general, changing outer-join ordering changes the results.  (This
>> is why the planner won't fix it for you.)

> FWIW mysql 4.1 (and i'm no fan at all of mysql) completes both these
queries
> in approximately 3 seconds.

Does mysql get the correct answer, though?  It's hard to see how they do
this fast unless they (a) are playing fast and loose with the semantics,
or (b) have very substantially more analysis logic for OUTER JOIN
semantics
than we do.  Perhaps mysql 5.x is better about this sort of thing, but
for 4.x I'd definitely find theory (a) more plausible than (b).

The cases that would be interesting are those where rearranging the
outer join order actually does change the correct answer --- it may not
in this particular case, I haven't thought hard about it.  It seems
fairly likely to me that they are rearranging the join order here, and
I'm just wondering whether they have the logic needed to verify that
such a transformation is correct.

			regards, tom lane


From pgsql-performance-owner@postgresql.org  Tue Oct 25 23:11:39 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 9303CDAEAE
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue, 25 Oct 2005 23:11:38 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 48995-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 02:11:33 +0000 (GMT)
Received: from mailer.eglobalreach.net (gc4-mx.gc4.com [202.124.128.22])
	by svr1.postgresql.org (Postfix) with ESMTP id 031D1DAECD
	for <pgsql-performance@postgresql.org>;
	Tue, 25 Oct 2005 23:11:34 -0300 (ADT)
Received: from ghwk02002147 (localhost [127.0.0.1] (may be forged))
	by mailer.eglobalreach.net (8.11.6p2/) with ESMTP id j9Q2BPx23751;
	Wed, 26 Oct 2005 10:11:25 +0800
From: "Christian Paul B. Cosinas" <cpc@cybees.com>
To: <pgsql-performance@postgresql.org>
Cc: "'Alvaro Nunes Melo'" <al_nunes@atua.com.br>
Subject: Re: Temporary Table
Date: Wed, 26 Oct 2005 02:15:37 -0000
Message-ID: <004a01c5d9d3$28199820$1e21100a@ghwk02002147>
MIME-Version: 1.0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit
X-Mailer: Microsoft Office Outlook 11
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506
thread-index: AcXZUvDG9UlwHeZWTqupmuaYzCrPXwAf4BSQ
In-Reply-To: <435E0F9B.3050101@atua.com.br>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.679 required=5 tests=[AWL=0.000,
	FORGED_RCVD_HELO=0.05, URIBL_SBL=0.629]
X-Spam-Level: 
X-Archive-Number: 200510/377
X-Sequence-Number: 15145

I am creating a temporary table in every function that I execute.
Which I think is bout 100,000 temporary tables a day.

What is the command for vacuuming these 3 tables?

Also I read about the auto vacuum of postgresql.
How can I execute this auto vacuum or the settings in the configuration?

-----Original Message-----
From: Alvaro Nunes Melo [mailto:al_nunes@atua.com.br]
Sent: Tuesday, October 25, 2005 10:58 AM
To: Christian Paul B. Cosinas
Subject: Re: [PERFORM] Temporary Table

Hi Christian,

Christian Paul B. Cosinas wrote:

> Does Creating Temporary table in a function and NOT dropping them 
> affects the performance of the database?
>
I believe it will depend on how many temporary tables you will create in a
daily basis. We had a performance problem caused by them, and by not
monitoring properly the database size. The pg_attribite, pg_class and
pg_depend tables grow a lot. When I found out that this was the problem I
saw some messages in the list archieve, and now the overall performance is
great.

What I do is daily run VACUUM FULL and REINDEX in this three tables.

Alvaro


I choose Polesoft Lockspam to fight spam, and you?
http://www.polesoft.com/refer.html    


From pgsql-performance-owner@postgresql.org  Wed Oct 26 01:24:13 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id BE118D7EA0
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 01:24:12 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 32543-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 04:24:08 +0000 (GMT)
Received: from hotmail.com (bay23-f21.bay23.hotmail.com [64.4.22.71])
	by svr1.postgresql.org (Postfix) with ESMTP id DA00CDAF0E
	for <pgsql-performance@postgresql.org>;
	Wed, 26 Oct 2005 01:24:07 -0300 (ADT)
Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC;
	Tue, 25 Oct 2005 21:24:07 -0700
Message-ID: <BAY23-F2182E28A539382AE59FC51CE690@phx.gbl>
Received: from 196.40.10.254 by by23fd.bay23.hotmail.msn.com with HTTP;
	Wed, 26 Oct 2005 04:24:06 GMT
X-Originating-IP: [196.40.10.254]
X-Originating-Email: [sidarlopez@hotmail.com]
X-Sender: sidarlopez@hotmail.com
From: =?iso-8859-1?B?U2lkYXIgTPNwZXogQ3J1eg==?= <sidarlopez@hotmail.com>
To: pgsql-performance@postgresql.org
Subject: blue prints please
Date: Tue, 25 Oct 2005 22:24:06 -0600
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1; format=flowed
X-OriginalArrivalTime: 26 Oct 2005 04:24:07.0334 (UTC)
	FILETIME=[1AFB4460:01C5D9E5]
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=1.331 required=5 tests=[AWL=-0.419,
	DNS_FROM_RFC_ABUSE=0.374, DNS_FROM_RFC_POST=1.376,
	MSGID_FROM_MTA_HEADER=0]
X-Spam-Level: *
X-Archive-Number: 200510/378
X-Sequence-Number: 15146

where can i find bests practices for tunning postgresql?

_________________________________________________________________
Consigue aqu� las mejores y mas recientes ofertas de trabajo en Am�rica 
Latina y USA: http://latam.msn.com/empleos/


From pgsql-performance-owner@postgresql.org  Wed Oct 26 01:26:49 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 6C984DAA6C
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 01:26:46 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 49384-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 04:26:44 +0000 (GMT)
Received: from hotmail.com (bay23-f12.bay23.hotmail.com [64.4.22.62])
	by svr1.postgresql.org (Postfix) with ESMTP id 554D4DA262
	for <pgsql-performance@postgresql.org>;
	Wed, 26 Oct 2005 01:26:44 -0300 (ADT)
Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC;
	Tue, 25 Oct 2005 21:26:43 -0700
Message-ID: <BAY23-F12AC56187BE1C2D1BAA64DCE690@phx.gbl>
Received: from 196.40.10.254 by by23fd.bay23.hotmail.msn.com with HTTP;
	Wed, 26 Oct 2005 04:26:43 GMT
X-Originating-IP: [196.40.10.254]
X-Originating-Email: [sidarlopez@hotmail.com]
X-Sender: sidarlopez@hotmail.com
From: =?iso-8859-1?B?U2lkYXIgTPNwZXogQ3J1eg==?= <sidarlopez@hotmail.com>
To: pgsql-performance@postgresql.org
Subject: zero performance on query
Date: Tue, 25 Oct 2005 22:26:43 -0600
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1; format=flowed
X-OriginalArrivalTime: 26 Oct 2005 04:26:43.0695 (UTC)
	FILETIME=[782E0FF0:01C5D9E5]
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=1.369 required=5 tests=[AWL=-0.381,
	DNS_FROM_RFC_ABUSE=0.374, DNS_FROM_RFC_POST=1.376,
	MSGID_FROM_MTA_HEADER=0]
X-Spam-Level: *
X-Archive-Number: 200510/379
X-Sequence-Number: 15147

what happend with postgresql 8.1b4 performance on query?
please help me !!!

look at this:
select count(*) from fotos where archivo not in (select archivo from 
archivos)
Aggregate  (cost=4899037992.36..4899037992.37 rows=1 width=0)
->  Seq Scan on fotos  (cost=22598.78..4899037338.07 rows=261716 width=0)
       Filter: (NOT (subplan))
       SubPlan
         ->  Materialize  (cost=22598.78..39304.22 rows=805344 width=58)
               ->  Seq Scan on archivos  (cost=0.00..13141.44 rows=805344 
width=58)

I WILL DIE WAITING FOR QUERY RESPONSE !!!
--
CREATE TABLE archivos ( archivo varchar(20)) WITHOUT OIDS;
CREATE INDEX archivos_archivo_idx  ON archivos  USING btree(archivo);
~800000 rows
--
CREATE TABLE fotos
(
cedula varchar(20),
nombre varchar(100),
apellido1 varchar(100),
apellido2 varchar(100),
archivo varchar(20)
) WITHOUT OIDS;
CREATE INDEX fotos_archivo_idx  ON fotos  USING btree (archivo);
CREATE INDEX fotos_cedula_idx   ON fotos   USING btree (cedula);
~500000 rows

_________________________________________________________________
Consigue aqu� las mejores y mas recientes ofertas de trabajo en Am�rica 
Latina y USA: http://latam.msn.com/empleos/


From pgsql-performance-owner@postgresql.org  Wed Oct 26 02:22:42 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 646BFDAECD
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 02:22:41 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 54881-06
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 05:22:38 +0000 (GMT)
Received: from mail.aveo.aveopharma.com (67.109.105.227.ptr.us.xo.net
	[67.109.105.227])
	by svr1.postgresql.org (Postfix) with SMTP id 2B867DAEBC
	for <pgsql-performance@postgresql.org>;
	Wed, 26 Oct 2005 02:22:38 -0300 (ADT)
X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0
Content-class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Subject: Re: zero performance on query
Date: Wed, 26 Oct 2005 01:25:45 -0400
Message-ID: <F18A6F7CF1661F46920F2CF713122FED46CCEA@mail.aveo.aveopharma.com>
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
Thread-Topic: [PERFORM] zero performance on query
Thread-Index: AcXZ5k0rDcwt+k6zQz2b1iFKxRRwJwABsgIg
From: "Dmitri Bichko" <dbichko@aveopharma.com>
To: =?iso-8859-1?Q?Sidar_L=F3pez_Cruz?= <sidarlopez@hotmail.com>,
	<pgsql-performance@postgresql.org>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.066 required=5 tests=[AWL=0.016,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/380
X-Sequence-Number: 15148

That seems like a pretty horrible way to do that query, given the table s=
izes.

What about something like:

SELECT count(*)
FROM fotos f
LEFT JOIN archivo a USING(archivo)
WHERE a.archivo IS NULL

Incidentally, can someone explain what the "Materialize" subplan does?  I=
s this new in 8.1?

Dmitri



> -----Original Message-----
> From: pgsql-performance-owner@postgresql.org=20
> [mailto:pgsql-performance-owner@postgresql.org] On Behalf Of=20
> Sidar L=F3pez Cruz
> Sent: Wednesday, October 26, 2005 12:27 AM
> To: pgsql-performance@postgresql.org
> Subject: [PERFORM] zero performance on query
>=20
>=20
> what happend with postgresql 8.1b4 performance on query?
> please help me !!!
>=20
> look at this:
> select count(*) from fotos where archivo not in (select archivo from=20=

> archivos)
> Aggregate  (cost=3D4899037992.36..4899037992.37 rows=3D1 width=3D0)
> ->  Seq Scan on fotos  (cost=3D22598.78..4899037338.07 rows=3D261716=20=

> -> width=3D0)
>        Filter: (NOT (subplan))
>        SubPlan
>          ->  Materialize  (cost=3D22598.78..39304.22=20
> rows=3D805344 width=3D58)
>                ->  Seq Scan on archivos  (cost=3D0.00..13141.44=20
> rows=3D805344=20
> width=3D58)
>=20
> I WILL DIE WAITING FOR QUERY RESPONSE !!!
> --
> CREATE TABLE archivos ( archivo varchar(20)) WITHOUT OIDS;=20
> CREATE INDEX archivos_archivo_idx  ON archivos  USING=20
> btree(archivo); ~800000 rows
> --
> CREATE TABLE fotos
> (
> cedula varchar(20),
> nombre varchar(100),
> apellido1 varchar(100),
> apellido2 varchar(100),
> archivo varchar(20)
> ) WITHOUT OIDS;
> CREATE INDEX fotos_archivo_idx  ON fotos  USING btree (archivo);
> CREATE INDEX fotos_cedula_idx   ON fotos   USING btree (cedula);
> ~500000 rows
>=20
> _________________________________________________________________
> Consigue aqu=ED las mejores y mas recientes ofertas de trabajo=20
> en Am=E9rica=20
> Latina y USA: http://latam.msn.com/empleos/
>=20
>=20
> ---------------------------(end of=20
> broadcast)---------------------------
> TIP 2: Don't 'kill -9' the postmaster
>=20
The information transmitted is intended only for the person or entity to =
which it is addressed and may contain confidential and/or privileged mate=
rial. Any review, retransmission, dissemination or other use of, or takin=
g of any action in reliance upon, this information by persons or entities=
 other than the intended recipient is prohibited. If you received this in=
 error, please contact the sender and delete the material from any comput=
er

From pgsql-performance-owner@postgresql.org  Wed Oct 26 03:01:47 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 5A5D9DAA8F
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 03:01:46 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 41373-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 06:01:42 +0000 (GMT)
Received: from mailer.eglobalreach.net (gc4-mx.gc4.com [202.124.128.22])
	by svr1.postgresql.org (Postfix) with ESMTP id C50CED97E5
	for <pgsql-performance@postgresql.org>;
	Wed, 26 Oct 2005 03:01:42 -0300 (ADT)
Received: from ghwk02002147 (localhost [127.0.0.1] (may be forged))
	by mailer.eglobalreach.net (8.11.6p2/) with ESMTP id j9Q61hR05886
	for <pgsql-performance@postgresql.org>; Wed, 26 Oct 2005 14:01:43 +0800
From: "Christian Paul B. Cosinas" <cpc@cybees.com>
To: <pgsql-performance@postgresql.org>
Subject: Configuration Suggestion
Date: Wed, 26 Oct 2005 06:05:55 -0000
Message-ID: <000601c5d9f3$5478f260$1e21100a@ghwk02002147>
MIME-Version: 1.0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit
X-Mailer: Microsoft Office Outlook 11
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506
Thread-Index: AcXZUvDG9UlwHeZWTqupmuaYzCrPXwAf4BSQAAfyfyA=
In-Reply-To: <004a01c5d9d3$28199820$1e21100a@ghwk02002147>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.679 required=5 tests=[AWL=0.000,
	FORGED_RCVD_HELO=0.05, URIBL_SBL=0.629]
X-Spam-Level: 
X-Archive-Number: 200510/381
X-Sequence-Number: 15149

Hi! Here is the Specifications of My Server.
I would really appreciate the best configuration of postgresql.conf for my
sevrer.

I have tried so many value in the parameters but It seems that I cannot get
the speed I want.

OS: Redhat Linux
CPU: Dual Xeon
Memory: 6 gigabyte
PostgreSQL Version 8.0

Most of my queries are having Order by Clause, and group by clause.
Creation of temporary table.

The biggest rows is about 3-5 million which I query almost every 5 seconds.

I'm just wondering is it normal to have this result in my memory usage:
             total       used       free     shared    buffers     cached
Mem:       6192460    6172488      19972          0      39904    5890824
-/+ buffers/cache:     241760    5950700
Swap:      2096472          0    2096472

What does this mean?


I choose Polesoft Lockspam to fight spam, and you?
http://www.polesoft.com/refer.html    


From pgsql-performance-owner@postgresql.org  Wed Oct 26 03:59:26 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 95110DAF12
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 03:59:25 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 61448-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 06:59:21 +0000 (GMT)
Received: from nproxy.gmail.com (nproxy.gmail.com [64.233.182.203])
	by svr1.postgresql.org (Postfix) with ESMTP id 6BA10DAF33
	for <pgsql-performance@postgresql.org>;
	Wed, 26 Oct 2005 03:59:22 -0300 (ADT)
Received: by nproxy.gmail.com with SMTP id q29so14346nfc
	for <pgsql-performance@postgresql.org>;
	Tue, 25 Oct 2005 23:59:22 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references;
	b=KAUVxHDouMuXaLTD/gG0JxeWak4xR6N84F3Jp2sBdtyuUCTQ9dT0JeSxfGWSVY41E9Dqr6LJLZiUOXxeLxW5opNCvA7eVFZzMgiviX73JGC0jZVnxr1KKThcIrnTWpnT9kOe0nYztJqnmqOUi5l3XVWW5KGIpE12WoQCiN5jLnU=
Received: by 10.48.247.7 with SMTP id u7mr136572nfh;
	Tue, 25 Oct 2005 23:59:22 -0700 (PDT)
Received: by 10.48.247.16 with HTTP; Tue, 25 Oct 2005 23:59:22 -0700 (PDT)
Message-ID: <4b09a0c0510252359x61e4808du@mail.gmail.com>
Date: Wed, 26 Oct 2005 08:59:22 +0200
From: Jean-Max Reymond <jmreymond@gmail.com>
To: =?ISO-8859-1?Q?Sidar_L=F3pez_Cruz?= <sidarlopez@hotmail.com>
Subject: Re: blue prints please
Cc: pgsql-performance@postgresql.org
In-Reply-To: <BAY23-F2182E28A539382AE59FC51CE690@phx.gbl>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
References: <BAY23-F2182E28A539382AE59FC51CE690@phx.gbl>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.064 required=5 tests=[AWL=0.040, RCVD_BY_IP=0.024]
X-Spam-Level: 
X-Archive-Number: 200510/382
X-Sequence-Number: 15150

2005/10/26, Sidar L=F3pez Cruz <sidarlopez@hotmail.com>:
> where can i find bests practices for tunning postgresql?

http://www.varlena.com/varlena/GeneralBits/Tidbits/perf.html

--
Jean-Max Reymond
CKR Solutions Open Source
Nice France
http://www.ckr-solutions.com

From pgsql-performance-owner@postgresql.org  Wed Oct 26 05:33:51 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id E5899DAF07
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 05:33:50 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 92812-06
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 08:33:47 +0000 (GMT)
Received: from europa.cosmos.opusvl.com (europa.cosmos.opusvl.com
	[213.106.249.125])
	by svr1.postgresql.org (Postfix) with ESMTP id E0377D6EBD
	for <pgsql-performance@postgresql.org>;
	Wed, 26 Oct 2005 05:33:48 -0300 (ADT)
Received: from localhost.localdomain ([127.0.0.1])
	by europa.cosmos.opusvl.com with esmtp (Exim 4.30)
	id 1EUgjF-0007Du-3U; Wed, 26 Oct 2005 09:33:49 +0100
Message-ID: <435F3F6C.3070203@opusvl.com>
Date: Wed, 26 Oct 2005 09:33:48 +0100
From: Rich Doughty <rich@opusvl.com>
Organization: Opus VL
User-Agent: Mozilla Thunderbird 1.0.2 (X11/20050317)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-performance@postgresql.org
Subject: Re: Outer join query plans and performance
References: <435E186A.3060003@opusvl.com> <13679.1130249522@sss.pgh.pa.us>
	<435E7952.8080403@opusvl.com> <29458.1130277780@sss.pgh.pa.us>
In-Reply-To: <29458.1130277780@sss.pgh.pa.us>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0 required=5 tests=[none]
X-Spam-Level: 
X-Archive-Number: 200510/383
X-Sequence-Number: 15151

Tom Lane wrote:
> Rich Doughty <rich@opusvl.com> writes:
> 
>>Tom Lane wrote:
>>
>>>The reason these are different is that the second case constrains only
>>>the last-to-be-joined table, so the full cartesian product of t and h1
>>>has to be formed.  If this wasn't what you had in mind, you might be
>>>able to rearrange the order of the LEFT JOINs, but bear in mind that
>>>in general, changing outer-join ordering changes the results.  (This
>>>is why the planner won't fix it for you.)
> 
> 
>>FWIW mysql 4.1 (and i'm no fan at all of mysql) completes both these queries
>>in approximately 3 seconds.
> 
> 
> Does mysql get the correct answer, though?  It's hard to see how they do
> this fast unless they (a) are playing fast and loose with the semantics,
> or (b) have very substantially more analysis logic for OUTER JOIN semantics
> than we do.  Perhaps mysql 5.x is better about this sort of thing, but
> for 4.x I'd definitely find theory (a) more plausible than (b).

i would assume so. i'll re-run my testcase later and verify the results of the
two side-by-side.

> The cases that would be interesting are those where rearranging the
> outer join order actually does change the correct answer --- it may not
> in this particular case, I haven't thought hard about it.  It seems
> fairly likely to me that they are rearranging the join order here, and
> I'm just wondering whether they have the logic needed to verify that
> such a transformation is correct.
> 
> 			regards, tom lane
> 


-- 

   - Rich Doughty

From pgsql-performance-owner@postgresql.org  Wed Oct 26 07:30:55 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 37EB0DAC8E
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 07:30:54 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 32395-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 10:30:48 +0000 (GMT)
Received: from cassarossa.samfundet.no (cassarossa.samfundet.no
	[129.241.93.19])
	by svr1.postgresql.org (Postfix) with ESMTP id 83C9ADAC41
	for <pgsql-performance@postgresql.org>;
	Wed, 26 Oct 2005 07:30:49 -0300 (ADT)
Received: from trofast.sesse.net ([129.241.93.32])
	by cassarossa.samfundet.no with esmtp (Exim 4.50) id 1EUiYT-0003kq-S0
	for pgsql-performance@postgresql.org; Wed, 26 Oct 2005 12:30:51 +0200
Received: from sesse by trofast.sesse.net with local (Exim 3.36 #1 (Debian))
	id 1EUiYV-0000WT-00
	for <pgsql-performance@postgresql.org>; Wed, 26 Oct 2005 12:30:51 +0200
Date: Wed, 26 Oct 2005 12:30:51 +0200
From: "Steinar H. Gunderson" <sgunderson@bigfoot.com>
To: pgsql-performance@postgresql.org
Subject: Re: zero performance on query
Message-ID: <20051026103051.GB1742@uio.no>
Mail-Followup-To: pgsql-performance@postgresql.org
References: <BAY23-F12AC56187BE1C2D1BAA64DCE690@phx.gbl>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
In-Reply-To: <BAY23-F12AC56187BE1C2D1BAA64DCE690@phx.gbl>
X-Operating-System: Linux 2.6.14-rc5 on a x86_64
X-Message-Flag: Outlook? --> http://www.mozilla.org/products/thunderbird/
User-Agent: Mutt/1.5.11
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.01 required=5 tests=[AWL=0.010]
X-Spam-Level: 
X-Archive-Number: 200510/384
X-Sequence-Number: 15152

On Tue, Oct 25, 2005 at 10:26:43PM -0600, Sidar López Cruz wrote:
> look at this:
> select count(*) from fotos where archivo not in (select archivo from 
> archivos)
> Aggregate  (cost=4899037992.36..4899037992.37 rows=1 width=0)
> ->  Seq Scan on fotos  (cost=22598.78..4899037338.07 rows=261716 width=0)
>       Filter: (NOT (subplan))
>       SubPlan
>         ->  Materialize  (cost=22598.78..39304.22 rows=805344 width=58)
>               ->  Seq Scan on archivos  (cost=0.00..13141.44 rows=805344 
> width=58)

Now, this is interesting; it seems to trigger exactly the same oddity as my
query did (at least one of them; the materialized sequential scan).

/* Steinar */
-- 
Homepage: http://www.sesse.net/

From pgsql-performance-owner@postgresql.org  Wed Oct 26 09:05:22 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 57CEBDA989
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 09:05:21 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 65650-09
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 12:05:17 +0000 (GMT)
Received: from Herge.rcsinc.local (mail.rcsonline.com [70.89.208.142])
	by svr1.postgresql.org (Postfix) with ESMTP id 47A0DDA924
	for <pgsql-performance@postgresql.org>;
	Wed, 26 Oct 2005 09:05:19 -0300 (ADT)
X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0
Content-class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Subject: Re: zero performance on query
Date: Wed, 26 Oct 2005 08:05:21 -0400
Message-ID: <6EE64EF3AB31D5448D0007DD34EEB3417DD6AF@Herge.rcsinc.local>
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
Thread-Topic: [PERFORM] zero performance on query
Thread-Index: AcXZ5d+gqmjnszfuSt6iRPE3JwUPcwAPuVlw
From: "Merlin Moncure" <merlin.moncure@rcsonline.com>
To: =?iso-8859-1?Q?Sidar_L=F3pez_Cruz?= <sidarlopez@hotmail.com>
Cc: <pgsql-performance@postgresql.org>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.082 required=5 tests=[AWL=0.032,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/385
X-Sequence-Number: 15153

> look at this:
> select count(*) from fotos where archivo not in (select archivo from
> archivos)
> Aggregate  (cost=3D4899037992.36..4899037992.37 rows=3D1 width=3D0)
> ->  Seq Scan on fotos  (cost=3D22598.78..4899037338.07 rows=3D261716 =
width=3D0)
>        Filter: (NOT (subplan))
>        SubPlan
>          ->  Materialize  (cost=3D22598.78..39304.22 rows=3D805344 =
width=3D58)
>                ->  Seq Scan on archivos  (cost=3D0.00..13141.44 =
rows=3D805344
> width=3D58)
>=20
> I WILL DIE WAITING FOR QUERY RESPONSE !!!

Try:
select count(*) from fotos f where not exists (select archivo from =
archivos a where a.archivo =3D f.archivo)=20

select count(*) from=20
(
	select archivo from fotos
	    except
	select archivo from archivos=09
);

From pgsql-performance-owner@postgresql.org  Wed Oct 26 12:22:32 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id BC472D9F0F
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 12:20:52 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 61160-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 15:20:49 +0000 (GMT)
Received: from cassarossa.samfundet.no (cassarossa.samfundet.no
	[129.241.93.19])
	by svr1.postgresql.org (Postfix) with ESMTP id AE0F1D6D96
	for <pgsql-performance@postgresql.org>;
	Wed, 26 Oct 2005 12:20:49 -0300 (ADT)
Received: from trofast.ipv6.sesse.net ([2001:700:300:dc03:20e:cff:fe36:a766]
	helo=trofast.sesse.net)
	by cassarossa.samfundet.no with esmtp (Exim 4.50) id 1EUn54-0000X6-6x
	for pgsql-performance@postgresql.org; Wed, 26 Oct 2005 17:20:47 +0200
Received: from sesse by trofast.sesse.net with local (Exim 3.36 #1 (Debian))
	id 1EUn55-00043g-00
	for <pgsql-performance@postgresql.org>; Wed, 26 Oct 2005 17:20:47 +0200
Date: Wed, 26 Oct 2005 17:20:47 +0200
From: "Steinar H. Gunderson" <sgunderson@bigfoot.com>
To: pgsql-performance@postgresql.org
Subject: Re: zero performance on query
Message-ID: <20051026152047.GA15377@uio.no>
Mail-Followup-To: pgsql-performance@postgresql.org
References: <6EE64EF3AB31D5448D0007DD34EEB3417DD6AF@Herge.rcsinc.local>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
In-Reply-To: <6EE64EF3AB31D5448D0007DD34EEB3417DD6AF@Herge.rcsinc.local>
X-Operating-System: Linux 2.6.14-rc5 on a x86_64
X-Message-Flag: Outlook? --> http://www.mozilla.org/products/thunderbird/
User-Agent: Mutt/1.5.11
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.01 required=5 tests=[AWL=0.010]
X-Spam-Level: 
X-Archive-Number: 200510/386
X-Sequence-Number: 15154

On Wed, Oct 26, 2005 at 08:05:21AM -0400, Merlin Moncure wrote:
> select count(*) from fotos f where not exists (select archivo from archivos a where a.archivo = f.archivo) 

This was an optimization before 7.4, but probably isn't anymore.

/* Steinar */
-- 
Homepage: http://www.sesse.net/

From pgsql-performance-owner@postgresql.org  Wed Oct 26 12:25:03 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id D4173DAEB9
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 12:25:02 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 57520-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 15:24:59 +0000 (GMT)
Received: from cicero1.cybercity.dk (cicero1.cybercity.dk [212.242.40.4])
	by svr1.postgresql.org (Postfix) with ESMTP id 80C8DDAEB6
	for <pgsql-performance@postgresql.org>;
	Wed, 26 Oct 2005 12:24:59 -0300 (ADT)
Received: from [192.168.0.79] (0x3e42eeca.adsl.cybercity.dk [62.66.238.202])
	by cicero1.cybercity.dk (Postfix) with ESMTP id 8FB7A7E3C89
	for <pgsql-performance@postgresql.org>;
	Wed, 26 Oct 2005 17:24:56 +0200 (CEST)
Message-ID: <435FA002.4060509@krap.dk>
Date: Wed, 26 Oct 2005 17:25:54 +0200
From: Svenne Krap <svenne@krap.dk>
User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: pgsql-performance@postgresql.org
Subject: Perfomance of views
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0 required=5 tests=[none]
X-Spam-Level: 
X-Archive-Number: 200510/387
X-Sequence-Number: 15155

Hi there.

I am currently building a system, where it would be nice to use multiple 
levels of views upon each other (it is a staticstics system, where 
traceability is important).

Is there any significant performance reduction in say 10 levels of views 
instead of one giant, nested sql-statement ? I especially think exection 
planner-wise.

The data mainly comes from one small to medium sized tabel (< 5 million 
rows) and a handfull small (< 5000 rows) support tables.
The hardware will be okay for the job, but nothing really fancy (specs 
are Xeon, 2G of memory, 6 SCSI-disks in a RAID1+0) . The base will be 
version 8.1 provided that it gets out of beta around end-of-year.

Svenne

From pgsql-performance-owner@postgresql.org  Wed Oct 26 15:07:07 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 976C7DAD5D
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 15:07:06 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 12986-10
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 18:07:03 +0000 (GMT)
Received: from wolff.to (wolff.to [66.93.197.194])
	by svr1.postgresql.org (Postfix) with SMTP id 769A0D9FA1
	for <pgsql-performance@postgresql.org>;
	Wed, 26 Oct 2005 15:07:03 -0300 (ADT)
Received: (qmail 21495 invoked by uid 500); 26 Oct 2005 18:08:46 -0000
Date: Wed, 26 Oct 2005 13:08:46 -0500
From: Bruno Wolff III <bruno@wolff.to>
To: Sidar =?iso-8859-1?Q?L=F3pez?= Cruz <sidarlopez@hotmail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: blue prints please
Message-ID: <20051026180846.GD11447@wolff.to>
Mail-Followup-To: Bruno Wolff III <bruno@wolff.to>,
	Sidar =?iso-8859-1?Q?L=F3pez?= Cruz <sidarlopez@hotmail.com>,
	pgsql-performance@postgresql.org
References: <BAY23-F2182E28A539382AE59FC51CE690@phx.gbl>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
In-Reply-To: <BAY23-F2182E28A539382AE59FC51CE690@phx.gbl>
User-Agent: Mutt/1.4.2.1i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.007 required=5 tests=[AWL=0.007]
X-Spam-Level: 
X-Archive-Number: 200510/388
X-Sequence-Number: 15156

On Tue, Oct 25, 2005 at 22:24:06 -0600,
  Sidar L�pez Cruz <sidarlopez@hotmail.com> wrote:
> where can i find bests practices for tunning postgresql?

You should first read the documentation. For 8.1, that would be here:
http://developer.postgresql.org/docs/postgres/runtime-config.html

There is also good information on techdocs at:
http://techdocs.postgresql.org/#techguides
(Look under the subcategory "optimising".)

From pgsql-performance-owner@postgresql.org  Wed Oct 26 17:33:36 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id CBD86DAFA1
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 17:33:35 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 80745-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 20:33:33 +0000 (GMT)
Received: from mail.picoip.com (external.xtracards.com [209.178.196.162])
	by svr1.postgresql.org (Postfix) with ESMTP id AAA4DDAF74
	for <pgsql-performance@postgresql.org>;
	Wed, 26 Oct 2005 17:33:33 -0300 (ADT)
Received: from localhost (localhost [127.0.0.1])
	by mail.picoip.com (Postfix) with ESMTP id 84AC45CE6F4;
	Wed, 26 Oct 2005 16:33:35 -0400 (EDT)
Received: from mail.picoip.com ([127.0.0.1])
	by localhost (mail.picoip.com [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 24545-09; Wed, 26 Oct 2005 16:33:34 -0400 (EDT)
Received: from [172.27.60.240] (unknown [172.27.60.240])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by mail.picoip.com (Postfix) with ESMTP id 712365CE6F3
	for <pgsql-performance@postgresql.org>;
	Wed, 26 Oct 2005 16:33:34 -0400 (EDT)
Message-ID: <435FE820.4070701@xtracards.com>
Date: Wed, 26 Oct 2005 16:33:36 -0400
From: "Edward Di Geronimo Jr." <edigeronimo@xtracards.com>
User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: pgsql-performance@postgresql.org
Subject: Performance issues with custom functions
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at mail.picoip.com
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.05 required=5 tests=[FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/389
X-Sequence-Number: 15157

I currently have an infrastructure that's based around SQL Server 2000. 
I'm trying to move some of the data over to Postgres, partly to reduce 
the load on the SQL Server machine and partly because some queries I'd 
like to run are too slow to be usuable on SQL Server. Mostly likely over 
time more and more data will move to Postgres. To help with this 
transition, I created a Postgres plugin which queries the contents of 
SQL Server tables via ODBC and returns a recordset. I then create views 
around the function and I can then read from the SQL Server tables as if 
they were local to Postgres.

I have four tables involved in this query. The major one is 
provider_location, which has about 2 million rows and is stored in 
Postgres. The other three are stored in SQL Server and accessed via 
views like I mentioned above. They are network, network_state, and 
xlat_tbl, and contain about 40, 250, and 500 rows. A simple select * 
from any of the views takes somewhere around 50ms.

This query in question was written for SQL Server. I have no idea why it 
was written in the form it was, but it ran at a reasonable speed when 
all the tables were on one machine. Running the original query (after 
adjusting for syntax differences) on Postgres resulted in a query that 
would run for hours, continually allocating more RAM. I eventually had 
to kill the process as it was devouring swap space. My assumption is 
that Postgres is doing the ODBC query for each row of a join somewhere, 
even though the function is marked stable (immutable didn't make a 
difference).

Flattening the query made it run in a few minutes. I think the flattened 
query is easier to read, and it runs faster, so I'm not complaining that 
I can't use the original query. But I'd like to know exactly what causes 
the bottleneck in the original query, and if there are other approaches 
to solving the issue in case I need them in future queries.

Below is the original query, the explain output, the modified query, the 
explain output, and the explain analyze output.

Ed

select
        pl.network_id,n.name as 
network_name,pl.state_cd,count(pl.state_cd) as provider_count
        from development.provider_location pl,development.network n
        where pl.network_id in (select ns.network_id
                        from development.network_state ns
                          where ns.from_date < current_time
                            and (ns.thru_date > current_time or 
ns.thru_date is null)
                        and (ns.state_cd = pl.state_cd or ns.state_cd='')
                          )
        and pl.network_id = n.network_id
        and pl.state_cd is not null
        and pl.state_cd in (select field_value from development.xlat_tbl 
where field_name ='State_CD')
        group by pl.state_cd,n.name,pl.network_id
        order by pl.state_cd,network_name;

Explain:

GroupAggregate  (cost=80548547.83..80549256.80 rows=47265 width=52)
  ->  Sort  (cost=80548547.83..80548665.99 rows=47265 width=52)
        Sort Key: pl.state_cd, odbc_select.name, pl.network_id
        ->  Hash Join  (cost=30.01..80543806.14 rows=47265 width=52)
              Hash Cond: (("outer".network_id)::text = 
("inner".network_id)::text)
              ->  Hash IN Join  (cost=15.01..80540931.61 rows=9453 width=20)
                    Hash Cond: (("outer".state_cd)::text = 
("inner".field_value)::text)
                    ->  Seq Scan on provider_location pl  
(cost=0.00..80535150.29 rows=1890593 width=20)
                          Filter: ((state_cd IS NOT NULL) AND (subplan))
                          SubPlan
                            ->  Function Scan on odbc_select  
(cost=0.00..42.50 rows=2 width=32)
                                  Filter: (((from_date)::text < 
(('now'::text)::time(6) with time zone)::text) AND (((thru_date)::text > 
(('now'::text)::time(6) with time zone)::text) OR (thru_date IS NULL)) 
AND (((state_cd)::text = ($0)::text) OR ((state_cd)::text = ''::text)))
                    ->  Hash  (cost=15.00..15.00 rows=5 width=32)
                          ->  Function Scan on odbc_select  
(cost=0.00..15.00 rows=5 width=32)
                                Filter: ((field_name)::text = 
'State_CD'::text)
              ->  Hash  (cost=12.50..12.50 rows=1000 width=64)
                    ->  Function Scan on odbc_select  (cost=0.00..12.50 
rows=1000 width=64)


Flattened query:

select
    pl.network_id,
    n.name as network_name,
    pl.state_cd,
    count(pl.state_cd) as provider_count
from
    development.network n,
    development.network_state ns,
    development.xlat_tbl xt,
    development.provider_location pl
where
    xt.field_name = 'State_CD'
    and n.network_id = ns.network_id
    and ns.from_date < current_timestamp
    and (ns.thru_date > current_timestamp or ns.thru_date is null)
    and (ns.state_cd = pl.state_cd or ns.state_cd='')
    and pl.network_id = n.network_id
    and pl.state_cd is not null
    and pl.state_cd = xt.field_value
group by
    pl.state_cd,
    n.name,
    pl.network_id
order by
    pl.state_cd,
    network_name;

Explain:

GroupAggregate  (cost=190089.94..190129.90 rows=2664 width=52)
  ->  Sort  (cost=190089.94..190096.60 rows=2664 width=52)
        Sort Key: pl.state_cd, odbc_select.name, pl.network_id
        ->  Merge Join  (cost=189895.73..189938.37 rows=2664 width=52)
              Merge Cond: ("outer"."?column4?" = "inner"."?column3?")
              ->  Sort  (cost=189833.40..189834.73 rows=533 width=52)
                    Sort Key: (pl.network_id)::text
                    ->  Hash Join  (cost=42.80..189809.26 rows=533 width=52)
                          Hash Cond: (("outer".network_id)::text = 
("inner".network_id)::text)
                          Join Filter: ((("inner".state_cd)::text = 
("outer".state_cd)::text) OR (("inner".state_cd)::text = ''::text))
                          ->  Hash Join  (cost=15.01..185908.10 
rows=94530 width=20)
                                Hash Cond: (("outer".state_cd)::text = 
("inner".field_value)::text)
                                ->  Seq Scan on provider_location pl  
(cost=0.00..166041.86 rows=3781186 width=20)
                                      Filter: (state_cd IS NOT NULL)
                                ->  Hash  (cost=15.00..15.00 rows=5 
width=32)
                                      ->  Function Scan on odbc_select  
(cost=0.00..15.00 rows=5 width=32)
                                            Filter: ((field_name)::text 
= 'State_CD'::text)
                          ->  Hash  (cost=27.50..27.50 rows=113 width=64)
                                ->  Function Scan on odbc_select  
(cost=0.00..27.50 rows=113 width=64)
                                      Filter: ((from_date < 
('now'::text)::timestamp(6) with time zone) AND ((thru_date > 
('now'::text)::timestamp(6) with time zone) OR (thru_date IS NULL)))
              ->  Sort  (cost=62.33..64.83 rows=1000 width=64)
                    Sort Key: (odbc_select.network_id)::text
                    ->  Function Scan on odbc_select  (cost=0.00..12.50 
rows=1000 width=64)

Explain Analyze:

"GroupAggregate  (cost=190089.94..190129.90 rows=2664 width=52) (actual 
time=254757.742..261725.786 rows=350 loops=1)"
"  ->  Sort  (cost=190089.94..190096.60 rows=2664 width=52) (actual 
time=254757.438..257267.224 rows=1316774 loops=1)"
"        Sort Key: pl.state_cd, odbc_select.name, pl.network_id"
"        ->  Merge Join  (cost=189895.73..189938.37 rows=2664 width=52) 
(actual time=189325.877..203579.050 rows=1316774 loops=1)"
"              Merge Cond: ("outer"."?column4?" = "inner"."?column3?")"
"              ->  Sort  (cost=189833.40..189834.73 rows=533 width=52) 
(actual time=189282.504..192284.766 rows=1316774 loops=1)"
"                    Sort Key: (pl.network_id)::text"
"                    ->  Hash Join  (cost=42.80..189809.26 rows=533 
width=52) (actual time=1177.758..151180.472 rows=1316774 loops=1)"
"                          Hash Cond: (("outer".network_id)::text = 
("inner".network_id)::text)"
"                          Join Filter: ((("inner".state_cd)::text = 
("outer".state_cd)::text) OR (("inner".state_cd)::text = ''::text))"
"                          ->  Hash Join  (cost=15.01..185908.10 
rows=94530 width=20) (actual time=1095.949..50495.766 rows=1890457 loops=1)"
"                                Hash Cond: (("outer".state_cd)::text = 
("inner".field_value)::text)"
"                                ->  Seq Scan on provider_location pl  
(cost=0.00..166041.86 rows=3781186 width=20) (actual 
time=1071.011..36224.961 rows=1891183 loops=1)"
"                                      Filter: (state_cd IS NOT NULL)"
"                                ->  Hash  (cost=15.00..15.00 rows=5 
width=32) (actual time=24.832..24.832 rows=0 loops=1)"
"                                      ->  Function Scan on odbc_select  
(cost=0.00..15.00 rows=5 width=32) (actual time=24.469..24.724 rows=51 
loops=1)"
"                                            Filter: ((field_name)::text 
= 'State_CD'::text)"
"                          ->  Hash  (cost=27.50..27.50 rows=113 
width=64) (actual time=81.684..81.684 rows=0 loops=1)"
"                                ->  Function Scan on odbc_select  
(cost=0.00..27.50 rows=113 width=64) (actual time=75.288..81.200 
rows=211 loops=1)"
"                                      Filter: ((from_date < 
('now'::text)::timestamp(6) with time zone) AND ((thru_date > 
('now'::text)::timestamp(6) with time zone) OR (thru_date IS NULL)))"
"              ->  Sort  (cost=62.33..64.83 rows=1000 width=64) (actual 
time=43.301..1258.901 rows=1289952 loops=1)"
"                    Sort Key: (odbc_select.network_id)::text"
"                    ->  Function Scan on odbc_select  (cost=0.00..12.50 
rows=1000 width=64) (actual time=43.010..43.109 rows=34 loops=1)"
"Total runtime: 261902.966 ms"


From pgsql-performance-owner@postgresql.org  Wed Oct 26 17:41:21 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id B1130DAF74
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 17:41:20 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 80370-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 20:41:15 +0000 (GMT)
Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.207])
	by svr1.postgresql.org (Postfix) with ESMTP id B57BCD9CA3
	for <pgsql-performance@postgresql.org>;
	Wed, 26 Oct 2005 17:41:15 -0300 (ADT)
Received: by wproxy.gmail.com with SMTP id 71so96696wra
	for <pgsql-performance@postgresql.org>;
	Wed, 26 Oct 2005 13:41:17 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:to:subject:mime-version:content-type;
	b=P9WWIXB2k8aAE4KHevfPFwODZHfW6kFjyHBCRRjFrWU68M/fwF/57zwIKstsBwgb6V7xocOfAtXswKYFj+2qwomgHBOfBCfleR/JffOYjz2IHQJ5qB0tc2C/ibOK1/qBt+GGJX1gW0yciI7I+effqBMR3aQgcGzmR381GX9leHA=
Received: by 10.54.80.7 with SMTP id d7mr656547wrb;
	Wed, 26 Oct 2005 13:41:17 -0700 (PDT)
Received: by 10.54.96.18 with HTTP; Wed, 26 Oct 2005 13:41:17 -0700 (PDT)
Message-ID: <cbd177510510261341l4ed7a214lda9d67af12f2ec21@mail.gmail.com>
Date: Wed, 26 Oct 2005 13:41:17 -0700
From: aurora <aurora00@gmail.com>
To: pgsql-performance@postgresql.org
Subject: browsing table with 2 million records
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="----=_Part_11717_26588224.1130359277791"
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.679 required=5 tests=[FROM_ENDS_IN_NUMS=0.516,
	HTML_00_10=0.138, HTML_MESSAGE=0.001, RCVD_BY_IP=0.024]
X-Spam-Level: 
X-Archive-Number: 200510/390
X-Sequence-Number: 15158

------=_Part_11717_26588224.1130359277791
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

I am running Postgre 7.4 on FreeBSD. The main table have 2 million record
(we would like to do at least 10 mil or more). It is mainly a FIFO structur=
e
with maybe 200,000 new records coming in each day that displace the older
records.

We have a GUI that let user browser through the record page by page at abou=
t
25 records a time. (Don't ask me why but we have to have this GUI). This
translates to something like

select count(*) from table <-- to give feedback about the DB size
select * from table order by date limit 25 offset 0

Tables seems properly indexed, with vacuum and analyze ran regularly. Still
this very basic SQLs takes up to a minute run.

I read some recent messages that select count(*) would need a table scan fo=
r
Postgre. That's disappointing. But I can accept an approximation if there
are some way to do so. But how can I optimize select * from table order by
date limit x offset y? One minute response time is not acceptable.

Any help would be appriciated.

Wy

------=_Part_11717_26588224.1130359277791
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

I am running Postgre 7.4 on FreeBSD. The main table have 2 million
record (we would like to do at least 10 mil or more). It is mainly a
FIFO structure with maybe 200,000 new records coming in each day that
displace the older records.<br>
<br>
We have a GUI that let user browser through the record page by page at
about 25 records a time. (Don't ask me why but we have to have this
GUI). This translates to something like<br>
<br>
&nbsp; select count(*) from table&nbsp;&nbsp; &lt;-- to give feedback about=
 the DB size<br>
&nbsp; select * from table order by date limit 25 offset 0<br>
<br>
Tables seems properly indexed, with vacuum and analyze ran regularly. Still=
 this very basic SQLs takes up to a minute run.<br>
<br>
I read some recent messages that select count(*) would need a table
scan for Postgre. That's disappointing. But I can accept an
approximation if there are some way to do so. But how can I optimize
select * from table order by date limit x offset y? One minute response
time is not acceptable.<br>
<br>
Any help would be appriciated.<br>
<br>
Wy<br>
<br>
<br>

------=_Part_11717_26588224.1130359277791--

From pgsql-performance-owner@postgresql.org  Wed Oct 26 17:59:46 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 1FAD3DAF8E
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 17:59:46 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 89971-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 20:59:43 +0000 (GMT)
Received: from mir3-fs.mir3.com (mail.mir3.com [65.208.188.100])
	by svr1.postgresql.org (Postfix) with ESMTP id 3528ADAF87
	for <pgsql-performance@postgresql.org>;
	Wed, 26 Oct 2005 17:59:43 -0300 (ADT)
Received: from archimedes ([172.16.2.68]) by mir3-fs.mir3.com with Microsoft
	SMTPSVC(5.0.2195.6713); Wed, 26 Oct 2005 14:03:09 -0700
Subject: Re: browsing table with 2 million records
From: Mark Lewis <mark.lewis@mir3.com>
To: aurora <aurora00@gmail.com>
Cc: pgsql-performance@postgresql.org
In-Reply-To: <cbd177510510261341l4ed7a214lda9d67af12f2ec21@mail.gmail.com>
References: <cbd177510510261341l4ed7a214lda9d67af12f2ec21@mail.gmail.com>
Content-Type: text/plain
Organization: MIR3, Inc.
Date: Wed, 26 Oct 2005 13:59:44 -0700
Message-Id: <1130360385.1156.12.camel@archimedes>
Mime-Version: 1.0
X-Mailer: Evolution 2.0.2 (2.0.2-22) 
Content-Transfer-Encoding: 7bit
X-OriginalArrivalTime: 26 Oct 2005 21:03:09.0552 (UTC)
	FILETIME=[AB53DF00:01C5DA70]
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.038 required=5 tests=[AWL=0.038]
X-Spam-Level: 
X-Archive-Number: 200510/391
X-Sequence-Number: 15159

Do you have an index on the date column?  Can you post an EXPLAIN
ANALYZE for the slow query?

-- Mark Lewis

On Wed, 2005-10-26 at 13:41 -0700, aurora wrote:
> I am running Postgre 7.4 on FreeBSD. The main table have 2 million
> record (we would like to do at least 10 mil or more). It is mainly a
> FIFO structure with maybe 200,000 new records coming in each day that
> displace the older records.
> 
> We have a GUI that let user browser through the record page by page at
> about 25 records a time. (Don't ask me why but we have to have this
> GUI). This translates to something like
> 
>   select count(*) from table   <-- to give feedback about the DB size
>   select * from table order by date limit 25 offset 0
> 
> Tables seems properly indexed, with vacuum and analyze ran regularly.
> Still this very basic SQLs takes up to a minute run.
> 
> I read some recent messages that select count(*) would need a table
> scan for Postgre. That's disappointing. But I can accept an
> approximation if there are some way to do so. But how can I optimize
> select * from table order by date limit x offset y? One minute
> response time is not acceptable.
> 
> Any help would be appriciated.
> 
> Wy
> 
> 


From pgsql-performance-owner@postgresql.org  Wed Oct 26 18:06:44 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 2EE59DAF7A
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 18:06:43 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 89392-10
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 21:06:38 +0000 (GMT)
Received: from koolancexeon.g2switchworks.com (mail.g2switchworks.com
	[63.87.162.25])
	by svr1.postgresql.org (Postfix) with ESMTP id 06370DAF5B
	for <pgsql-performance@postgresql.org>;
	Wed, 26 Oct 2005 18:06:39 -0300 (ADT)
Received: mail.g2switchworks.com 10.10.1.8 from 10.10.1.37 10.10.1.37 via HTTP
	with MS-WebStorage 6.5.6944
Received: from state.g2switchworks.com by mail.g2switchworks.com;
	26 Oct 2005 16:06:38 -0500
Subject: Re: browsing table with 2 million records
From: Scott Marlowe <smarlowe@g2switchworks.com>
To: aurora <aurora00@gmail.com>
Cc: pgsql-performance@postgresql.org
In-Reply-To: <cbd177510510261341l4ed7a214lda9d67af12f2ec21@mail.gmail.com>
References: <cbd177510510261341l4ed7a214lda9d67af12f2ec21@mail.gmail.com>
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Message-Id: <1130360798.2872.57.camel@state.g2switchworks.com>
Mime-Version: 1.0
X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) 
Date: Wed, 26 Oct 2005 16:06:38 -0500
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.007 required=5 tests=[AWL=0.007]
X-Spam-Level: 
X-Archive-Number: 200510/392
X-Sequence-Number: 15160

On Wed, 2005-10-26 at 15:41, aurora wrote:
> I am running Postgre 7.4 on FreeBSD. The main table have 2 million
> record (we would like to do at least 10 mil or more). It is mainly a
> FIFO structure with maybe 200,000 new records coming in each day that
> displace the older records.
> 
> We have a GUI that let user browser through the record page by page at
> about 25 records a time. (Don't ask me why but we have to have this
> GUI). This translates to something like
> 
>   select count(*) from table   <-- to give feedback about the DB size
>   select * from table order by date limit 25 offset 0
> 
> Tables seems properly indexed, with vacuum and analyze ran regularly.
> Still this very basic SQLs takes up to a minute run.
> 
> I read some recent messages that select count(*) would need a table
> scan for Postgre. That's disappointing. But I can accept an
> approximation if there are some way to do so. But how can I optimize
> select * from table order by date limit x offset y? One minute
> response time is not acceptable.

Have you run your script without the select count(*) part and timed it?

What does

explain analyze select * from table order by date limit 25 offset 0

say? 

Is date indexed?

From pgsql-performance-owner@postgresql.org  Wed Oct 26 18:09:35 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 0C39EDAFA3
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 18:09:34 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 95553-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 21:09:30 +0000 (GMT)
Received: from hosting.commandprompt.com (128.commandprompt.com
	[207.173.200.128])
	by svr1.postgresql.org (Postfix) with ESMTP id BAF4DDAF9F
	for <pgsql-performance@postgresql.org>;
	Wed, 26 Oct 2005 18:09:31 -0300 (ADT)
Received: from [192.168.1.55] (fc1smp [66.93.38.87]) (authenticated bits=0)
	by hosting.commandprompt.com (8.13.4/8.13.4) with ESMTP id
	j9QL5hbM013004; Wed, 26 Oct 2005 14:05:44 -0700
Subject: Re: browsing table with 2 million records
From: "Joshua D. Drake" <jd@commandprompt.com>
Reply-To: jd@commandprompt.com
To: aurora <aurora00@gmail.com>
Cc: pgsql-performance@postgresql.org
In-Reply-To: <cbd177510510261341l4ed7a214lda9d67af12f2ec21@mail.gmail.com>
References: <cbd177510510261341l4ed7a214lda9d67af12f2ec21@mail.gmail.com>
Content-Type: text/plain
Organization: Command Prompt, Inc.
Date: Wed, 26 Oct 2005 14:09:37 -0700
Message-Id: <1130360977.21880.23.camel@jd.commandprompt.com>
Mime-Version: 1.0
X-Mailer: Evolution 2.4.0 (2.4.0-3.1.fc4.nr) 
Content-Transfer-Encoding: 7bit
X-Greylist: Sender succeded SMTP AUTH authentication, not delayed by
	milter-greylist-1.6 (hosting.commandprompt.com [192.168.1.101]);
	Wed, 26 Oct 2005 14:05:44 -0700 (PDT)
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.011 required=5 tests=[AWL=0.011]
X-Spam-Level: 
X-Archive-Number: 200510/393
X-Sequence-Number: 15161


> We have a GUI that let user browser through the record page by page at
> about 25 records a time. (Don't ask me why but we have to have this
> GUI). This translates to something like
> 
>   select count(*) from table   <-- to give feedback about the DB size

Do you have a integer field that is an ID that increments? E.g; serial?

>   select * from table order by date limit 25 offset 0

You could use a cursor.

Sincerely,

Joshua D. Drake


> 
> Tables seems properly indexed, with vacuum and analyze ran regularly.
> Still this very basic SQLs takes up to a minute run.
> 
> I read some recent messages that select count(*) would need a table
> scan for Postgre. That's disappointing. But I can accept an
> approximation if there are some way to do so. But how can I optimize
> select * from table order by date limit x offset y? One minute
> response time is not acceptable.
> 
> Any help would be appriciated.
> 
> Wy
> 
> 
-- 
The PostgreSQL Company - Command Prompt, Inc. 1.503.667.4564
PostgreSQL Replication, Consulting, Custom Development, 24x7 support
Managed Services, Shared and Dedicated Hosting
Co-Authors: plPHP, plPerlNG - http://www.commandprompt.com/


From pgsql-performance-owner@postgresql.org  Wed Oct 26 18:22:58 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 3DA49DAE64
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 18:22:58 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 99935-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 21:22:54 +0000 (GMT)
Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.194])
	by svr1.postgresql.org (Postfix) with ESMTP id E0587DAF97
	for <pgsql-performance@postgresql.org>;
	Wed, 26 Oct 2005 18:22:55 -0300 (ADT)
Received: by wproxy.gmail.com with SMTP id 71so99921wra
	for <pgsql-performance@postgresql.org>;
	Wed, 26 Oct 2005 14:22:58 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references;
	b=YP7QNdqlwgePnlHyAkpWHVYiJdE6uSkFqsW1bz3VctS8NK1wLq3XnH2rQW27azeimWz76NuOGH+/aT/i0Ya6lHJAai+eRyHYOYy3pEOF/y2iHuH8B86Mym57D56OAdKxtHab64MevKO60LAj7Lvg8t2gL4RV/I5v8jcvlVa4NuY=
Received: by 10.54.76.5 with SMTP id y5mr691637wra;
	Wed, 26 Oct 2005 14:22:58 -0700 (PDT)
Received: by 10.54.96.18 with HTTP; Wed, 26 Oct 2005 14:22:58 -0700 (PDT)
Message-ID: <cbd177510510261422h17f277d3w92c834164cf75a4e@mail.gmail.com>
Date: Wed, 26 Oct 2005 14:22:58 -0700
From: aurora <aurora00@gmail.com>
To: Mark Lewis <mark.lewis@mir3.com>
Subject: Re: browsing table with 2 million records
Cc: pgsql-performance@postgresql.org
In-Reply-To: <1130360385.1156.12.camel@archimedes>
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="----=_Part_12145_3071535.1130361778152"
References: <cbd177510510261341l4ed7a214lda9d67af12f2ec21@mail.gmail.com>
	<1130360385.1156.12.camel@archimedes>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.758 required=5 tests=[AWL=-0.078,
	FROM_ENDS_IN_NUMS=0.516, HTML_10_20=0.295, HTML_MESSAGE=0.001,
	RCVD_BY_IP=0.024]
X-Spam-Level: 
X-Archive-Number: 200510/394
X-Sequence-Number: 15162

------=_Part_12145_3071535.1130361778152
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

>> select * from table order by date limit 25 offset 0

> Do you have an index on the date column? Can you post an EXPLAIN
> ANALYZE for the slow query?

Wow! Now that I look again there are actually 2 date fields. One is indexed
and one is not. Order by was done on the column without index. Using the
indexed column turn a seq scan into index scan and the query performance is
totally fine now.

It would still be helpful if select count(*) can perform well.

Thanks!

Wy

------=_Part_12145_3071535.1130361778152
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

&gt;&gt;
&nbsp; select * from table order by date limit 25 offset 0<br>
<br>
&gt; Do you have an index on the date column? &nbsp;Can you post an EXPLAIN=
<br>
&gt; ANALYZE for the slow query?<br>
<br>
Wow! Now that I look again there are actually 2 date fields. One is
indexed and one is not. Order by was done on the column without index.
Using the indexed column turn a seq scan into index scan and the query
performance is totally fine now.<br>
<br>
It would still be helpful if select count(*) can perform well.<br>
<br>
Thanks!<br>
<br>
Wy<br>

------=_Part_12145_3071535.1130361778152--

From pgsql-performance-owner@postgresql.org  Wed Oct 26 18:28:37 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 14D23D9CA3
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 18:28:37 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 01401-03
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 21:28:32 +0000 (GMT)
Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.205])
	by svr1.postgresql.org (Postfix) with ESMTP id 9EEA9DAF83
	for <pgsql-performance@postgresql.org>;
	Wed, 26 Oct 2005 18:28:33 -0300 (ADT)
Received: by wproxy.gmail.com with SMTP id 71so100305wra
	for <pgsql-performance@postgresql.org>;
	Wed, 26 Oct 2005 14:28:36 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references;
	b=LCdOdfiySlPuhI7MN4GhmTzAvNopXieKf2X8cuxVQFHXvWycv4gDfC3aA7PHIZvMW8NjbVtQS1hReaBGZ7jbOgUdRmVNMD+YeFNj/KNksPXhHSvsqTTu/7lJn3xjS6HetjUREc/sjHaTxXgq/aE3VLvpLabvkTjM5jEQW6yx3Gk=
Received: by 10.54.112.11 with SMTP id k11mr695765wrc;
	Wed, 26 Oct 2005 14:28:36 -0700 (PDT)
Received: by 10.54.84.8 with HTTP; Wed, 26 Oct 2005 14:28:36 -0700 (PDT)
Message-ID: <33c6269f0510261428s1d320fc6w5e0ea16cfa333175@mail.gmail.com>
Date: Wed, 26 Oct 2005 17:28:36 -0400
From: Alex Turner <armtuk@gmail.com>
To: jd@commandprompt.com
Subject: Re: browsing table with 2 million records
Cc: aurora <aurora00@gmail.com>, pgsql-performance@postgresql.org
In-Reply-To: <1130360977.21880.23.camel@jd.commandprompt.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
References: <cbd177510510261341l4ed7a214lda9d67af12f2ec21@mail.gmail.com>
	<1130360977.21880.23.camel@jd.commandprompt.com>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.111 required=5 tests=[AWL=0.087, RCVD_BY_IP=0.024]
X-Spam-Level: 
X-Archive-Number: 200510/395
X-Sequence-Number: 15163

You could also create your own index so to speak as a table that
simply contains a list of primary keys and an order value field that
you can use as your offset.  This can be kept in sync with the master
table using triggers pretty easily.  2 million is not very much if you
only have a integer pkey, and an integer order value, then you can
join it against the main table.

create table my_index_table (
primary_key_value int,
order_val int,
primary key (primary_key_value));

create index my_index_table_order_val_i on index_table (order_val);

select * from main_table a, my_index_table b where b.order_val>=3D25 and
b.order_val<50 and a.primary_key_id=3Db.primary_key_id

If the data updates alot then this won't work as well though as the
index table will require frequent updates to potentialy large number
of records (although a small number of pages so it still won't be
horrible).

Alex Turner
NetEconomist

On 10/26/05, Joshua D. Drake <jd@commandprompt.com> wrote:
>
> > We have a GUI that let user browser through the record page by page at
> > about 25 records a time. (Don't ask me why but we have to have this
> > GUI). This translates to something like
> >
> >   select count(*) from table   <-- to give feedback about the DB size
>
> Do you have a integer field that is an ID that increments? E.g; serial?
>
> >   select * from table order by date limit 25 offset 0
>
> You could use a cursor.
>
> Sincerely,
>
> Joshua D. Drake
>
>
> >
> > Tables seems properly indexed, with vacuum and analyze ran regularly.
> > Still this very basic SQLs takes up to a minute run.
> >
> > I read some recent messages that select count(*) would need a table
> > scan for Postgre. That's disappointing. But I can accept an
> > approximation if there are some way to do so. But how can I optimize
> > select * from table order by date limit x offset y? One minute
> > response time is not acceptable.
> >
> > Any help would be appriciated.
> >
> > Wy
> >
> >
> --
> The PostgreSQL Company - Command Prompt, Inc. 1.503.667.4564
> PostgreSQL Replication, Consulting, Custom Development, 24x7 support
> Managed Services, Shared and Dedicated Hosting
> Co-Authors: plPHP, plPerlNG - http://www.commandprompt.com/
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: don't forget to increase your free space map settings
>

From pgsql-performance-owner@postgresql.org  Wed Oct 26 18:32:01 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id AAB82DAFA4
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 18:32:00 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 01691-03
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 21:31:57 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id 9CE42DAFA3
	for <pgsql-performance@postgresql.org>;
	Wed, 26 Oct 2005 18:31:58 -0300 (ADT)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j9QLVvwD011776;
	Wed, 26 Oct 2005 17:31:57 -0400 (EDT)
To: aurora <aurora00@gmail.com>
Cc: Mark Lewis <mark.lewis@mir3.com>,
	pgsql-performance@postgresql.org
Subject: Re: browsing table with 2 million records 
In-reply-to: <cbd177510510261422h17f277d3w92c834164cf75a4e@mail.gmail.com> 
References: <cbd177510510261341l4ed7a214lda9d67af12f2ec21@mail.gmail.com>
	<1130360385.1156.12.camel@archimedes>
	<cbd177510510261422h17f277d3w92c834164cf75a4e@mail.gmail.com>
Comments: In-reply-to aurora <aurora00@gmail.com>
	message dated "Wed, 26 Oct 2005 14:22:58 -0700"
Date: Wed, 26 Oct 2005 17:31:57 -0400
Message-ID: <11775.1130362317@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/396
X-Sequence-Number: 15164

aurora <aurora00@gmail.com> writes:
> It would still be helpful if select count(*) can perform well.

If you can settle for an approximate count, pg_class.reltuples might
help you.

			regards, tom lane

From pgsql-performance-owner@postgresql.org  Wed Oct 26 18:37:28 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id D8CB6DAF89
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 18:37:27 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 05207-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 21:37:24 +0000 (GMT)
Received: from cassarossa.samfundet.no (cassarossa.samfundet.no
	[129.241.93.19])
	by svr1.postgresql.org (Postfix) with ESMTP id 41D36DAF7B
	for <pgsql-performance@postgresql.org>;
	Wed, 26 Oct 2005 18:37:25 -0300 (ADT)
Received: from trofast.ipv6.sesse.net ([2001:700:300:dc03:20e:cff:fe36:a766]
	helo=trofast.sesse.net)
	by cassarossa.samfundet.no with esmtp (Exim 4.50) id 1EUsxZ-0006My-Ax
	for pgsql-performance@postgresql.org; Wed, 26 Oct 2005 23:37:26 +0200
Received: from sesse by trofast.sesse.net with local (Exim 3.36 #1 (Debian))
	id 1EUsxe-0000gS-00
	for <pgsql-performance@postgresql.org>; Wed, 26 Oct 2005 23:37:30 +0200
Date: Wed, 26 Oct 2005 23:37:30 +0200
From: "Steinar H. Gunderson" <sgunderson@bigfoot.com>
To: pgsql-performance@postgresql.org
Subject: Re: Materializing a sequential scan
Message-ID: <20051026213730.GA2295@uio.no>
Mail-Followup-To: pgsql-performance@postgresql.org
References: <20051019174544.GA32303@samfundet.no>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
In-Reply-To: <20051019174544.GA32303@samfundet.no>
X-Operating-System: Linux 2.6.14-rc5 on a x86_64
X-Message-Flag: Outlook? --> http://www.mozilla.org/products/thunderbird/
User-Agent: Mutt/1.5.11
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.01 required=5 tests=[AWL=0.010]
X-Spam-Level: 
X-Archive-Number: 200510/397
X-Sequence-Number: 15165

Hi,

I finally found what I believe is the root cause for the hopeless
performance, after a lot of query rewriting:

>  Subquery Scan mdb_effektiv_tilgang  (cost=19821.69..4920621.69 rows=10000 width=48)
>    Filter: ((NOT (hashed subplan)) AND (NOT (subplan)))

The problem here is simply that 8.1 refuses to hash this part of the plan:

>      ->  Materialize  (cost=546.45..742.37 rows=19592 width=38)
>            ->  Seq Scan on rita_tilgang  (cost=0.00..526.86 rows=19592 width=38)
>      ->  Seq Scan on personer_nylig_slettet  (cost=0.00..31.40 rows=2140 width=4)

probably because of the NOT IN with a function inside; I rewrote it to an
EXCEPT (which is not equivalent, but good enough for my use), and it
instantly hashed the other subplan, and the query went speedily. Well, at
least in four seconds and not several hours...

Any good ideas why 8.1 would refuse to do this, when 7.4 would do it? It does
not matter how high I set my work_mem; even at 2.000.000 it refused to hash
the subplan.

/* Steinar */
-- 
Homepage: http://www.sesse.net/

From pgsql-performance-owner@postgresql.org  Wed Oct 26 18:49:58 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id F2D4DDA99E
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 18:49:56 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 07188-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 21:49:53 +0000 (GMT)
Received: from boutiquenumerique.com (boutiquenumerique.com [82.67.9.10])
	by svr1.postgresql.org (Postfix) with ESMTP id 2304DDA970
	for <pgsql-performance@postgresql.org>;
	Wed, 26 Oct 2005 18:49:53 -0300 (ADT)
Received: (qmail 5803 invoked from network); 26 Oct 2005 23:51:06 +0200
Received: from unknown (HELO localhost) (boutiquenumerique-lists@192.168.0.4)
	by boutiquenumerique.com with SMTP; 26 Oct 2005 23:51:06 +0200
Date: Wed, 26 Oct 2005 23:49:54 +0200
To: aurora <aurora00@gmail.com>, pgsql-performance@postgresql.org
Subject: Re: browsing table with 2 million records
References: <cbd177510510261341l4ed7a214lda9d67af12f2ec21@mail.gmail.com>
From: PFC <lists@boutiquenumerique.com>
Organization: =?iso-8859-15?Q?La_Boutique_Num=E9rique?=
Content-Type: text/plain; format=flowed; delsp=yes; charset=iso-8859-15
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Message-ID: <op.sy9v9gketh1vuj@localhost>
In-Reply-To: <cbd177510510261341l4ed7a214lda9d67af12f2ec21@mail.gmail.com>
User-Agent: Opera M2/8.0 (Linux, build 1095)
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/398
X-Sequence-Number: 15166


> I am running Postgre 7.4 on FreeBSD. The main table have 2 million record
> (we would like to do at least 10 mil or more). It is mainly a FIFO  
> structure
> with maybe 200,000 new records coming in each day that displace the older
> records.

	I'm so sorry, but I have to rant XDDD

	People who present a list of 100 items, paginated with 10 items per page  
so that it fits on half a 800x600 screen should be shot.
	I can scroll with my mousewheel and use text search in my browser...

	People who present a paginated view with 100.000 pages where you have to  
apply bisection search by hand to find records starting with "F" are on  
page 38651 should be forced to use a keyboard with just 1 key and type in  
morse code.

	Problem of pagination is that the page number is meaningless and rather  
useless to the user. It is also meaningless to the database, which means  
you have to use slow kludges like count() and limit/offset. And as people  
insert stuff in the table while you browse, when you hit next page you  
will see on top, half of what was on the previous page, because it was  
pushed down by new records. Or you might miss records.

	So, rather than using a meaningless "record offset" as a page number, you  
can use something meaningful, like a date, first letter of a name, region,  
etc.

	Of course, MySQL, always eager to encourage sucky-sucky practices,  
provides a neat CALC_FOUND_ROWS hack, which, while not being super SQL  
standard compliant, allows you to retrieve the number of rows the query  
would have returned if you wouldn't have used limit, so you can compute  
the number of pages and grab one page with only one query.

	So people use paginators instead of intelligent solutions, like  
xmlhttp+javascript enabled autocompletion in forms, etc. And you have to  
scroll to page 38651 to find letter "F".

	So if you need to paginate on your site :

	CHEAT !!!!

	Who needs a paginated view with 100.000 pages ?

	- Select min(date) and max(date) from your table
	- Present a nifty date selector to choose the records from any day, hour,  
minute, second
	- show them, with "next day" and "previous day" buttons

	- It's more useful to the user (most likely he wants to know what  
happened on 01/05/2005 rather than view page 2857)
	- It's faster (no more limit/offset ! just "date BETWEEN a AND b",  
indexed of course)
	- no more new items pushing old ones to the next page while you browse
	- you can pretend to your boss it's just like a paginated list

	












From pgsql-performance-owner@postgresql.org  Wed Oct 26 19:48:19 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id DA14FDAF79
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 19:48:18 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 30192-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 22:48:15 +0000 (GMT)
Received: from window.monsterlabs.com (window.monsterlabs.com
	[216.183.105.176])
	by svr1.postgresql.org (Postfix) with SMTP id 04C00D9F7F
	for <pgsql-performance@postgresql.org>;
	Wed, 26 Oct 2005 19:48:16 -0300 (ADT)
Received: (qmail 4128 invoked from network); 26 Oct 2005 22:48:19 -0000
Received: from pcp0012204803pcs.blairblvd.tn.nash.comcast.net (HELO
	?192.168.15.103?) (69.245.49.69)
	by 0 with SMTP; 26 Oct 2005 22:48:19 -0000
In-Reply-To: <dj5gjc$q0g$1@news.host.net>
References: <dj5gjc$q0g$1@news.host.net>
Mime-Version: 1.0 (Apple Message framework v734)
Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed
Message-Id: <48454B5A-D7D5-4387-B00F-CF5D1B9916EC@sitening.com>
Cc: PgSQL Performance <pgsql-performance@postgresql.org>
Content-Transfer-Encoding: 7bit
From: "Thomas F. O'Connell" <tfo@sitening.com>
Subject: Re: tuning seqscan costs
Date: Wed, 26 Oct 2005 17:48:17 -0500
To: Katherine Stoovs <ambrosiac@nedsenta.nl>
X-Mailer: Apple Mail (2.734)
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.016 required=5 tests=[AWL=0.016]
X-Spam-Level: 
X-Archive-Number: 200510/399
X-Sequence-Number: 15167


On Oct 19, 2005, at 9:51 AM, Katherine Stoovs wrote:

> I want to correlate two index rows of different tables to find an
> offset so that
>
> table1.value = table2.value AND table1.id = table2.id + offset
>
> is true for a maximum number of rows.
>
> To achieve this, I have the two tables and a table with possible
> offset values and execute a query:
>
> SELECT value,(SELECT COUNT(*) FROM table1,table2
>                               WHERE table1.value = table2.value AND
>                                     table1.id = table2.id + offset)
>              AS matches FROM offsets ORDER BY matches;
>
> The query is very inefficient, however, because the planner doesn't
> use my indexes and executes seqscans instead. I can get it to execute
> fast by setting ENABLE_SEQSCAN to OFF, but I have read this will make
> the performance bad on other query types so I want to know how to
> tweak the planner costs or possibly other stats so the planner will
> plan the query correctly and use index scans. There must be something
> wrong in the planning parameters after all if a plan that is slower by
> a factor of tens or hundreds becomes estimated better than the fast
> variant.
>
> I have already issued ANALYZE commands on the tables.
>
> Thanks for your help,
> Katherine Stoovs

Katherine,

If offset is a column in offsets, can you add an index on the  
expresion table2.id + offset?

http://www.postgresql.org/docs/8.0/static/indexes-expressional.html

--
Thomas F. O'Connell
Co-Founder, Information Architect
Sitening, LLC

Open Source Solutions. Optimized Web Development.

http://www.sitening.com/
110 30th Avenue North, Suite 6
Nashville, TN 37203-6320
615-469-5150
615-469-5151 (fax)

From pgsql-performance-owner@postgresql.org  Wed Oct 26 20:06:21 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id BD227DAF95
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 20:06:19 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 30334-04
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 23:06:16 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id A6860DAF7D
	for <pgsql-performance@postgresql.org>;
	Wed, 26 Oct 2005 20:06:17 -0300 (ADT)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j9QN6FIQ012334;
	Wed, 26 Oct 2005 19:06:15 -0400 (EDT)
To: "Steinar H. Gunderson" <sgunderson@bigfoot.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Materializing a sequential scan 
In-reply-to: <20051026213730.GA2295@uio.no> 
References: <20051019174544.GA32303@samfundet.no>
	<20051026213730.GA2295@uio.no>
Comments: In-reply-to "Steinar H. Gunderson" <sgunderson@bigfoot.com>
	message dated "Wed, 26 Oct 2005 23:37:30 +0200"
Date: Wed, 26 Oct 2005 19:06:15 -0400
Message-ID: <12333.1130367975@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/400
X-Sequence-Number: 15168

"Steinar H. Gunderson" <sgunderson@bigfoot.com> writes:
> Any good ideas why 8.1 would refuse to do this, when 7.4 would do it? It does
> not matter how high I set my work_mem; even at 2.000.000 it refused to hash
> the subplan.

AFAICS, subplan_is_hashable() is testing the same conditions in 7.4 and
HEAD, so this isn't clear.  Want to step through it and see where it's
deciding not to hash?

			regards, tom lane

From pgsql-performance-owner@postgresql.org  Wed Oct 26 20:18:36 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 5BEBBDAF91
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 20:18:36 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 40812-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 23:18:32 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id 46E9ADAF7B
	for <pgsql-performance@postgresql.org>;
	Wed, 26 Oct 2005 20:18:34 -0300 (ADT)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j9QNIbt6012438;
	Wed, 26 Oct 2005 19:18:37 -0400 (EDT)
To: "Edward Di Geronimo Jr." <edigeronimo@xtracards.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Performance issues with custom functions 
In-reply-to: <435FE820.4070701@xtracards.com> 
References: <435FE820.4070701@xtracards.com>
Comments: In-reply-to "Edward Di Geronimo Jr." <edigeronimo@xtracards.com>
	message dated "Wed, 26 Oct 2005 16:33:36 -0400"
Date: Wed, 26 Oct 2005 19:18:37 -0400
Message-ID: <12437.1130368717@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/401
X-Sequence-Number: 15169

"Edward Di Geronimo Jr." <edigeronimo@xtracards.com> writes:
> ... I'd like to know exactly what causes 
> the bottleneck in the original query, and if there are other approaches 
> to solving the issue in case I need them in future queries.

This is fairly hard to read ... it would help a lot if you had shown the
view definitions that the query relies on, so that we could match up the
plan elements with the query a bit better.

However, I'm thinking the problem is with this IN clause:

>         where pl.network_id in (select ns.network_id
>                         from development.network_state ns
>                           where ns.from_date < current_time
>                             and (ns.thru_date > current_time or 
> ns.thru_date is null)
>                         and (ns.state_cd = pl.state_cd or ns.state_cd='')
>                           )

Because the sub-SELECT references pl.state_cd (an outer variable
reference), there's no chance of optimizing this into a join-style IN.
So the sub-SELECT has to be re-executed for each row of the outer query.

BTW, it's not apparent to me that your "flattened" query gives the same
answers as the original.  What if a pl row can join to more than one
row of the ns output?

			regards, tom lane

From pgsql-performance-owner@postgresql.org  Wed Oct 26 20:22:18 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 6D77EDAF62
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 20:22:17 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 38939-04
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 23:22:11 +0000 (GMT)
Received: from cassarossa.samfundet.no (cassarossa.samfundet.no
	[129.241.93.19])
	by svr1.postgresql.org (Postfix) with ESMTP id 60F11DAFA7
	for <pgsql-performance@postgresql.org>;
	Wed, 26 Oct 2005 20:22:13 -0300 (ADT)
Received: from trofast.sesse.net ([129.241.93.32])
	by cassarossa.samfundet.no with esmtp (Exim 4.50) id 1EUub0-0007KW-Fs
	for pgsql-performance@postgresql.org; Thu, 27 Oct 2005 01:22:15 +0200
Received: from sesse by trofast.sesse.net with local (Exim 3.36 #1 (Debian))
	id 1EUub6-0001pO-00
	for <pgsql-performance@postgresql.org>; Thu, 27 Oct 2005 01:22:20 +0200
Date: Thu, 27 Oct 2005 01:22:19 +0200
From: "Steinar H. Gunderson" <sgunderson@bigfoot.com>
To: pgsql-performance@postgresql.org
Subject: Re: Materializing a sequential scan
Message-ID: <20051026232219.GA6390@uio.no>
Mail-Followup-To: pgsql-performance@postgresql.org
References: <20051019174544.GA32303@samfundet.no>
	<20051026213730.GA2295@uio.no> <12333.1130367975@sss.pgh.pa.us>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
In-Reply-To: <12333.1130367975@sss.pgh.pa.us>
X-Operating-System: Linux 2.6.14-rc5 on a x86_64
X-Message-Flag: Outlook? --> http://www.mozilla.org/products/thunderbird/
User-Agent: Mutt/1.5.11
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.01 required=5 tests=[AWL=0.010]
X-Spam-Level: 
X-Archive-Number: 200510/402
X-Sequence-Number: 15170

On Wed, Oct 26, 2005 at 07:06:15PM -0400, Tom Lane wrote:
> AFAICS, subplan_is_hashable() is testing the same conditions in 7.4 and
> HEAD, so this isn't clear.  Want to step through it and see where it's
> deciding not to hash?

Line 639, ie.:

635                 if (!optup->oprcanhash || optup->oprcom != opid ||
636                         !func_strict(optup->oprcode))
637                 {
638                         ReleaseSysCache(tup);
639                         return false;
640                 }

gdb gives

(gdb) print *optup
$2 = {oprname = {
    data = "\220Ü2\b\000\000\000\000\000\000\000\000\005\230-\b", '\0' <repeats 16 times>, "X\0305\b\020\000\000\000\000\000\000\000ئ>\b\020\000\000\000\000\000\000\000ð\213>\b\020\000\000", alignmentDummy = 137550992}, oprnamespace = 137542808, oprowner = 64, oprkind = 8 '\b', oprcanhash = -112 '\220', oprleft = 2, oprright = 0, 
  oprresult = 0, oprcom = 0, oprnegate = 0, oprlsortop = 0, oprrsortop = 0, oprltcmpop = 0, oprgtcmpop = 0, oprcode = 0, oprrest = 0, oprjoin = 0}

(gdb) print opid 
$3 = 2373

So it's complaining about the optup->oprcom != opid part. This is of course
on the third run through the loop, ie. it's complaining about the argument
which is run through the function kortsys2.effektiv_dato(date)... For
convenience, I've listed it again here:

CREATE FUNCTION kortsys2.effektiv_dato(date) RETURNS date
AS
        'SELECT CASE WHEN $1 < CURRENT_DATE THEN CURRENT_DATE ELSE $1 END'
LANGUAGE SQL STABLE;
	
/* Steinar */
-- 
Homepage: http://www.sesse.net/

From pgsql-performance-owner@postgresql.org  Wed Oct 26 20:47:32 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 4221ED9F7F
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 20:47:31 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 41141-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 23:47:27 +0000 (GMT)
Received: from hotmail.com (bay23-f3.bay23.hotmail.com [64.4.22.53])
	by svr1.postgresql.org (Postfix) with ESMTP id D9623D8640
	for <pgsql-performance@postgresql.org>;
	Wed, 26 Oct 2005 20:47:28 -0300 (ADT)
Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC;
	Wed, 26 Oct 2005 16:47:32 -0700
Message-ID: <BAY23-F36614886359D96AC48B8BCE690@phx.gbl>
Received: from 196.40.18.42 by by23fd.bay23.hotmail.msn.com with HTTP;
	Wed, 26 Oct 2005 23:47:31 GMT
X-Originating-IP: [196.40.18.42]
X-Originating-Email: [sidarlopez@hotmail.com]
X-Sender: sidarlopez@hotmail.com
From: =?iso-8859-1?B?U2lkYXIgTPNwZXogQ3J1eg==?= <sidarlopez@hotmail.com>
To: pgsql-performance@postgresql.org
Subject: performance on query
Date: Wed, 26 Oct 2005 17:47:31 -0600
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1; format=flowed
X-OriginalArrivalTime: 26 Oct 2005 23:47:32.0305 (UTC)
	FILETIME=[A1FC8C10:01C5DA87]
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=1.326 required=5 tests=[AWL=-0.424,
	DNS_FROM_RFC_ABUSE=0.374, DNS_FROM_RFC_POST=1.376,
	MSGID_FROM_MTA_HEADER=0]
X-Spam-Level: *
X-Archive-Number: 200510/403
X-Sequence-Number: 15171

I DON'T KNOW WHAT TO DO WITH THIS QUERYS...
Comparation with sql server, sql server wins !!!


Table sizes:
archivos: 40MB
fotos: 55MB

select count(1) from fotos f where not exists (select a.archivo from 
archivos a where a.archivo=f.archivo)
173713 ms.
110217 ms.
83122 ms.

select count(*) from
(
	select archivo from fotos
	    except
	select archivo from archivos
) x;
201479 ms.

SELECT count(*)
FROM fotos f
LEFT JOIN archivos a USING(archivo)
WHERE a.archivo IS NULL
199523 ms.

_________________________________________________________________
MSN Amor: busca tu � naranja http://latam.msn.com/amor/


From pgsql-performance-owner@postgresql.org  Wed Oct 26 20:53:05 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 2313CDAFAB
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 20:53:05 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 44426-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 23:53:01 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id 67967DAF7B
	for <pgsql-performance@postgresql.org>;
	Wed, 26 Oct 2005 20:53:03 -0300 (ADT)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j9QNr21U012709;
	Wed, 26 Oct 2005 19:53:02 -0400 (EDT)
To: "Steinar H. Gunderson" <sgunderson@bigfoot.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Materializing a sequential scan 
In-reply-to: <20051026232219.GA6390@uio.no> 
References: <20051019174544.GA32303@samfundet.no>
	<20051026213730.GA2295@uio.no> <12333.1130367975@sss.pgh.pa.us>
	<20051026232219.GA6390@uio.no>
Comments: In-reply-to "Steinar H. Gunderson" <sgunderson@bigfoot.com>
	message dated "Thu, 27 Oct 2005 01:22:19 +0200"
Date: Wed, 26 Oct 2005 19:53:02 -0400
Message-ID: <12708.1130370782@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/404
X-Sequence-Number: 15172

"Steinar H. Gunderson" <sgunderson@bigfoot.com> writes:
> On Wed, Oct 26, 2005 at 07:06:15PM -0400, Tom Lane wrote:
>> AFAICS, subplan_is_hashable() is testing the same conditions in 7.4 and
>> HEAD, so this isn't clear.  Want to step through it and see where it's
>> deciding not to hash?

> (gdb) print opid 
> $3 = 2373

I don't think you're getting a correct reading for optup, but OID
2373 is timestamp = date:

regression=# select * from pg_operator where oid = 2373;
 oprname | oprnamespace | oprowner | oprkind | oprcanhash | oprleft | oprright | oprresult | oprcom | oprnegate | oprlsortop | oprrsortop | oprltcmpop | oprgtcmpop |      oprcode      | oprrest |  oprjoin
---------+--------------+----------+---------+------------+---------+----------+-----------+--------+-----------+------------+------------+------------+------------+-------------------+---------+-----------
 =       |           11 |       10 | b       | f          |    1114 |     1082 |        16 |   2347 |      2376 |       2062 |       1095 |       2371 |       2375 | timestamp_eq_date | eqsel   | eqjoinsel
(1 row)

which is marked not hashable, quite correctly since the input datatypes
aren't even the same.

My recollection is that there was no such operator in 7.4; probably in
7.4 the IN ended up using timestamp = timestamp which is hashable.

What's not clear though is why you're getting that operator --- aren't
both sides of the IN of type "date"?

			regards, tom lane

From pgsql-performance-owner@postgresql.org  Wed Oct 26 21:13:45 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id ABF86DAF8E
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 21:13:44 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 52345-09
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 00:13:39 +0000 (GMT)
Received: from cassarossa.samfundet.no (cassarossa.samfundet.no
	[129.241.93.19])
	by svr1.postgresql.org (Postfix) with ESMTP id 8A4E2DAFAB
	for <pgsql-performance@postgresql.org>;
	Wed, 26 Oct 2005 21:13:41 -0300 (ADT)
Received: from trofast.ipv6.sesse.net ([2001:700:300:dc03:20e:cff:fe36:a766]
	helo=trofast.sesse.net)
	by cassarossa.samfundet.no with esmtp (Exim 4.50) id 1EUvOo-0007ic-QL
	for pgsql-performance@postgresql.org; Thu, 27 Oct 2005 02:13:44 +0200
Received: from sesse by trofast.sesse.net with local (Exim 3.36 #1 (Debian))
	id 1EUvOu-0002X1-00
	for <pgsql-performance@postgresql.org>; Thu, 27 Oct 2005 02:13:48 +0200
Date: Thu, 27 Oct 2005 02:13:48 +0200
From: "Steinar H. Gunderson" <sgunderson@bigfoot.com>
To: pgsql-performance@postgresql.org
Subject: Re: Materializing a sequential scan
Message-ID: <20051027001348.GA7756@uio.no>
Mail-Followup-To: pgsql-performance@postgresql.org
References: <20051019174544.GA32303@samfundet.no>
	<20051026213730.GA2295@uio.no> <12333.1130367975@sss.pgh.pa.us>
	<20051026232219.GA6390@uio.no> <12708.1130370782@sss.pgh.pa.us>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
In-Reply-To: <12708.1130370782@sss.pgh.pa.us>
X-Operating-System: Linux 2.6.14-rc5 on a x86_64
X-Message-Flag: Outlook? --> http://www.mozilla.org/products/thunderbird/
User-Agent: Mutt/1.5.11
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.01 required=5 tests=[AWL=0.010]
X-Spam-Level: 
X-Archive-Number: 200510/405
X-Sequence-Number: 15173

On Wed, Oct 26, 2005 at 07:53:02PM -0400, Tom Lane wrote:
> I don't think you're getting a correct reading for optup, but OID
> 2373 is timestamp = date:
>
> [...]
> 
> My recollection is that there was no such operator in 7.4; probably in
> 7.4 the IN ended up using timestamp = timestamp which is hashable.

You are quite correct, there is no such operator (whether by oid or by
description) in my 7.4 installation.

> What's not clear though is why you're getting that operator --- aren't
> both sides of the IN of type "date"?

Aha!

Figured out the "start" column wasn't the problem after all. The problem was
the "stopp" column, which was timestamp on one side and date on the other...

So, it can be fixed for this instance, but this feels a bit like the pre-8.0
joins on differing data types -- is there any way to fix it? :-)

/* QSteinar */
-- 
Homepage: http://www.sesse.net/

From pgsql-performance-owner@postgresql.org  Wed Oct 26 21:51:08 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 5006BDA988
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 21:51:07 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 69229-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 00:51:03 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id 306BBDA957
	for <pgsql-performance@postgresql.org>;
	Wed, 26 Oct 2005 21:51:05 -0300 (ADT)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j9R0p347013035;
	Wed, 26 Oct 2005 20:51:03 -0400 (EDT)
To: "Steinar H. Gunderson" <sgunderson@bigfoot.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Materializing a sequential scan 
In-reply-to: <20051027001348.GA7756@uio.no> 
References: <20051019174544.GA32303@samfundet.no>
	<20051026213730.GA2295@uio.no> <12333.1130367975@sss.pgh.pa.us>
	<20051026232219.GA6390@uio.no> <12708.1130370782@sss.pgh.pa.us>
	<20051027001348.GA7756@uio.no>
Comments: In-reply-to "Steinar H. Gunderson" <sgunderson@bigfoot.com>
	message dated "Thu, 27 Oct 2005 02:13:48 +0200"
Date: Wed, 26 Oct 2005 20:51:03 -0400
Message-ID: <13034.1130374263@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/406
X-Sequence-Number: 15174

"Steinar H. Gunderson" <sgunderson@bigfoot.com> writes:
> Aha!

> Figured out the "start" column wasn't the problem after all. The problem was
> the "stopp" column, which was timestamp on one side and date on the other...

Ah-hah.

> So, it can be fixed for this instance, but this feels a bit like the pre-8.0
> joins on differing data types -- is there any way to fix it? :-)

I have some ideas in the back of my head about supporting
cross-data-type hashing.  Essentially this would require that the hash
functions for two types be compatible in that they generate the same
hash value for two values that would be considered equal.  (For
instance, the integer hash functions already have the property that
42::int2, 42::int4, and 42::int8 will all generate the same hash code.
The date and timestamp hash functions don't have such a property ATM,
but probably could be made to.)  For types that share a hash coding
convention, cross-type equality functions could be marked hashable.
This is all pretty handwavy at the moment though, and I don't know
how soon it will get done.

			regards, tom lane

From pgsql-performance-owner@postgresql.org  Wed Oct 26 21:57:12 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 58D8ADAF8E
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 21:57:11 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 70096-10
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 00:57:06 +0000 (GMT)
Received: from cassarossa.samfundet.no (cassarossa.samfundet.no
	[129.241.93.19])
	by svr1.postgresql.org (Postfix) with ESMTP id 6FD1FDAFFA
	for <pgsql-performance@postgresql.org>;
	Wed, 26 Oct 2005 21:57:08 -0300 (ADT)
Received: from trofast.ipv6.sesse.net ([2001:700:300:dc03:20e:cff:fe36:a766]
	helo=trofast.sesse.net)
	by cassarossa.samfundet.no with esmtp (Exim 4.50) id 1EUw4s-00085p-3l
	for pgsql-performance@postgresql.org; Thu, 27 Oct 2005 02:57:11 +0200
Received: from sesse by trofast.sesse.net with local (Exim 3.36 #1 (Debian))
	id 1EUw4x-000344-00
	for <pgsql-performance@postgresql.org>; Thu, 27 Oct 2005 02:57:15 +0200
Date: Thu, 27 Oct 2005 02:57:15 +0200
From: "Steinar H. Gunderson" <sgunderson@bigfoot.com>
To: pgsql-performance@postgresql.org
Subject: Re: Materializing a sequential scan
Message-ID: <20051027005715.GA11032@uio.no>
Mail-Followup-To: pgsql-performance@postgresql.org
References: <20051019174544.GA32303@samfundet.no>
	<20051026213730.GA2295@uio.no> <12333.1130367975@sss.pgh.pa.us>
	<20051026232219.GA6390@uio.no> <12708.1130370782@sss.pgh.pa.us>
	<20051027001348.GA7756@uio.no> <13034.1130374263@sss.pgh.pa.us>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
In-Reply-To: <13034.1130374263@sss.pgh.pa.us>
X-Operating-System: Linux 2.6.14-rc5 on a x86_64
X-Message-Flag: Outlook? --> http://www.mozilla.org/products/thunderbird/
User-Agent: Mutt/1.5.11
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.01 required=5 tests=[AWL=0.010]
X-Spam-Level: 
X-Archive-Number: 200510/407
X-Sequence-Number: 15175

On Wed, Oct 26, 2005 at 08:51:03PM -0400, Tom Lane wrote:
> I have some ideas in the back of my head about supporting
> cross-data-type hashing.  Essentially this would require that the hash
> functions for two types be compatible in that they generate the same
> hash value for two values that would be considered equal.

OK, another entry for the TODO then.

Anyhow, my query is now on about the same performance level with 8.1 as it
was with 7.4 (or rather, a bit faster), so it's no longer a 8.1 blocker for
us. Thanks. :-)

/* Steinar */
-- 
Homepage: http://www.sesse.net/

From pgsql-performance-owner@postgresql.org  Wed Oct 26 22:41:55 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 61208DAFE4
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 22:41:54 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 81213-09
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 01:41:49 +0000 (GMT)
Received: from houston.familyhealth.com.au (houston.au.fhnetwork.com
	[203.22.197.21])
	by svr1.postgresql.org (Postfix) with ESMTP id 7C872DAFC1
	for <pgsql-performance@postgresql.org>;
	Wed, 26 Oct 2005 22:41:51 -0300 (ADT)
Received: from houston.familyhealth.com.au (localhost [127.0.0.1])
	by houston.familyhealth.com.au (Postfix) with ESMTP id 7D38125072;
	Thu, 27 Oct 2005 09:41:55 +0800 (WST)
Received: from [127.0.0.1] (work-40.internal [192.168.0.40])
	by houston.familyhealth.com.au (Postfix) with ESMTP id 593EA24FF7;
	Thu, 27 Oct 2005 09:41:54 +0800 (WST)
Message-ID: <436030BC.1000404@familyhealth.com.au>
Date: Thu, 27 Oct 2005 09:43:24 +0800
From: Christopher Kings-Lynne <chriskl@familyhealth.com.au>
User-Agent: Mozilla Thunderbird 1.0.7 (Windows/20050923)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: aurora <aurora00@gmail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: browsing table with 2 million records
References: <cbd177510510261341l4ed7a214lda9d67af12f2ec21@mail.gmail.com>
In-Reply-To: <cbd177510510261341l4ed7a214lda9d67af12f2ec21@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-familyhealth-MailScanner-Information: Please contact the ISP for more
	information
X-familyhealth-MailScanner: Found to be clean
X-familyhealth-MailScanner-From: chriskl@familyhealth.com.au
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.06 required=5 tests=[AWL=0.010,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/408
X-Sequence-Number: 15176

> We have a GUI that let user browser through the record page by page at 
> about 25 records a time. (Don't ask me why but we have to have this 
> GUI). This translates to something like
> 
>   select count(*) from table   <-- to give feedback about the DB size
>   select * from table order by date limit 25 offset 0

Heh, sounds like phpPgAdmin...I really should do something about that.

> Tables seems properly indexed, with vacuum and analyze ran regularly. 
> Still this very basic SQLs takes up to a minute run.

Yes, COUNT(*) on a large table is always slow in PostgreSQL.  Search the 
mailing lists for countless discussions about it.

Chris


From pgsql-performance-owner@postgresql.org  Wed Oct 26 22:44:46 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 0035BDB00B
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Wed, 26 Oct 2005 22:44:44 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 90927-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 01:44:40 +0000 (GMT)
Received: from houston.familyhealth.com.au (houston.au.fhnetwork.com
	[203.22.197.21])
	by svr1.postgresql.org (Postfix) with ESMTP id AE654DB007
	for <pgsql-performance@postgresql.org>;
	Wed, 26 Oct 2005 22:44:42 -0300 (ADT)
Received: from houston.familyhealth.com.au (localhost [127.0.0.1])
	by houston.familyhealth.com.au (Postfix) with ESMTP id C154C25074;
	Thu, 27 Oct 2005 09:44:46 +0800 (WST)
Received: from [127.0.0.1] (work-40.internal [192.168.0.40])
	by houston.familyhealth.com.au (Postfix) with ESMTP id 7DF6425072;
	Thu, 27 Oct 2005 09:44:44 +0800 (WST)
Message-ID: <43603166.40705@familyhealth.com.au>
Date: Thu, 27 Oct 2005 09:46:14 +0800
From: Christopher Kings-Lynne <chriskl@familyhealth.com.au>
User-Agent: Mozilla Thunderbird 1.0.7 (Windows/20050923)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: PFC <lists@boutiquenumerique.com>
Cc: aurora <aurora00@gmail.com>, pgsql-performance@postgresql.org
Subject: Re: browsing table with 2 million records
References: <cbd177510510261341l4ed7a214lda9d67af12f2ec21@mail.gmail.com>
	<op.sy9v9gketh1vuj@localhost>
In-Reply-To: <op.sy9v9gketh1vuj@localhost>
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit
X-familyhealth-MailScanner-Information: Please contact the ISP for more
	information
X-familyhealth-MailScanner: Found to be clean
X-familyhealth-MailScanner-From: chriskl@familyhealth.com.au
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.06 required=5 tests=[AWL=0.010,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/409
X-Sequence-Number: 15177

>     Who needs a paginated view with 100.000 pages ?
> 
>     - Select min(date) and max(date) from your table
>     - Present a nifty date selector to choose the records from any day, 
> hour,  minute, second
>     - show them, with "next day" and "previous day" buttons
> 
>     - It's more useful to the user (most likely he wants to know what  
> happened on 01/05/2005 rather than view page 2857)
>     - It's faster (no more limit/offset ! just "date BETWEEN a AND b",  
> indexed of course)
>     - no more new items pushing old ones to the next page while you browse
>     - you can pretend to your boss it's just like a paginated list

All very well and good, but now do it generically...


From pgsql-performance-owner@postgresql.org  Thu Oct 27 00:00:22 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 92FF5DB00B
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 00:00:20 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 17760-03
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 03:00:17 +0000 (GMT)
Received: from flake.decibel.org (flake.decibel.org [67.100.216.10])
	by svr1.postgresql.org (Postfix) with ESMTP id A6FA3DB00C
	for <pgsql-performance@postgresql.org>;
	Thu, 27 Oct 2005 00:00:16 -0300 (ADT)
Received: by flake.decibel.org (Postfix, from userid 1001)
	id A475D15231; Wed, 26 Oct 2005 22:00:13 -0500 (CDT)
Date: Wed, 26 Oct 2005 22:00:13 -0500
From: "Jim C. Nasby" <jnasby@pervasive.com>
To: Sidar L?pez Cruz <sidarlopez@hotmail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: performance on query
Message-ID: <20051027030013.GE16682@pervasive.com>
References: <BAY23-F36614886359D96AC48B8BCE690@phx.gbl>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <BAY23-F36614886359D96AC48B8BCE690@phx.gbl>
X-Operating-System: FreeBSD 4.11-RELEASE-p10 i386
X-Distributed: Join the Effort!  http://www.distributed.net
User-Agent: Mutt/1.5.9i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.008 required=5 tests=[AWL=0.008]
X-Spam-Level: 
X-Archive-Number: 200510/410
X-Sequence-Number: 15178

So the issue is that instead of taking 174 seconds the query now takes
201?

I'm guessing that SQL server might be using index covering, but that's
just a guess. Posting query plans (prefferably with actual timing info;
EXPLAIN ANALYZE on PostgreSQL and whatever the equivalent would be for
MSSQL) might give us some idea.

On Wed, Oct 26, 2005 at 05:47:31PM -0600, Sidar L?pez Cruz wrote:
> I DON'T KNOW WHAT TO DO WITH THIS QUERYS...
> Comparation with sql server, sql server wins !!!
> 
> 
> Table sizes:
> archivos: 40MB
> fotos: 55MB
> 
> select count(1) from fotos f where not exists (select a.archivo from 
> archivos a where a.archivo=f.archivo)
> 173713 ms.
> 110217 ms.
> 83122 ms.
> 
> select count(*) from
> (
> 	select archivo from fotos
> 	    except
> 	select archivo from archivos
> ) x;
> 201479 ms.
> 
> SELECT count(*)
> FROM fotos f
> LEFT JOIN archivos a USING(archivo)
> WHERE a.archivo IS NULL
> 199523 ms.
> 
> _________________________________________________________________
> MSN Amor: busca tu ? naranja http://latam.msn.com/amor/
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 2: Don't 'kill -9' the postmaster
> 

-- 
Jim C. Nasby, Sr. Engineering Consultant      jnasby@pervasive.com
Pervasive Software      http://pervasive.com    work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf       cell: 512-569-9461

From pgsql-performance-owner@postgresql.org  Thu Oct 27 06:36:47 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 5E6E0DAA85
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 06:35:39 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 57295-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 09:35:19 +0000 (GMT)
Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75])
	by svr1.postgresql.org (Postfix) with ESMTP id 0540DDAAA1
	for <pgsql-performance@postgresql.org>;
	Thu, 27 Oct 2005 06:35:21 -0300 (ADT)
Received: from mainbox.archonet.com
	(84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99])
	by smtp.metronet.co.uk (MetroNet Mail) with ESMTP
	id F202F4181D5; Thu, 27 Oct 2005 10:35:16 +0100 (BST)
Received: from localhost (localhost.localdomain [127.0.0.1])
	by mainbox.archonet.com (Postfix) with ESMTP id 24C4B15F55;
	Thu, 27 Oct 2005 10:33:46 +0100 (BST)
Received: from mainbox.archonet.com ([127.0.0.1])
	by localhost (mainbox [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 01372-09; Thu, 27 Oct 2005 10:33:41 +0100 (BST)
Received: from [192.168.1.17] (client17.office.archonet.com [192.168.1.17])
	by mainbox.archonet.com (Postfix) with ESMTP id 5B06C15F1E;
	Thu, 27 Oct 2005 10:33:41 +0100 (BST)
Message-ID: <43609EF4.8060907@archonet.com>
Date: Thu, 27 Oct 2005 10:33:40 +0100
From: Richard Huxton <dev@archonet.com>
User-Agent: Mozilla Thunderbird 1.0.7 (X11/20051013)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: Svenne Krap <svenne@krap.dk>
Cc: pgsql-performance@postgresql.org
Subject: Re: Perfomance of views
References: <435FA002.4060509@krap.dk>
In-Reply-To: <435FA002.4060509@krap.dk>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.059 required=5 tests=[AWL=0.009,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/411
X-Sequence-Number: 15179

Svenne Krap wrote:
> Hi there.
> 
> I am currently building a system, where it would be nice to use multiple 
> levels of views upon each other (it is a staticstics system, where 
> traceability is important).
> 
> Is there any significant performance reduction in say 10 levels of views 
> instead of one giant, nested sql-statement ? I especially think exection 
> planner-wise.

The planner tries to push conditions "inside" views where it can. It's 
not perfect though, and if you're writing a big query by hand you might 
be able to do better than it.

In short, I'd test if you can.
-- 
   Richard Huxton
   Archonet Ltd

From pgsql-performance-owner@postgresql.org  Thu Oct 27 08:02:18 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 7546BDB09D
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 08:02:15 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 85198-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 11:02:11 +0000 (GMT)
Received: from cicero2.cybercity.dk (cicero2.cybercity.dk [212.242.40.53])
	by svr1.postgresql.org (Postfix) with ESMTP id 613D2DB082
	for <pgsql-performance@postgresql.org>;
	Thu, 27 Oct 2005 08:02:12 -0300 (ADT)
Received: from [192.168.0.79] (0x3e42eeca.adsl.cybercity.dk [62.66.238.202])
	by cicero2.cybercity.dk (Postfix) with ESMTP id CCFAC191473
	for <pgsql-performance@postgresql.org>;
	Thu, 27 Oct 2005 13:00:51 +0200 (CEST)
Message-ID: <4360B375.8000303@krap.dk>
Date: Thu, 27 Oct 2005 13:01:09 +0200
From: Svenne Krap <svenne@krap.dk>
User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: pgsql-performance@postgresql.org
Subject: Re: Perfomance of views
References: <435FA002.4060509@krap.dk> <43609EF4.8060907@archonet.com>
In-Reply-To: <43609EF4.8060907@archonet.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0 required=5 tests=[none]
X-Spam-Level: 
X-Archive-Number: 200510/412
X-Sequence-Number: 15180

What do you mean exactly but "pushing conditions inside" ?

I don't think I will have the option of testing on the full queries, as 
these take many days to write (the current ones, they are replacing on a 
mssql takes up more that 5kb of query). The current ones are nightmares 
from a maintaince standpoint.

Basicly what the application is doing is selecting some base data from 
the "large" table for a point in time (usually a quarter) and selects 
all matching auxilliare data from the other tables. They are made in a 
time-travel like manner with a first and last useable date.

The ways I have considered was :
1) write a big query in hand (not preferred as it gets hard to manage)
2) write layers of views (still not prefered as I still have to remember 
to put on the right conditions everywhere)
3) write layers of sql-functions (returning the right sets of rows from 
the underlying tables) - which I prefer from a development angel .. it 
gets very clean and I cant forget a parameter anywhere.

But I seem to remember (and I have used PGSQL in production since 7.0) 
that the planner has some problems with solution 3 (i.e. estimating the 
cost and rearranging the query), but frankly that would be the way I 
would like to go.

Based on the current (non-optimal) design and hardware constraints, I 
still have to make sure, the query runs fairly optimal - that means the 
planner must use indexes intelligently and other stuff as if it was 
(well-)written using solution 1.

What do you think of the three solutions ? And is there some ressource 
about the planners capabilites for someone like me (that is very used to 
write reasonably fast and complex sql, can read c-code, but does not 
really want to dig into the source code)

Regards

Svenne

Richard Huxton wrote:

> Svenne Krap wrote:
>
>> Hi there.
>>
>> I am currently building a system, where it would be nice to use 
>> multiple levels of views upon each other (it is a staticstics system, 
>> where traceability is important).
>>
>> Is there any significant performance reduction in say 10 levels of 
>> views instead of one giant, nested sql-statement ? I especially think 
>> exection planner-wise.
>
>
> The planner tries to push conditions "inside" views where it can. It's 
> not perfect though, and if you're writing a big query by hand you 
> might be able to do better than it.
>
> In short, I'd test if you can.



From pgsql-performance-owner@postgresql.org  Thu Oct 27 08:30:33 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id C1FE6DB03D
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 08:30:32 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 93600-03
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 11:30:23 +0000 (GMT)
Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75])
	by svr1.postgresql.org (Postfix) with ESMTP id 28667DB069
	for <pgsql-performance@postgresql.org>;
	Thu, 27 Oct 2005 08:30:25 -0300 (ADT)
Received: from mainbox.archonet.com
	(84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99])
	by smtp.metronet.co.uk (MetroNet Mail) with ESMTP
	id 2AB2B415294; Thu, 27 Oct 2005 12:30:20 +0100 (BST)
Received: from localhost (localhost.localdomain [127.0.0.1])
	by mainbox.archonet.com (Postfix) with ESMTP id 0B7E715EDA;
	Thu, 27 Oct 2005 12:29:44 +0100 (BST)
Received: from mainbox.archonet.com ([127.0.0.1])
	by localhost (mainbox [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 05351-09; Thu, 27 Oct 2005 12:29:39 +0100 (BST)
Received: from [192.168.1.17] (client17.office.archonet.com [192.168.1.17])
	by mainbox.archonet.com (Postfix) with ESMTP id 2CD4A15ED5;
	Thu, 27 Oct 2005 12:29:39 +0100 (BST)
Message-ID: <4360BA22.5050606@archonet.com>
Date: Thu, 27 Oct 2005 12:29:38 +0100
From: Richard Huxton <dev@archonet.com>
User-Agent: Mozilla Thunderbird 1.0.7 (X11/20051013)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: Svenne Krap <svenne@krap.dk>,
	'Postgresql Performance' <pgsql-performance@postgresql.org>
Subject: Re: Perfomance of views
References: <435FA002.4060509@krap.dk> <43609EF4.8060907@archonet.com>
	<4360AE59.6010209@krap.dk>
In-Reply-To: <4360AE59.6010209@krap.dk>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.058 required=5 tests=[AWL=0.008,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/413
X-Sequence-Number: 15181


Don't forget to CC the list


Svenne Krap wrote:
> What do you mean exactly but "pushing conditions inside" ?

If I have something like "SELECT * FROM complicated_view WHERE foo = 7" 
then the planner can look "inside" complicated_view and see where it can 
attach the condition "foo=7", rather than running the query and applying 
the condition at the end.

There are cases where it is safe for the planner to do this, but it 
isn't smart enough to do so.

> I don't think I will have the option of testing on the full queries, as 
> these take many days to write (the current ones, they are replacing on a 
> mssql takes up more that 5kb of query). The current ones are nightmares 
> from a maintaince standpoint.

Hmm - it sounds like they would be.

> Basicly what the application is doing is selecting some base data from 
> the "large" table for a point in time (usually a quarter) and selects 
> all matching auxilliare data from the other tables. They are made in a 
> time-travel like manner with a first and last useable date.
> 
> The ways I have considered was :
> 1) write a big query in hand (not preferred as it gets hard to manage)

Agreed.

> 2) write layers of views (still not prefered as I still have to remember 
> to put on the right conditions everywhere)

This is what I'd probably do, but of course I don't have full 
information about your situation.

> 3) write layers of sql-functions (returning the right sets of rows from 
> the underlying tables) - which I prefer from a development angel .. it 
> gets very clean and I cant forget a parameter anywhere.
> 
> But I seem to remember (and I have used PGSQL in production since 7.0) 
> that the planner has some problems with solution 3 (i.e. estimating the 
> cost and rearranging the query), but frankly that would be the way I 
> would like to go.

Well, 8.x can "inline" a simple sql function into a larger query, but it 
doesn't sound like that will be enough in your case. Once a function 
becomes a "black box" then there's not much the planner can do to figure 
out what to do.

> Based on the current (non-optimal) design and hardware constraints, I 
> still have to make sure, the query runs fairly optimal - that means the 
> planner must use indexes intelligently and other stuff as if it was 
> (well-)written using solution 1.

Well, #1,#2 are likely to be the most efficient, but you won't know for 
sure about #2 until you test it.

There are a couple of other options though:

#4 - Write a set-returning function that breaks the query into steps and 
executes each in turn. So - fetch IDs from the main table in step 1 and 
store them in a temporary table, join other tables in later steps.

#5 - Write a function that writes your big query for you and either 
returns the SQL to your application, or runs it and returns the results.

> What do you think of the three solutions ? And is there some ressource 
> about the planners capabilites for someone like me (that is very used to 
> write reasonably fast and complex sql, can read c-code, but does not 
> really want to dig into the source code)

There is some stuff in the "Internals" section of the manuals and it 
might be worth rummaging around on http://techdocs.postgresql.org

--
   Richard Huxton
   Archonet Ltd

From pgsql-performance-owner@postgresql.org  Thu Oct 27 09:59:52 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id A9FFADB0A2
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 09:59:50 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 26256-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 12:59:46 +0000 (GMT)
Received: from Herge.rcsinc.local (mail.rcsonline.com [70.89.208.142])
	by svr1.postgresql.org (Postfix) with ESMTP id CE4C9DB08A
	for <pgsql-performance@postgresql.org>;
	Thu, 27 Oct 2005 09:59:48 -0300 (ADT)
X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0
Content-class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Subject: Re: browsing table with 2 million records
Date: Thu, 27 Oct 2005 08:59:51 -0400
Message-ID: <6EE64EF3AB31D5448D0007DD34EEB3417DD6D2@Herge.rcsinc.local>
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
Thread-Topic: [PERFORM] browsing table with 2 million records
Thread-Index: AcXamGXN6l2L0+PPR5eWJVxVfGtwqwAXBFCA
From: "Merlin Moncure" <merlin.moncure@rcsonline.com>
To: "Christopher Kings-Lynne" <chriskl@familyhealth.com.au>
Cc: <pgsql-performance@postgresql.org>,
	"PFC" <lists@boutiquenumerique.com>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.081 required=5 tests=[AWL=0.031,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/414
X-Sequence-Number: 15182

Christopher=20
> >     - Present a nifty date selector to choose the records from any
day,
> > hour,  minute, second
> >     - show them, with "next day" and "previous day" buttons
> >
> >     - It's more useful to the user (most likely he wants to know
what
> > happened on 01/05/2005 rather than view page 2857)
> >     - It's faster (no more limit/offset ! just "date BETWEEN a AND
b",
> > indexed of course)
> >     - no more new items pushing old ones to the next page while you
> browse
> >     - you can pretend to your boss it's just like a paginated list
>=20
> All very well and good, but now do it generically...

I've done it... =20
First of all I totally agree with PFC's rant regarding absolute
positioning while browsing datasets.  Among other things, it has serious
problems if you have multiple updating your table.  Also it's kind of
silly to be doing this in a set based data paradigm.

The 'SQL' way to browse a dataset is by key.  If your key has multiple
parts or you are trying to sort on two or more fields, you are supposed
to use the row constructor:

select * from t where (x, y) > (xc, yc) order by x,y;

Unfortunately, this gives the wrong answer in postgresql :(.

The alternative is to use boolean logic.  Here is a log snippit from my
ISAM driver (in ISAM, you are *always* browsing datasets):

prepare system_read_next_menu_item_favorite_file_0 (character varying,
int4, int4, int4)
	as select from system.menu_item_favorite_file
	where mif_user_id >=3D $1 and=20
		(mif_user_id >  $1 or  mif_menu_item_id >=3D $2) and=20
		(mif_user_id >  $1 or  mif_menu_item_id >  $2 or
mif_sequence_no >  $3)=20
	order by mif_user_id, mif_menu_item_id, mif_sequence_no
	limit $4

This is a Boolean based 'get next record' in a 3 part key plus a
parameterized limit.  You can do this without using prepared statements
of course but with the prepared version you can at least do=20

execute system_read_next_menu_item_favorite_file_0('abc', 1, 2, 1);

Merlin


From pgsql-performance-owner@postgresql.org  Thu Oct 27 10:44:43 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id CA346DB0A8
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 10:44:41 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 36994-10
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 13:44:34 +0000 (GMT)
Received: from my.endian.it (unknown [62.146.87.34])
	by svr1.postgresql.org (Postfix) with ESMTP id 7DE05DB0B4
	for <pgsql-performance@postgresql.org>;
	Thu, 27 Oct 2005 10:44:36 -0300 (ADT)
Received: from 1006.org (localhost.localdomain [127.0.0.1])
	by my.endian.it (8.11.6/8.11.6) with SMTP id j9RDe4c09650;
	Thu, 27 Oct 2005 15:40:04 +0200
Received: from unibz.it ([193.206.186.101])
	(SquirrelMail authenticated user list@1006.org)
	by www.endian.it with HTTP; Thu, 27 Oct 2005 15:40:04 +0200 (CEST)
Message-ID: <34757.193.206.186.101.1130420404.squirrel@www.endian.it>
Date: Thu, 27 Oct 2005 15:40:04 +0200 (CEST)
Subject: Re: insertion of bytea
From: "Chris Mair" <list@1006.org>
To: <mstone+postgres@mathom.us>
In-Reply-To: <20051025140549.GC17398@mathom.us>
References: <54222.193.206.186.101.1130247876.squirrel@www.endian.it>
	<20051025140549.GC17398@mathom.us>
X-Priority: 3
Importance: Normal
X-MSMail-Priority: Normal
Cc: <pgsql-performance@postgresql.org>
X-Mailer: SquirrelMail (version 1.2.7)
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0 required=5 tests=[none]
X-Spam-Level: 
X-Archive-Number: 200510/416
X-Sequence-Number: 15184

> On Tue, Oct 25, 2005 at 03:44:36PM +0200, Chris Mair wrote:
>>Is there a better, faster way to do these inserts?
>
> COPY is generally the fastest way to do bulk inserts (see
> PQputCopyData).


Hi,

I've rewritten the testclient now to use COPY, but I'm getting
the exact same results as when doing bundled, prepared inserts.

I'm CPU-bound with an I/O well below what my disks could do :(


Bye, Chris.


PS1: someone off-list suggested using oprofile, which I will do.

PS2: in case somebody is iterested, the test client is here:
     http://www.1006.org/tmp/20051027/

     pgclient-1.1.c is prepared inserts, 2.0 is binary copy.





From pgsql-performance-owner@postgresql.org  Thu Oct 27 10:41:59 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 18358DAAAE
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 10:41:58 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 39134-10
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 13:41:34 +0000 (GMT)
Received: from smtp016.mail.yahoo.com (smtp016.mail.yahoo.com
	[216.136.174.113])
	by svr1.postgresql.org (Postfix) with SMTP id AFAE3DA72E
	for <pgsql-performance@postgresql.org>;
	Thu, 27 Oct 2005 10:41:36 -0300 (ADT)
Received: (qmail 82994 invoked from network); 27 Oct 2005 13:41:33 -0000
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=Yahoo.com;
	h=Received:Message-ID:Date:From:User-Agent:X-Accept-Language:MIME-Version:To:CC:Subject:References:In-Reply-To:Content-Type:Content-Transfer-Encoding;
	b=g4cUvYbUmLvSiZXT4w1HwNXh3Sj2KNsvYsNqohcNijddIzkcK5qVrBFaXwhvmhEzakh//oyRxw5eFRXwDKwNPgrniuCQf9s8Nh/zK2iDSLZ7swlSZCrUUNx8z0/yMwjICTSPTP2DzxkyOenwbVO8q3EN611OMd7Gzd55+KsBrVY=
	;
Received: from unknown (HELO jupiter.black-lion.info) (janwieck@68.80.245.191
	with login)
	by smtp016.mail.yahoo.com with SMTP; 27 Oct 2005 13:41:33 -0000
Received: from [172.21.8.23] (ismtp.afilias.com [216.217.55.254])
	(authenticated bits=0)
	by jupiter.black-lion.info (8.12.10/8.12.9) with ESMTP id
	j9RDfT1o035578; Thu, 27 Oct 2005 09:41:29 -0400 (EDT)
	(envelope-from JanWieck@Yahoo.com)
Message-ID: <4360D906.3060504@Yahoo.com>
Date: Thu, 27 Oct 2005 09:41:26 -0400
From: Jan Wieck <JanWieck@Yahoo.com>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US;
	rv:1.7.1) Gecko/20040707
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: Richard Huxton <dev@archonet.com>
Cc: Svenne Krap <svenne@krap.dk>,
	"'Postgresql Performance'" <pgsql-performance@postgresql.org>
Subject: Re: Perfomance of views
References: <435FA002.4060509@krap.dk> <43609EF4.8060907@archonet.com>
	<4360AE59.6010209@krap.dk> <4360BA22.5050606@archonet.com>
In-Reply-To: <4360BA22.5050606@archonet.com>
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=1.019 required=5 tests=[AWL=1.019]
X-Spam-Level: *
X-Archive-Number: 200510/415
X-Sequence-Number: 15183

On 10/27/2005 7:29 AM, Richard Huxton wrote:

> Don't forget to CC the list
> 
> 
> Svenne Krap wrote:
>> What do you mean exactly but "pushing conditions inside" ?
> 
> If I have something like "SELECT * FROM complicated_view WHERE foo = 7" 
> then the planner can look "inside" complicated_view and see where it can 
> attach the condition "foo=7", rather than running the query and applying 
> the condition at the end.

Sorry, but the planner doesn't attach the condition anywhere. It is the 
rewriter that takes the actual query, replaces the views rangetable and 
expression entries with the actual underlying objects and adds the views 
condition with an AND to the queries condition. Simply example:

Given a view

     create view v1 as select a1, b1, c2 from t1, t2 where a1 = a2;

The statement

     select * from v1 where b1 = 'foo';

will result in a parsetree equivalent to what you would get if the 
original query was

     select a1, b1, c2 from t1, t2 where (b1 = 'foo') and (a1 = a2);

It is the planners and optimizers job to recognize where in the 
execution plan it can push qualifications down into filters or even 
scankeys. The planner should be able to realize that

     select * from v1 where a1 = 42;

is in fact equivalent to

     select a1, b1, c2 from t1, t2 where a1 = 42 and a1 = a2;

as well as

     select a1, b1, c2 from t1, t2 where a1 = 42 and a1 = a2 and a2 = 42;

This very last addition of "a2 = 42" because of "a2 = a1 = 42" allows it 
to put a constant scankey onto the scan of t2. The 8.0 planner does 
that, so the resulting query plan for the last three selects above is 
absolutely identical.

> 
> There are cases where it is safe for the planner to do this, but it 
> isn't smart enough to do so.

Example?


Jan

> 
>> I don't think I will have the option of testing on the full queries, as 
>> these take many days to write (the current ones, they are replacing on a 
>> mssql takes up more that 5kb of query). The current ones are nightmares 
>> from a maintaince standpoint.
> 
> Hmm - it sounds like they would be.
> 
>> Basicly what the application is doing is selecting some base data from 
>> the "large" table for a point in time (usually a quarter) and selects 
>> all matching auxilliare data from the other tables. They are made in a 
>> time-travel like manner with a first and last useable date.
>> 
>> The ways I have considered was :
>> 1) write a big query in hand (not preferred as it gets hard to manage)
> 
> Agreed.
> 
>> 2) write layers of views (still not prefered as I still have to remember 
>> to put on the right conditions everywhere)
> 
> This is what I'd probably do, but of course I don't have full 
> information about your situation.
> 
>> 3) write layers of sql-functions (returning the right sets of rows from 
>> the underlying tables) - which I prefer from a development angel .. it 
>> gets very clean and I cant forget a parameter anywhere.
>> 
>> But I seem to remember (and I have used PGSQL in production since 7.0) 
>> that the planner has some problems with solution 3 (i.e. estimating the 
>> cost and rearranging the query), but frankly that would be the way I 
>> would like to go.
> 
> Well, 8.x can "inline" a simple sql function into a larger query, but it 
> doesn't sound like that will be enough in your case. Once a function 
> becomes a "black box" then there's not much the planner can do to figure 
> out what to do.
> 
>> Based on the current (non-optimal) design and hardware constraints, I 
>> still have to make sure, the query runs fairly optimal - that means the 
>> planner must use indexes intelligently and other stuff as if it was 
>> (well-)written using solution 1.
> 
> Well, #1,#2 are likely to be the most efficient, but you won't know for 
> sure about #2 until you test it.
> 
> There are a couple of other options though:
> 
> #4 - Write a set-returning function that breaks the query into steps and 
> executes each in turn. So - fetch IDs from the main table in step 1 and 
> store them in a temporary table, join other tables in later steps.
> 
> #5 - Write a function that writes your big query for you and either 
> returns the SQL to your application, or runs it and returns the results.
> 
>> What do you think of the three solutions ? And is there some ressource 
>> about the planners capabilites for someone like me (that is very used to 
>> write reasonably fast and complex sql, can read c-code, but does not 
>> really want to dig into the source code)
> 
> There is some stuff in the "Internals" section of the manuals and it 
> might be worth rummaging around on http://techdocs.postgresql.org
> 
> --
>    Richard Huxton
>    Archonet Ltd
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
> 
>                http://archives.postgresql.org


-- 
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me.                                  #
#================================================== JanWieck@Yahoo.com #

From pgsql-performance-owner@postgresql.org  Thu Oct 27 11:27:23 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 92EA4DB0D9
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 11:25:25 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 57747-07
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 14:25:20 +0000 (GMT)
Received: from hotmail.com (bay23-f28.bay23.hotmail.com [64.4.22.78])
	by svr1.postgresql.org (Postfix) with ESMTP id 45988DAEAC
	for <pgsql-performance@postgresql.org>;
	Thu, 27 Oct 2005 11:25:22 -0300 (ADT)
Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC;
	Thu, 27 Oct 2005 07:25:23 -0700
Message-ID: <BAY23-F28F5DD23A4A73C7BFE3CD1CE680@phx.gbl>
Received: from 196.40.18.42 by by23fd.bay23.hotmail.msn.com with HTTP;
	Thu, 27 Oct 2005 14:25:23 GMT
X-Originating-IP: [196.40.18.42]
X-Originating-Email: [sidarlopez@hotmail.com]
X-Sender: sidarlopez@hotmail.com
From: =?iso-8859-1?B?U2lkYXIgTPNwZXogQ3J1eg==?= <sidarlopez@hotmail.com>
To: pgsql-performance@postgresql.org
Subject: how postgresql request the computer resources
Date: Thu, 27 Oct 2005 08:25:23 -0600
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1; format=flowed
X-OriginalArrivalTime: 27 Oct 2005 14:25:23.0928 (UTC)
	FILETIME=[44B86580:01C5DB02]
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=1.324 required=5 tests=[AWL=-0.426,
	DNS_FROM_RFC_ABUSE=0.374, DNS_FROM_RFC_POST=1.376,
	MSGID_FROM_MTA_HEADER=0]
X-Spam-Level: *
X-Archive-Number: 200510/417
X-Sequence-Number: 15185

Is there something that tells postgres to take the resorces from computer 
(RAM, HDD, SWAP on linux) as it need, not modifying variables on 
postgresql.conf and other operating system things?

A days ago i am trying to show that postgres is better than mssql but when 
execute a simple query like:

(1)
select count(*) from
(
	select archivo from fotos
	    except
	select archivo from archivos
) x;
Aggregate  (cost=182162.83..182162.84 rows=1 width=0) (actual 
time=133974.495..133974.498 rows=1 loops=1)
  ->  Subquery Scan x  (cost=173857.98..181830.63 rows=132878 width=0) 
(actual time=109148.158..133335.279 rows=169672 loops=1)
        ->  SetOp Except  (cost=173857.98..180501.86 rows=132878 width=58) 
(actual time=109148.144..132094.382 rows=169672 loops=1)
              ->  Sort  (cost=173857.98..177179.92 rows=1328775 width=58) 
(actual time=109147.656..113870.975 rows=1328775 loops=1)
                    Sort Key: archivo
                    ->  Append  (cost=0.00..38710.50 rows=1328775 width=58) 
(actual time=27.062..29891.075 rows=1328775 loops=1)
                          ->  Subquery Scan "*SELECT* 1"  
(cost=0.00..17515.62 rows=523431 width=58) (actual time=27.052..9560.719 
rows=523431 loops=1)
                                ->  Seq Scan on fotos  (cost=0.00..12281.31 
rows=523431 width=58) (actual time=27.038..5390.238 rows=523431 loops=1)
                          ->  Subquery Scan "*SELECT* 2"  
(cost=0.00..21194.88 rows=805344 width=58) (actual time=10.803..12117.788 
rows=805344 loops=1)
                                ->  Seq Scan on archivos  
(cost=0.00..13141.44 rows=805344 width=58) (actual time=10.784..5420.164 
rows=805344 loops=1)
Total runtime: 134552.325 ms


(2)
select count(*) from fotos where archivo not in (select archivo from 
archivos)
Aggregate  (cost=29398.98..29398.99 rows=1 width=0) (actual 
time=26660.565..26660.569 rows=1 loops=1)
  ->  Seq Scan on fotos  (cost=15154.80..28744.69 rows=261716 width=0) 
(actual time=13930.060..25859.340 rows=169799 loops=1)
        Filter: (NOT (hashed subplan))
        SubPlan
          ->  Seq Scan on archivos  (cost=0.00..13141.44 rows=805344 
width=58) (actual time=0.319..5647.043 rows=805344 loops=1)
Total runtime: 26747.236 ms


(3)
select count(1) from fotos f where not exists (select a.archivo from 
archivos a where a.archivo=f.archivo)
Aggregate  (cost=1761354.08..1761354.09 rows=1 width=0) (actual 
time=89765.384..89765.387 rows=1 loops=1)
  ->  Seq Scan on fotos f  (cost=0.00..1760699.79 rows=261716 width=0) 
(actual time=75.556..88880.234 rows=169799 loops=1)
        Filter: (NOT (subplan))
        SubPlan
          ->  Index Scan using archivos_archivo_idx on archivos a  
(cost=0.00..13451.40 rows=4027 width=58) (actual time=0.147..0.147 rows=1 
loops=523431)
                Index Cond: ((archivo)::text = ($0)::text)
Total runtime: 89765.714 ms



(4)
SELECT count(*)
FROM fotos f
LEFT JOIN archivos a USING(archivo)
WHERE a.archivo IS NULL
Aggregate  (cost=31798758.40..31798758.41 rows=1 width=0) (actual 
time=114267.337..114267.341 rows=1 loops=1)
  ->  Merge Left Join  (cost=154143.73..31772412.02 rows=10538550 width=0) 
(actual time=85472.696..113392.399 rows=169799 loops=1)
        Merge Cond: ("outer"."?column2?" = "inner"."?column2?")
        Filter: ("inner".archivo IS NULL)
        ->  Sort  (cost=62001.08..63309.66 rows=523431 width=58) (actual 
time=38018.343..39998.201 rows=523431 loops=1)
              Sort Key: (f.archivo)::text
              ->  Seq Scan on fotos f  (cost=0.00..12281.31 rows=523431 
width=58) (actual time=0.158..4904.410 rows=523431 loops=1)
        ->  Sort  (cost=92142.65..94156.01 rows=805344 width=58) (actual 
time=47453.790..50811.216 rows=805701 loops=1)
              Sort Key: (a.archivo)::text
              ->  Seq Scan on archivos a  (cost=0.00..13141.44 rows=805344 
width=58) (actual time=0.206..7160.148 rows=805344 loops=1)
Total runtime: 114893.116 ms




WITH ANY OF THIS QUERIES MSSQL TAKES NOT MUCH OF 7 SECONDS....


PLEASE HELP ME

_________________________________________________________________
Consigue aqu� las mejores y mas recientes ofertas de trabajo en Am�rica 
Latina y USA: http://latam.msn.com/empleos/


From pgsql-performance-owner@postgresql.org  Thu Oct 27 11:34:04 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 14B79DB052
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 11:34:03 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 62702-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 14:33:54 +0000 (GMT)
Received: from boutiquenumerique.com (boutiquenumerique.com [82.67.9.10])
	by svr1.postgresql.org (Postfix) with ESMTP id F3537D7830
	for <pgsql-performance@postgresql.org>;
	Thu, 27 Oct 2005 11:33:55 -0300 (ADT)
Received: (qmail 28300 invoked from network); 27 Oct 2005 16:35:03 +0200
Received: from unknown (HELO localhost) (boutiquenumerique-lists@192.168.0.4)
	by boutiquenumerique.com with SMTP; 27 Oct 2005 16:35:03 +0200
Date: Thu, 27 Oct 2005 16:33:51 +0200
To: "Merlin Moncure" <merlin.moncure@rcsonline.com>,
	"Christopher Kings-Lynne" <chriskl@familyhealth.com.au>
Subject: Re: browsing table with 2 million records
Cc: pgsql-performance@postgresql.org
References: <6EE64EF3AB31D5448D0007DD34EEB3417DD6D2@Herge.rcsinc.local>
From: PFC <lists@boutiquenumerique.com>
Organization: =?iso-8859-15?Q?La_Boutique_Num=E9rique?=
Content-Type: text/plain; format=flowed; delsp=yes; charset=iso-8859-15
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Message-ID: <op.sza6qpz4th1vuj@localhost>
In-Reply-To: <6EE64EF3AB31D5448D0007DD34EEB3417DD6D2@Herge.rcsinc.local>
User-Agent: Opera M2/8.0 (Linux, build 1095)
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/418
X-Sequence-Number: 15186



> I've done it...
> First of all I totally agree with PFC's rant regarding absolute
> positioning while browsing datasets.  Among other things, it has serious
> problems if you have multiple updating your table.  Also it's kind of
> silly to be doing this in a set based data paradigm.

	Recently I've been browsing some site and it had this problem : as users  
kept adding new entries as I was browsing the list page after page, when I  
hit "next page" I got on the next page half of what I already saw on the  
previous page. Of course the webmaster has set the "visited links" color  
the same as "unvisited links", so I couldn't tell, and had to use my  
brain, which was quite upsetting XDDD

	And bookmarking a page to resume browsing at some later time does not  
work either, because if I bookmark page 15, then when I come back, users  
have added 10 pages of content and what I bookmarked is now on page 25...

>> All very well and good, but now do it generically...

	Hehe. I like ranting...
	It is not possible to do it in a generic way that works in all cases. For  
instance :

	Forum topic case :
	- posts are added at the bottom and not at the top
	- page number is relevant and meaningful

	However, in most cases, you can use a multipart key and get it right.
	Suppose that, for instance, you have a base of several million records,  
organized according to :

	- date (like the original poster)
	or :
	- country, region, city, customer last name, first name.

	You could ask for the first three, but then you'll get 50000 Smiths in  
New York and 1 Van Bliezinsky.

	Or you could precalculate, once a week, a key interval distribution that  
creates reasonable sized intervals (for instance, 100 values in each),  
maybe asking that each interval should only contain only one city. So, you  
would get :

	Country Region City	LastName	FirstName
	USA	NYC	NY	Smith,	''
	USA	NYC	NY	Smith,	Albert
	USA	NYC	NY	Smith,	Bernard
	.....
	USA	NYC	NY	Smith,	William
	...
	USA	NYC	NY	Von Braun
	...

	So you'd predetermine your "page breaks" ahead of time, and recompute  
them once in a while. You won't get identically sized pages, but if the  
statistical distribution of the data plays nice, you should get evenly  
sized pages.

	The interesting part is that you can present the user with a selector  
which presents meaningful and useful data, AND is fast to compute, AND is  
fast to use.
	In this case, it would amount to "Select country, region, city", then,  
display a list like this :
	Smith, ...Albert
	Smith, Albus...Bernard
	...
	Smith, William...
	...
	Von Braun...Von Schwarts
	...

	So Jeannette Smith would be easy to find, being in the link "Smith,  
Jean...John" for instance.

	If the aim is to quickly locate a particular record, I like  
javascript-powered autocompletion better ; but for browsing, this  
pagination method is cool.

	Regards !


























From pgsql-performance-owner@postgresql.org  Thu Oct 27 11:35:42 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id B1944DB095
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 11:35:37 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 64642-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 14:35:32 +0000 (GMT)
Received: from mail.picoip.com (external.xtracards.com [209.178.196.162])
	by svr1.postgresql.org (Postfix) with ESMTP id 9DEE6DB052
	for <pgsql-performance@postgresql.org>;
	Thu, 27 Oct 2005 11:35:34 -0300 (ADT)
Received: from localhost (localhost [127.0.0.1])
	by mail.picoip.com (Postfix) with ESMTP id B0E5F5D3DF6;
	Thu, 27 Oct 2005 10:35:38 -0400 (EDT)
Received: from mail.picoip.com ([127.0.0.1])
	by localhost (mail.picoip.com [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 08991-01; Thu, 27 Oct 2005 10:35:38 -0400 (EDT)
Received: from [172.27.60.240] (unknown [172.27.60.240])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by mail.picoip.com (Postfix) with ESMTP id 4993F5D3DA2
	for <pgsql-performance@postgresql.org>;
	Thu, 27 Oct 2005 10:35:38 -0400 (EDT)
Message-ID: <4360E5BD.2040508@xtracards.com>
Date: Thu, 27 Oct 2005 10:35:41 -0400
From: "Edward Di Geronimo Jr." <edigeronimo@xtracards.com>
User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: pgsql-performance@postgresql.org
Subject: Re: Performance issues with custom functions
References: <435FE820.4070701@xtracards.com> <12437.1130368717@sss.pgh.pa.us>
In-Reply-To: <12437.1130368717@sss.pgh.pa.us>
Content-Type: multipart/alternative;
	boundary="------------040700040100090000070404"
X-Virus-Scanned: by amavisd-new at mail.picoip.com
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.079 required=5 tests=[AWL=-0.028,
	FORGED_RCVD_HELO=0.05, HTML_30_40=0.056, HTML_MESSAGE=0.001]
X-Spam-Level: 
X-Archive-Number: 200510/419
X-Sequence-Number: 15187

This is a multi-part message in MIME format.
--------------040700040100090000070404
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Tom Lane wrote:

>This is fairly hard to read ... it would help a lot if you had shown the
>view definitions that the query relies on, so that we could match up the
>plan elements with the query a bit better.
>  
>
I wasn't sure how helpful it would be. Here they are:

create view development.network as
select * from odbc_select('amsterdam', 'bob.dbo.network') as (
    network_id varchar ,
    status_cd varchar  ,
    name varchar  ,
    network_action varchar  ,
    physical_type_cd varchar  ,
    service_type_cd varchar  ,
    parent_network_id varchar  ,
    commission_network_id varchar  ,
    rep_id varchar  ,
    tax_id varchar  ,
    url varchar  ,
    entry_method_cd varchar  ,
    entry_individual_type_cd varchar  ,
    entry_individual_id varchar  ,
    service varchar (30),
    cost_routine varchar (150),
    commission_rate numeric(5, 5)  ,
    directory_number varchar (11),
    search_url varchar (200),
    member_rate numeric(15, 2)  ,
    free_months numeric(18, 0)  ,
    eligibility_hound varchar (60)
)

create view development.network_state as
select * from odbc_select('amsterdam', 'bob.dbo.network_state') as (
    network_id varchar,
    state_cd varchar,
    product varchar (100) ,
    status_cd varchar,
    entry_method_cd varchar,
    entry_individual_type_cd varchar,
    entry_individual_id varchar,
    logo_id int ,
    from_date timestamp ,
    thru_date timestamp
)

create view development.xlat_tbl as
select * from odbc_select('amsterdam', 'xlat_tbl') as (
    field_name varchar  ,
    field_value varchar  ,
    status_cd varchar  ,
    descr varchar  ,
    descrshort varchar  ,
    entry_method_cd varchar  ,
    entry_individual_type_cd varchar  ,
    entry_individual_id varchar
)

>However, I'm thinking the problem is with this IN clause:
>
>  
>
>>        where pl.network_id in (select ns.network_id
>>                        from development.network_state ns
>>                          where ns.from_date < current_time
>>                            and (ns.thru_date > current_time or 
>>ns.thru_date is null)
>>                        and (ns.state_cd = pl.state_cd or ns.state_cd='')
>>                          )
>>    
>>
>
>Because the sub-SELECT references pl.state_cd (an outer variable
>reference), there's no chance of optimizing this into a join-style IN.
>So the sub-SELECT has to be re-executed for each row of the outer query.
>
>BTW, it's not apparent to me that your "flattened" query gives the same
>answers as the original.  What if a pl row can join to more than one
>row of the ns output?
>  
>
Well, I guess you are right. As far as the database can tell, the 
queries aren't the same. In practice, they are. network_state is 
essentially tracking our contract dates with different discount 
healthcare networks. from_date and thru_date track the timeframe we use 
that network, with thru_date being null for the current networks. Some 
networks cover all states, in which case state_cd is an empty string. 
Otherwise, there will be a row per state covered. I can't think of any 
way to enforce data integrity on this other than maybe via triggers. Is 
there any way to make things more clear to the database (both in general 
and on the postgres end of this) ? At the moment, the SQL Server table 
has the primary key defined as (network_id, state_cd, product), which is 
ok for now, but I'm realizing going forward could be an issue if we ever 
stopped using a network in a state and then went back to it.

I guess the next question is, is there any way I can give postgres hints 
about what constraints exist on the data in these views?

Ed

--------------040700040100090000070404
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Tom Lane wrote:
<blockquote cite="mid12437.1130368717@sss.pgh.pa.us" type="cite">
  <pre wrap="">This is fairly hard to read ... it would help a lot if you had shown the
view definitions that the query relies on, so that we could match up the
plan elements with the query a bit better.
  </pre>
</blockquote>
I wasn't sure how helpful it would be. Here they are:<br>
<br>
create view development.network as <br>
select * from odbc_select('amsterdam', 'bob.dbo.network') as (<br>
&nbsp;&nbsp;&nbsp; network_id varchar ,<br>
&nbsp;&nbsp;&nbsp; status_cd varchar&nbsp; ,<br>
&nbsp;&nbsp;&nbsp; name varchar&nbsp; ,<br>
&nbsp;&nbsp;&nbsp; network_action varchar&nbsp; ,<br>
&nbsp;&nbsp;&nbsp; physical_type_cd varchar&nbsp; ,<br>
&nbsp;&nbsp;&nbsp; service_type_cd varchar&nbsp; ,<br>
&nbsp;&nbsp;&nbsp; parent_network_id varchar&nbsp; ,<br>
&nbsp;&nbsp;&nbsp; commission_network_id varchar&nbsp; ,<br>
&nbsp;&nbsp;&nbsp; rep_id varchar&nbsp; ,<br>
&nbsp;&nbsp;&nbsp; tax_id varchar&nbsp; ,<br>
&nbsp;&nbsp;&nbsp; url varchar&nbsp; ,<br>
&nbsp;&nbsp;&nbsp; entry_method_cd varchar&nbsp; ,<br>
&nbsp;&nbsp;&nbsp; entry_individual_type_cd varchar&nbsp; ,<br>
&nbsp;&nbsp;&nbsp; entry_individual_id varchar&nbsp; ,<br>
&nbsp;&nbsp;&nbsp; service varchar (30),<br>
&nbsp;&nbsp;&nbsp; cost_routine varchar (150),<br>
&nbsp;&nbsp;&nbsp; commission_rate numeric(5, 5)&nbsp; ,<br>
&nbsp;&nbsp;&nbsp; directory_number varchar (11),<br>
&nbsp;&nbsp;&nbsp; search_url varchar (200),<br>
&nbsp;&nbsp;&nbsp; member_rate numeric(15, 2)&nbsp; ,<br>
&nbsp;&nbsp;&nbsp; free_months numeric(18, 0)&nbsp; ,<br>
&nbsp;&nbsp;&nbsp; eligibility_hound varchar (60)<br>
)<br>
<br>
create view development.network_state as <br>
select * from odbc_select('amsterdam', 'bob.dbo.network_state') as (<br>
&nbsp;&nbsp;&nbsp; network_id varchar,<br>
&nbsp;&nbsp;&nbsp; state_cd varchar,<br>
&nbsp;&nbsp;&nbsp; product varchar (100) ,<br>
&nbsp;&nbsp;&nbsp; status_cd varchar,<br>
&nbsp;&nbsp;&nbsp; entry_method_cd varchar,<br>
&nbsp;&nbsp;&nbsp; entry_individual_type_cd varchar,<br>
&nbsp;&nbsp;&nbsp; entry_individual_id varchar,<br>
&nbsp;&nbsp;&nbsp; logo_id int ,<br>
&nbsp;&nbsp;&nbsp; from_date timestamp ,<br>
&nbsp;&nbsp;&nbsp; thru_date timestamp <br>
)<br>
<br>
create view development.xlat_tbl as<br>
select * from odbc_select('amsterdam', 'xlat_tbl') as (<br>
&nbsp;&nbsp;&nbsp; field_name varchar&nbsp; ,<br>
&nbsp;&nbsp;&nbsp; field_value varchar&nbsp; ,<br>
&nbsp;&nbsp;&nbsp; status_cd varchar&nbsp; ,<br>
&nbsp;&nbsp;&nbsp; descr varchar&nbsp; ,<br>
&nbsp;&nbsp;&nbsp; descrshort varchar&nbsp; ,<br>
&nbsp;&nbsp;&nbsp; entry_method_cd varchar&nbsp; ,<br>
&nbsp;&nbsp;&nbsp; entry_individual_type_cd varchar&nbsp; ,<br>
&nbsp;&nbsp;&nbsp; entry_individual_id varchar <br>
)<br>
<br>
<blockquote cite="mid12437.1130368717@sss.pgh.pa.us" type="cite">
  <pre wrap="">However, I'm thinking the problem is with this IN clause:

  </pre>
  <blockquote type="cite">
    <pre wrap="">        where pl.network_id in (select ns.network_id
                        from development.network_state ns
                          where ns.from_date &lt; current_time
                            and (ns.thru_date &gt; current_time or 
ns.thru_date is null)
                        and (ns.state_cd = pl.state_cd or ns.state_cd='')
                          )
    </pre>
  </blockquote>
  <pre wrap=""><!---->
Because the sub-SELECT references pl.state_cd (an outer variable
reference), there's no chance of optimizing this into a join-style IN.
So the sub-SELECT has to be re-executed for each row of the outer query.

BTW, it's not apparent to me that your "flattened" query gives the same
answers as the original.  What if a pl row can join to more than one
row of the ns output?
  </pre>
</blockquote>
Well, I guess you are right. As far as the database can tell, the
queries aren't the same. In practice, they are. network_state is
essentially tracking our contract dates with different discount
healthcare networks. from_date and thru_date track the timeframe we use
that network, with thru_date being null for the current networks. Some
networks cover all states, in which case state_cd is an empty string.
Otherwise, there will be a row per state covered. I can't think of any
way to enforce data integrity on this other than maybe via triggers. Is
there any way to make things more clear to the database (both in
general and on the postgres end of this) ? At the moment, the SQL
Server table has the primary key defined as (network_id, state_cd,
product), which is ok for now, but I'm realizing going forward could be
an issue if we ever stopped using a network in a state and then went
back to it.<br>
<br>
I guess the next question is, is there any way I can give postgres
hints about what constraints exist on the data in these views?<br>
<br>
Ed<br>
</body>
</html>

--------------040700040100090000070404--

From pgsql-performance-owner@postgresql.org  Thu Oct 27 11:38:08 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 01CB9DAEAC
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 11:38:07 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 63725-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 14:38:02 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id CDADADAD5F
	for <pgsql-performance@postgresql.org>;
	Thu, 27 Oct 2005 11:38:04 -0300 (ADT)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j9REc23c018900;
	Thu, 27 Oct 2005 10:38:02 -0400 (EDT)
To: Svenne Krap <svenne@krap.dk>
Cc: pgsql-performance@postgresql.org
Subject: Re: Perfomance of views 
In-reply-to: <4360B375.8000303@krap.dk> 
References: <435FA002.4060509@krap.dk> <43609EF4.8060907@archonet.com>
	<4360B375.8000303@krap.dk>
Comments: In-reply-to Svenne Krap <svenne@krap.dk>
	message dated "Thu, 27 Oct 2005 13:01:09 +0200"
Date: Thu, 27 Oct 2005 10:38:02 -0400
Message-ID: <18899.1130423882@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/420
X-Sequence-Number: 15188

Svenne Krap <svenne@krap.dk> writes:
> The ways I have considered was :
> 1) write a big query in hand (not preferred as it gets hard to manage)
> 2) write layers of views (still not prefered as I still have to remember 
> to put on the right conditions everywhere)
> 3) write layers of sql-functions (returning the right sets of rows from 
> the underlying tables) - which I prefer from a development angel .. it 
> gets very clean and I cant forget a parameter anywhere.

#1 and #2 should behave pretty similarly, assuming that the "one big
query" would have been structured the same way as the nest of views is.
#3 unfortunately will pretty much suck, because there's no chance for
cross-level optimization.

There's been some discussion of inline-expanding SQL functions that
return sets when they are called in FROM, which would make a SQL
function that contains just a SELECT effectively equivalent to a view
as far as the planner's powers of optimization go.  No one's tried to
make it happen yet though.

			regards, tom lane

From pgsql-performance-owner@postgresql.org  Thu Oct 27 12:09:45 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 14229DB0D4
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 12:09:43 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 80389-03
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 15:09:38 +0000 (GMT)
Received: from cicero2.cybercity.dk (cicero2.cybercity.dk [212.242.40.53])
	by svr1.postgresql.org (Postfix) with ESMTP id C731ADB0C1
	for <pgsql-performance@postgresql.org>;
	Thu, 27 Oct 2005 12:09:37 -0300 (ADT)
Received: from [192.168.0.79] (0x3e42eeca.adsl.cybercity.dk [62.66.238.202])
	by cicero2.cybercity.dk (Postfix) with ESMTP
	id C1FE1190099; Thu, 27 Oct 2005 17:09:34 +0200 (CEST)
Message-ID: <4360EDE5.9050400@krap.dk>
Date: Thu, 27 Oct 2005 17:10:29 +0200
From: Svenne Krap <svenne@krap.dk>
User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-performance@postgresql.org
Subject: Re: Perfomance of views
References: <435FA002.4060509@krap.dk> <43609EF4.8060907@archonet.com>
	<4360B375.8000303@krap.dk> <18899.1130423882@sss.pgh.pa.us>
In-Reply-To: <18899.1130423882@sss.pgh.pa.us>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0 required=5 tests=[none]
X-Spam-Level: 
X-Archive-Number: 200510/421
X-Sequence-Number: 15189

Tom Lane wrote:

>There's been some discussion of inline-expanding SQL functions that
>return sets when they are called in FROM, which would make a SQL
>function that contains just a SELECT effectively equivalent to a view
>as far as the planner's powers of optimization go.  No one's tried to
>make it happen yet though.
>  
>

This is exactly what would be brilliant in my case. Use the functions as 
a kind of strict, parameterized views, that in the planner (or wherever) 
gets replaced down to a simple (?!?!) sql-statement.
This would imho be highly valuable for almost any kind of complex 
time-travel application (and surely dozens of other applications).

And before anyone suggests it, I don't code C well enough (*cough* 
rusty) to try to do it myself. I would apriciate if it went on the todo 
for 8.2 though. (I might even be willing to sponsor some money (a single 
or perhpas two thousands of US dollars) for getting it done and release 
it immediately under postgresql standard license (BSD)).

I by the way also support the idea of a way to force a table into a 
PgSQL managed cache like discussed a while ago. Sometimes overall speed 
for the system is less important than speed of a single query.

I must also say, that I am very impressed with the performance 
enhancements of 8.1 beta, the bitmap index scans are amazing ! Good job, 
guys - PgSQL has come a far way from 7.0 (where I started) and the 
future looks bright ;)

Svenne

From pgsql-performance-owner@postgresql.org  Thu Oct 27 12:45:47 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 7F58ED7758
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 12:45:45 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 92654-03
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 15:45:43 +0000 (GMT)
Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75])
	by svr1.postgresql.org (Postfix) with ESMTP id 4B651D76B8
	for <pgsql-performance@postgresql.org>;
	Thu, 27 Oct 2005 12:45:43 -0300 (ADT)
Received: from mainbox.archonet.com
	(84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99])
	by smtp.metronet.co.uk (MetroNet Mail) with ESMTP
	id 891B841BB54; Thu, 27 Oct 2005 16:45:30 +0100 (BST)
Received: from localhost (localhost.localdomain [127.0.0.1])
	by mainbox.archonet.com (Postfix) with ESMTP id 856CA15ED5;
	Thu, 27 Oct 2005 16:40:53 +0100 (BST)
Received: from mainbox.archonet.com ([127.0.0.1])
	by localhost (mainbox [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 12820-10; Thu, 27 Oct 2005 16:40:47 +0100 (BST)
Received: from [192.168.1.17] (client17.office.archonet.com [192.168.1.17])
	by mainbox.archonet.com (Postfix) with ESMTP id DF24215EE1;
	Thu, 27 Oct 2005 16:40:39 +0100 (BST)
Message-ID: <4360F4F7.8070503@archonet.com>
Date: Thu, 27 Oct 2005 16:40:39 +0100
From: Richard Huxton <dev@archonet.com>
User-Agent: Mozilla Thunderbird 1.0.7 (X11/20051013)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: Jan Wieck <JanWieck@Yahoo.com>
Cc: Svenne Krap <svenne@krap.dk>,
	'Postgresql Performance' <pgsql-performance@postgresql.org>
Subject: Re: Perfomance of views
References: <435FA002.4060509@krap.dk> <43609EF4.8060907@archonet.com>
	<4360AE59.6010209@krap.dk> <4360BA22.5050606@archonet.com>
	<4360D906.3060504@Yahoo.com>
In-Reply-To: <4360D906.3060504@Yahoo.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.058 required=5 tests=[AWL=0.008,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/423
X-Sequence-Number: 15191

Jan Wieck wrote:
> On 10/27/2005 7:29 AM, Richard Huxton wrote:
>> Svenne Krap wrote:
>>
>>> What do you mean exactly but "pushing conditions inside" ?
>>
>> If I have something like "SELECT * FROM complicated_view WHERE foo = 
>> 7" then the planner can look "inside" complicated_view and see where 
>> it can attach the condition "foo=7", rather than running the query and 
>> applying the condition at the end.
> 
> Sorry, but the planner doesn't attach the condition anywhere. It is the 
> rewriter that takes the actual query, replaces the views rangetable and 
> expression entries with the actual underlying objects and adds the views 
> condition with an AND to the queries condition. Simply example:

Thanks for the correction Jan.

-- 
   Richard Huxton
   Archonet Ltd

From pgsql-performance-owner@postgresql.org  Thu Oct 27 12:41:30 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id ECEEBDAB07
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 12:41:27 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 88033-10
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 15:41:24 +0000 (GMT)
Received: from floppy.pyrenet.fr (news.pyrenet.fr [194.116.145.2])
	by svr1.postgresql.org (Postfix) with ESMTP id 0D7CDD7758
	for <pgsql-performance@postgresql.org>;
	Thu, 27 Oct 2005 12:41:24 -0300 (ADT)
Received: by floppy.pyrenet.fr (Postfix, from userid 106)
	id AFA0031059; Thu, 27 Oct 2005 17:41:23 +0200 (MET DST)
From: Denis <denis.sailer@yellowbook.com>
X-Newsgroups: pgsql.performance
Subject: Update using primary key slow
Date: Thu, 27 Oct 2005 15:41:22 +0000 (UTC)
Organization: Yellow Book
Lines: 115
Message-ID: <Xns96FC6CBBEC0CDdenissaileryellowboo@200.46.204.72>
X-Complaints-To: usenet@news.hub.org
User-Agent: Xnews/5.04.25
To: pgsql-performance@postgresql.org
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.696 required=5 tests=[AWL=0.489,
	UPPERCASE_25_50=0.207]
X-Spam-Level: 
X-Archive-Number: 200510/422
X-Sequence-Number: 15190

The following update was captured in the database log and the elapsed time 
was 1058.956 ms.  A later explain analyze shows total run time of 730 ms.  
Although isn't the actual time to update the row 183 ms.  Where is the 
other 547 ms coming from?  Updating the two secondary indexes??


Oct 27 08:09:48 ybcdrdwdb01 postgres[12315]: [145-1] LOG:  duration: 
1058.956 ms  statement: UPDATE CONTRACT SET CUSTOMER_KEY = 143567 
,SOURCE_CODE_KEY = null ,PRIOR_CONTRACT =
Oct 27 08:09:48 ybcdrdwdb01 postgres[12315]: [145-2]  
'265985' ,PRIOR_CONTRACT_ELITE = null ,CONTRACT_NEW = 'N' ,RENEWAL_CONTRACT 
= '1373990'  ,RENEWAL_CONTRACT_ELITE = null
Oct 27 08:09:48 ybcdrdwdb01 postgres[12315]: [145-3]  ,CONTRACT_DROPPED = 
'N' ,TOTAL_SALE_DOLLARS = 3492.00 ,TARGET_DOLLARS = 3576 
,ASSIGN_DOLLARS_OVERRIDE = null ,BOOK_KEY = 160
Oct 27 08:09:48 ybcdrdwdb01 postgres[12315]: [145-4]  ,PUB_SEQUENCE = 25 
,DROP_DATE = null ,OUT_OF_BUSINESS = 'N' ,RENEWAL_SALESREP_KEY = 3639 
,SALESREP_KEY = 3639 ,NEW_CATEGORY =
Oct 27 08:09:48 ybcdrdwdb01 postgres[12315]: [145-5]  
'NEW_INSERT' ,PENDING_DELETE_DATE = null ,CLIENT_NAME = null ,DATE_SOLD = 
'2004-08-30'  ,DATE_RECEIVED = '2004-09-03' 
Oct 27 08:09:48 ybcdrdwdb01 postgres[12315]: [145-6]  ,DATE_ENTERED = 
'2004-09-07'  ,DATE_SHELLED = null  ,DATE_APPROVED = '2004-09-09'  WHERE 
REGION_KEY = 14  AND CONTRACT_KEY =
Oct 27 08:09:48 ybcdrdwdb01 postgres[12315]: [145-7]  1070135


The explain for this update is as follows.


dw=# begin;
BEGIN
dw=#
dw=# explain analyze UPDATE CONTRACT SET CUSTOMER_KEY = 143567, 
SOURCE_CODE_KEY = null ,
dw-# PRIOR_CONTRACT = '265985' ,PRIOR_CONTRACT_ELITE = null ,CONTRACT_NEW = 
'N' ,RENEWAL_CONTRACT = '1373990'  ,RENEWAL_CONTRACT_ELITE = null
dw-#  ,CONTRACT_DROPPED = 'N' ,TOTAL_SALE_DOLLARS = 3492.00 ,TARGET_DOLLARS 
= 3576 ,ASSIGN_DOLLARS_OVERRIDE = null ,BOOK_KEY = 160
dw-#  ,PUB_SEQUENCE = 25 ,DROP_DATE = null ,OUT_OF_BUSINESS = 
'N' ,RENEWAL_SALESREP_KEY = 3639 ,SALESREP_KEY = 3639
dw-#  ,NEW_CATEGORY = 'NEW_INSERT' ,PENDING_DELETE_DATE = null ,CLIENT_NAME 
= null ,DATE_SOLD = '2004-08-30'  ,DATE_RECEIVED = '2004-09-03'
dw-#   ,DATE_ENTERED = '2004-09-07'  ,DATE_SHELLED = null  ,DATE_APPROVED = 
'2004-09-09'
dw-# WHERE REGION_KEY = 14  AND CONTRACT_KEY = 1070135;
                                                        QUERY PLAN
---------------------------------------------------------------------------
------------------------------------------------
 Index Scan using contract_pkey on contract  (cost=0.00..10.61 rows=3 
width=115) (actual time=0.181..0.183 rows=1 loops=1)
   Index Cond: ((contract_key = 1070135) AND (region_key = 14))
 Total runtime: 0.730 ms
(3 rows)

dw=# rollback;
ROLLBACK



Here is the table and index definitions

dw=# \d contract
                         Table "ods.contract"
         Column          |            Type             |   Modifiers
-------------------------+-----------------------------+---------------
 contract_key            | integer                     | not null
 customer_key            | integer                     | not null
 source_code_key         | integer                     |
 prior_contract          | character varying(20)       |
 prior_contract_elite    | character varying(20)       |
 renewal_contract        | character varying(20)       |
 contract_dropped        | character varying(1)        | not null
 renewal_contract_elite  | character varying(20)       |
 total_sale_dollars      | numeric(9,2)                | not null
 assign_dollars_override | numeric(9,2)                |
 target_dollars          | numeric(9,2)                |
 book_key                | integer                     | not null
 pub_sequence            | integer                     |
 drop_date               | timestamp without time zone |
 out_of_business         | character varying(1)        | not null
 salesrep_key            | integer                     |
 renewal_salesrep_key    | integer                     |
 new_category            | character varying(20)       |
 region_key              | integer                     | not null
 contract_new            | character varying(1)        | not null
 pending_delete_date     | timestamp without time zone |
 client_name             | character varying(150)      |
 fuzzy_client_name       | character varying(150)      |
 last_update_date        | timestamp without time zone | default now()
 date_sold               | date                        |
 date_received           | date                        |
 date_entered            | date                        |
 date_shelled            | date                        |
 date_approved           | date                        |
Indexes:
    "contract_pkey" primary key, btree (contract_key, region_key)
    "XIE1_Contract" btree (region_key, book_key, pub_sequence)
    "XIE2_Contract" btree (customer_key, region_key)


The table contains approximately 5 million rows

Postgres version is PostgreSQL 7.4.3 on i686-pc-linux-gnu, compiled by GCC 
gcc (GCC) 3.2.2


The machine has 4 Intel Xeon 3.0GHz processors and 3GB of memory

shared_buffers = 16384
sort_mem = 8192
vacuum_mem = 8192
effective_cache_size = 262144



From pgsql-performance-owner@postgresql.org  Thu Oct 27 13:00:28 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id BE654DAABD
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 13:00:26 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 99328-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 16:00:24 +0000 (GMT)
Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75])
	by svr1.postgresql.org (Postfix) with ESMTP id 9FB46DA743
	for <pgsql-performance@postgresql.org>;
	Thu, 27 Oct 2005 13:00:24 -0300 (ADT)
Received: from mainbox.archonet.com
	(84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99])
	by smtp.metronet.co.uk (MetroNet Mail) with ESMTP
	id DEE8F40D05D; Thu, 27 Oct 2005 17:00:11 +0100 (BST)
Received: from localhost (localhost.localdomain [127.0.0.1])
	by mainbox.archonet.com (Postfix) with ESMTP id C270915EDA;
	Thu, 27 Oct 2005 16:56:54 +0100 (BST)
Received: from mainbox.archonet.com ([127.0.0.1])
	by localhost (mainbox [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 13353-08; Thu, 27 Oct 2005 16:56:50 +0100 (BST)
Received: from [192.168.1.17] (client17.office.archonet.com [192.168.1.17])
	by mainbox.archonet.com (Postfix) with ESMTP id 4011715ED5;
	Thu, 27 Oct 2005 16:56:50 +0100 (BST)
Message-ID: <4360F8C1.4040202@archonet.com>
Date: Thu, 27 Oct 2005 16:56:49 +0100
From: Richard Huxton <dev@archonet.com>
User-Agent: Mozilla Thunderbird 1.0.7 (X11/20051013)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: =?ISO-8859-1?Q?Sidar_L=F3pez_Cruz?= <sidarlopez@hotmail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: how postgresql request the computer resources
References: <BAY23-F28F5DD23A4A73C7BFE3CD1CE680@phx.gbl>
In-Reply-To: <BAY23-F28F5DD23A4A73C7BFE3CD1CE680@phx.gbl>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: quoted-printable
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.058 required=5 tests=[AWL=0.008,
	FORGED_RCVD_HELO=0.05]
X-Spam-Level: 
X-Archive-Number: 200510/424
X-Sequence-Number: 15192

Sidar L=F3pez Cruz wrote:
> Is there something that tells postgres to take the resorces from=20
> computer (RAM, HDD, SWAP on linux) as it need, not modifying variables =

> on postgresql.conf and other operating system things?

Ah, and how is it to know what to share with other processes?

> A days ago i am trying to show that postgres is better than mssql but=20
> when execute a simple query like:
>=20
> (1)
> select count(*) from
> Total runtime: 134552.325 ms
>=20
> (2)
> select count(*) from fotos where archivo not in (select archivo from=20
> Total runtime: 26747.236 ms
>=20
> (3)
> select count(1) from fotos f where not exists (select a.archivo from=20
> Total runtime: 89765.714 ms
>=20
> (4)
> SELECT count(*)
> Total runtime: 114893.116 ms

> WITH ANY OF THIS QUERIES MSSQL TAKES NOT MUCH OF 7 SECONDS....

In which case they make a bad choice for showing PostgreSQL is faster=20
than MSSQL. Is this the only query you have, or are others giving you=20
problems too?

I think count(*) is about the weakest point in PG, but I don't think=20
there'll be a general solution available soon. As I'm sure someone has=20
mentioned, whatever else, PG needs to check the row for its visibility=20
information.

 From the start of your email, you seem to suspect your configuration=20
needs some work. Once you are happy that your settings in general are=20
good, you can override some by issuing set statements before your query. =

For example:
	SET work_mem =3D 10000;
might well improve example #2 where you had a hash.

--
   Richard Huxton
   Archonet Ltd


From pgsql-performance-owner@postgresql.org  Thu Oct 27 13:18:12 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 52106DB0F5
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 13:18:06 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 03537-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 16:18:04 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id E9958DB0E7
	for <pgsql-performance@postgresql.org>;
	Thu, 27 Oct 2005 13:18:03 -0300 (ADT)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j9RGI3UQ019723;
	Thu, 27 Oct 2005 12:18:03 -0400 (EDT)
To: Denis <denis.sailer@yellowbook.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Update using primary key slow 
In-reply-to: <Xns96FC6CBBEC0CDdenissaileryellowboo@200.46.204.72> 
References: <Xns96FC6CBBEC0CDdenissaileryellowboo@200.46.204.72>
Comments: In-reply-to Denis <denis.sailer@yellowbook.com>
	message dated "Thu, 27 Oct 2005 15:41:22 -0000"
Date: Thu, 27 Oct 2005 12:18:03 -0400
Message-ID: <19722.1130429883@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006]
X-Spam-Level: 
X-Archive-Number: 200510/425
X-Sequence-Number: 15193

Denis <denis.sailer@yellowbook.com> writes:
> The following update was captured in the database log and the elapsed time 
> was 1058.956 ms.  A later explain analyze shows total run time of 730 ms.  
> Although isn't the actual time to update the row 183 ms.  Where is the 
> other 547 ms coming from?  Updating the two secondary indexes??

The 183 msec is the time needed to *fetch* the row, not the time to
update it.  So it could well be that the other time is just the time
needed to update the table and indexes.  If this seems slower than
your hardware ought to be able to handle, I'd wonder about how recently
the table has been vacuumed.

			regards, tom lane

From pgsql-performance-owner@postgresql.org  Thu Oct 27 15:10:08 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id EF1A4DB128
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 15:10:07 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 09956-03
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 18:10:01 +0000 (GMT)
Received: from floppy.pyrenet.fr (news.pyrenet.fr [194.116.145.2])
	by svr1.postgresql.org (Postfix) with ESMTP id 8FDB9DB0E9
	for <pgsql-performance@postgresql.org>;
	Thu, 27 Oct 2005 15:10:01 -0300 (ADT)
Received: by floppy.pyrenet.fr (Postfix, from userid 106)
	id D9F7131059; Thu, 27 Oct 2005 20:10:00 +0200 (MET DST)
From: Denis <denis.sailer@yellowbook.com>
X-Newsgroups: pgsql.performance
Subject: Re: Update using primary key slow
Date: Thu, 27 Oct 2005 18:09:57 +0000 (UTC)
Organization: Yellow Book
Lines: 102
Message-ID: <Xns96FC85EFAC158denissaileryellowboo@200.46.204.72>
References: <Xns96FC6CBBEC0CDdenissaileryellowboo@200.46.204.72>
	<19722.1130429883@sss.pgh.pa.us>
X-Complaints-To: usenet@news.hub.org
User-Agent: Xnews/5.04.25
To: pgsql-performance@postgresql.org
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.267 required=5 tests=[AWL=0.267]
X-Spam-Score: 0.267
X-Spam-Level: 
X-Archive-Number: 200510/426
X-Sequence-Number: 15194

tgl@sss.pgh.pa.us (Tom Lane) wrote in
news:19722.1130429883@sss.pgh.pa.us: 

> Denis <denis.sailer@yellowbook.com> writes:
>> The following update was captured in the database log and the elapsed
>> time was 1058.956 ms.  A later explain analyze shows total run time
>> of 730 ms.  Although isn't the actual time to update the row 183 ms. 
>> Where is the other 547 ms coming from?  Updating the two secondary
>> indexes?? 
> 
> The 183 msec is the time needed to *fetch* the row, not the time to
> update it.  So it could well be that the other time is just the time
> needed to update the table and indexes.  If this seems slower than
> your hardware ought to be able to handle, I'd wonder about how
> recently the table has been vacuumed.
> 
>                regards, tom lane
> 
> ---------------------------(end of
> broadcast)--------------------------- TIP 1: if posting/reading
> through Usenet, please send an appropriate 
>        subscribe-nomail command to majordomo@postgresql.org so that
>        your message can get through to the mailing list cleanly
> 
> 

There is a vacuumdb done at 6 AM and 5PM

In addition this table is vacuumed at 2AM, 8AM, 10AM, 12PM, 2PM, and 4PM

This is the vacuum from last night at 5PM


INFO:  vacuuming "ods.contract"
INFO:  index "XIE1_Contract" now contains 5105322 row versions in 27710 
pages
DETAIL:  2174 index row versions were removed.
893 index pages have been deleted, 893 are currently reusable.
CPU 1.91s/1.58u sec elapsed 34.14 sec.
INFO:  index "XIE2_Contract" now contains 5105331 row versions in 21701 
pages
DETAIL:  2174 index row versions were removed.
0 index pages have been deleted, 0 are currently reusable.
CPU 1.40s/1.42u sec elapsed 22.73 sec.
INFO:  index "contract_pkey" now contains 5105337 row versions in 21480 
pages
DETAIL:  2174 index row versions were removed.
0 index pages have been deleted, 0 are currently reusable.
CPU 1.80s/1.52u sec elapsed 18.59 sec.
INFO:  "contract": removed 2174 row versions in 893 pages
DETAIL:  CPU 0.42s/0.08u sec elapsed 1.22 sec.
INFO:  "contract": found 2174 removable, 5105321 nonremovable row 
versions in 129154 pages
DETAIL:  1357 dead row versions cannot be removed yet.
There were 1967941 unused item pointers.
0 pages are entirely empty.
CPU 11.38s/5.09u sec elapsed 85.48 sec.
INFO:  analyzing "ods.contract"
INFO:  "contract": 129154 pages, 3000 rows sampled, 5277622 estimated 
total rows


Here is the latest vacuum today.

INFO:  vacuuming "ods.contract"
INFO:  index "XIE1_Contract" now contains 5106346 row versions in 28233 
pages
DETAIL:  64146 index row versions were removed.
706 index pages have been deleted, 669 are currently reusable.
CPU 2.03s/2.33u sec elapsed 20.08 sec.
INFO:  index "XIE2_Contract" now contains 5106347 row versions in 21951 
pages
DETAIL:  64146 index row versions were removed.
0 index pages have been deleted, 0 are currently reusable.
CPU 2.16s/3.39u sec elapsed 12.23 sec.
INFO:  index "contract_pkey" now contains 5106347 row versions in 21516 
pages
DETAIL:  64146 index row versions were removed.
0 index pages have been deleted, 0 are currently reusable.
CPU 1.76s/2.47u sec elapsed 11.80 sec.
INFO:  "contract": removed 64146 row versions in 26115 pages
DETAIL:  CPU 1.94s/2.55u sec elapsed 7.78 sec.
INFO:  "contract": found 64146 removable, 5106307 nonremovable row 
versions in 129154 pages
DETAIL:  890 dead row versions cannot be removed yet.
There were 1905028 unused item pointers.
0 pages are entirely empty.
CPU 14.83s/11.48u sec elapsed 60.96 sec.
INFO:  analyzing "ods.contract"
INFO:  "contract": 129154 pages, 3000 rows sampled, 5236929 estimated 
total rows


I would think this should be very fast.  I already described the CPU and 
memory.  THe disk is backed by an EMC DMX2000.  This particular server 
has 1 physical volume group of 500GB which is split over two logical 
volumes.  One for $PGDATA and the other ofr PG_XLOG.  THis split was not 
really done for performance since it comes from the same physical volume 
group, but more for space manageability.  The physical volume group 
consists of 11GB stripes from across the EMC san.  So that would be 
about 50 stripes which is really coming from dozens of backend disk 
drives.  Typical I/O response times for these is 3-5 ms.

From pgsql-performance-owner@postgresql.org  Thu Oct 27 16:31:49 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id DCC77DB08F
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 16:31:48 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 03553-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 19:31:44 +0000 (GMT)
Received: from floppy.pyrenet.fr (news.pyrenet.fr [194.116.145.2])
	by svr1.postgresql.org (Postfix) with ESMTP id 95FC4DAEEA
	for <pgsql-performance@postgresql.org>;
	Thu, 27 Oct 2005 16:31:45 -0300 (ADT)
Received: by floppy.pyrenet.fr (Postfix, from userid 106)
	id 625BE31059; Thu, 27 Oct 2005 21:31:46 +0200 (MET DST)
From: "PostgreSQL" <martin@portant.com>
X-Newsgroups: pgsql.performance
Subject: How much memory?
Date: Thu, 27 Oct 2005 14:31:43 -0500
Organization: Hub.Org Networking Services
Lines: 4
Message-ID: <djr9uu$72d$1@news.hub.org>
X-Complaints-To: usenet@news.hub.org
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
X-RFC2646: Format=Flowed; Original
To: pgsql-performance@postgresql.org
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0 required=5 tests=[none]
X-Spam-Score: 0
X-Spam-Level: 
X-Archive-Number: 200510/427
X-Sequence-Number: 15195

Is there a rule-of-thumb for determining the amount of system memory a 
database requres (other than "all you can afford")? 



From pgsql-performance-owner@postgresql.org  Thu Oct 27 16:41:07 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id D99FFDACA4
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 16:41:06 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 04151-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 19:41:03 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id 5012CDAACC
	for <pgsql-performance@postgresql.org>;
	Thu, 27 Oct 2005 16:41:04 -0300 (ADT)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j9RJf3Ex023323;
	Thu, 27 Oct 2005 15:41:03 -0400 (EDT)
To: Denis <denis.sailer@yellowbook.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Update using primary key slow 
In-reply-to: <Xns96FC85EFAC158denissaileryellowboo@200.46.204.72> 
References: <Xns96FC6CBBEC0CDdenissaileryellowboo@200.46.204.72>
	<19722.1130429883@sss.pgh.pa.us>
	<Xns96FC85EFAC158denissaileryellowboo@200.46.204.72>
Comments: In-reply-to Denis <denis.sailer@yellowbook.com>
	message dated "Thu, 27 Oct 2005 18:09:57 -0000"
Date: Thu, 27 Oct 2005 15:41:03 -0400
Message-ID: <23322.1130442063@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.006 required=5 tests=[AWL=0.006]
X-Spam-Score: 0.006
X-Spam-Level: 
X-Archive-Number: 200510/428
X-Sequence-Number: 15196

Denis <denis.sailer@yellowbook.com> writes:
> tgl@sss.pgh.pa.us (Tom Lane) wrote in
> news:19722.1130429883@sss.pgh.pa.us: 
>> The 183 msec is the time needed to *fetch* the row, not the time to
>> update it.  So it could well be that the other time is just the time
>> needed to update the table and indexes.  If this seems slower than
>> your hardware ought to be able to handle, I'd wonder about how
>> recently the table has been vacuumed.

> Here is the latest vacuum today.

> INFO:  "contract": removed 64146 row versions in 26115 pages
> DETAIL:  CPU 1.94s/2.55u sec elapsed 7.78 sec.
> INFO:  "contract": found 64146 removable, 5106307 nonremovable row 
> versions in 129154 pages
> DETAIL:  890 dead row versions cannot be removed yet.
> There were 1905028 unused item pointers.

The "unused item pointers" number seems a bit high, but otherwise that
looks pretty reasonable.

Is it possible that the particular row you were updating has been
updated quite a lot of times since the last vacuum?  Or even quite
a few times within a single transaction?  The only thing I can think
of that would explain such a slow fetch is if the code has to reject
a bunch of recently-dead versions of the row.

			regards, tom lane

From pgsql-performance-owner@postgresql.org  Thu Oct 27 17:41:17 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 6D616DAACC
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 17:41:16 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 27271-07
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 20:41:13 +0000 (GMT)
Received: from floppy.pyrenet.fr (news.pyrenet.fr [194.116.145.2])
	by svr1.postgresql.org (Postfix) with ESMTP id 6DB57DAAC7
	for <pgsql-performance@postgresql.org>;
	Thu, 27 Oct 2005 17:41:14 -0300 (ADT)
Received: by floppy.pyrenet.fr (Postfix, from userid 106)
	id A81E931059; Thu, 27 Oct 2005 22:41:15 +0200 (MET DST)
From: "PostgreSQL" <martin@portant.com>
X-Newsgroups: pgsql.performance
Subject: Re: What gets cached?
Date: Thu, 27 Oct 2005 15:41:10 -0500
Organization: Hub.Org Networking Services
Lines: 51
Message-ID: <djre16$uqq$1@news.hub.org>
References: <pan.2005.10.21.12.34.29.712700@portant.com>
	<1129931087.19971.12.camel@localhost.localdomain>
	<33c6269f0510240809k47f91a71t387a0b5ab0339f4c@mail.gmail.com>
	<20051024153248.GA24601@samfundet.no>
X-Complaints-To: usenet@news.hub.org
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
X-RFC2646: Format=Flowed; Original
To: pgsql-performance@postgresql.org
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0 required=5 tests=[none]
X-Spam-Score: 0
X-Spam-Level: 
X-Archive-Number: 200510/429
X-Sequence-Number: 15197

Thank each of you for your replies.  I'm just beginning to understand the 
scope of my opportunities.

Someone (I apologize, I forgot who) recently posted this query:
    SELECT oid::regclass, reltuples, relpages
    FROM pg_class
    ORDER BY 3 DESC

Though the application is a relatively low-volume TP system, it is 
structured a lot like a data warehouse with one primary table that 
everything else hangs off.  What the query above shows is that my largest 
table, at 34 million rows, takes almost 1.4 million pages or 10+ Gb if my 
math is good.  The same table has 14 indexes, totaling another 12Gb.  All 
this is running on a box with 4Gb of memory.

So what I believe I see happening is that almost every query is clearing out 
memory to load the particular index it needs.  Hence my "first queries are 
the fastest" observation at the beginning of this thread.

There are certainly design improvements to be done, but I've already started 
the process of getting the memory increased on our production db server.  We 
are btw running 8.1 beta 3.

""Steinar H. Gunderson"" <sgunderson@bigfoot.com> wrote in message 
news:20051024153248.GA24601@samfundet.no...
> On Mon, Oct 24, 2005 at 11:09:55AM -0400, Alex Turner wrote:
>> Just to play devils advocate here for as second, but if we have an 
>> algorithm
>> that is substational better than just plain old LRU, which is what I 
>> believe
>> the kernel is going to use to cache pages (I'm no kernel hacker), then 
>> why
>> don't we apply that and have a significantly larger page cache a la 
>> Oracle?
>
> There have (AFAIK) been reports of setting huge amounts of shared_buffers
> (close to the total amount of RAM) performing much better in 8.1 than in
> earlier versions, so this might actually be okay these days.
>
> I haven't heard of anybody reporting increase setting such values, though.
>
> /* Steinar */
> -- 
> Homepage: http://www.sesse.net/
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: Don't 'kill -9' the postmaster
> 



From pgsql-performance-owner@postgresql.org  Thu Oct 27 18:02:05 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 8FC3BDB098
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 18:02:04 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 29036-09
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 21:01:59 +0000 (GMT)
Received: from h1.bettercom.de (h1.bettercom.de [213.239.194.41])
	by svr1.postgresql.org (Postfix) with ESMTP id 42853DB0E4
	for <pgsql-performance@postgresql.org>;
	Thu, 27 Oct 2005 18:01:59 -0300 (ADT)
Received: (qmail 2678 invoked by uid 208); 27 Oct 2005 21:02:00 -0000
Received: from 213.39.214.61 by h1 (envelope-from <ml-pgsql@bettercom.de>,
	uid 0) with qmail-scanner-1.23
	(clamdscan: 0.87. spamassassin: 3.04.  Clear:RC:1(213.39.214.61):.
	Processed in 0.96462 secs); 27 Oct 2005 21:02:00 -0000
Received: from unknown (HELO nb-aspire.bettercom.de) ([213.39.214.61])
	(envelope-sender <ml-pgsql@bettercom.de>)
	by h1.bettercom.de (qmail-ldap-1.03) with SMTP
	for <denis.sailer@yellowbook.com>; 27 Oct 2005 21:01:57 -0000
Received: (nullmailer pid 10410 invoked by uid 1000);
	Thu, 27 Oct 2005 21:01:55 -0000
Cc: Denis <denis.sailer@yellowbook.com>,
	pgsql-performance@postgresql.org
Subject: Re: Reasons and drawbacks for unused item pointers (was: Update using
	primary key slow)
X-PGP-Key: http://bettercom.de/misc/3A547DE6.asc
X-Face: 
 "d[&>8')a)wbF:+L#^<_cohnX6#m5RCCeKF/6_gD(iQ9bX?xe2~Aq*!')D(1ks`?YhomOYbL3R:{4e4a]qft_]<.q/Lf4hIr,`G+LX33&TYp}XGf<b?+GPT;
	3I8k/|[DR#MO1N(h>e~^5m$28R"$C(EwnB\n8t
In-Reply-To: <23322.1130442063@sss.pgh.pa.us> (Tom Lane's message of "Thu,
	27 Oct 2005 15:41:03 -0400")
References: <Xns96FC6CBBEC0CDdenissaileryellowboo@200.46.204.72>
	<19722.1130429883@sss.pgh.pa.us>
	<Xns96FC85EFAC158denissaileryellowboo@200.46.204.72>
	<23322.1130442063@sss.pgh.pa.us>
To: pgsql-performance@postgresql.org
From: Martin Lesser <ml-pgsql@bettercom.de>
Date: Thu, 27 Oct 2005 23:01:55 +0200
Message-ID: <87y84eznb0.fsf_-_@nb-aspire.bettercom.de>
User-Agent: Gnus/5.1007 (Gnus v5.10.7) XEmacs/21.4 (Jumbo Shrimp, linux)
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.013 required=5 tests=[AWL=0.013]
X-Spam-Score: 0.013
X-Spam-Level: 
X-Archive-Number: 200510/430
X-Sequence-Number: 15198

Tom Lane <tgl@sss.pgh.pa.us> writes:

> Denis <denis.sailer@yellowbook.com> writes:
>> There were 1905028 unused item pointers.
> The "unused item pointers" number seems a bit high, but otherwise that
> looks pretty reasonable.
>
> Is it possible that the particular row you were updating has been
> updated quite a lot of times since the last vacuum?  Or even quite
> a few times within a single transaction?

What causes this "unused item pointers" and which impact do they have
regarding performance?

If I understood your last posting correctly more than one update on a
single row between two vacuum's would i.e. result in one ore more
"unused item pointer". Does this slow down the vacuum process and/or
other processes?  Until now I could not find an answer what this number
implies.

Regards

Martin

From pgsql-performance-owner@postgresql.org  Thu Oct 27 18:36:50 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id E8A97DB09A
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 18:36:49 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 41521-09
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 21:36:47 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id 27986DB0EE
	for <pgsql-performance@postgresql.org>;
	Thu, 27 Oct 2005 18:36:48 -0300 (ADT)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j9RLaaiP024261;
	Thu, 27 Oct 2005 17:36:36 -0400 (EDT)
To: Martin Lesser <ml-pgsql@bettercom.de>
Cc: pgsql-performance@postgresql.org,
	Denis <denis.sailer@yellowbook.com>
Subject: Re: Reasons and drawbacks for unused item pointers (was: Update using
	primary key slow)
In-reply-to: <87y84eznb0.fsf_-_@nb-aspire.bettercom.de> 
References: <Xns96FC6CBBEC0CDdenissaileryellowboo@200.46.204.72>
	<19722.1130429883@sss.pgh.pa.us>
	<Xns96FC85EFAC158denissaileryellowboo@200.46.204.72>
	<23322.1130442063@sss.pgh.pa.us>
	<87y84eznb0.fsf_-_@nb-aspire.bettercom.de>
Comments: In-reply-to Martin Lesser <ml-pgsql@bettercom.de>
	message dated "Thu, 27 Oct 2005 23:01:55 +0200"
Date: Thu, 27 Oct 2005 17:36:36 -0400
Message-ID: <24260.1130448996@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.006 required=5 tests=[AWL=0.006]
X-Spam-Score: 0.006
X-Spam-Level: 
X-Archive-Number: 200510/431
X-Sequence-Number: 15199

Martin Lesser <ml-pgsql@bettercom.de> writes:
> What causes this "unused item pointers" and which impact do they have
> regarding performance?

Those are item pointer slots that were once used but aren't used at the
moment.  VACUUM leaves an empty slot behind when it removes a dead
tuple, and the slot is then available for re-use next time a tuple is
created on that page.  See
http://developer.postgresql.org/docs/postgres/storage-page-layout.html

The direct performance impact is really pretty minimal (and none at all
on indexscans, AFAIR).  The reason Denis' number drew my attention was
that it implied that the table had gone un-vacuumed for awhile at some
time in the past.  His stats were showing about 64000 tuples deleted
per vacuum pass, which would have created 64000 unused item pointers
--- but in a steady-state situation those would be eaten up again by
the time of the next vacuum.  To have 1905028 unused pointers in a
table with only 5106307 live entries suggests that at some point there
were 1.9 million (or so) dead but not-yet-vacuumed tuples, which
suggests insufficient vacuuming.

			regards, tom lane

From pgsql-performance-owner@postgresql.org  Thu Oct 27 18:59:03 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id DE5FADB09A
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 18:59:01 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 58480-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 21:58:56 +0000 (GMT)
Received: from madoka.pendragon.org (www.pendragon.org [216.194.85.20])
	by svr1.postgresql.org (Postfix) with ESMTP id F3DA7DB098
	for <pgsql-performance@postgresql.org>;
	Thu, 27 Oct 2005 18:58:57 -0300 (ADT)
Received: from localhost (localhost.localdomain [127.0.0.1])
	by madoka.pendragon.org (Postfix) with ESMTP id 5455C112EDA
	for <pgsql-performance@postgresql.org>;
	Thu, 27 Oct 2005 15:46:34 -0600 (MDT)
Received: from madoka.pendragon.org ([127.0.0.1])
	by localhost (madoka.pendragon.org [127.0.0.1]) (amavisd-new,
	port 10024)
	with ESMTP id 01508-01 for <pgsql-performance@postgresql.org>;
	Thu, 27 Oct 2005 15:46:33 -0600 (MDT)
Received: from [192.168.2.102] (130.209-89-70-0.interbaun.com [209.89.70.130])
	by madoka.pendragon.org (Postfix) with ESMTP id 07C9F112ED9
	for <pgsql-performance@postgresql.org>;
	Thu, 27 Oct 2005 15:46:32 -0600 (MDT)
Message-ID: <43614D9F.9010600@pendragon.org>
Date: Thu, 27 Oct 2005 15:58:55 -0600
From: Michael Best <mbest@pendragon.org>
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US;
	rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: pgsql-performance@postgresql.org
Subject: Re: how postgresql request the computer resources
References: <BAY23-F28F5DD23A4A73C7BFE3CD1CE680@phx.gbl>
	<4360F8C1.4040202@archonet.com>
In-Reply-To: <4360F8C1.4040202@archonet.com>
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at pendragon.org
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0 required=5 tests=[none]
X-Spam-Score: 0
X-Spam-Level: 
X-Archive-Number: 200510/432
X-Sequence-Number: 15200

Richard Huxton wrote:
>> WITH ANY OF THIS QUERIES MSSQL TAKES NOT MUCH OF 7 SECONDS....
> 
> 
> In which case they make a bad choice for showing PostgreSQL is faster 
> than MSSQL. Is this the only query you have, or are others giving you 
> problems too?
> 
> I think count(*) is about the weakest point in PG, but I don't think 
> there'll be a general solution available soon. As I'm sure someone has 
> mentioned, whatever else, PG needs to check the row for its visibility 
> information.
> 
>  From the start of your email, you seem to suspect your configuration 
> needs some work. Once you are happy that your settings in general are 
> good, you can override some by issuing set statements before your query. 
> For example:
>     SET work_mem = 10000;
> might well improve example #2 where you had a hash.
> 
> -- 
>   Richard Huxton
>   Archonet Ltd

Someone had suggested keeping a vector table with +1 and -1 for row 
insertion and deletion and then running a cron to sum the vectors and 
update a table so that you could select from that table to get the row 
count.  Perhaps some sort of SUM() on a column function.

Since this seems like a reasonable approach (or perhaps there may be yet 
another better mechanism), cannot someone add this sort of functionality 
to Postgresql to do behind the scenes?

-Mike

From pgsql-performance-owner@postgresql.org  Thu Oct 27 19:09:48 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 1F9A7DB103
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 19:09:47 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 54954-10
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 22:09:44 +0000 (GMT)
Received: from h1.bettercom.de (h1.bettercom.de [213.239.194.41])
	by svr1.postgresql.org (Postfix) with ESMTP id 2A35DDB113
	for <pgsql-performance@postgresql.org>;
	Thu, 27 Oct 2005 19:09:44 -0300 (ADT)
Received: (qmail 3978 invoked by uid 208); 27 Oct 2005 22:09:47 -0000
Received: from 213.39.214.61 by h1 (envelope-from <ml-pgsql@bettercom.de>,
	uid 0) with qmail-scanner-1.23
	(clamdscan: 0.87. spamassassin: 3.04.  Clear:RC:1(213.39.214.61):.
	Processed in 0.034149 secs); 27 Oct 2005 22:09:47 -0000
Received: from unknown (HELO nb-aspire.bettercom.de) ([213.39.214.61])
	(envelope-sender <ml-pgsql@bettercom.de>)
	by h1.bettercom.de (qmail-ldap-1.03) with SMTP
	for <pgsql-performance@postgresql.org>; 27 Oct 2005 22:09:47 -0000
Received: (nullmailer pid 10451 invoked by uid 1000);
	Thu, 27 Oct 2005 22:09:46 -0000
Subject: Re: Reasons and drawbacks for unused item pointers
X-PGP-Key: http://bettercom.de/misc/3A547DE6.asc
X-Face: 
 "d[&>8')a)wbF:+L#^<_cohnX6#m5RCCeKF/6_gD(iQ9bX?xe2~Aq*!')D(1ks`?YhomOYbL3R:{4e4a]qft_]<.q/Lf4hIr,`G+LX33&TYp}XGf<b?+GPT;
	3I8k/|[DR#MO1N(h>e~^5m$28R"$C(EwnB\n8t
In-Reply-To: <24260.1130448996@sss.pgh.pa.us> (Tom Lane's message of "Thu,
	27 Oct 2005 17:36:36 -0400")
References: <Xns96FC6CBBEC0CDdenissaileryellowboo@200.46.204.72>
	<19722.1130429883@sss.pgh.pa.us>
	<Xns96FC85EFAC158denissaileryellowboo@200.46.204.72>
	<23322.1130442063@sss.pgh.pa.us>
	<87y84eznb0.fsf_-_@nb-aspire.bettercom.de>
	<24260.1130448996@sss.pgh.pa.us>
To: pgsql-performance@postgresql.org
From: Martin Lesser <ml-pgsql@bettercom.de>
Date: Fri, 28 Oct 2005 00:09:46 +0200
Message-ID: <87u0f2zk5x.fsf@nb-aspire.bettercom.de>
User-Agent: Gnus/5.1007 (Gnus v5.10.7) XEmacs/21.4 (Jumbo Shrimp, linux)
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.005 required=5 tests=[AWL=0.005]
X-Spam-Score: 0.005
X-Spam-Level: 
X-Archive-Number: 200510/433
X-Sequence-Number: 15201

Tom Lane <tgl@sss.pgh.pa.us> writes:

> Martin Lesser <ml-pgsql@bettercom.de> writes:
>> What causes this "unused item pointers" and which impact do they have
>> regarding performance?
> The direct performance impact is really pretty minimal (and none at
> all on indexscans, AFAIR).  The reason Denis' number drew my attention
> was that it implied that the table had gone un-vacuumed for awhile at
> some time in the past. [...]  To have 1905028 unused pointers in a
> table with only 5106307 live entries suggests that at some point there
> were 1.9 million (or so) dead but not-yet-vacuumed tuples, which
> suggests insufficient vacuuming.

Does each update of a single row result in an "unused item pointer"?
I.e. if I update one row 10 times between VACUUMing the table the result
are 10 unused pointers?

Some rows in some of my tables are updated much more frequently than
others so I'm not sure whether the number of unused pointers implie that
I should VACUUM more often than every 24 hours.

Martin

From pgsql-performance-owner@postgresql.org  Thu Oct 27 19:39:39 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id D4EEDDB105
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 19:39:36 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 64045-07
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 22:39:34 +0000 (GMT)
Received: from pop-gadwall.atl.sa.earthlink.net
	(pop-gadwall.atl.sa.earthlink.net [207.69.195.61])
	by svr1.postgresql.org (Postfix) with ESMTP id 8E36ADB0F5
	for <pgsql-performance@postgresql.org>;
	Thu, 27 Oct 2005 19:39:35 -0300 (ADT)
Received: from elwamui-norfolk.atl.sa.earthlink.net ([209.86.224.43])
	by pop-gadwall.atl.sa.earthlink.net with esmtp (Exim 3.36 #10)
	id 1EVGPG-0000Ot-00; Thu, 27 Oct 2005 18:39:34 -0400
Message-ID: 
 <7021105.1130452773950.JavaMail.root@elwamui-norfolk.atl.sa.earthlink.net>
Date: Thu, 27 Oct 2005 18:39:33 -0400 (EDT)
From: Ron Peacetree <rjpeace@earthlink.net>
Reply-To: Ron Peacetree <rjpeace@earthlink.net>
To: PostgreSQL <martin@portant.com>, pgsql-performance@postgresql.org
Subject: Re: How much memory?
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: EarthLink Zoo Mail 1.0
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.31 required=5 tests=[AWL=-0.169,
	DNS_FROM_RFC_ABUSE=0.479]
X-Spam-Score: 0.31
X-Spam-Level: 
X-Archive-Number: 200510/434
X-Sequence-Number: 15202

Databases basically come in 4 sizes:

1= The entire DB fits into memory.
2= The performance critical table(s) fit(s) into memory
3= The indexes of the performance critical table(s) fit into memory.
4= Neither the performance critical tables nor their indexes fit into memory.

Performance decreases (exponentially), and development + maintenance cost/difficulty/pain increases (exponentially), as you go down the list.

While it is often not possible to be in class "1" above, do everything you can to be in at least class "3" and do everything you can to avoid class "4".

At ~$75-$150 per GB as of this post, RAM is the cheapest investment you can make in a high perfomance, low hassle DBMS.  IWill's and Tyan's 16 DIMM slot mainboards are worth every penny.

ron


-----Original Message-----
From: PostgreSQL <martin@portant.com>
Sent: Oct 27, 2005 3:31 PM
To: pgsql-performance@postgresql.org
Subject: [PERFORM] How much memory?

Is there a rule-of-thumb for determining the amount of system memory a 
database requres (other than "all you can afford")? 

From pgsql-performance-owner@postgresql.org  Thu Oct 27 19:48:58 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id B6A95DB103
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 19:48:56 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 70866-04
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 22:48:52 +0000 (GMT)
Received: from flake.decibel.org (flake.decibel.org [67.100.216.10])
	by svr1.postgresql.org (Postfix) with ESMTP id DE957DB139
	for <pgsql-performance@postgresql.org>;
	Thu, 27 Oct 2005 19:48:53 -0300 (ADT)
Received: by flake.decibel.org (Postfix, from userid 1001)
	id 301A41529F; Thu, 27 Oct 2005 17:48:56 -0500 (CDT)
Date: Thu, 27 Oct 2005 17:48:56 -0500
From: "Jim C. Nasby" <jnasby@pervasive.com>
To: PostgreSQL <martin@portant.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: What gets cached?
Message-ID: <20051027224855.GS63747@pervasive.com>
References: <pan.2005.10.21.12.34.29.712700@portant.com>
	<1129931087.19971.12.camel@localhost.localdomain>
	<33c6269f0510240809k47f91a71t387a0b5ab0339f4c@mail.gmail.com>
	<20051024153248.GA24601@samfundet.no> <djre16$uqq$1@news.hub.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <djre16$uqq$1@news.hub.org>
X-Operating-System: FreeBSD 4.11-RELEASE-p10 i386
X-Distributed: Join the Effort!  http://www.distributed.net
User-Agent: Mutt/1.5.9i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.008 required=5 tests=[AWL=0.008]
X-Spam-Score: 0.008
X-Spam-Level: 
X-Archive-Number: 200510/435
X-Sequence-Number: 15203

Did the patch that allows multiple seqscans to piggyback on each other
make it into 8.1? It might help in this situation.

BTW, if a query requires loading more than a few percent of an index
PostgreSQL will usually go with a sequential scan instead. You should
check explain/explain analyze on your queries and see what's actually
happening. If you've got stats turned on you can also look at
pg_stat_user_indexes to get a better idea of what indexes are and aren't
being used.

On Thu, Oct 27, 2005 at 03:41:10PM -0500, PostgreSQL wrote:
> Thank each of you for your replies.  I'm just beginning to understand the 
> scope of my opportunities.
> 
> Someone (I apologize, I forgot who) recently posted this query:
>     SELECT oid::regclass, reltuples, relpages
>     FROM pg_class
>     ORDER BY 3 DESC
> 
> Though the application is a relatively low-volume TP system, it is 
> structured a lot like a data warehouse with one primary table that 
> everything else hangs off.  What the query above shows is that my largest 
> table, at 34 million rows, takes almost 1.4 million pages or 10+ Gb if my 
> math is good.  The same table has 14 indexes, totaling another 12Gb.  All 
> this is running on a box with 4Gb of memory.
> 
> So what I believe I see happening is that almost every query is clearing out 
> memory to load the particular index it needs.  Hence my "first queries are 
> the fastest" observation at the beginning of this thread.
> 
> There are certainly design improvements to be done, but I've already started 
> the process of getting the memory increased on our production db server.  We 
> are btw running 8.1 beta 3.
> 
> ""Steinar H. Gunderson"" <sgunderson@bigfoot.com> wrote in message 
> news:20051024153248.GA24601@samfundet.no...
> > On Mon, Oct 24, 2005 at 11:09:55AM -0400, Alex Turner wrote:
> >> Just to play devils advocate here for as second, but if we have an 
> >> algorithm
> >> that is substational better than just plain old LRU, which is what I 
> >> believe
> >> the kernel is going to use to cache pages (I'm no kernel hacker), then 
> >> why
> >> don't we apply that and have a significantly larger page cache a la 
> >> Oracle?
> >
> > There have (AFAIK) been reports of setting huge amounts of shared_buffers
> > (close to the total amount of RAM) performing much better in 8.1 than in
> > earlier versions, so this might actually be okay these days.
> >
> > I haven't heard of anybody reporting increase setting such values, though.
> >
> > /* Steinar */
> > -- 
> > Homepage: http://www.sesse.net/
> >
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 2: Don't 'kill -9' the postmaster
> > 
> 
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
>        subscribe-nomail command to majordomo@postgresql.org so that your
>        message can get through to the mailing list cleanly
> 

-- 
Jim C. Nasby, Sr. Engineering Consultant      jnasby@pervasive.com
Pervasive Software      http://pervasive.com    work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf       cell: 512-569-9461

From pgsql-performance-owner@postgresql.org  Thu Oct 27 19:52:26 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id D7684DB077
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 19:52:25 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 71237-09
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 22:52:23 +0000 (GMT)
Received: from flake.decibel.org (flake.decibel.org [67.100.216.10])
	by svr1.postgresql.org (Postfix) with ESMTP id 728A5DB06F
	for <pgsql-performance@postgresql.org>;
	Thu, 27 Oct 2005 19:52:24 -0300 (ADT)
Received: by flake.decibel.org (Postfix, from userid 1001)
	id B4EB21529A; Thu, 27 Oct 2005 17:52:27 -0500 (CDT)
Date: Thu, 27 Oct 2005 17:52:27 -0500
From: "Jim C. Nasby" <jnasby@pervasive.com>
To: Michael Best <mbest@pendragon.org>
Cc: pgsql-performance@postgresql.org
Subject: Re: how postgresql request the computer resources
Message-ID: <20051027225227.GT63747@pervasive.com>
References: <BAY23-F28F5DD23A4A73C7BFE3CD1CE680@phx.gbl>
	<4360F8C1.4040202@archonet.com> <43614D9F.9010600@pendragon.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <43614D9F.9010600@pendragon.org>
X-Operating-System: FreeBSD 4.11-RELEASE-p10 i386
X-Distributed: Join the Effort!  http://www.distributed.net
User-Agent: Mutt/1.5.9i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.008 required=5 tests=[AWL=0.008]
X-Spam-Score: 0.008
X-Spam-Level: 
X-Archive-Number: 200510/436
X-Sequence-Number: 15204

On Thu, Oct 27, 2005 at 03:58:55PM -0600, Michael Best wrote:
> Richard Huxton wrote:
> >>WITH ANY OF THIS QUERIES MSSQL TAKES NOT MUCH OF 7 SECONDS....
> >
> >
> >In which case they make a bad choice for showing PostgreSQL is faster 
> >than MSSQL. Is this the only query you have, or are others giving you 
> >problems too?
> >
> >I think count(*) is about the weakest point in PG, but I don't think 
> >there'll be a general solution available soon. As I'm sure someone has 
> >mentioned, whatever else, PG needs to check the row for its visibility 
> >information.
> >
> > From the start of your email, you seem to suspect your configuration 
> >needs some work. Once you are happy that your settings in general are 
> >good, you can override some by issuing set statements before your query. 
> >For example:
> >    SET work_mem = 10000;
> >might well improve example #2 where you had a hash.
> >
> >-- 
> >  Richard Huxton
> >  Archonet Ltd
> 
> Someone had suggested keeping a vector table with +1 and -1 for row 
> insertion and deletion and then running a cron to sum the vectors and 
> update a table so that you could select from that table to get the row 
> count.  Perhaps some sort of SUM() on a column function.
> 
> Since this seems like a reasonable approach (or perhaps there may be yet 
> another better mechanism), cannot someone add this sort of functionality 
> to Postgresql to do behind the scenes?

There's all kinds of things that could be added; the issue is
ascertaining what the performance trade-offs are (there's no such thing
as a free lunch) and if the additional code complexity is worth it.

Note that your suggestion probably wouldn't work in this case because
the user isn't doing a simple SELECT count(*) FROM table;. I'd bet that
MSSQL is using index covering to answer his queries so quickly,
something that currently just isn't possible with PostgreSQL. But if you
search the -hackers archives, you'll find a discussion on adding limited
heap tuple visibility information to indexes. That would allow for
partial index covering in many cases, which would probably be a huge win
for the queries the user was asking about.
-- 
Jim C. Nasby, Sr. Engineering Consultant      jnasby@pervasive.com
Pervasive Software      http://pervasive.com    work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf       cell: 512-569-9461

From pgsql-performance-owner@postgresql.org  Thu Oct 27 19:55:17 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 370A4DB129
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 19:55:16 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 75959-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Thu, 27 Oct 2005 22:55:13 +0000 (GMT)
Received: from flake.decibel.org (flake.decibel.org [67.100.216.10])
	by svr1.postgresql.org (Postfix) with ESMTP id A70FFDB123
	for <pgsql-performance@postgresql.org>;
	Thu, 27 Oct 2005 19:55:14 -0300 (ADT)
Received: by flake.decibel.org (Postfix, from userid 1001)
	id 9083A1529A; Thu, 27 Oct 2005 17:55:17 -0500 (CDT)
Date: Thu, 27 Oct 2005 17:55:17 -0500
From: "Jim C. Nasby" <jnasby@pervasive.com>
To: Ron Peacetree <rjpeace@earthlink.net>
Cc: PostgreSQL <martin@portant.com>, pgsql-performance@postgresql.org
Subject: Re: How much memory?
Message-ID: <20051027225517.GU63747@pervasive.com>
References: 
 <7021105.1130452773950.JavaMail.root@elwamui-norfolk.atl.sa.earthlink.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: 
 <7021105.1130452773950.JavaMail.root@elwamui-norfolk.atl.sa.earthlink.net>
X-Operating-System: FreeBSD 4.11-RELEASE-p10 i386
X-Distributed: Join the Effort!  http://www.distributed.net
User-Agent: Mutt/1.5.9i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.008 required=5 tests=[AWL=0.008]
X-Spam-Score: 0.008
X-Spam-Level: 
X-Archive-Number: 200510/437
X-Sequence-Number: 15205

On Thu, Oct 27, 2005 at 06:39:33PM -0400, Ron Peacetree wrote:
> Databases basically come in 4 sizes:
> 
> 1= The entire DB fits into memory.
> 2= The performance critical table(s) fit(s) into memory
> 3= The indexes of the performance critical table(s) fit into memory.
> 4= Neither the performance critical tables nor their indexes fit into memory.
> 
> Performance decreases (exponentially), and development + maintenance cost/difficulty/pain increases (exponentially), as you go down the list.
> 
> While it is often not possible to be in class "1" above, do everything you can to be in at least class "3" and do everything you can to avoid class "4".
> 
> At ~$75-$150 per GB as of this post, RAM is the cheapest investment you can make in a high perfomance, low hassle DBMS.  IWill's and Tyan's 16 DIMM slot mainboards are worth every penny.

And note that your next investment after RAM should be better disk IO.
More CPUs *generally* don't buy you much (if anything). My rule of
thumb: the only time your database should be CPU-bound is if you've got
a bad design*.

*NOTE: before everyone goes off about query parallelism and big
in-memory sorts and what-not, keep in mind I said "rule of thumb". :)
-- 
Jim C. Nasby, Sr. Engineering Consultant      jnasby@pervasive.com
Pervasive Software      http://pervasive.com    work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf       cell: 512-569-9461

From pgsql-performance-owner@postgresql.org  Fri Oct 28 10:34:52 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 82E05DAC08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 28 Oct 2005 10:34:50 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 36806-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 28 Oct 2005 13:34:46 +0000 (GMT)
Received: from mailr.qinetiq-tim.net (mailr.qinetiq-tim.net [128.98.1.9])
	by svr1.postgresql.org (Postfix) with SMTP id 4CAB0D8413
	for <pgsql-performance@postgresql.org>;
	Fri, 28 Oct 2005 10:34:47 -0300 (ADT)
Received: (qmail 22733 invoked from network); 28 Oct 2005 13:15:40 -0000
Received: from mailhost.eris.qinetiq.com (128.98.2.2)
	by 128.98.1.9 with SMTP; 28 Oct 2005 13:15:40 -0000
Received: (qmail 28283 invoked from network); 28 Oct 2005 12:24:16 -0000
Received: from unknown (HELO frost.eris.qinetiq.com) (128.98.76.221)
	by mailhost.eris.qinetiq.com with SMTP; 28 Oct 2005 12:24:16 -0000
From: Nick Howden <n.howden@eris.qinetiq.com>
Reply-To: n.howden@eris.qinetiq.com
Organization: QinetiQ
To: pgsql-performance@postgresql.org
Subject: UNSUBSCRIBE
Date: Fri, 28 Oct 2005 13:22:44 +0100
User-Agent: KMail/1.5.3
References: <Xns96FC6CBBEC0CDdenissaileryellowboo@200.46.204.72>
	<24260.1130448996@sss.pgh.pa.us>
	<87u0f2zk5x.fsf@nb-aspire.bettercom.de>
In-Reply-To: <87u0f2zk5x.fsf@nb-aspire.bettercom.de>
MIME-Version: 1.0
Content-Type: text/plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Message-Id: <200510281322.44083.n.howden@eris.qinetiq.com>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.5 required=5 tests=[RAZOR2_CHECK=0.5]
X-Spam-Score: 0.5
X-Spam-Level: 
X-Archive-Number: 200510/438
X-Sequence-Number: 15206

UNSUBSCRIBE


From pgsql-performance-owner@postgresql.org  Fri Oct 28 11:02:39 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 5BC58D83C3
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 28 Oct 2005 11:02:38 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 46017-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 28 Oct 2005 14:02:34 +0000 (GMT)
Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.200])
	by svr1.postgresql.org (Postfix) with ESMTP id 79145DB21D
	for <pgsql-performance@postgresql.org>;
	Fri, 28 Oct 2005 11:02:36 -0300 (ADT)
Received: by wproxy.gmail.com with SMTP id 71so251531wra
	for <pgsql-performance@postgresql.org>;
	Fri, 28 Oct 2005 07:02:41 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references;
	b=geovcuviEXvLAAT2DWM4fe1Y8ZNYUtrGD6KtMZL/f4xkwu7mGvRNwoDRiM7qRJ8dLmmItTw0nZ7O5PjQ53WDsGaSh8ecOpYu2I6xSjBCsaTr7/URS1Yfx6yOCGj+dQ6Z8ZjE12VKc6f2QtYXrl9R7YjdBaC+TGH3jisywVQlrHc=
Received: by 10.54.76.5 with SMTP id y5mr181223wra;
	Fri, 28 Oct 2005 07:02:41 -0700 (PDT)
Received: by 10.54.84.8 with HTTP; Fri, 28 Oct 2005 07:02:41 -0700 (PDT)
Message-ID: <33c6269f0510280702n2584f59we26b5256cd3422f6@mail.gmail.com>
Date: Fri, 28 Oct 2005 10:02:41 -0400
From: Alex Turner <armtuk@gmail.com>
To: "Jim C. Nasby" <jnasby@pervasive.com>
Subject: Re: How much memory?
Cc: Ron Peacetree <rjpeace@earthlink.net>,
	PostgreSQL <martin@portant.com>, pgsql-performance@postgresql.org
In-Reply-To: <20051027225517.GU63747@pervasive.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
References: 
 <7021105.1130452773950.JavaMail.root@elwamui-norfolk.atl.sa.earthlink.net>
	<20051027225517.GU63747@pervasive.com>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.099 required=5 tests=[AWL=0.099]
X-Spam-Score: 0.099
X-Spam-Level: 
X-Archive-Number: 200510/439
X-Sequence-Number: 15207

Reasons not to buy from Sun or Compaq - why get Opteron 252 when a 240
will do just fine for a fraction of the cost, which of course they
don't stock, white box all the way baby ;).  My box from Sun or Compaq
or IBM is 2x the whitebox cost because you can't buy apples to apples.
 We have a bitchin' DB server for $7.5k

Alex

On 10/27/05, Jim C. Nasby <jnasby@pervasive.com> wrote:
> On Thu, Oct 27, 2005 at 06:39:33PM -0400, Ron Peacetree wrote:
> > Databases basically come in 4 sizes:
> >
> > 1=3D The entire DB fits into memory.
> > 2=3D The performance critical table(s) fit(s) into memory
> > 3=3D The indexes of the performance critical table(s) fit into memory.
> > 4=3D Neither the performance critical tables nor their indexes fit into=
 memory.
> >
> > Performance decreases (exponentially), and development + maintenance co=
st/difficulty/pain increases (exponentially), as you go down the list.
> >
> > While it is often not possible to be in class "1" above, do everything =
you can to be in at least class "3" and do everything you can to avoid clas=
s "4".
> >
> > At ~$75-$150 per GB as of this post, RAM is the cheapest investment you=
 can make in a high perfomance, low hassle DBMS.  IWill's and Tyan's 16 DIM=
M slot mainboards are worth every penny.
>
> And note that your next investment after RAM should be better disk IO.
> More CPUs *generally* don't buy you much (if anything). My rule of
> thumb: the only time your database should be CPU-bound is if you've got
> a bad design*.
>
> *NOTE: before everyone goes off about query parallelism and big
> in-memory sorts and what-not, keep in mind I said "rule of thumb". :)
> --
> Jim C. Nasby, Sr. Engineering Consultant      jnasby@pervasive.com
> Pervasive Software      http://pervasive.com    work: 512-231-6117
> vcard: http://jim.nasby.net/pervasive.vcf       cell: 512-569-9461
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: Don't 'kill -9' the postmaster
>

From pgsql-performance-owner@postgresql.org  Fri Oct 28 12:14:30 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 52056DB21F
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 28 Oct 2005 12:14:26 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 91216-07
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 28 Oct 2005 15:14:25 +0000 (GMT)
Received: from mail.ecircle.de (mail.ecircle.de [195.140.186.200])
	by svr1.postgresql.org (Postfix) with ESMTP id EA68DDB20D
	for <pgsql-performance@postgresql.org>;
	Fri, 28 Oct 2005 12:14:24 -0300 (ADT)
Received: from [192.168.1.110] (unknown [192.168.1.110])
	by mail.ecircle.de (READY) with ESMTP id 1235D9541A3
	for <pgsql-performance@postgresql.org>;
	Fri, 28 Oct 2005 17:14:22 +0200 (CEST)
Subject: How long it takes to vacuum a big table
From: Csaba Nagy <nagy@ecircle-ag.com>
To: postgres performance list <pgsql-performance@postgresql.org>
Content-Type: text/plain
Message-Id: <1130512461.25950.20.camel@coppola.muc.ecircle.de>
Mime-Version: 1.0
X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) 
Date: Fri, 28 Oct 2005 17:14:21 +0200
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.014 required=5 tests=[AWL=0.014]
X-Spam-Score: 0.014
X-Spam-Level: 
X-Archive-Number: 200510/440
X-Sequence-Number: 15208

Hi all,

I wonder what is the main driving factor for vacuum's duration: the size
of the table, or the number of dead tuples it has to clean ?

We have a few big tables which are also heavily updated, and I couldn't
figure out a way to properly vacuum them. Vacuuming any of those took
very long amounts of time (I started one this morning and after ~5h30min
it's still running - and it's not even the biggest or most updated
table), which I can't really afford because it prevents other vacuum
processes on smaller tables to do their job due to the transaction open
for the long-running vacuum. 

BTW, is it in any way feasible to implement to make one vacuum not
blocking other vacuums from cleaning dead tuples after the first one
started ? I know it's the transaction not the vacuum which blocks, but
then wouldn't be a way to run vacuum somehow in "out of transaction
context" mode ?

Another issue: vacuum is not responding to cancel requests, at least not
in a reasonable amount of time...

Thanks in advance,
Csaba.
 



From pgsql-performance-owner@postgresql.org  Fri Oct 28 13:48:54 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 450E1DB20B
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 28 Oct 2005 13:48:53 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 33972-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 28 Oct 2005 16:48:51 +0000 (GMT)
Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.206])
	by svr1.postgresql.org (Postfix) with ESMTP id D789DDB222
	for <pgsql-performance@postgresql.org>;
	Fri, 28 Oct 2005 13:48:51 -0300 (ADT)
Received: by xproxy.gmail.com with SMTP id i30so362287wxd
	for <pgsql-performance@postgresql.org>;
	Fri, 28 Oct 2005 09:48:52 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references;
	b=Sg2jmEzoej9/kbCnlSQ6yiQwOR4HLHgvQT6yevGJOLG0rhw2elodIl74Suqt/kjwTmS+Rm9S0lsTYSshoc+Qgx4ot+clKsWuJ1wbgy6F48b8Kx0TClZE77E1nLgoz+DxPPVS2Z6LBY/KXRDZozQQoRSh9Z8tUQeCHpLDW6wwnLo=
Received: by 10.70.109.20 with SMTP id h20mr312531wxc;
	Fri, 28 Oct 2005 09:48:51 -0700 (PDT)
Received: by 10.70.105.15 with HTTP; Fri, 28 Oct 2005 09:48:51 -0700 (PDT)
Message-ID: <72e966b00510280948h15fd8d56qc3aaca7840f2348d@mail.gmail.com>
Date: Fri, 28 Oct 2005 10:48:51 -0600
From: Jan Peterson <jan.l.peterson@gmail.com>
To: Csaba Nagy <nagy@ecircle-ag.com>
Subject: Re: How long it takes to vacuum a big table
Cc: postgres performance list <pgsql-performance@postgresql.org>
In-Reply-To: <1130512461.25950.20.camel@coppola.muc.ecircle.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
References: <1130512461.25950.20.camel@coppola.muc.ecircle.de>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.678 required=5 tests=[AWL=-0.654,
	RCVD_IN_BL_SPAMCOP_NET=1.332]
X-Spam-Score: 0.678
X-Spam-Level: 
X-Archive-Number: 200510/441
X-Sequence-Number: 15209

We've also experienced problems with VACUUM running for a long time.=20
A VACUUM on our pg_largeobject table, for example, can take over 24
hours to complete (pg_largeobject in our database has over 45million
rows).  With our other tables, we've been able to partition them
(using inheritance) to keep any single table from getting "too large",
but we've been unable to do that with pg_largeobject.  Currently,
we're experimenting with moving some of our bulk (large object) data
outside of the database and storing it in the filesystem directly.

I know that Hannu Krosing has developed some patches that allow
concurrent VACUUMs to run more effectively.  Unfortunately, these
patches didn't get into 8.1 so far as I know.  You can search the
performance mailing list for more information.

        -jan-
--
Jan L. Peterson
<jan.l.peterson@gmail.com>

From pgsql-performance-owner@postgresql.org  Fri Oct 28 18:39:12 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 84431DB29D
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 28 Oct 2005 18:39:09 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 56353-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 28 Oct 2005 21:39:07 +0000 (GMT)
Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.205])
	by svr1.postgresql.org (Postfix) with ESMTP id 332DFDB286
	for <pgsql-performance@postgresql.org>;
	Fri, 28 Oct 2005 18:39:08 -0300 (ADT)
Received: by xproxy.gmail.com with SMTP id s14so355058wxc
	for <pgsql-performance@postgresql.org>;
	Fri, 28 Oct 2005 14:39:10 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:to:subject:mime-version:content-type;
	b=ptlHeae5JiM53Nh1YS8uKlljQlIT2tOLzMtULCO97jMZyGOSrTnQujgaDR3m/D4vO8JMiGOa+3NjXgAffbjQmD9yDf3qikYBXbNATFuq1y5rSZWCsXdc8xxSRXUCXy6/Y5kQ2qHnT3/0LGFj2q75XSdxhIGPGNoeCKpqCig2xqQ=
Received: by 10.65.177.1 with SMTP id e1mr408600qbp;
	Fri, 28 Oct 2005 14:39:10 -0700 (PDT)
Received: by 10.65.240.20 with HTTP; Fri, 28 Oct 2005 14:39:10 -0700 (PDT)
Message-ID: <3cf983d0510281439s648fac45vbd7af544eeca4fc3@mail.gmail.com>
Date: Fri, 28 Oct 2005 18:39:10 -0300
From: Rodrigo Madera <rodrigo.madera@gmail.com>
To: pgsql-performance@postgresql.org
Subject: Best way to check for new data.
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="----=_Part_6078_19933507.1130535550853"
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.001 required=5 tests=[HTML_MESSAGE=0.001]
X-Spam-Score: 0.001
X-Spam-Level: 
X-Archive-Number: 200510/442
X-Sequence-Number: 15210

------=_Part_6078_19933507.1130535550853
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

I have a table that holds entries as in a ficticious table Log(id integer,
msg text).
 Lets say then that I have the program log_tail that has as it=B4s sole
purpose to print newly added data elements.
 What is the best solution in terms of performace?
 Thank you for your time,
Rodrigo

------=_Part_6078_19933507.1130535550853
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

<div>I have a table that holds entries as in a ficticious table Log(id inte=
ger, msg text).</div>
<div>&nbsp;</div>
<div>Lets say then that I have the program log_tail that has as it=B4s sole=
 purpose to print newly added data elements.</div>
<div>&nbsp;</div>
<div>What is the best solution in terms of performace?</div>
<div>&nbsp;</div>
<div>Thank you for your time,</div>
<div>Rodrigo</div>
<div>&nbsp;</div>

------=_Part_6078_19933507.1130535550853--

From pgsql-performance-owner@postgresql.org  Fri Oct 28 18:53:31 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 4977DDAABE
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 28 Oct 2005 18:53:31 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 60815-03
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 28 Oct 2005 21:53:28 +0000 (GMT)
Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.207])
	by svr1.postgresql.org (Postfix) with ESMTP id 76A30DB284
	for <pgsql-performance@postgresql.org>;
	Fri, 28 Oct 2005 18:53:29 -0300 (ADT)
Received: by xproxy.gmail.com with SMTP id s14so358464wxc
	for <pgsql-performance@postgresql.org>;
	Fri, 28 Oct 2005 14:53:32 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition;
	b=ASF8yu/iVWy6BwbaIAzNR0EncUOIyE+cCQsvNpy6wS+NFIluHE1291jSZ94/nbT66xBI1rHfaOI+HZQdkmLLJDnROLiEBvzNXmq5UpsfZQYNPR7WpLu400vf8wAR/IRUk9p9K5hVZLzvERc03xNAAcLd38ufGwPNtGnnefz7oag=
Received: by 10.65.98.9 with SMTP id a9mr435371qbm;
	Fri, 28 Oct 2005 14:53:32 -0700 (PDT)
Received: by 10.65.157.7 with HTTP; Fri, 28 Oct 2005 14:53:32 -0700 (PDT)
Message-ID: <df01c91b0510281453v5c7ed502rfb3757e886046607@mail.gmail.com>
Date: Fri, 28 Oct 2005 14:53:32 -0700
From: Collin Peters <cadiolis@gmail.com>
To: pgsql-performance@postgresql.org
Subject: Simple query: how to optimize
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0 required=5 tests=[none]
X-Spam-Score: 0
X-Spam-Level: 
X-Archive-Number: 200510/443
X-Sequence-Number: 15211

I have two tables, one is called 'users' the other is 'user_activity'.
 The 'users' table simply contains the users in the system there is
about 30,000 rows.  The 'user_activity' table stores the activities
the user has taken.  This table has about 430,000 rows and also
(notably) has a column which tracks the type of activity.  90% of the
table is type 7 which indicates the user logged into the system.

I am trying to write a simple query that returns the last time each
user logged into the system.  This is how the query looks at the
moment:

SELECT u.user_id, MAX(ua.activity_date)
FROM pp_users u
LEFT OUTER JOIN user_activity ua ON (u.user_id =3D ua.user_id AND
ua.user_activity_type_id =3D 7)
WHERE u.userstatus_id <> 4
AND age(u.joined_date) < interval '30 days'
GROUP BY u.user_id

The above query takes about 5 seconds but I'm wondering how it can be
optimized.  When the query is formatted as above it does use an index
on the user_id column of the user_activity table... but the cost is
huge (cost=3D0.00..1396700.80).

I have tried formatting it another way with a sub-query but it takes
about the same amount to completed:

SELECT u.user_id, ua.last
FROM pp_users u
LEFT OUTER JOIN (SELECT max(activity_date) as last, user_id FROM
user_activity WHERE user_activity_type_id =3D 7 GROUP BY user_id) as ua
ON (u.user_id =3D ua.user_id)
WHERE u.userstatus_id <> 4
AND age(u.joined_date) < interval '30 days'

Can anybody offer any pointers on this scenario?

Regards,
Collin

From pgsql-performance-owner@postgresql.org  Fri Oct 28 19:13:33 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 6D8EADB2B0
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 28 Oct 2005 19:13:32 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 66342-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 28 Oct 2005 22:13:29 +0000 (GMT)
Received: from viefep18-int.chello.at (viefep18-int.chello.at [213.46.255.21])
	by svr1.postgresql.org (Postfix) with ESMTP id 3AD01DB2AE
	for <pgsql-performance@postgresql.org>;
	Fri, 28 Oct 2005 19:13:29 -0300 (ADT)
Received: from OTTO ([213.222.172.216]) by viefep18-int.chello.at
	(InterMail vM.6.01.04.04 201-2131-118-104-20050224) with SMTP
	id <20051028221326.SZAW27617.viefep18-int.chello.at@OTTO>;
	Sat, 29 Oct 2005 00:13:26 +0200
Message-ID: <01cb01c5dc0c$cce42830$8400a8c0@OTTO>
From: =?iso-8859-1?Q?Havasv=F6lgyi_Ott=F3?= <h.otto@freemail.hu>
To: "Rodrigo Madera" <rodrigo.madera@gmail.com>,
	<pgsql-performance@postgresql.org>
References: <3cf983d0510281439s648fac45vbd7af544eeca4fc3@mail.gmail.com>
Subject: Re: Best way to check for new data.
Date: Sat, 29 Oct 2005 00:13:18 +0200
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="----=_NextPart_000_01C8_01C5DC1D.904488A0"
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 6.00.2900.2527
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=-0.078 required=5 tests=[AWL=-0.079,
	HTML_MESSAGE=0.001]
X-Spam-Score: -0.078
X-Spam-Level: 
X-Archive-Number: 200510/444
X-Sequence-Number: 15212

This is a multi-part message in MIME format.

------=_NextPart_000_01C8_01C5DC1D.904488A0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Rodrigo,

You could use LISTEN + NOTIFY with triggers.
In after_insert_statement trigger you could notify a listener, the =
client could query it immediately.

Best Regards,
Otto

  ----- Original Message -----=20
  From: Rodrigo Madera=20
  To: pgsql-performance@postgresql.org=20
  Sent: Friday, October 28, 2005 11:39 PM
  Subject: [PERFORM] Best way to check for new data.


  I have a table that holds entries as in a ficticious table Log(id =
integer, msg text).

  Lets say then that I have the program log_tail that has as it=B4s sole =
purpose to print newly added data elements.

  What is the best solution in terms of performace?

  Thank you for your time,
  Rodrigo

------=_NextPart_000_01C8_01C5DC1D.904488A0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2900.2769" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Rodrigo,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>You could use LISTEN + NOTIFY with=20
triggers.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>In after_insert_statement trigger you =
could notify=20
a listener, the client could query it immediately.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Best Regards,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Otto</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV>
  <DIV=20
  style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
  <A title=3Drodrigo.madera@gmail.com=20
  href=3D"mailto:rodrigo.madera@gmail.com">Rodrigo Madera</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A=20
  title=3Dpgsql-performance@postgresql.org=20
  =
href=3D"mailto:pgsql-performance@postgresql.org">pgsql-performance@postgr=
esql.org</A>=20
  </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Friday, October 28, 2005 =
11:39=20
  PM</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> [PERFORM] Best way to =
check for=20
  new data.</DIV>
  <DIV><BR></DIV>
  <DIV>I have a table that holds entries as in a ficticious table Log(id =

  integer, msg text).</DIV>
  <DIV>&nbsp;</DIV>
  <DIV>Lets say then that I have the program log_tail that has as it=B4s =
sole=20
  purpose to print newly added data elements.</DIV>
  <DIV>&nbsp;</DIV>
  <DIV>What is the best solution in terms of performace?</DIV>
  <DIV>&nbsp;</DIV>
  <DIV>Thank you for your time,</DIV>
  <DIV>Rodrigo</DIV>
  <DIV>&nbsp;</DIV></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_01C8_01C5DC1D.904488A0--



From pgsql-performance-owner@postgresql.org  Fri Oct 28 19:40:44 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id BE334DB29B
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 28 Oct 2005 19:40:42 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 74665-06
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 28 Oct 2005 22:40:39 +0000 (GMT)
Received: from sj1-exch-01.us.corp.kailea.com (mail.ragingnet.net
	[209.249.149.2])
	by svr1.postgresql.org (Postfix) with ESMTP id 3207EDB29A
	for <pgsql-performance@postgresql.org>;
	Fri, 28 Oct 2005 19:40:40 -0300 (ADT)
X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0
Content-class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Subject: Re: Simple query: how to optimize
Date: Fri, 28 Oct 2005 15:40:40 -0700
Message-ID: 
 <DB28E9B548192448A4E8C8A3C1B1E475611DAF@sj1-exch-01.us.corp.kailea.com>
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
Thread-Topic: [PERFORM] Simple query: how to optimize
Thread-Index: AcXcCv29qEL+6TmiR26SyCxfzCc11AABNY/w
From: "Roger Hand" <RHand@kailea.com>
To: "Collin Peters" <cadiolis@gmail.com>,
	<pgsql-performance@postgresql.org>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.042 required=5 tests=[AWL=0.042]
X-Spam-Score: 0.042
X-Spam-Level: 
X-Archive-Number: 200510/445
X-Sequence-Number: 15213

On October 28, 2005 2:54 PM
Collin Peters wrote:
> I have two tables, one is called 'users' the other is 'user_activity'.
...
> I am trying to write a simple query that returns the last time each
> user logged into the system.  This is how the query looks at the
> moment:
>=20
> SELECT u.user_id, MAX(ua.activity_date)
> FROM pp_users u
> LEFT OUTER JOIN user_activity ua ON (u.user_id =3D ua.user_id AND
> ua.user_activity_type_id =3D 7)
> WHERE u.userstatus_id <> 4
> AND age(u.joined_date) < interval '30 days'
> GROUP BY u.user_id

You're first joining against the entire user table, then filtering out =
the users
you don't need.

Instead, filter out the users you don't need first, then do the join:

SELECT users.user_id, MAX(ua.activity_date)
FROM=20
(SELECT u.user_id=20
FROM pp_users u
WHERE u.userstatus_id <> 4
AND age(u.joined_date) < interval '30 days'
) users
LEFT OUTER JOIN user_activity ua=20
  ON (users.user_id =3D ua.user_id=20
  AND ua.user_activity_type_id =3D 7)
GROUP BY users.user_id

(disclaimer: I haven't actually tried this sql)

From pgsql-performance-owner@postgresql.org  Fri Oct 28 20:56:40 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id D0E50DB1F5
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 28 Oct 2005 20:56:38 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 00237-10
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 28 Oct 2005 23:56:35 +0000 (GMT)
Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.204])
	by svr1.postgresql.org (Postfix) with ESMTP id 87DBDDB14B
	for <pgsql-performance@postgresql.org>;
	Fri, 28 Oct 2005 20:56:37 -0300 (ADT)
Received: by xproxy.gmail.com with SMTP id s14so382512wxc
	for <pgsql-performance@postgresql.org>;
	Fri, 28 Oct 2005 16:56:41 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references;
	b=usAtfz/w8ly5eFeiSzn1m4dhte4KdiAlcCkBAozsQgnGpf5jUkebcTgZTARxrLvGGrlz0WQtd0g1ceNnrWozOo0DIRI5xD/sLcNFEc6HaT5qLlCa9qKoit6Hfi1fHXU+lDt8Gew2lqDZ67FBECerkb7MF7kn3DvZjsJb0BN7b5E=
Received: by 10.65.239.16 with SMTP id q16mr498895qbr;
	Fri, 28 Oct 2005 16:56:40 -0700 (PDT)
Received: by 10.65.157.7 with HTTP; Fri, 28 Oct 2005 16:56:40 -0700 (PDT)
Message-ID: <df01c91b0510281656gcae9b79r31fd096f0b31eefa@mail.gmail.com>
Date: Fri, 28 Oct 2005 16:56:40 -0700
From: Collin Peters <cadiolis@gmail.com>
Subject: Re: Simple query: how to optimize
Cc: pgsql-performance@postgresql.org
In-Reply-To: 
 <DB28E9B548192448A4E8C8A3C1B1E475611DAF@sj1-exch-01.us.corp.kailea.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
References: 
 <DB28E9B548192448A4E8C8A3C1B1E475611DAF@sj1-exch-01.us.corp.kailea.com>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.761 required=5 tests=[AWL=-0.760,
	MISSING_HEADERS=0.189, RCVD_IN_BL_SPAMCOP_NET=1.332]
X-Spam-Score: 0.761
X-Spam-Level: 
X-Archive-Number: 200510/446
X-Sequence-Number: 15214

These two queries execute at exactly the same speed.  When I run run
EXPLAIN on them both they return the *exact* same query plan as well.=20
I find this strange... but it is also kind of what I expected from
reading up on various things.  I am under the impression the
postgresql will break up your query and run it as it sees best.   So
in the case of these two queries... it seems it is actually almost
converting one into the other.  Maybe I am wrong.

Is there a good resource list somewhere for postgresql query
optimization?  There are entire books devoted to the subject for
oracle but I can't find more than a few small articles on postgresql
query optimizations on the web.

Regards,
Collin

On 10/28/05, Roger Hand <RHand@kailea.com> wrote:
> > SELECT u.user_id, MAX(ua.activity_date)
> > FROM pp_users u
> > LEFT OUTER JOIN user_activity ua ON (u.user_id =3D ua.user_id AND
> > ua.user_activity_type_id =3D 7)
> > WHERE u.userstatus_id <> 4
> > AND age(u.joined_date) < interval '30 days'
> > GROUP BY u.user_id
>
> You're first joining against the entire user table, then filtering out th=
e users
> you don't need.
>
> Instead, filter out the users you don't need first, then do the join:
>
> SELECT users.user_id, MAX(ua.activity_date)
> FROM
> (SELECT u.user_id
> FROM pp_users u
> WHERE u.userstatus_id <> 4
> AND age(u.joined_date) < interval '30 days'
> ) users
> LEFT OUTER JOIN user_activity ua
>   ON (users.user_id =3D ua.user_id
>   AND ua.user_activity_type_id =3D 7)
> GROUP BY users.user_id
>
> (disclaimer: I haven't actually tried this sql)
>

From pgsql-performance-owner@postgresql.org  Fri Oct 28 21:04:31 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 56961DAABE
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 28 Oct 2005 21:04:30 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 97599-09
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 29 Oct 2005 00:04:27 +0000 (GMT)
Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.197])
	by svr1.postgresql.org (Postfix) with ESMTP id 184C2DA3EA
	for <pgsql-performance@postgresql.org>;
	Fri, 28 Oct 2005 21:04:28 -0300 (ADT)
Received: by xproxy.gmail.com with SMTP id s14so383810wxc
	for <pgsql-performance@postgresql.org>;
	Fri, 28 Oct 2005 17:04:33 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references;
	b=PQZ29jsfgywZ4X/WX5jTImfChkcatvU+oyjTBXfeetMG0rulFtMRkfLUiVV8wP9SlA7oOgDDlLfEwJhrwJKJNZTAJlPIr73seKaC6qOZSp031QUg8qOMD+x91tjXu7cKkFd1gnly1asEsZXLAMfM5wn3RgnJIP8Wttv5WdLuY9s=
Received: by 10.65.236.1 with SMTP id n1mr500742qbr;
	Fri, 28 Oct 2005 17:04:32 -0700 (PDT)
Received: by 10.65.157.7 with HTTP; Fri, 28 Oct 2005 17:04:32 -0700 (PDT)
Message-ID: <df01c91b0510281704u552a6b2ree60eec6b371ef74@mail.gmail.com>
Date: Fri, 28 Oct 2005 17:04:32 -0700
From: Collin Peters <cadiolis@gmail.com>
Subject: Re: Simple query: how to optimize
Cc: pgsql-performance@postgresql.org
In-Reply-To: <df01c91b0510281656gcae9b79r31fd096f0b31eefa@mail.gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
References: 
 <DB28E9B548192448A4E8C8A3C1B1E475611DAF@sj1-exch-01.us.corp.kailea.com>
	<df01c91b0510281656gcae9b79r31fd096f0b31eefa@mail.gmail.com>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.475 required=5 tests=[AWL=0.286,
	MISSING_HEADERS=0.189]
X-Spam-Score: 0.475
X-Spam-Level: 
X-Archive-Number: 200510/447
X-Sequence-Number: 15215

A little bit more on my last post that I forget to mention.  The two
queries run at the same speed and have the same plan only if I have an
index on the user_activity.user_id column.  Otherwise they run at
different speeds.  The query you gave me actually runs slower without
the index.  All  this is making my head spin!! :O

On 10/28/05, Collin Peters <cadiolis@gmail.com> wrote:
> These two queries execute at exactly the same speed.  When I run run
> EXPLAIN on them both they return the *exact* same query plan as well.
> I find this strange... but it is also kind of what I expected from
> reading up on various things.  I am under the impression the
> postgresql will break up your query and run it as it sees best.   So
> in the case of these two queries... it seems it is actually almost
> converting one into the other.  Maybe I am wrong.
>
> Is there a good resource list somewhere for postgresql query
> optimization?  There are entire books devoted to the subject for
> oracle but I can't find more than a few small articles on postgresql
> query optimizations on the web.
>
> Regards,
> Collin
>
> On 10/28/05, Roger Hand <RHand@kailea.com> wrote:
> > > SELECT u.user_id, MAX(ua.activity_date)
> > > FROM pp_users u
> > > LEFT OUTER JOIN user_activity ua ON (u.user_id =3D ua.user_id AND
> > > ua.user_activity_type_id =3D 7)
> > > WHERE u.userstatus_id <> 4
> > > AND age(u.joined_date) < interval '30 days'
> > > GROUP BY u.user_id
> >
> > You're first joining against the entire user table, then filtering out =
the users
> > you don't need.
> >
> > Instead, filter out the users you don't need first, then do the join:
> >
> > SELECT users.user_id, MAX(ua.activity_date)
> > FROM
> > (SELECT u.user_id
> > FROM pp_users u
> > WHERE u.userstatus_id <> 4
> > AND age(u.joined_date) < interval '30 days'
> > ) users
> > LEFT OUTER JOIN user_activity ua
> >   ON (users.user_id =3D ua.user_id
> >   AND ua.user_activity_type_id =3D 7)
> > GROUP BY users.user_id
> >
> > (disclaimer: I haven't actually tried this sql)
> >
>

From pgsql-performance-owner@postgresql.org  Fri Oct 28 21:12:10 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 2E3C0DB2B6
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 28 Oct 2005 21:12:09 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 14117-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 29 Oct 2005 00:12:05 +0000 (GMT)
Received: from cassarossa.samfundet.no (cassarossa.samfundet.no
	[129.241.93.19])
	by svr1.postgresql.org (Postfix) with ESMTP id 41DB4DB257
	for <pgsql-performance@postgresql.org>;
	Fri, 28 Oct 2005 21:12:06 -0300 (ADT)
Received: from trofast.ipv6.sesse.net ([2001:700:300:dc03:20e:cff:fe36:a766]
	helo=trofast.sesse.net)
	by cassarossa.samfundet.no with esmtp (Exim 4.50) id 1EVeKM-0005Ce-Tj
	for pgsql-performance@postgresql.org; Sat, 29 Oct 2005 02:12:08 +0200
Received: from sesse by trofast.sesse.net with local (Exim 3.36 #1 (Debian))
	id 1EVeKe-0001oE-00
	for <pgsql-performance@postgresql.org>; Sat, 29 Oct 2005 02:12:24 +0200
Date: Sat, 29 Oct 2005 02:12:24 +0200
From: "Steinar H. Gunderson" <sgunderson@bigfoot.com>
To: pgsql-performance@postgresql.org
Subject: Re: Simple query: how to optimize
Message-ID: <20051029001224.GA6611@uio.no>
Mail-Followup-To: pgsql-performance@postgresql.org
References: 
 <DB28E9B548192448A4E8C8A3C1B1E475611DAF@sj1-exch-01.us.corp.kailea.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
In-Reply-To: 
 <DB28E9B548192448A4E8C8A3C1B1E475611DAF@sj1-exch-01.us.corp.kailea.com>
X-Operating-System: Linux 2.6.14-rc5 on a x86_64
X-Message-Flag: Outlook? --> http://www.mozilla.org/products/thunderbird/
User-Agent: Mutt/1.5.11
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.009 required=5 tests=[AWL=0.009]
X-Spam-Score: 0.009
X-Spam-Level: 
X-Archive-Number: 200510/448
X-Sequence-Number: 15216

On Fri, Oct 28, 2005 at 03:40:40PM -0700, Roger Hand wrote:
> You're first joining against the entire user table, then filtering out the users
> you don't need.

That's just wrong, sorry -- the planner is perfectly able to push the WHERE
down before the join.

I'd guess the problem is the age() query; age() doesn't really return what
you'd expect, and I don't think it can use an index easily (I might be wrong
here, though). Instead, try something like

  WHERE u.joined_date >= current_date - interval '30 days'

except that if you're running pre-8.0, you might want to precalculate the
right-hand side on the client.

I couldn't see EXPLAIN ANALYZE of your query, BTW -- having it would be
useful.

/* Steinar */
-- 
Homepage: http://www.sesse.net/

From pgsql-performance-owner@postgresql.org  Fri Oct 28 21:37:25 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id C19A4DABB9
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Fri, 28 Oct 2005 21:37:23 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 14554-07
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 29 Oct 2005 00:37:20 +0000 (GMT)
Received: from floppy.pyrenet.fr (floppy.pyrenet.fr [194.116.145.2])
	by svr1.postgresql.org (Postfix) with ESMTP id 0B9CADAABE
	for <pgsql-performance@postgresql.org>;
	Fri, 28 Oct 2005 21:37:22 -0300 (ADT)
Received: by floppy.pyrenet.fr (Postfix, from userid 106)
	id 215773105A; Sat, 29 Oct 2005 02:37:24 +0200 (MET DST)
From: "PostgreSQL" <martin@portant.com>
X-Newsgroups: pgsql.performance
Subject: Re: Simple query: how to optimize
Date: Fri, 28 Oct 2005 19:37:11 -0500
Organization: Hub.Org Networking Services
Lines: 69
Message-ID: <djug7r$lth$1@news.hub.org>
References: <df01c91b0510281453v5c7ed502rfb3757e886046607@mail.gmail.com>
X-Complaints-To: usenet@news.hub.org
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
X-RFC2646: Format=Flowed; Original
To: pgsql-performance@postgresql.org
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0 required=5 tests=[none]
X-Spam-Score: 0
X-Spam-Level: 
X-Archive-Number: 200510/449
X-Sequence-Number: 15217

Postgres is somewhat speed-challenged on aggregate functions.
The most-repeated work-around would be something like:

SELECT u.user_id,
(SELECT activity_date
  FROM user_activity
  WHERE user_activity.user_id = pp_users.user_id
  AND user_activity_type_id = 7
  ORDER BY activity_date DESC
  LIMIT 1)
FROM pp_users u
WHERE u.userstatus_id <> 4
AND age(u.joined_date) < interval '30 days'

(code above is untested) I've read that aggregate functions are
improved in the 8.1 code.  I'm running 8.1beta3 on one machine
but haven't experimented to verify the claimed improvements.

Martin Nickel

"Collin Peters" <cadiolis@gmail.com> wrote in message 
news:df01c91b0510281453v5c7ed502rfb3757e886046607@mail.gmail.com...
>I have two tables, one is called 'users' the other is 'user_activity'.
> The 'users' table simply contains the users in the system there is
> about 30,000 rows.  The 'user_activity' table stores the activities
> the user has taken.  This table has about 430,000 rows and also
> (notably) has a column which tracks the type of activity.  90% of the
> table is type 7 which indicates the user logged into the system.
>
> I am trying to write a simple query that returns the last time each
> user logged into the system.  This is how the query looks at the
> moment:
>
> SELECT u.user_id, MAX(ua.activity_date)
> FROM pp_users u
> LEFT OUTER JOIN user_activity ua ON (u.user_id = ua.user_id AND
> ua.user_activity_type_id = 7)
> WHERE u.userstatus_id <> 4
> AND age(u.joined_date) < interval '30 days'
> GROUP BY u.user_id
>
> The above query takes about 5 seconds but I'm wondering how it can be
> optimized.  When the query is formatted as above it does use an index
> on the user_id column of the user_activity table... but the cost is
> huge (cost=0.00..1396700.80).
>
> I have tried formatting it another way with a sub-query but it takes
> about the same amount to completed:
>
> SELECT u.user_id, ua.last
> FROM pp_users u
> LEFT OUTER JOIN (SELECT max(activity_date) as last, user_id FROM
> user_activity WHERE user_activity_type_id = 7 GROUP BY user_id) as ua
> ON (u.user_id = ua.user_id)
> WHERE u.userstatus_id <> 4
> AND age(u.joined_date) < interval '30 days'
>
> Can anybody offer any pointers on this scenario?
>
> Regards,
> Collin
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
>       subscribe-nomail command to majordomo@postgresql.org so that your
>       message can get through to the mailing list cleanly
> 



From pgsql-performance-owner@postgresql.org  Sat Oct 29 08:10:36 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id CE5C7DB376
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 29 Oct 2005 08:10:33 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 49301-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 29 Oct 2005 11:10:30 +0000 (GMT)
Received: from h1.bettercom.de (h1.bettercom.de [213.239.194.41])
	by svr1.postgresql.org (Postfix) with ESMTP id ABB09DB36F
	for <pgsql-performance@postgresql.org>;
	Sat, 29 Oct 2005 08:10:31 -0300 (ADT)
Received: (qmail 24038 invoked by uid 208); 29 Oct 2005 11:10:33 -0000
Received: from 213.39.147.134 by h1 (envelope-from <ml-pgsql@bettercom.de>,
	uid 0) with qmail-scanner-1.23
	(clamdscan: 0.87. spamassassin: 3.04.  Clear:RC:1(213.39.147.134):.
	Processed in 0.045217 secs); 29 Oct 2005 11:10:33 -0000
Received: from unknown (HELO nb-aspire.bettercom.de) ([213.39.147.134])
	(envelope-sender <ml-pgsql@bettercom.de>)
	by h1.bettercom.de (qmail-ldap-1.03) with SMTP
	for <pgsql-performance@postgresql.org>; 29 Oct 2005 11:10:32 -0000
Received: (nullmailer pid 14010 invoked by uid 1000);
	Sat, 29 Oct 2005 11:10:32 -0000
Subject: Effects of cascading references in foreign keys
X-PGP-Key: http://bettercom.de/misc/3A547DE6.asc
X-Face: 
 "d[&>8')a)wbF:+L#^<_cohnX6#m5RCCeKF/6_gD(iQ9bX?xe2~Aq*!')D(1ks`?YhomOYbL3R:{4e4a]qft_]<.q/Lf4hIr,`G+LX33&TYp}XGf<b?+GPT;
	3I8k/|[DR#MO1N(h>e~^5m$28R"$C(EwnB\n8t
To: pgsql-performance@postgresql.org
From: Martin Lesser <ml-pgsql@bettercom.de>
Date: Sat, 29 Oct 2005 13:10:31 +0200
Message-ID: <87acgszihk.fsf@nb-aspire.bettercom.de>
User-Agent: Gnus/5.1007 (Gnus v5.10.7) XEmacs/21.4 (Jumbo Shrimp, linux)
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.004 required=5 tests=[AWL=0.004]
X-Spam-Score: 0.004
X-Spam-Level: 
X-Archive-Number: 200510/450
X-Sequence-Number: 15218

Which effects have UPDATEs on REFERENCEd TABLEs when only columns in the
referenced table are updated which are not part of the FOREIGN KEY
constraint?

I have one "master"-table like

 create table t_master (
   m_id   serial primary key,
   m_fld1 ...,
   m_fld2 ...,
   ...
 )

The table above is referenced from several (~30) other tables, i.e. like

 create table t_detail (
   d_ebid int REFERENCES t_master (m_id) ON UPDATE CASCADE ON DELETE CASCADE,
   d_fld1 ...,
   d_fld2 ...,
   ...
 )

All tables which reference t_master have appropriate indexes on the
referencing columns, vacuum/analyze is done regularly (daily).

Does an UPDATE of e.g. m_fld1 in t_master cause a 'lookup' in all tables
which have a cascading update-rule or is this 'lookup' only triggered if
the referenced column in t_master is explicitly updated? After removing
some detail tables which are not longer needed we see an improvemed
performance so at the moment it _looks_ like each update in t_master
triggers a 'lookup' in each referencing table also if the referenced
column (m_id) is not changed.

I've read "If the row is updated, but the referenced column is not
actually changed, no action is done." in the docs but it is not clear
for me whether this "no action" really means "null action" and so the
improved performance has other reasons.

TIA, Martin

From pgsql-performance-owner@postgresql.org  Sat Oct 29 11:24:51 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 969F0DB326
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 29 Oct 2005 11:24:50 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 47280-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 29 Oct 2005 14:24:44 +0000 (GMT)
Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158])
	by svr1.postgresql.org (Postfix) with ESMTP id 0BCB1DABC4
	for <pgsql-performance@postgresql.org>;
	Sat, 29 Oct 2005 11:24:45 -0300 (ADT)
Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1])
	by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id j9TEOWNW008705
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);
	Sat, 29 Oct 2005 08:24:35 -0600 (MDT)
	(envelope-from mfuhr@winnie.fuhr.org)
Received: from winnie.fuhr.org (localhost [127.0.0.1])
	by winnie.fuhr.org (8.13.4/8.13.4) with ESMTP id j9TEOWdn079717;
	Sat, 29 Oct 2005 08:24:32 -0600 (MDT)
	(envelope-from mfuhr@winnie.fuhr.org)
Received: (from mfuhr@localhost)
	by winnie.fuhr.org (8.13.4/8.13.4/Submit) id j9TEOWQ7079716;
	Sat, 29 Oct 2005 08:24:32 -0600 (MDT) (envelope-from mfuhr)
Date: Sat, 29 Oct 2005 08:24:32 -0600
From: Michael Fuhr <mike@fuhr.org>
To: Martin Lesser <ml-pgsql@bettercom.de>
Cc: pgsql-performance@postgresql.org
Subject: Re: Effects of cascading references in foreign keys
Message-ID: <20051029142432.GA79557@winnie.fuhr.org>
References: <87acgszihk.fsf@nb-aspire.bettercom.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <87acgszihk.fsf@nb-aspire.bettercom.de>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.006 required=5 tests=[AWL=0.006]
X-Spam-Score: 0.006
X-Spam-Level: 
X-Archive-Number: 200510/451
X-Sequence-Number: 15219

> Does an UPDATE of e.g. m_fld1 in t_master cause a 'lookup' in all tables
> which have a cascading update-rule or is this 'lookup' only triggered if
> the referenced column in t_master is explicitly updated?

My tests suggest that a lookup on the referring key is done only
if the referenced key is changed.  Here's an example from 8.1beta4;
I used this version because EXPLAIN ANALYZE shows triggers and the
time spent in them, but I see similar performance characteristics
in earlier versions.  I've intentionally not put an index on the
referring column to make lookups on it slow.

CREATE TABLE foo (id serial PRIMARY KEY, x integer NOT NULL);
CREATE TABLE bar (fooid integer NOT NULL REFERENCES foo ON UPDATE CASCADE);

INSERT INTO foo (x) SELECT * FROM generate_series(1, 100000);
INSERT INTO bar (fooid) SELECT * FROM generate_series(1, 100000);

ANALYZE foo;
ANALYZE bar;

EXPLAIN ANALYZE UPDATE foo SET x = 1 WHERE id = 100000;
                                                  QUERY PLAN                                                   
---------------------------------------------------------------------------------------------------------------
 Index Scan using foo_pkey on foo  (cost=0.00..3.01 rows=1 width=10) (actual time=0.059..0.070 rows=1 loops=1)
   Index Cond: (id = 100000)
 Total runtime: 0.633 ms
(3 rows)

EXPLAIN ANALYZE UPDATE foo SET x = 1, id = 200000 WHERE id = 100000;
                                                  QUERY PLAN                                                  
--------------------------------------------------------------------------------------------------------------
 Index Scan using foo_pkey on foo  (cost=0.00..3.01 rows=1 width=6) (actual time=0.082..0.092 rows=1 loops=1)
   Index Cond: (id = 100000)
 Trigger for constraint bar_fooid_fkey: time=232.612 calls=1
 Total runtime: 233.073 ms
(4 rows)

I'm not sure if this is the right place to look, but I see several
places in src/backend/utils/adt/ri_triggers.c with code that looks
like this:

    /*
     * No need to do anything if old and new keys are equal
     */
    if (ri_KeysEqual(pk_rel, old_row, new_row, &qkey,
                     RI_KEYPAIR_PK_IDX))
    {
        heap_close(fk_rel, RowExclusiveLock);
        return PointerGetDatum(NULL);
    }

> After removing some detail tables which are not longer needed we
> see an improvemed performance so at the moment it _looks_ like each
> update in t_master triggers a 'lookup' in each referencing table
> also if the referenced column (m_id) is not changed.

Do you have statistics enabled?  You might be able to infer what
happens by looking at pg_stat_user_tables or pg_statio_user_tables
before and after an update, assuming that no concurrent activity
is also affecting the statistics.

I suppose there's overhead just from having a foreign key constraint,
and possibly additional overhead for each constraint.  If so then
that might explain at least some of the performance improvement.
Maybe one of the developers will comment.

-- 
Michael Fuhr

From pgsql-performance-owner@postgresql.org  Sat Oct 29 11:46:42 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 068A6D84AC
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 29 Oct 2005 11:46:42 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 48066-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 29 Oct 2005 14:46:38 +0000 (GMT)
Received: from wolff.to (wolff.to [66.93.197.194])
	by svr1.postgresql.org (Postfix) with SMTP id DAB62D6F96
	for <pgsql-performance@postgresql.org>;
	Sat, 29 Oct 2005 11:46:39 -0300 (ADT)
Received: (qmail 28906 invoked by uid 500); 29 Oct 2005 14:48:35 -0000
Date: Sat, 29 Oct 2005 09:48:35 -0500
From: Bruno Wolff III <bruno@wolff.to>
To: Martin Lesser <ml-pgsql@bettercom.de>
Cc: pgsql-performance@postgresql.org
Subject: Re: Effects of cascading references in foreign keys
Message-ID: <20051029144835.GA21068@wolff.to>
Mail-Followup-To: Bruno Wolff III <bruno@wolff.to>,
	Martin Lesser <ml-pgsql@bettercom.de>,
	pgsql-performance@postgresql.org
References: <87acgszihk.fsf@nb-aspire.bettercom.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <87acgszihk.fsf@nb-aspire.bettercom.de>
User-Agent: Mutt/1.4.2.1i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.006 required=5 tests=[AWL=0.006]
X-Spam-Score: 0.006
X-Spam-Level: 
X-Archive-Number: 200510/452
X-Sequence-Number: 15220

On Sat, Oct 29, 2005 at 13:10:31 +0200,
  Martin Lesser <ml-pgsql@bettercom.de> wrote:
> Which effects have UPDATEs on REFERENCEd TABLEs when only columns in the
> referenced table are updated which are not part of the FOREIGN KEY
> constraint?

In 8.1 there is a check to see if the foreign key value has changed and if
not a trigger isn't queued. In the currently released versions any update
will fire triggers.
The check in comment for trigger.c didn't say if this optimization applied
to both referencing and referenced keys or just one of those.
If you need to know more you can look at the code at:
http://developer.postgresql.org/cvsweb.cgi/pgsql/src/backend/commands/
for trigger.c.

From pgsql-performance-owner@postgresql.org  Sat Oct 29 11:47:56 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 46FA7DB330
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 29 Oct 2005 11:47:55 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 61978-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 29 Oct 2005 14:47:51 +0000 (GMT)
Received: from wolff.to (wolff.to [66.93.197.194])
	by svr1.postgresql.org (Postfix) with SMTP id A2BC0DB32D
	for <pgsql-performance@postgresql.org>;
	Sat, 29 Oct 2005 11:47:53 -0300 (ADT)
Received: (qmail 29239 invoked by uid 500); 29 Oct 2005 14:49:47 -0000
Date: Sat, 29 Oct 2005 09:49:47 -0500
From: Bruno Wolff III <bruno@wolff.to>
To: Michael Fuhr <mike@fuhr.org>
Cc: Martin Lesser <ml-pgsql@bettercom.de>,
	pgsql-performance@postgresql.org
Subject: Re: Effects of cascading references in foreign keys
Message-ID: <20051029144947.GB21068@wolff.to>
Mail-Followup-To: Bruno Wolff III <bruno@wolff.to>,
	Michael Fuhr <mike@fuhr.org>, Martin Lesser <ml-pgsql@bettercom.de>,
	pgsql-performance@postgresql.org
References: <87acgszihk.fsf@nb-aspire.bettercom.de>
	<20051029142432.GA79557@winnie.fuhr.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20051029142432.GA79557@winnie.fuhr.org>
User-Agent: Mutt/1.4.2.1i
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.006 required=5 tests=[AWL=0.006]
X-Spam-Score: 0.006
X-Spam-Level: 
X-Archive-Number: 200510/453
X-Sequence-Number: 15221

On Sat, Oct 29, 2005 at 08:24:32 -0600,
  Michael Fuhr <mike@fuhr.org> wrote:
> > Does an UPDATE of e.g. m_fld1 in t_master cause a 'lookup' in all tables
> > which have a cascading update-rule or is this 'lookup' only triggered if
> > the referenced column in t_master is explicitly updated?
> 
> My tests suggest that a lookup on the referring key is done only
> if the referenced key is changed.  Here's an example from 8.1beta4;
> I used this version because EXPLAIN ANALYZE shows triggers and the
> time spent in them, but I see similar performance characteristics
> in earlier versions.  I've intentionally not put an index on the
> referring column to make lookups on it slow.

It looks like this feature was added last May, so I think it only applies
to 8.1.

From pgsql-performance-owner@postgresql.org  Sat Oct 29 13:05:57 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 7B49BDB12E
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 29 Oct 2005 13:05:56 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 81596-09
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 29 Oct 2005 16:05:55 +0000 (GMT)
Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158])
	by svr1.postgresql.org (Postfix) with ESMTP id 16428DB096
	for <pgsql-performance@postgresql.org>;
	Sat, 29 Oct 2005 13:05:54 -0300 (ADT)
Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1])
	by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id j9TG5UOD008791
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);
	Sat, 29 Oct 2005 10:05:32 -0600 (MDT)
	(envelope-from mfuhr@winnie.fuhr.org)
Received: from winnie.fuhr.org (localhost [127.0.0.1])
	by winnie.fuhr.org (8.13.4/8.13.4) with ESMTP id j9TG5TKr080223;
	Sat, 29 Oct 2005 10:05:30 -0600 (MDT)
	(envelope-from mfuhr@winnie.fuhr.org)
Received: (from mfuhr@localhost)
	by winnie.fuhr.org (8.13.4/8.13.4/Submit) id j9TG5RtA080222;
	Sat, 29 Oct 2005 10:05:27 -0600 (MDT) (envelope-from mfuhr)
Date: Sat, 29 Oct 2005 10:05:27 -0600
From: Michael Fuhr <mike@fuhr.org>
To: Bruno Wolff III <bruno@wolff.to>, Martin Lesser <ml-pgsql@bettercom.de>,
	pgsql-performance@postgresql.org
Subject: Re: Effects of cascading references in foreign keys
Message-ID: <20051029160527.GA80135@winnie.fuhr.org>
References: <87acgszihk.fsf@nb-aspire.bettercom.de>
	<20051029142432.GA79557@winnie.fuhr.org>
	<20051029144947.GB21068@wolff.to>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20051029144947.GB21068@wolff.to>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.006 required=5 tests=[AWL=0.006]
X-Spam-Score: 0.006
X-Spam-Level: 
X-Archive-Number: 200510/454
X-Sequence-Number: 15222

On Sat, Oct 29, 2005 at 09:49:47AM -0500, Bruno Wolff III wrote:
> On Sat, Oct 29, 2005 at 08:24:32 -0600, Michael Fuhr <mike@fuhr.org> wrote:
> > My tests suggest that a lookup on the referring key is done only
> > if the referenced key is changed.  Here's an example from 8.1beta4;
> > I used this version because EXPLAIN ANALYZE shows triggers and the
> > time spent in them, but I see similar performance characteristics
> > in earlier versions.  I've intentionally not put an index on the
> > referring column to make lookups on it slow.
> 
> It looks like this feature was added last May, so I think it only applies
> to 8.1.

Earlier versions appear to have at least some kind of optimization.
Here's a test in 7.3.11 using the same tables I used in 8.1beta4,
although on a slower box.

test=> UPDATE foo SET x = 1 WHERE id = 100000;
UPDATE 1
Time: 32.18 ms

test=> UPDATE foo SET x = 1, id = 200000 WHERE id = 100000;
UPDATE 1
Time: 4144.95 ms

test=> DROP TABLE bar;
DROP TABLE
Time: 240.87 ms

test=> UPDATE foo SET x = 1, id = 100000 WHERE id = 200000;
UPDATE 1
Time: 63.52 ms

-- 
Michael Fuhr

From pgsql-performance-owner@postgresql.org  Sat Oct 29 13:05:59 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 9A43FDB31D
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 29 Oct 2005 13:05:58 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 92205-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 29 Oct 2005 16:05:57 +0000 (GMT)
Received: from candle.pha.pa.us (candle.pha.pa.us [64.139.89.126])
	by svr1.postgresql.org (Postfix) with ESMTP id B3E35DB325
	for <pgsql-performance@postgresql.org>;
	Sat, 29 Oct 2005 13:05:56 -0300 (ADT)
Received: (from pgman@localhost)
	by candle.pha.pa.us (8.11.6/8.11.6) id j9TG5XX07593;
	Sat, 29 Oct 2005 12:05:33 -0400 (EDT)
From: Bruce Momjian <pgman@candle.pha.pa.us>
Message-Id: <200510291605.j9TG5XX07593@candle.pha.pa.us>
Subject: Re: Effects of cascading references in foreign keys
In-Reply-To: <20051029144835.GA21068@wolff.to>
To: Bruno Wolff III <bruno@wolff.to>
Date: Sat, 29 Oct 2005 12:05:33 -0400 (EDT)
Cc: Martin Lesser <ml-pgsql@bettercom.de>,
	pgsql-performance@postgresql.org
X-Mailer: ELM [version 2.4ME+ PL121 (25)]
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=US-ASCII
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.014 required=5 tests=[AWL=0.014]
X-Spam-Score: 0.014
X-Spam-Level: 
X-Archive-Number: 200510/455
X-Sequence-Number: 15223

Bruno Wolff III wrote:
> On Sat, Oct 29, 2005 at 13:10:31 +0200,
>   Martin Lesser <ml-pgsql@bettercom.de> wrote:
> > Which effects have UPDATEs on REFERENCEd TABLEs when only columns in the
> > referenced table are updated which are not part of the FOREIGN KEY
> > constraint?
> 
> In 8.1 there is a check to see if the foreign key value has changed and if
> not a trigger isn't queued. In the currently released versions any update
> will fire triggers.
> The check in comment for trigger.c didn't say if this optimization applied
> to both referencing and referenced keys or just one of those.
> If you need to know more you can look at the code at:
> http://developer.postgresql.org/cvsweb.cgi/pgsql/src/backend/commands/
> for trigger.c.

It applies to both.  See
src/backend/utils/adt/ri_triggers.c::RI_FKey_keyequal_upd_pk() and
RI_FKey_keyequal_upd_fk().  The first is for primary keys (pk), the
second for foreign keys (fk). These are called by
src/backend/command/triggers.c::AfterTriggerSaveEvent().  The checks
prevent the trigger from being registered at all if there is no change
in the primary/foreign key relationship.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

From pgsql-performance-owner@postgresql.org  Sat Oct 29 13:19:31 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id F1C27DACB6
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 29 Oct 2005 13:19:28 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 95767-01
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 29 Oct 2005 16:19:27 +0000 (GMT)
Received: from candle.pha.pa.us (candle.pha.pa.us [64.139.89.126])
	by svr1.postgresql.org (Postfix) with ESMTP id 5326DDAC97
	for <pgsql-performance@postgresql.org>;
	Sat, 29 Oct 2005 13:19:27 -0300 (ADT)
Received: (from pgman@localhost)
	by candle.pha.pa.us (8.11.6/8.11.6) id j9TGJE009833;
	Sat, 29 Oct 2005 12:19:14 -0400 (EDT)
From: Bruce Momjian <pgman@candle.pha.pa.us>
Message-Id: <200510291619.j9TGJE009833@candle.pha.pa.us>
Subject: Re: Effects of cascading references in foreign keys
In-Reply-To: <20051029160527.GA80135@winnie.fuhr.org>
To: Michael Fuhr <mike@fuhr.org>
Date: Sat, 29 Oct 2005 12:19:14 -0400 (EDT)
Cc: Bruno Wolff III <bruno@wolff.to>, Martin Lesser <ml-pgsql@bettercom.de>,
	pgsql-performance@postgresql.org
X-Mailer: ELM [version 2.4ME+ PL121 (25)]
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=US-ASCII
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.014 required=5 tests=[AWL=0.014]
X-Spam-Score: 0.014
X-Spam-Level: 
X-Archive-Number: 200510/456
X-Sequence-Number: 15224

Michael Fuhr wrote:
> On Sat, Oct 29, 2005 at 09:49:47AM -0500, Bruno Wolff III wrote:
> > On Sat, Oct 29, 2005 at 08:24:32 -0600, Michael Fuhr <mike@fuhr.org> wrote:
> > > My tests suggest that a lookup on the referring key is done only
> > > if the referenced key is changed.  Here's an example from 8.1beta4;
> > > I used this version because EXPLAIN ANALYZE shows triggers and the
> > > time spent in them, but I see similar performance characteristics
> > > in earlier versions.  I've intentionally not put an index on the
> > > referring column to make lookups on it slow.
> > 
> > It looks like this feature was added last May, so I think it only applies
> > to 8.1.
> 
> Earlier versions appear to have at least some kind of optimization.
> Here's a test in 7.3.11 using the same tables I used in 8.1beta4,
> although on a slower box.
> 
> test=> UPDATE foo SET x = 1 WHERE id = 100000;
> UPDATE 1
> Time: 32.18 ms
> 
> test=> UPDATE foo SET x = 1, id = 200000 WHERE id = 100000;
> UPDATE 1
> Time: 4144.95 ms
> 
> test=> DROP TABLE bar;
> DROP TABLE
> Time: 240.87 ms
> 
> test=> UPDATE foo SET x = 1, id = 100000 WHERE id = 200000;
> UPDATE 1
> Time: 63.52 ms

Yes, I think in 8.0.X those triggers were queued on firing did nothing
while in 8.1 the triggers are not even fired.

The 8.1 commit to ri_triggers.c has:

	revision 1.79
	date: 2005/05/30 07:20:58;  author: neilc;  state: Exp;  lines: +131 -65
	When enqueueing after-row triggers for updates of a table with a foreign
	key, compare the new and old row versions. If the foreign key column has
	not changed, we needn't enqueue the trigger, since the update cannot
	violate the foreign key. This optimization was previously applied in the
	RI trigger function, but it is more efficient to avoid firing the
	trigger altogether. Per recent discussion on pgsql-hackers.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

From pgsql-performance-owner@postgresql.org  Sat Oct 29 15:02:15 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 81700DB330
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 29 Oct 2005 15:02:13 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 27622-07
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 29 Oct 2005 18:02:11 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id DE598DB32E
	for <pgsql-performance@postgresql.org>;
	Sat, 29 Oct 2005 15:02:11 -0300 (ADT)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j9TI1wJq011905;
	Sat, 29 Oct 2005 14:01:58 -0400 (EDT)
To: Michael Fuhr <mike@fuhr.org>
Cc: Bruno Wolff III <bruno@wolff.to>, Martin Lesser <ml-pgsql@bettercom.de>,
	Stephan Szabo <sszabo@megazone.bigpanda.com>,
	pgsql-performance@postgresql.org
Subject: Re: Effects of cascading references in foreign keys 
In-reply-to: <20051029160527.GA80135@winnie.fuhr.org> 
References: <87acgszihk.fsf@nb-aspire.bettercom.de>
	<20051029142432.GA79557@winnie.fuhr.org>
	<20051029144947.GB21068@wolff.to>
	<20051029160527.GA80135@winnie.fuhr.org>
Comments: In-reply-to Michael Fuhr <mike@fuhr.org>
	message dated "Sat, 29 Oct 2005 10:05:27 -0600"
Date: Sat, 29 Oct 2005 14:01:58 -0400
Message-ID: <11904.1130608918@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.006 required=5 tests=[AWL=0.006]
X-Spam-Score: 0.006
X-Spam-Level: 
X-Archive-Number: 200510/457
X-Sequence-Number: 15225

Michael Fuhr <mike@fuhr.org> writes:
> On Sat, Oct 29, 2005 at 09:49:47AM -0500, Bruno Wolff III wrote:
>> It looks like this feature was added last May, so I think it only applies
>> to 8.1.

> Earlier versions appear to have at least some kind of optimization.

Yeah.  IIRC, for quite some time we've had tests inside the FK update
triggers to not bother to search the other table if the key value hasn't
changed.  What we did in 8.1 was to push that test further upstream, so
that the trigger event isn't even queued if the key value hasn't
changed.  (This is why you don't see the trigger shown as being called
even once.)

Looking at this, I wonder if there isn't a bug or at least an
inefficiency in 8.1.  The KeysEqual short circuit tests are still there
in ri_triggers.c; aren't they now redundant with the test in triggers.c?
And don't they need to account for the special case mentioned in the
comment in triggers.c, that the RI check must still be done if we are
looking at a row updated by the same transaction that created it?

			regards, tom lane

From pgsql-performance-owner@postgresql.org  Sat Oct 29 15:35:39 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 84419DB345
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 29 Oct 2005 15:35:38 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 38970-04
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sat, 29 Oct 2005 18:35:36 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id 43BD5DB340
	for <pgsql-performance@postgresql.org>;
	Sat, 29 Oct 2005 15:35:37 -0300 (ADT)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j9TIZPCd012098;
	Sat, 29 Oct 2005 14:35:25 -0400 (EDT)
To: Michael Fuhr <mike@fuhr.org>
Cc: Bruno Wolff III <bruno@wolff.to>, Martin Lesser <ml-pgsql@bettercom.de>,
	Stephan Szabo <sszabo@megazone.bigpanda.com>,
	pgsql-performance@postgresql.org
Subject: Re: Effects of cascading references in foreign keys 
In-reply-to: <11904.1130608918@sss.pgh.pa.us> 
References: <87acgszihk.fsf@nb-aspire.bettercom.de>
	<20051029142432.GA79557@winnie.fuhr.org>
	<20051029144947.GB21068@wolff.to>
	<20051029160527.GA80135@winnie.fuhr.org>
	<11904.1130608918@sss.pgh.pa.us>
Comments: In-reply-to Tom Lane <tgl@sss.pgh.pa.us>
	message dated "Sat, 29 Oct 2005 14:01:58 -0400"
Date: Sat, 29 Oct 2005 14:35:25 -0400
Message-ID: <12097.1130610925@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.006 required=5 tests=[AWL=0.006]
X-Spam-Score: 0.006
X-Spam-Level: 
X-Archive-Number: 200510/458
X-Sequence-Number: 15226

I wrote:
> Looking at this, I wonder if there isn't a bug or at least an
> inefficiency in 8.1.  The KeysEqual short circuit tests are still there
> in ri_triggers.c; aren't they now redundant with the test in triggers.c?
> And don't they need to account for the special case mentioned in the
> comment in triggers.c, that the RI check must still be done if we are
> looking at a row updated by the same transaction that created it?

OK, I take back the possible-bug comment: the special case only applies
to the FK-side triggers, which is to say RI_FKey_check, and that routine
doesn't attempt to skip the check on equal old/new keys.  I'm still
wondering though if the KeysEqual tests in the other RI triggers aren't
now a waste of cycles.

			regards, tom lane

From pgsql-performance-owner@postgresql.org  Sun Oct 30 01:32:26 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 9B539D7114
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 30 Oct 2005 01:32:25 -0300 (ADT)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 10774-03
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 30 Oct 2005 04:32:24 +0000 (GMT)
Received: from window.monsterlabs.com (window.monsterlabs.com
	[216.183.105.176])
	by svr1.postgresql.org (Postfix) with SMTP id B64EFD6F96
	for <pgsql-performance@postgresql.org>;
	Sun, 30 Oct 2005 01:32:23 -0300 (ADT)
Received: (qmail 598 invoked from network); 30 Oct 2005 04:32:22 -0000
Received: from pcp0012204803pcs.blairblvd.tn.nash.comcast.net (HELO
	?192.168.15.103?) (69.245.49.69)
	by 0 with SMTP; 30 Oct 2005 04:32:22 -0000
Mime-Version: 1.0 (Apple Message framework v734)
In-Reply-To: <20051029144835.GA21068@wolff.to>
References: <87acgszihk.fsf@nb-aspire.bettercom.de>
	<20051029144835.GA21068@wolff.to>
Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed
Message-Id: <F7B49CB0-86E6-4744-9D37-3C1EAEDBA15E@sitening.com>
Content-Transfer-Encoding: 7bit
From: "Thomas F. O'Connell" <tfo@sitening.com>
Subject: Re: Effects of cascading references in foreign keys
Date: Sat, 29 Oct 2005 23:32:21 -0500
To: PgSQL Performance <pgsql-performance@postgresql.org>
X-Mailer: Apple Mail (2.734)
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.015 required=5 tests=[AWL=0.015]
X-Spam-Score: 0.015
X-Spam-Level: 
X-Archive-Number: 200510/459
X-Sequence-Number: 15227


On Oct 29, 2005, at 9:48 AM, Bruno Wolff III wrote:

> On Sat, Oct 29, 2005 at 13:10:31 +0200,
>   Martin Lesser <ml-pgsql@bettercom.de> wrote:
>
>> Which effects have UPDATEs on REFERENCEd TABLEs when only columns  
>> in the
>> referenced table are updated which are not part of the FOREIGN KEY
>> constraint?
>
> In 8.1 there is a check to see if the foreign key value has changed  
> and if
> not a trigger isn't queued. In the currently released versions any  
> update
> will fire triggers.
> The check in comment for trigger.c didn't say if this optimization  
> applied
> to both referencing and referenced keys or just one of those.
> If you need to know more you can look at the code at:
> http://developer.postgresql.org/cvsweb.cgi/pgsql/src/backend/commands/
> for trigger.c.

It seems like this warrants an item somewhere in the release notes,  
and I'm not currently seeing it (or a related item) anywhere. Perhaps  
E.1.3.1 (Performance Improvements)? For some of the more extreme  
UPDATE scenarios I've seen, this could be a big win.

--
Thomas F. O'Connell
Co-Founder, Information Architect
Sitening, LLC

Open Source Solutions. Optimized Web Development.

http://www.sitening.com/
110 30th Avenue North, Suite 6
Nashville, TN 37203-6320
615-469-5150
615-469-5151 (fax)

From pgsql-performance-owner@postgresql.org  Sun Oct 30 10:10:51 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id DDC8EDACCE
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 30 Oct 2005 10:10:49 -0400 (AST)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 96033-07
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 30 Oct 2005 14:10:46 +0000 (GMT)
Received: from candle.pha.pa.us (candle.pha.pa.us [64.139.89.126])
	by svr1.postgresql.org (Postfix) with ESMTP id 1CD6CDACAF
	for <pgsql-performance@postgresql.org>;
	Sun, 30 Oct 2005 10:10:47 -0400 (AST)
Received: (from pgman@localhost)
	by candle.pha.pa.us (8.11.6/8.11.6) id j9UEAnj02881;
	Sun, 30 Oct 2005 09:10:49 -0500 (EST)
From: Bruce Momjian <pgman@candle.pha.pa.us>
Message-Id: <200510301410.j9UEAnj02881@candle.pha.pa.us>
Subject: Re: Effects of cascading references in foreign keys
In-Reply-To: <F7B49CB0-86E6-4744-9D37-3C1EAEDBA15E@sitening.com>
To: "Thomas F. O'Connell" <tfo@sitening.com>
Date: Sun, 30 Oct 2005 09:10:49 -0500 (EST)
Cc: PgSQL Performance <pgsql-performance@postgresql.org>
X-Mailer: ELM [version 2.4ME+ PL121 (25)]
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=US-ASCII
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.014 required=5 tests=[AWL=0.014]
X-Spam-Score: 0.014
X-Spam-Level: 
X-Archive-Number: 200510/460
X-Sequence-Number: 15228

Thomas F. O'Connell wrote:
> > In 8.1 there is a check to see if the foreign key value has changed  
> > and if
> > not a trigger isn't queued. In the currently released versions any  
> > update
> > will fire triggers.
> > The check in comment for trigger.c didn't say if this optimization  
> > applied
> > to both referencing and referenced keys or just one of those.
> > If you need to know more you can look at the code at:
> > http://developer.postgresql.org/cvsweb.cgi/pgsql/src/backend/commands/
> > for trigger.c.
> 
> It seems like this warrants an item somewhere in the release notes,  
> and I'm not currently seeing it (or a related item) anywhere. Perhaps  
> E.1.3.1 (Performance Improvements)? For some of the more extreme  
> UPDATE scenarios I've seen, this could be a big win.

Hard to say, perhaps:

	Prevent referential integrity triggers from firing if referenced
	columns are not changed by an UPDATE

	Previously, triggers would fire but do nothing.

However, the description seems more complex than it is worth.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

From pgsql-performance-owner@postgresql.org  Sun Oct 30 13:14:32 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 02F05DB40A
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 30 Oct 2005 13:14:31 -0400 (AST)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 61683-04
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 30 Oct 2005 17:14:29 +0000 (GMT)
Received: from cicero1.cybercity.dk (cicero1.cybercity.dk [212.242.40.4])
	by svr1.postgresql.org (Postfix) with ESMTP id C6736DB3FB
	for <pgsql-performance@postgresql.org>;
	Sun, 30 Oct 2005 13:14:28 -0400 (AST)
Received: from [192.168.0.79] (0x3e42eeca.adsl.cybercity.dk [62.66.238.202])
	by cicero1.cybercity.dk (Postfix) with ESMTP id 769467E3905
	for <pgsql-performance@postgresql.org>;
	Sun, 30 Oct 2005 18:14:25 +0100 (CET)
Message-ID: <4364FFD4.2020801@krap.dk>
Date: Sun, 30 Oct 2005 18:16:04 +0100
From: Svenne Krap <svenne@krap.dk>
User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: PgSQL Performance <pgsql-performance@postgresql.org>
Subject: multi-layered view join performance oddities
Content-Type: multipart/mixed; boundary="------------070103070709060603040607"
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0 required=5 tests=[none]
X-Spam-Score: 0
X-Spam-Level: 
X-Archive-Number: 200510/461
X-Sequence-Number: 15229

This is a multi-part message in MIME format.
--------------070103070709060603040607
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Hi there.

I have tried to implement the layered views as suggested earlier on one 
of the simplest queries (just to get a feel for it). And there seems to 
be something odd going on.

Attached are all the statemens needed to see, how the database is made 
and the contents of postgresql.conf and two explain analyzes:

The machine is a single cpu Xeon, with 2G of memory and 2 scsi-drives in 
a mirror (is going to be extended to 6 within a few weeks) running 
8.1beta3.  The whole database has been vacuum analyzed just before the 
explain analyzes.

I have spend a few hours fiddling around with the performance of it, but 
seems to go nowhere - I might have become snowblind and missed something 
obvious though.

There are a few things, that strikes me:
- the base view (ord_result_pct) is reasonable fast (41 ms) - it does a 
lot of seq scans, but right now there are not enough data there to do 
otherwise
- the pretty version (for output) is 17,5 times slower (722ms) even 
though it just joins against three tiny tables ( < 100 rows each) and 
the plan seems very different
- the slow query (the _pretty) has lower expected costs as the other ( 
338 vs 487 "performance units") , this looks like some cost parameters 
need tweaking. I cannot figure out which though.
- the top nested loop seems to eat most of the time, I have a little 
trouble seeing what this nested loop is doing there anyways

Thanks in advance

Svenne

--------------070103070709060603040607
Content-Type: text/plain;
 name="postgresql-perfomance-oddities.txt"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="postgresql-perfomance-oddities.txt"

create table nb_property_type(  
        id integer not null,
        description_dk varchar not null,
        description_us varchar not null,
        primary key(id)
);

--- 8 rows in nb_property_type, not growing


create table groups (
id int4 not null default nextval('role_id_seq'),
groupname varchar not null,
is_home_group bool not null default 'f'::bool,
valid bool not null default 't'::bool,
created_at timestamp not null default current_timestamp,
changed_at timestamp,
stopped_at timestamp,
primary key(id));

-- at the moment approx. 20 rows, expected a few hundres when going online

create table ord_dataset(
        id serial,
        first_observation date not null,
        last_observation date,
        is_mainline bool not null default 't',
        is_visible bool not null default 'f',
        description_dk varchar,
        description_us varchar,
        created_by int4 not null references users,
        created_at timestamp not null default current_timestamp,
        primary key(id)
);

create unique index ord_dataset_fo_idx on ord_dataset(first_observation) where is_mainline = 't';

-- approx. 35 rows, growing 4 rows each year


create table ord_entrydata_current(
        dataset_id integer not null references ord_dataset,
        institut integer not null references groups,
        nb_property_type_id int4 not null references nb_property_type,
        amount int8 not null
);

create index ord_ed_cur_dataset_id on ord_entrydata_current(dataset_id);
create index ord_ed_cur_institut on ord_entrydata_current(institut);
create index ord_ed_cur_propertytype on ord_entrydata_current(nb_property_type_id);


-- filled by a trigger, approx. 3,000 rows, grows approx. 250 rows each year

create view ord_property_type_sums as
 SELECT ord_entrydata_current.dataset_id, 0 AS nb_property_type_id, ord_entrydata_current.institut, sum(ord_entrydata_current.amount) AS amount
   FROM ord_entrydata_current
  GROUP BY ord_entrydata_current.dataset_id, ord_entrydata_current.institut;

create view ord_property_type_all as
 SELECT ord_property_type_sums.dataset_id, ord_property_type_sums.nb_property_type_id, ord_property_type_sums.institut, ord_property_type_sums.amount
   FROM ord_property_type_sums
UNION ALL
 SELECT ord_entrydata_current.dataset_id, ord_entrydata_current.nb_property_type_id, ord_entrydata_current.institut, ord_entrydata_current.amount
   FROM ord_entrydata_current;

create view ord_institutes_sum as
 SELECT ord_property_type_all.dataset_id, ord_property_type_all.nb_property_type_id, 0 AS institut, sum(ord_property_type_all.amount) AS amount
   FROM ord_property_type_all
 GROUP BY ord_property_type_all.dataset_id, ord_property_type_all.nb_property_type_id;

create view ord_result_pct as
 SELECT t1.dataset_id, t1.nb_property_type_id, t1.institut, t1.amount / t2.amount * 100::numeric AS pct
   FROM ord_property_type_all t1, ord_institutes_sum t2
  WHERE t1.dataset_id = t2.dataset_id AND t1.nb_property_type_id = t2.nb_property_type_id;

create view ord_result_pct_pretty as
        select od.id, od.first_observation, od.description_dk as dsd_dk, od.description_us as dsd_us ,g.groupname,orp.institut, orp.nb_property_type_id, npt.description_dk as pd_dk, npt.description_us as pd_us, pct   from ord_result_pct orp, ord_dataset od, nb_property_type npt, groups g
                where orp.dataset_id = od.id and orp.institut = g.id and orp.nb_property_type_id = npt.id and od.is_visible = 't'::bool;


-- contents of postgresql.conf 


listen_addresses = 'localhost'
port = 5432
max_connections = 100 
superuser_reserved_connections = 1
shared_buffers = 20000
work_mem = 10240 
maintenance_work_mem = 163840
max_stack_depth = 2048
max_fsm_pages = 50000
max_fsm_relations = 3000 
max_files_per_process = 1000
bgwriter_delay = 200
bgwriter_all_percent = 1.0 
bgwriter_all_maxpages = 10 
fsync = on 
wal_buffers = 128 
checkpoint_segments = 32 
effective_cache_size = 50000


-- now for the queries
rkr=# explain analyze select * from ord_result_pct ;
                                                                        QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------------------------------
 Merge Join  (cost=466.54..487.20 rows=15 width=76) (actual time=30.185..39.857 rows=2532 loops=1)
   Merge Cond: (("outer".nb_property_type_id = "inner".nb_property_type_id) AND ("outer".dataset_id = "inner".dataset_id))
   ->  Sort  (cost=286.05..292.24 rows=2476 width=44) (actual time=14.591..15.519 rows=2532 loops=1)
         Sort Key: t1.nb_property_type_id, t1.dataset_id
         ->  Append  (cost=54.38..121.72 rows=2476 width=44) (actual time=4.895..10.879 rows=2532 loops=1)
               ->  HashAggregate  (cost=54.38..57.20 rows=226 width=16) (actual time=4.894..5.111 rows=282 loops=1)
                     ->  Seq Scan on ord_entrydata_current  (cost=0.00..37.50 rows=2250 width=16) (actual time=0.004..1.271 rows=2250 loops=1)
               ->  Subquery Scan "*SELECT* 2"  (cost=0.00..60.00 rows=2250 width=20) (actual time=0.005..4.162 rows=2250 loops=1)
                     ->  Seq Scan on ord_entrydata_current  (cost=0.00..37.50 rows=2250 width=20) (actual time=0.002..1.669 rows=2250 loops=1)
   ->  Sort  (cost=180.49..181.11 rows=248 width=40) (actual time=15.578..16.533 rows=2526 loops=1)
         Sort Key: t2.nb_property_type_id, t2.dataset_id
         ->  Subquery Scan t2  (cost=165.05..170.63 rows=248 width=40) (actual time=14.597..15.014 rows=288 loops=1)
               ->  HashAggregate  (cost=165.05..168.15 rows=248 width=40) (actual time=14.595..14.822 rows=288 loops=1)
                     ->  Append  (cost=54.38..121.72 rows=2476 width=44) (actual time=4.901..11.027 rows=2532 loops=1)
                           ->  HashAggregate  (cost=54.38..57.20 rows=226 width=16) (actual time=4.901..5.105 rows=282 loops=1)
                                 ->  Seq Scan on ord_entrydata_current  (cost=0.00..37.50 rows=2250 width=16) (actual time=0.002..1.308 rows=2250 loops=1)
                           ->  Subquery Scan "*SELECT* 2"  (cost=0.00..60.00 rows=2250 width=20) (actual time=0.006..4.312 rows=2250 loops=1)
                                 ->  Seq Scan on ord_entrydata_current  (cost=0.00..37.50 rows=2250 width=20) (actual time=0.002..1.697 rows=2250 loops=1)
 Total runtime: 41.076 ms
(19 rows)

rkr=# explain analyze select * from ord_result_pct_pretty ;
                                                                        QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------------------------------
 Nested Loop  (cost=223.09..338.61 rows=1 width=174) (actual time=20.213..721.361 rows=2250 loops=1)
   Join Filter: (("outer".dataset_id = "inner".dataset_id) AND ("outer".nb_property_type_id = "inner".nb_property_type_id))
   ->  Hash Join  (cost=58.04..164.26 rows=1 width=150) (actual time=5.510..22.088 rows=2250 loops=1)
         Hash Cond: ("outer".institut = "inner".id)
         ->  Hash Join  (cost=56.88..163.00 rows=16 width=137) (actual time=5.473..19.165 rows=2250 loops=1)
               Hash Cond: ("outer".dataset_id = "inner".id)
               ->  Hash Join  (cost=55.48..160.95 rows=99 width=101) (actual time=5.412..16.264 rows=2250 loops=1)
                     Hash Cond: ("outer".nb_property_type_id = "inner".id)
                     ->  Append  (cost=54.38..121.72 rows=2476 width=44) (actual time=4.900..12.869 rows=2532 loops=1)
                           ->  HashAggregate  (cost=54.38..57.20 rows=226 width=16) (actual time=4.900..5.094 rows=282 loops=1)
                                 ->  Seq Scan on ord_entrydata_current  (cost=0.00..37.50 rows=2250 width=16) (actual time=0.002..1.266 rows=2250 loops=1)
                           ->  Subquery Scan "*SELECT* 2"  (cost=0.00..60.00 rows=2250 width=20) (actual time=0.009..6.063 rows=2250 loops=1)
                                 ->  Seq Scan on ord_entrydata_current  (cost=0.00..37.50 rows=2250 width=20) (actual time=0.002..2.755 rows=2250 loops=1)
                     ->  Hash  (cost=1.08..1.08 rows=8 width=57) (actual time=0.016..0.016 rows=8 loops=1)
                           ->  Seq Scan on nb_property_type npt  (cost=0.00..1.08 rows=8 width=57) (actual time=0.002..0.010 rows=8 loops=1)
               ->  Hash  (cost=1.32..1.32 rows=32 width=36) (actual time=0.054..0.054 rows=32 loops=1)
                     ->  Seq Scan on ord_dataset od  (cost=0.00..1.32 rows=32 width=36) (actual time=0.003..0.027 rows=32 loops=1)
                           Filter: is_visible
         ->  Hash  (cost=1.13..1.13 rows=13 width=17) (actual time=0.029..0.029 rows=13 loops=1)
               ->  Seq Scan on groups g  (cost=0.00..1.13 rows=13 width=17) (actual time=0.007..0.019 rows=13 loops=1)
   ->  HashAggregate  (cost=165.05..168.15 rows=248 width=40) (actual time=0.007..0.204 rows=288 loops=2250)
         ->  Append  (cost=54.38..121.72 rows=2476 width=44) (actual time=4.983..11.132 rows=2532 loops=1)
               ->  HashAggregate  (cost=54.38..57.20 rows=226 width=16) (actual time=4.982..5.192 rows=282 loops=1)
                     ->  Seq Scan on ord_entrydata_current  (cost=0.00..37.50 rows=2250 width=16) (actual time=0.001..1.333 rows=2250 loops=1)
               ->  Subquery Scan "*SELECT* 2"  (cost=0.00..60.00 rows=2250 width=20) (actual time=0.008..4.329 rows=2250 loops=1)
                     ->  Seq Scan on ord_entrydata_current  (cost=0.00..37.50 rows=2250 width=20) (actual time=0.002..1.747 rows=2250 loops=1)
 Total runtime: 722.350 ms
(27 rows)

--------------070103070709060603040607--

From pgsql-performance-owner@postgresql.org  Sun Oct 30 13:44:58 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 72696DB37B
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 30 Oct 2005 13:44:56 -0400 (AST)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 76115-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 30 Oct 2005 17:44:53 +0000 (GMT)
Received: from cassarossa.samfundet.no (cassarossa.samfundet.no
	[129.241.93.19])
	by svr1.postgresql.org (Postfix) with ESMTP id 9571EDA848
	for <pgsql-performance@postgresql.org>;
	Sun, 30 Oct 2005 13:44:53 -0400 (AST)
Received: from trofast.ipv6.sesse.net ([2001:700:300:dc03:20e:cff:fe36:a766]
	helo=trofast.sesse.net)
	by cassarossa.samfundet.no with esmtp (Exim 4.50)
	id 1EWHEf-0002up-IJ; Sun, 30 Oct 2005 18:44:51 +0100
Received: from sesse by trofast.sesse.net with local (Exim 3.36 #1 (Debian))
	id 1EWHEg-0005ul-00; Sun, 30 Oct 2005 18:44:50 +0100
Date: Sun, 30 Oct 2005 18:44:50 +0100
From: "Steinar H. Gunderson" <sgunderson@bigfoot.com>
To: Svenne Krap <svenne@krap.dk>
Cc: PgSQL Performance <pgsql-performance@postgresql.org>
Subject: Re: multi-layered view join performance oddities
Message-ID: <20051030174450.GA22399@uio.no>
Mail-Followup-To: Svenne Krap <svenne@krap.dk>,
	PgSQL Performance <pgsql-performance@postgresql.org>
References: <4364FFD4.2020801@krap.dk>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
In-Reply-To: <4364FFD4.2020801@krap.dk>
X-Operating-System: Linux 2.6.14-rc5 on a x86_64
X-Message-Flag: Outlook? --> http://www.mozilla.org/products/thunderbird/
User-Agent: Mutt/1.5.11
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.009 required=5 tests=[AWL=0.009]
X-Spam-Score: 0.009
X-Spam-Level: 
X-Archive-Number: 200510/462
X-Sequence-Number: 15230

On Sun, Oct 30, 2005 at 06:16:04PM +0100, Svenne Krap wrote:
>  Nested Loop  (cost=223.09..338.61 rows=1 width=174) (actual time=20.213..721.361 rows=2250 loops=1)
>    Join Filter: (("outer".dataset_id = "inner".dataset_id) AND ("outer".nb_property_type_id = "inner".nb_property_type_id))
>    ->  Hash Join  (cost=58.04..164.26 rows=1 width=150) (actual time=5.510..22.088 rows=2250 loops=1)

There's horrible misestimation here. It expects one row and thus starts a
nested loop, but gets 2250. No wonder it's slow :-)

The misestimation can be traced all the way down here:

>          Hash Cond: ("outer".institut = "inner".id)
>          ->  Hash Join  (cost=56.88..163.00 rows=16 width=137) (actual time=5.473..19.165 rows=2250 loops=1)
>                Hash Cond: ("outer".dataset_id = "inner".id)
>                ->  Hash Join  (cost=55.48..160.95 rows=99 width=101) (actual time=5.412..16.264 rows=2250 loops=1)

where the planner misestimates the selectivity of your join (it estimates 99
rows, and there are 2250).

I've had problems joining with Append nodes in the past, and solved the
problem by moving the UNION ALL a bit out, but I'm not sure if it's a very
good general solution, or a solution to your problems here.

If all else fails, you could "set enable_nestloop=false", but that is not a
good idea in the long run, I'd guess -- it's much better to make sure the
planner has good estimates and let it do the correct decisions from there.

/* Steinar */
-- 
Homepage: http://www.sesse.net/

From pgsql-performance-owner@postgresql.org  Sun Oct 30 14:27:20 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 1A3C8DB420
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 30 Oct 2005 14:27:17 -0400 (AST)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 92881-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 30 Oct 2005 18:27:13 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id 54430DB411
	for <pgsql-performance@postgresql.org>;
	Sun, 30 Oct 2005 14:27:13 -0400 (AST)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j9UIR1HV013994;
	Sun, 30 Oct 2005 13:27:01 -0500 (EST)
To: Svenne Krap <svenne@krap.dk>
Cc: PgSQL Performance <pgsql-performance@postgresql.org>
Subject: Re: multi-layered view join performance oddities 
In-reply-to: <4364FFD4.2020801@krap.dk> 
References: <4364FFD4.2020801@krap.dk>
Comments: In-reply-to Svenne Krap <svenne@krap.dk>
	message dated "Sun, 30 Oct 2005 18:16:04 +0100"
Date: Sun, 30 Oct 2005 13:27:01 -0500
Message-ID: <13993.1130696821@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.006 required=5 tests=[AWL=0.006]
X-Spam-Score: 0.006
X-Spam-Level: 
X-Archive-Number: 200510/463
X-Sequence-Number: 15231

Svenne Krap <svenne@krap.dk> writes:
> create view ord_institutes_sum as
>  SELECT ord_property_type_all.dataset_id, ord_property_type_all.nb_property_type_id, 0 AS institut, sum(ord_property_type_all.amount) AS amount
>    FROM ord_property_type_all
>  GROUP BY ord_property_type_all.dataset_id, ord_property_type_all.nb_property_type_id;

> create view ord_result_pct as
>  SELECT t1.dataset_id, t1.nb_property_type_id, t1.institut, t1.amount / t2.amount * 100::numeric AS pct
>    FROM ord_property_type_all t1, ord_institutes_sum t2
>   WHERE t1.dataset_id = t2.dataset_id AND t1.nb_property_type_id = t2.nb_property_type_id;

This is really pretty horrid code: you're requesting double evaluation
of the ord_property_type_all view, and then joining the two calculations
to each other.  No, the planner will not detect how silly this is :-(,
nor will it realize that there's guaranteed to be a match for every row
--- I believe the latter is the reason for the serious misestimation
that Steinar noted.  The misestimation doesn't hurt particularly when
evaluating ord_result_pct by itself, because there are no higher-level
decisions to make ... but it hurts a lot when you join ord_result_pct to
some other stuff.

It seems like there must be a way to get the percentage amounts with
only one evaluation of ord_property_type_all, but I'm not seeing it
right offhand.

			regards, tom lane

From pgsql-performance-owner@postgresql.org  Sun Oct 30 14:32:14 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id B9BFCDB411
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 30 Oct 2005 14:32:11 -0400 (AST)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 97628-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 30 Oct 2005 18:32:09 +0000 (GMT)
Received: from cicero2.cybercity.dk (cicero2.cybercity.dk [212.242.40.53])
	by svr1.postgresql.org (Postfix) with ESMTP id A1B42DB40F
	for <pgsql-performance@postgresql.org>;
	Sun, 30 Oct 2005 14:32:06 -0400 (AST)
Received: from [192.168.0.79] (0x3e42eeca.adsl.cybercity.dk [62.66.238.202])
	by cicero2.cybercity.dk (Postfix) with ESMTP
	id 5BFA818FCC3; Sun, 30 Oct 2005 19:32:03 +0100 (CET)
Message-ID: <436511DF.5020800@krap.dk>
Date: Sun, 30 Oct 2005 19:33:03 +0100
From: Svenne Krap <svenne@krap.dk>
User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: "Steinar H. Gunderson" <sgunderson@bigfoot.com>
Cc: PgSQL Performance <pgsql-performance@postgresql.org>
Subject: Re: multi-layered view join performance oddities
References: <4364FFD4.2020801@krap.dk> <20051030174450.GA22399@uio.no>
In-Reply-To: <20051030174450.GA22399@uio.no>
Content-Type: multipart/alternative;
	boundary="------------070008080702050201010600"
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.473 required=5 tests=[AWL=-0.473, HTML_10_20=0.945,
	HTML_MESSAGE=0.001]
X-Spam-Score: 0.473
X-Spam-Level: 
X-Archive-Number: 200510/464
X-Sequence-Number: 15232

This is a multi-part message in MIME format.
--------------070008080702050201010600
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Hi.

Your suggestion with disableing the nested loop really worked well:

rkr=# set enable_nestloop=false;
SET
rkr=# explain analyze select * from ord_result_pct_pretty ;
                                                                        
QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------------------------------
 Hash Join  (cost=230.06..337.49 rows=1 width=174) (actual 
time=21.893..42.356 rows=2250 loops=1)
   Hash Cond: (("outer".dataset_id = "inner".dataset_id) AND 
("outer".nb_property_type_id = "inner".nb_property_type_id))
   ->  Hash Join  (cost=56.94..164.10 rows=26 width=93) (actual 
time=5.073..17.906 rows=2532 loops=1)
         Hash Cond: ("outer".dataset_id = "inner".id)
         ->  Hash Join  (cost=55.54..161.63 rows=161 width=57) (actual 
time=4.996..14.775 rows=2532 loops=1)
               Hash Cond: ("outer".institut = "inner".id)
               ->  Append  (cost=54.38..121.72 rows=2476 width=44) 
(actual time=4.964..11.827 rows=2532 loops=1)
                     ->  HashAggregate  (cost=54.38..57.20 rows=226 
width=16) (actual time=4.964..5.174 rows=282 loops=1)
                           ->  Seq Scan on ord_entrydata_current  
(cost=0.00..37.50 rows=2250 width=16) (actual time=0.002..1.305 
rows=2250 loops=1)
                     ->  Subquery Scan "*SELECT* 2"  (cost=0.00..60.00 
rows=2250 width=20) (actual time=0.009..4.948 rows=2250 loops=1)
                           ->  Seq Scan on ord_entrydata_current  
(cost=0.00..37.50 rows=2250 width=20) (actual time=0.003..2.098 
rows=2250 loops=1)
               ->  Hash  (cost=1.13..1.13 rows=13 width=17) (actual 
time=0.022..0.022 rows=13 loops=1)
                     ->  Seq Scan on groups g  (cost=0.00..1.13 rows=13 
width=17) (actual time=0.003..0.013 rows=13 loops=1)
         ->  Hash  (cost=1.32..1.32 rows=32 width=36) (actual 
time=0.070..0.070 rows=32 loops=1)
               ->  Seq Scan on ord_dataset od  (cost=0.00..1.32 rows=32 
width=36) (actual time=0.009..0.043 rows=32 loops=1)
                     Filter: is_visible
   ->  Hash  (cost=173.07..173.07 rows=10 width=97) (actual 
time=15.472..15.472 rows=256 loops=1)
         ->  Hash Join  (cost=166.15..173.07 rows=10 width=97) (actual 
time=14.666..15.203 rows=256 loops=1)
               Hash Cond: ("outer".nb_property_type_id = "inner".id)
               ->  HashAggregate  (cost=165.05..168.15 rows=248 
width=40) (actual time=14.619..14.849 rows=288 loops=1)
                     ->  Append  (cost=54.38..121.72 rows=2476 width=44) 
(actual time=5.012..11.130 rows=2532 loops=1)
                           ->  HashAggregate  (cost=54.38..57.20 
rows=226 width=16) (actual time=5.011..5.222 rows=282 loops=1)
                                 ->  Seq Scan on ord_entrydata_current  
(cost=0.00..37.50 rows=2250 width=16) (actual time=0.001..1.261 
rows=2250 loops=1)
                           ->  Subquery Scan "*SELECT* 2"  
(cost=0.00..60.00 rows=2250 width=20) (actual time=0.010..4.308 
rows=2250 loops=1)
                                 ->  Seq Scan on ord_entrydata_current  
(cost=0.00..37.50 rows=2250 width=20) (actual time=0.002..1.694 
rows=2250 loops=1)
               ->  Hash  (cost=1.08..1.08 rows=8 width=57) (actual 
time=0.026..0.026 rows=8 loops=1)
                     ->  Seq Scan on nb_property_type npt  
(cost=0.00..1.08 rows=8 width=57) (actual time=0.004..0.019 rows=8 loops=1)
 Total runtime: 43.297 ms
(28 rows)

Now, the whole question becomes, how do I get the planner to make a 
better estimation of the returned rows.

I am not sure, I can follow your moving-the-union-all-further-out 
advice, as I see no different place for the unioning of the two datasets.

Maybe one of the core devs know, where to fiddle :)

Svenne

Steinar H. Gunderson wrote:

>On Sun, Oct 30, 2005 at 06:16:04PM +0100, Svenne Krap wrote:
>  
>
>> Nested Loop  (cost=223.09..338.61 rows=1 width=174) (actual time=20.213..721.361 rows=2250 loops=1)
>>   Join Filter: (("outer".dataset_id = "inner".dataset_id) AND ("outer".nb_property_type_id = "inner".nb_property_type_id))
>>   ->  Hash Join  (cost=58.04..164.26 rows=1 width=150) (actual time=5.510..22.088 rows=2250 loops=1)
>>    
>>
>
>There's horrible misestimation here. It expects one row and thus starts a
>nested loop, but gets 2250. No wonder it's slow :-)
>
>The misestimation can be traced all the way down here:
>
>  
>
>>         Hash Cond: ("outer".institut = "inner".id)
>>         ->  Hash Join  (cost=56.88..163.00 rows=16 width=137) (actual time=5.473..19.165 rows=2250 loops=1)
>>               Hash Cond: ("outer".dataset_id = "inner".id)
>>               ->  Hash Join  (cost=55.48..160.95 rows=99 width=101) (actual time=5.412..16.264 rows=2250 loops=1)
>>    
>>
>
>where the planner misestimates the selectivity of your join (it estimates 99
>rows, and there are 2250).
>
>I've had problems joining with Append nodes in the past, and solved the
>problem by moving the UNION ALL a bit out, but I'm not sure if it's a very
>good general solution, or a solution to your problems here.
>
>If all else fails, you could "set enable_nestloop=false", but that is not a
>good idea in the long run, I'd guess -- it's much better to make sure the
>planner has good estimates and let it do the correct decisions from there.
>
>/* Steinar */
>  
>


--------------070008080702050201010600
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content=3D"text/html;charset=3DUTF-8" http-equiv=3D"Content-Type"=
>
</head>
<body bgcolor=3D"#ffffff" text=3D"#000000">
Hi.<br>
<br>
Your suggestion with disableing the nested loop really worked well: <br>
<br>
rkr=3D# set enable_nestloop=3Dfalse;<br>
SET<br>
rkr=3D# explain analyze select * from ord_result_pct_pretty ;<br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0
QUERY PLAN<br>
-------------------------------------------------------------------------=
-------------------------------------------------------------------------=
---------<br>
=C2=A0Hash Join=C2=A0 (cost=3D230.06..337.49 rows=3D1 width=3D174) (actua=
l
time=3D21.893..42.356 rows=3D2250 loops=3D1)<br>
=C2=A0=C2=A0 Hash Cond: (("outer".dataset_id =3D "inner".dataset_id) AND
("outer".nb_property_type_id =3D "inner".nb_property_type_id))<br>
=C2=A0=C2=A0 -&gt;=C2=A0 Hash Join=C2=A0 (cost=3D56.94..164.10 rows=3D26 =
width=3D93) (actual
time=3D5.073..17.906 rows=3D2532 loops=3D1)<br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Hash Cond: ("outer".data=
set_id =3D "inner".id)<br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 -&gt;=C2=A0 Hash Join=C2=
=A0 (cost=3D55.54..161.63 rows=3D161 width=3D57)
(actual time=3D4.996..14.775 rows=3D2532 loops=3D1)<br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0 Hash Cond: ("outer".institut =3D "inner".id)<br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0 -&gt;=C2=A0 Append=C2=A0 (cost=3D54.38..121.72 rows=3D2476 widt=
h=3D44)
(actual time=3D4.964..11.827 rows=3D2532 loops=3D1)<br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 -&gt;=C2=A0 HashAggregate=C2=
=A0 (cost=3D54.38..57.20 rows=3D226
width=3D16) (actual time=3D4.964..5.174 rows=3D282 loops=3D1)<br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0 -&gt;=C2=A0 Seq Scan on ord_entrydata_current=C2=A0
(cost=3D0.00..37.50 rows=3D2250 width=3D16) (actual time=3D0.002..1.305
rows=3D2250 loops=3D1)<br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 -&gt;=C2=A0 Subquery Scan "=
*SELECT* 2"=C2=A0
(cost=3D0.00..60.00 rows=3D2250 width=3D20) (actual time=3D0.009..4.948
rows=3D2250 loops=3D1)<br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0 -&gt;=C2=A0 Seq Scan on ord_entrydata_current=C2=A0
(cost=3D0.00..37.50 rows=3D2250 width=3D20) (actual time=3D0.003..2.098
rows=3D2250 loops=3D1)<br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0 -&gt;=C2=A0 Hash=C2=A0 (cost=3D1.13..1.13 rows=3D13 width=3D17)=
 (actual
time=3D0.022..0.022 rows=3D13 loops=3D1)<br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 -&gt;=C2=A0 Seq Scan on gro=
ups g=C2=A0 (cost=3D0.00..1.13
rows=3D13 width=3D17) (actual time=3D0.003..0.013 rows=3D13 loops=3D1)<br=
>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 -&gt;=C2=A0 Hash=C2=A0 (=
cost=3D1.32..1.32 rows=3D32 width=3D36) (actual
time=3D0.070..0.070 rows=3D32 loops=3D1)<br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0 -&gt;=C2=A0 Seq Scan on ord_dataset od=C2=A0 (cost=3D0.00..1.32=

rows=3D32 width=3D36) (actual time=3D0.009..0.043 rows=3D32 loops=3D1)<br=
>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Filter: is_visible<br>
=C2=A0=C2=A0 -&gt;=C2=A0 Hash=C2=A0 (cost=3D173.07..173.07 rows=3D10 widt=
h=3D97) (actual
time=3D15.472..15.472 rows=3D256 loops=3D1)<br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 -&gt;=C2=A0 Hash Join=C2=
=A0 (cost=3D166.15..173.07 rows=3D10 width=3D97)
(actual time=3D14.666..15.203 rows=3D256 loops=3D1)<br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0 Hash Cond: ("outer".nb_property_type_id =3D "inner".id)<br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0 -&gt;=C2=A0 HashAggregate=C2=A0 (cost=3D165.05..168.15 rows=3D2=
48
width=3D40) (actual time=3D14.619..14.849 rows=3D288 loops=3D1)<br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 -&gt;=C2=A0 Append=C2=A0 (c=
ost=3D54.38..121.72 rows=3D2476
width=3D44) (actual time=3D5.012..11.130 rows=3D2532 loops=3D1)<br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0 -&gt;=C2=A0 HashAggregate=C2=A0 (cost=3D54.38..57.20
rows=3D226 width=3D16) (actual time=3D5.011..5.222 rows=3D282 loops=3D1)<=
br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 -&gt;=C2=A0 Seq Scan on
ord_entrydata_current=C2=A0 (cost=3D0.00..37.50 rows=3D2250 width=3D16) (=
actual
time=3D0.001..1.261 rows=3D2250 loops=3D1)<br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0 -&gt;=C2=A0 Subquery Scan "*SELECT* 2"=C2=A0
(cost=3D0.00..60.00 rows=3D2250 width=3D20) (actual time=3D0.010..4.308
rows=3D2250 loops=3D1)<br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 -&gt;=C2=A0 Seq Scan on
ord_entrydata_current=C2=A0 (cost=3D0.00..37.50 rows=3D2250 width=3D20) (=
actual
time=3D0.002..1.694 rows=3D2250 loops=3D1)<br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0 -&gt;=C2=A0 Hash=C2=A0 (cost=3D1.08..1.08 rows=3D8 width=3D57) =
(actual
time=3D0.026..0.026 rows=3D8 loops=3D1)<br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 -&gt;=C2=A0 Seq Scan on nb_=
property_type npt=C2=A0
(cost=3D0.00..1.08 rows=3D8 width=3D57) (actual time=3D0.004..0.019 rows=3D=
8
loops=3D1)<br>
=C2=A0Total runtime: 43.297 ms<br>
(28 rows)<br>
<br>
Now, the whole question becomes, how do I get the planner to make a
better estimation of the returned rows. <br>
<br>
I am not sure, I can follow your moving-the-union-all-further-out
advice, as I see no different place for the unioning of the two
datasets.<br>
<br>
Maybe one of the core devs know, where to fiddle :)<br>
<br>
Svenne<br>
<br>
Steinar H. Gunderson wrote:
<blockquote cite=3D"mid20051030174450.GA22399@uio.no" type=3D"cite">
  <pre wrap=3D"">On Sun, Oct 30, 2005 at 06:16:04PM +0100, Svenne Krap wr=
ote:
  </pre>
  <blockquote type=3D"cite">
    <pre wrap=3D""> Nested Loop  (cost=3D223.09..338.61 rows=3D1 width=3D=
174) (actual time=3D20.213..721.361 rows=3D2250 loops=3D1)
   Join Filter: (("outer".dataset_id =3D "inner".dataset_id) AND ("outer"=
=2Enb_property_type_id =3D "inner".nb_property_type_id))
   -&gt;  Hash Join  (cost=3D58.04..164.26 rows=3D1 width=3D150) (actual =
time=3D5.510..22.088 rows=3D2250 loops=3D1)
    </pre>
  </blockquote>
  <pre wrap=3D""><!---->
There's horrible misestimation here. It expects one row and thus starts a=

nested loop, but gets 2250. No wonder it's slow :-)

The misestimation can be traced all the way down here:

  </pre>
  <blockquote type=3D"cite">
    <pre wrap=3D"">         Hash Cond: ("outer".institut =3D "inner".id)
         -&gt;  Hash Join  (cost=3D56.88..163.00 rows=3D16 width=3D137) (=
actual time=3D5.473..19.165 rows=3D2250 loops=3D1)
               Hash Cond: ("outer".dataset_id =3D "inner".id)
               -&gt;  Hash Join  (cost=3D55.48..160.95 rows=3D99 width=3D=
101) (actual time=3D5.412..16.264 rows=3D2250 loops=3D1)
    </pre>
  </blockquote>
  <pre wrap=3D""><!---->
where the planner misestimates the selectivity of your join (it estimates=
 99
rows, and there are 2250).

I've had problems joining with Append nodes in the past, and solved the
problem by moving the UNION ALL a bit out, but I'm not sure if it's a ver=
y
good general solution, or a solution to your problems here.

If all else fails, you could "set enable_nestloop=3Dfalse", but that is n=
ot a
good idea in the long run, I'd guess -- it's much better to make sure the=

planner has good estimates and let it do the correct decisions from there=
=2E

/* Steinar */
  </pre>
</blockquote>
<br>
</body>
</html>

--------------070008080702050201010600--

From pgsql-performance-owner@postgresql.org  Sun Oct 30 14:48:10 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 0FB5EDB436
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 30 Oct 2005 14:48:08 -0400 (AST)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 05704-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 30 Oct 2005 18:48:06 +0000 (GMT)
Received: from cicero1.cybercity.dk (cicero1.cybercity.dk [212.242.40.4])
	by svr1.postgresql.org (Postfix) with ESMTP id D6240DB434
	for <pgsql-performance@postgresql.org>;
	Sun, 30 Oct 2005 14:48:05 -0400 (AST)
Received: from [192.168.0.79] (0x3e42eeca.adsl.cybercity.dk [62.66.238.202])
	by cicero1.cybercity.dk (Postfix) with ESMTP
	id 1B0CA7E39EB; Sun, 30 Oct 2005 19:48:04 +0100 (CET)
Message-ID: <436515A6.8040909@krap.dk>
Date: Sun, 30 Oct 2005 19:49:10 +0100
From: Svenne Krap <svenne@krap.dk>
User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: PgSQL Performance <pgsql-performance@postgresql.org>
Subject: Re: multi-layered view join performance oddities
References: <4364FFD4.2020801@krap.dk> <13993.1130696821@sss.pgh.pa.us>
In-Reply-To: <13993.1130696821@sss.pgh.pa.us>
Content-Type: multipart/alternative;
	boundary="------------010502090203050105080605"
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.095 required=5 tests=[AWL=0.094,
 HTML_MESSAGE=0.001]
X-Spam-Score: 0.095
X-Spam-Level: 
X-Archive-Number: 200510/465
X-Sequence-Number: 15233

This is a multi-part message in MIME format.
--------------010502090203050105080605
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Tom Lane wrote:

>Svenne Krap <svenne@krap.dk> writes:
>  
>
>>create view ord_institutes_sum as
>> SELECT ord_property_type_all.dataset_id, ord_property_type_all.nb_property_type_id, 0 AS institut, sum(ord_property_type_all.amount) AS amount
>>   FROM ord_property_type_all
>> GROUP BY ord_property_type_all.dataset_id, ord_property_type_all.nb_property_type_id;
>>    
>>
>
>  
>
>>create view ord_result_pct as
>> SELECT t1.dataset_id, t1.nb_property_type_id, t1.institut, t1.amount / t2.amount * 100::numeric AS pct
>>   FROM ord_property_type_all t1, ord_institutes_sum t2
>>  WHERE t1.dataset_id = t2.dataset_id AND t1.nb_property_type_id = t2.nb_property_type_id;
>>    
>>
>
>This is really pretty horrid code: you're requesting double evaluation
>of the ord_property_type_all view, and then joining the two calculations
>to each other.  No, the planner will not detect how silly this is :-(,
>nor will it realize that there's guaranteed to be a match for every row
>--- I believe the latter is the reason for the serious misestimation
>that Steinar noted.  The misestimation doesn't hurt particularly when
>evaluating ord_result_pct by itself, because there are no higher-level
>decisions to make ... but it hurts a lot when you join ord_result_pct to
>some other stuff.
>  
>
I don't really see, how this query is horrid from a user perspective, 
this is exactly the way, the percentage has to be calculated from a 
"philosophical" standpoint (performance considerations left out).
This is very bad news for me, as most of the other (much larger) queries 
have the same issue, that the views will be used multiple times got get 
slightly different data, that has to be joined (also more than 2 times 
as in this case)

I think, it has to run multiple times as it returns two different types 
of data.

>It seems like there must be a way to get the percentage amounts with
>only one evaluation of ord_property_type_all, but I'm not seeing it
>right offhand.
>  
>

I will think about how to remove the second evaluation of the view in 
question, if anyone knows how, a hint is very appriciated :)

I could of course go the "materialized view" way, but would really 
prefer not to.

Svenne

--------------010502090203050105080605
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Tom Lane wrote:
<blockquote cite="mid13993.1130696821@sss.pgh.pa.us" type="cite">
  <pre wrap="">Svenne Krap <a class="moz-txt-link-rfc2396E" href="mailto:svenne@krap.dk">&lt;svenne@krap.dk&gt;</a> writes:
  </pre>
  <blockquote type="cite">
    <pre wrap="">create view ord_institutes_sum as
 SELECT ord_property_type_all.dataset_id, ord_property_type_all.nb_property_type_id, 0 AS institut, sum(ord_property_type_all.amount) AS amount
   FROM ord_property_type_all
 GROUP BY ord_property_type_all.dataset_id, ord_property_type_all.nb_property_type_id;
    </pre>
  </blockquote>
  <pre wrap=""><!---->
  </pre>
  <blockquote type="cite">
    <pre wrap="">create view ord_result_pct as
 SELECT t1.dataset_id, t1.nb_property_type_id, t1.institut, t1.amount / t2.amount * 100::numeric AS pct
   FROM ord_property_type_all t1, ord_institutes_sum t2
  WHERE t1.dataset_id = t2.dataset_id AND t1.nb_property_type_id = t2.nb_property_type_id;
    </pre>
  </blockquote>
  <pre wrap=""><!---->
This is really pretty horrid code: you're requesting double evaluation
of the ord_property_type_all view, and then joining the two calculations
to each other.  No, the planner will not detect how silly this is :-(,
nor will it realize that there's guaranteed to be a match for every row
--- I believe the latter is the reason for the serious misestimation
that Steinar noted.  The misestimation doesn't hurt particularly when
evaluating ord_result_pct by itself, because there are no higher-level
decisions to make ... but it hurts a lot when you join ord_result_pct to
some other stuff.
  </pre>
</blockquote>
I don't really see, how this query is horrid from a user perspective,
this is exactly the way, the percentage has to be calculated from a
"philosophical" standpoint (performance considerations left out). <br>
This is very bad news for me, as most of the other (much larger)
queries have the same issue, that the views will be used multiple times
got get slightly different data, that has to be joined (also more than
2 times as in this case)<br>
<br>
I think, it has to run multiple times as it returns two different types
of data. <br>
<br>
<blockquote cite="mid13993.1130696821@sss.pgh.pa.us" type="cite">
  <pre wrap="">It seems like there must be a way to get the percentage amounts with
only one evaluation of ord_property_type_all, but I'm not seeing it
right offhand.
  </pre>
</blockquote>
<br>
I will think about how to remove the second evaluation of the view in
question, if anyone knows how, a hint is very appriciated :)<br>
<br>
I could of course go the "materialized view" way, but would really
prefer not to.<br>
<br>
Svenne<br>
</body>
</html>

--------------010502090203050105080605--

From pgsql-performance-owner@postgresql.org  Sun Oct 30 16:16:29 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 0E7CDDB40F
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 30 Oct 2005 16:16:29 -0400 (AST)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 56125-06
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Sun, 30 Oct 2005 20:16:23 +0000 (GMT)
Received: from h1.bettercom.de (h1.bettercom.de [213.239.194.41])
	by svr1.postgresql.org (Postfix) with ESMTP id BD2CEDB3BF
	for <pgsql-performance@postgresql.org>;
	Sun, 30 Oct 2005 16:16:23 -0400 (AST)
Received: (qmail 22605 invoked by uid 208); 30 Oct 2005 20:16:20 -0000
Received: from 80.171.82.228 by h1 (envelope-from <ml-pgsql@bettercom.de>,
	uid 0) with qmail-scanner-1.23
	(clamdscan: 0.87. spamassassin: 3.04.  Clear:RC:1(80.171.82.228):.
	Processed in 0.15354 secs); 30 Oct 2005 20:16:20 -0000
Received: from unknown (HELO nb-aspire.bettercom.de) ([80.171.82.228])
	(envelope-sender <ml-pgsql@bettercom.de>)
	by h1.bettercom.de (qmail-ldap-1.03) with SMTP
	for <pgsql-performance@postgresql.org>; 30 Oct 2005 20:16:20 -0000
Received: (nullmailer pid 4657 invoked by uid 1000);
	Sun, 30 Oct 2005 20:16:20 -0000
Subject: Re: Effects of cascading references in foreign keys
X-PGP-Key: http://bettercom.de/misc/3A547DE6.asc
X-Face: 
 "d[&>8')a)wbF:+L#^<_cohnX6#m5RCCeKF/6_gD(iQ9bX?xe2~Aq*!')D(1ks`?YhomOYbL3R:{4e4a]qft_]<.q/Lf4hIr,`G+LX33&TYp}XGf<b?+GPT;
	3I8k/|[DR#MO1N(h>e~^5m$28R"$C(EwnB\n8t
In-Reply-To: <200510301410.j9UEAnj02881@candle.pha.pa.us> (Bruce Momjian's
	message of "Sun, 30 Oct 2005 09:10:49 -0500 (EST)")
References: <200510301410.j9UEAnj02881@candle.pha.pa.us>
To: pgsql-performance@postgresql.org
From: Martin Lesser <ml-pgsql@bettercom.de>
Date: Sun, 30 Oct 2005 21:16:20 +0100
Message-ID: <87fyqiu5ez.fsf@nb-aspire.bettercom.de>
User-Agent: Gnus/5.1007 (Gnus v5.10.7) XEmacs/21.4 (Jumbo Shrimp, linux)
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0 required=5 tests=[none]
X-Spam-Score: 0
X-Spam-Level: 
X-Archive-Number: 200510/466
X-Sequence-Number: 15234

Bruce Momjian <pgman@candle.pha.pa.us> writes:

> Thomas F. O'Connell wrote:
>> It seems like this warrants an item somewhere in the release notes,  
>> and I'm not currently seeing it (or a related item) anywhere. Perhaps  
>> E.1.3.1 (Performance Improvements)? For some of the more extreme  
>> UPDATE scenarios I've seen, this could be a big win.
> Hard to say, perhaps:
>
> 	Prevent referential integrity triggers from firing if referenced
> 	columns are not changed by an UPDATE
>
> 	Previously, triggers would fire but do nothing.

And this "firing" has negative effects for the performance at least in
versions before 8.1 (we use 8.0.3 in our production).

One really dirty hack that comes in mind is to put an additional
pk_table (with only one field, the pk from the master) between the
"master"-table and the ~30 detail-tables so each update in the "master"
would in most cases only trigger a lookup in one table. Only if a pk was
really changed the CASCADEd trigger would force a triggered UPDATE in
the detail-tables.

After denormalization of two of the largest detail-tables into one table
the performance improvement was about 10% due to the fact that up to 1
mio. of rows (of about 30 mio) in the "master"-table are updated daily
and triggered a lookup in 190 mio. rows (before denormalization)
resp. 115 rows (after denormalization).

From pgsql-performance-owner@postgresql.org  Mon Oct 31 05:49:35 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id E22E7DB528
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 31 Oct 2005 05:49:33 -0400 (AST)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 95535-04
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 31 Oct 2005 09:48:32 +0000 (GMT)
Received: from floppy.pyrenet.fr (floppy.pyrenet.fr [194.116.145.2])
	by svr1.postgresql.org (Postfix) with ESMTP id CF38FDB4DE
	for <pgsql-performance@postgresql.org>;
	Mon, 31 Oct 2005 05:48:32 -0400 (AST)
Received: by floppy.pyrenet.fr (Postfix, from userid 106)
	id B847A31059; Mon, 31 Oct 2005 10:48:34 +0100 (MET)
From: "Qingqing Zhou" <zhouqq@cs.toronto.edu>
X-Newsgroups: pgsql.performance
Subject: Re: performance of implicit join vs. explicit conditions on inet
	queries?
Date: Mon, 31 Oct 2005 04:48:41 -0500
Organization: Hub.Org Networking Services
Lines: 92
Message-ID: <dk4p9d$30q4$1@news.hub.org>
References: <20051024035809.GA18261@edmonds.ath.cx>
X-Complaints-To: usenet@news.hub.org
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-RFC2646: Format=Flowed; Original
To: pgsql-performance@postgresql.org
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.718 required=5 tests=[AWL=0.442,
	MAILTO_TO_SPAM_ADDR=0.276]
X-Spam-Score: 0.718
X-Spam-Level: 
X-Archive-Number: 200510/467
X-Sequence-Number: 15235

"Robert Edmonds" <edmonds42@bellsouth.net> wrote
>
> EXPLAIN ANALYZE
> SELECT *
>  FROM inet_addresses
> WHERE addr << inet('10.2.0.0/24')
>    OR addr << inet('10.4.0.0/24')
>    OR addr << inet('10.8.0.0/24');
>
> Bitmap Heap Scan on inet_addresses  (cost=6.51..324.48 rows=1792335 
> width=11) (actual time=0.350..1.104 rows=381 loops=1)
>   Recheck Cond: ((addr << '10.2.0.0/24'::inet) OR (addr << 
> '10.4.0.0/24'::inet) OR (addr << '10.8.0.0/24'::inet))
>   Filter: ((addr << '10.2.0.0/24'::inet) OR (addr << '10.4.0.0/24'::inet) 
> OR (addr << '10.8.0.0/24'::inet))
>   ->  BitmapOr  (cost=6.51..6.51 rows=85 width=0) (actual 
> time=0.336..0.336 rows=0 loops=1)
>         ->  Bitmap Index Scan on inet_addresses_pkey  (cost=0.00..2.17 
> rows=28 width=0) (actual time=0.127..0.127 rows=127 loops=1)
>               Index Cond: ((addr > '10.2.0.0/24'::inet) AND (addr <= 
> '10.2.0.255'::inet))
>         ->  Bitmap Index Scan on inet_addresses_pkey  (cost=0.00..2.17 
> rows=28 width=0) (actual time=0.109..0.109 rows=127 loops=1)
>               Index Cond: ((addr > '10.4.0.0/24'::inet) AND (addr <= 
> '10.4.0.255'::inet))
>         ->  Bitmap Index Scan on inet_addresses_pkey  (cost=0.00..2.17 
> rows=28 width=0) (actual time=0.096..0.096 rows=127 loops=1)
>               Index Cond: ((addr > '10.8.0.0/24'::inet) AND (addr <= 
> '10.8.0.255'::inet))
> Total runtime: 1.613 ms
>
>
>    Instead of specifying explicit address ranges in the query, I'd like
>    to store the ranges in a table:
>
>
> inet_test_db=# \d inet_ranges
>   Table "public.inet_ranges"
>  Column  |  Type   | Modifiers
> ----------+---------+-----------
> range    | inet    | not null
> range_id | integer |
> Indexes:
>    "inet_ranges_pkey" PRIMARY KEY, btree (range)
>    "inet_ranges_range_id_idx" btree (range_id)
>
> inet_test_db=# SELECT * FROM inet_ranges;
>    range     | range_id
> --------------+----------
> 10.2.0.0/24  |        1
> 10.4.0.0/24  |        1
> 10.8.0.0/24  |        1
> 10.16.0.0/24 |        2
> 10.32.0.0/24 |        2
> 10.64.0.0/24 |        2
> (6 rows)
>
>
>
> EXPLAIN ANALYZE
> SELECT *
>  FROM inet_addresses as ia, inet_ranges as ir
> WHERE ia.addr << ir.range
>   AND ir.range_id=1;
>
> Nested Loop  (cost=0.00..171485.93 rows=3072574 width=26) (actual 
> time=1465.803..16922.979 rows=381 loops=1)
>   Join Filter: ("inner".addr << "outer".range)
>   ->  Seq Scan on inet_ranges ir  (cost=0.00..1.07 rows=3 width=15) 
> (actual time=0.008..0.021 rows=3 loops=1)
>         Filter: (range_id = 1)
>   ->  Seq Scan on inet_addresses ia  (cost=0.00..31556.83 rows=2048383 
> width=11) (actual time=0.003..2919.405 rows=2048383 loops=3)
> Total runtime: 16923.457 ms
>

Good illustration. I guess we have a problem of the historgram statistical 
information. That is, the historgrams we used can effectively record the 
linear space ranges(like ordinary <, >, =), but failed to do it for 
nonlinear ranges like inet data type. So the Nested Loop node make an error 
in estmating number of rows (est: 3072574, real: 381), thus a sequential 
scan is obviously better under this estimation.

I am thinking the historgram problem is not easy to fix, but is there a way 
to change Inet type a little bit to make it linear for your range operators? 
(for example, align the length to 000.000.000.000/00?)

Regards,
Qingqing




From pgsql-performance-owner@postgresql.org  Mon Oct 31 09:43:19 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 32169D8127
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 31 Oct 2005 09:43:18 -0400 (AST)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 83523-10
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 31 Oct 2005 13:43:14 +0000 (GMT)
Received: from out3.smtp.messagingengine.com (out3.smtp.messagingengine.com
	[66.111.4.27])
	by svr1.postgresql.org (Postfix) with ESMTP id 68716D8043
	for <pgsql-performance@postgresql.org>;
	Mon, 31 Oct 2005 09:43:16 -0400 (AST)
Received: from frontend1.internal (mysql-sessions.internal [10.202.2.149])
	by frontend1.messagingengine.com (Postfix) with ESMTP id 6205CCD72EA;
	Mon, 31 Oct 2005 08:43:19 -0500 (EST)
Received: from frontend2.messagingengine.com ([10.202.2.151])
	by frontend1.internal (MEProxy); Mon, 31 Oct 2005 08:43:19 -0500
X-Sasl-enc: dLh5is3gOxouDs/jj8w8C/vuaXzlGFcm/XQE5gGeAO3I 1130766198
Received: from [149.182.235.91] (unknown [129.230.248.1])
	by frontend2.messagingengine.com (Postfix) with ESMTP id 4DF9257070D;
	Mon, 31 Oct 2005 08:43:17 -0500 (EST)
Message-ID: <43661F70.6060006@diroussel.xsmail.com>
Date: Mon, 31 Oct 2005 13:43:12 +0000
From: David Roussel <pgsql-performance@diroussel.xsmail.com>
User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: Rodrigo Madera <rodrigo.madera@gmail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Best way to check for new data.
References: <3cf983d0510281439s648fac45vbd7af544eeca4fc3@mail.gmail.com>
In-Reply-To: <3cf983d0510281439s648fac45vbd7af544eeca4fc3@mail.gmail.com>
Content-Type: multipart/alternative;
	boundary="------------090204000504050705010008"
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.001 required=5 tests=[HTML_MESSAGE=0.001]
X-Spam-Score: 0.001
X-Spam-Level: 
X-Archive-Number: 200510/468
X-Sequence-Number: 15236

This is a multi-part message in MIME format.
--------------090204000504050705010008
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit

Rodrigo Madera wrote:

> I have a table that holds entries as in a ficticious table Log(id 
> integer, msg text).
>  
> Lets say then that I have the program log_tail that has as it�s sole 
> purpose to print newly added data elements.
>  
> What is the best solution in terms of performace?

I have a system that does this.  We do it by PK, the PK is bigint, and 
always increases, the client remembers the last key seen as queries 
based on that key...

select ... where events.event_id > ?::bigint order by events.event_id 
limit 2000

it works, but when alot of data is added, it can become sensative to the 
index statistics getting out of sync with the data.  Best to insert, 
then update the statistics, then read the data.  For us these three 
activities are independent, but it still seems to work.

I'd investigate the notify mechanism suggested by Otto if you can afford 
to use a postgres specific mechanism like that.

David



--------------090204000504050705010008
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#333333">
Rodrigo Madera wrote:
<blockquote
 cite="mid3cf983d0510281439s648fac45vbd7af544eeca4fc3@mail.gmail.com"
 type="cite">
  <meta http-equiv="Context-Type"
 content="text/html; charset=ISO-8859-1">
  <div>I have a table that holds entries as in a ficticious table
Log(id integer, msg text).</div>
  <div>&nbsp;</div>
  <div>Lets say then that I have the program log_tail that has as it&acute;s
sole purpose to print newly added data elements.</div>
  <div>&nbsp;</div>
  <div>What is the best solution in terms of performace?</div>
</blockquote>
I have a system that does this.&nbsp; We do it by PK, the PK is bigint, and
always increases, the client remembers the last key seen as queries
based on that key...<br>
<br>
select ... where events.event_id &gt; ?::bigint order by
events.event_id limit 2000<br>
<br>
it works, but when alot of data is added, it can become sensative to
the index statistics getting out of sync with the data.&nbsp; Best to
insert, then update the statistics, then read the data.&nbsp; For us these
three activities are independent, but it still seems to work.<br>
<br>
I'd investigate the notify mechanism suggested by Otto if you can
afford to use a postgres specific mechanism like that.<br>
<br>
David<br>
<br>
<br>
</body>
</html>

--------------090204000504050705010008--

From pgsql-performance-owner@postgresql.org  Mon Oct 31 09:47:30 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 0B2B3DB486
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 31 Oct 2005 09:47:28 -0400 (AST)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 87335-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 31 Oct 2005 13:47:24 +0000 (GMT)
Received: from Herge.rcsinc.local (mail.rcsonline.com [70.89.208.142])
	by svr1.postgresql.org (Postfix) with ESMTP id 8D8E0DADBA
	for <pgsql-performance@postgresql.org>;
	Mon, 31 Oct 2005 09:47:26 -0400 (AST)
X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0
Content-class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Subject: Re: Best way to check for new data.
Date: Mon, 31 Oct 2005 08:47:29 -0500
Message-ID: <6EE64EF3AB31D5448D0007DD34EEB3417DD719@Herge.rcsinc.local>
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
Thread-Topic: [PERFORM] Best way to check for new data.
Thread-Index: AcXcCJeQXSu4OZ9sQaSVOMEoWnI53QCF4GMg
From: "Merlin Moncure" <merlin.moncure@rcsonline.com>
To: "Rodrigo Madera" <rodrigo.madera@gmail.com>
Cc: <pgsql-performance@postgresql.org>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.054 required=5 tests=[AWL=0.054]
X-Spam-Score: 0.054
X-Spam-Level: 
X-Archive-Number: 200510/469
X-Sequence-Number: 15237

There are a few ways to do this...thinking about it a bit, I would add a =
timestamp column to your log table (indexed) and keep a control table =
which keeps track of the last log print sweep operation.

The print operation would just do=20
select * from log where logtime > (select lastlogtime());

The idea here is not to have to keep track of anything on the log table =
like a flag indicating print status, which will cause some bloat issues. =
 All you have to do is reindex once in a while.

lastlogtime() is a function which returns the last log time sweep from =
the control table.  we use a function declared immutable to force =
planner to treat as a constant (others might tell you to do different =
here).

Merlin

________________________________________
From: pgsql-performance-owner@postgresql.org =
[mailto:pgsql-performance-owner@postgresql.org] On Behalf Of Rodrigo =
Madera
Sent: Friday, October 28, 2005 5:39 PM
To: pgsql-performance@postgresql.org
Subject: [PERFORM] Best way to check for new data.

I have a table that holds entries as in a ficticious table Log(id =
integer, msg text).
=A0
Lets say then that I have the program log_tail that has as it=B4s sole =
purpose to print newly added data elements.
=A0
What is the best solution in terms of performace?
=A0
Thank you for your time,
Rodrigo
=A0

From pgsql-performance-owner@postgresql.org  Mon Oct 31 10:24:15 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 2A428DB52D
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 31 Oct 2005 10:24:14 -0400 (AST)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 05027-04
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 31 Oct 2005 14:24:10 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id 602B2DAB77
	for <pgsql-performance@postgresql.org>;
	Mon, 31 Oct 2005 10:24:12 -0400 (AST)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j9VEOA4L029865;
	Mon, 31 Oct 2005 09:24:10 -0500 (EST)
To: "Qingqing Zhou" <zhouqq@cs.toronto.edu>
Cc: pgsql-performance@postgresql.org, edmonds42@bellsouth.net
Subject: Re: performance of implicit join vs. explicit conditions on inet
	queries?
In-reply-to: <dk4p9d$30q4$1@news.hub.org> 
References: <20051024035809.GA18261@edmonds.ath.cx>
	<dk4p9d$30q4$1@news.hub.org>
Comments: In-reply-to "Qingqing Zhou" <zhouqq@cs.toronto.edu>
	message dated "Mon, 31 Oct 2005 04:48:41 -0500"
Date: Mon, 31 Oct 2005 09:24:10 -0500
Message-ID: <29864.1130768650@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.144 required=5 tests=[AWL=-0.132,
	MAILTO_TO_SPAM_ADDR=0.276]
X-Spam-Score: 0.144
X-Spam-Level: 
X-Archive-Number: 200510/470
X-Sequence-Number: 15238

"Qingqing Zhou" <zhouqq@cs.toronto.edu> writes:
> "Robert Edmonds" <edmonds42@bellsouth.net> wrote
>> Instead of specifying explicit address ranges in the query, I'd like
>> to store the ranges in a table:

> Good illustration. I guess we have a problem of the historgram statistical 
> information.

No, that's completely irrelevant to his problem.  The reason we can't do
this is that the transformation from "x << const" to a range check on x
is a plan-time transformation; there's no mechanism in place to do it
at runtime.  This is not easy to fix, because the mechanism that's doing
it is primarily intended for LIKE/regex index optimization, and in that
case a runtime pattern might well not be optimizable at all.

			regards, tom lane

From pgsql-performance-owner@postgresql.org  Mon Oct 31 10:29:36 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 3F1FBDA873
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 31 Oct 2005 10:29:35 -0400 (AST)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 08166-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 31 Oct 2005 14:29:31 +0000 (GMT)
Received: from my.endian.it (unknown [62.146.87.34])
	by svr1.postgresql.org (Postfix) with ESMTP id 7B2BDDA845
	for <pgsql-performance@postgresql.org>;
	Mon, 31 Oct 2005 10:29:32 -0400 (AST)
Received: from 192.168.1.2 (host118-59.pool8258.interbusiness.it
	[82.58.59.118]) (authenticated (0 bits))
	by my.endian.it (8.11.6/8.11.6) with ESMTP id j9VEP2c21318
	for <pgsql-performance@postgresql.org>; Mon, 31 Oct 2005 15:25:03 +0100
Subject: Re: SOLVED: insertion of bytea
From: Chris Mair <list@1006.org>
To: pgsql-performance@postgresql.org
In-Reply-To: <34757.193.206.186.101.1130420404.squirrel@www.endian.it>
References: <54222.193.206.186.101.1130247876.squirrel@www.endian.it>
	<20051025140549.GC17398@mathom.us>
	<34757.193.206.186.101.1130420404.squirrel@www.endian.it>
Content-Type: text/plain
Date: Mon, 31 Oct 2005 15:29:17 +0100
Message-Id: <1130768957.6383.37.camel@dell.1006.org>
Mime-Version: 1.0
X-Mailer: Evolution 2.0.2 (2.0.2-22) 
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0 required=5 tests=[none]
X-Spam-Score: 0
X-Spam-Level: 
X-Archive-Number: 200510/471
X-Sequence-Number: 15239


> I'm CPU-bound with an I/O well below what my disks could do :(
> [...]
> 
> PS1: someone off-list suggested using oprofile, which I will do.

I've used oprofile and found out that with my test client (lots of
bytea inserts) the server burns a lot of CPU time in pglz_compress.

I'm using random data and my production data will be closed to random
(due to noise!), so compression is of course pointless.

By using
alter table dbtest alter img set storage external;
I can tell the server not to compress.

On a test box this brought net insert rate up by 50%,
which is enough to meet the requirements.

Thanks again :)

Bye, Chris.





From pgsql-performance-owner@postgresql.org  Mon Oct 31 13:12:16 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 887B7DB531
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 31 Oct 2005 13:12:13 -0400 (AST)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 98978-03
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 31 Oct 2005 17:12:11 +0000 (GMT)
Received: from tbmail.tradebot.com
	(Tradebot-Systems-1096753.cust-rtr.swbell.net [68.90.170.2])
	by svr1.postgresql.org (Postfix) with ESMTP id E9601DB4FF
	for <pgsql-performance@postgresql.org>;
	Mon, 31 Oct 2005 13:12:08 -0400 (AST)
Received: from 192.168.200.29 ([192.168.200.29]) by tbmail.tradebot.com
	([192.168.1.50]) with Microsoft Exchange Server HTTP-DAV ;
	Mon, 31 Oct 2005 17:12:05 +0000
Received: from krb06 by TBMAIL; 31 Oct 2005 11:12:05 -0600
Subject: 8.x index insert performance
From: Kelly Burkhart <kelly@tradebotsystems.com>
To: pgsql-performance@postgresql.org
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Date: Mon, 31 Oct 2005 11:12:05 -0600
Message-Id: <1130778725.7026.33.camel@krb06.tradebot.com>
Mime-Version: 1.0
X-Mailer: Evolution 2.2.1 
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.026 required=5 tests=[AWL=0.025,
	UNPARSEABLE_RELAY=0.001]
X-Spam-Score: 0.026
X-Spam-Level: 
X-Archive-Number: 200510/472
X-Sequence-Number: 15240

Greetings,

We are running some performance tests in which we are attempting to
insert about 100,000,000 rows in a database at a sustained rate.  About
50M rows in, our performance drops dramatically.

This test is with data that we believe to be close to what we will
encounter in production.  However in tests with purely generated,
sequential data, we did not notice this slowdown.  I'm trying to figure
out what patterns in the "real" data may be causing us problems.

I have log,data and indexes on separate LUNs on an EMC SAN.  Prior to
slowdown, each partition is writing at a consistent rate.  Index
partition is reading at a much lower rate.  At the time of slowdown,
index partition read rate increases, all write rates decrease.  CPU
utilization drops.

The server is doing nothing aside from running the DB.  It is a dual
opteron (dual core, looks like 4 cpus) with 4GB RAM.  shared_buffers =
32768.  fsync = off.  Postgres version is 8.1.b4.  OS is SuSE Enterprise
server 9.

My leading hypothesis is that one indexed column may be leading to our
issue.  The column in question is a varchar(12) column which is non-null
in about 2% of the rows.  The value of this column is 5 characters which
are the same for every row, followed by a 7 character zero filled base
36 integer.  Thus, every value of this field will be exactly 12 bytes
long, and will be substantially the same down to the last bytes.

Could this pattern be pessimal for a postgresql btree index?  I'm
running a test now to see if I can verify, but my runs take quite a long
time...

If this sounds like an unlikely culprit how can I go about tracking down
the issue?

Thanks,

-K

From pgsql-performance-owner@postgresql.org  Mon Oct 31 13:32:13 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id C612CDB55D
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 31 Oct 2005 13:32:11 -0400 (AST)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 07198-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 31 Oct 2005 17:32:10 +0000 (GMT)
Received: from Herge.rcsinc.local (mail.rcsonline.com [70.89.208.142])
	by svr1.postgresql.org (Postfix) with ESMTP id 18B4DDB559
	for <pgsql-performance@postgresql.org>;
	Mon, 31 Oct 2005 13:32:09 -0400 (AST)
X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0
Content-class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Subject: Re: 8.x index insert performance
Date: Mon, 31 Oct 2005 12:32:03 -0500
Message-ID: <6EE64EF3AB31D5448D0007DD34EEB3417DD725@Herge.rcsinc.local>
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
Thread-Topic: [PERFORM] 8.x index insert performance
Thread-Index: AcXePqinJxAna3QcT/C0QkDCVpfaOwAAbZ3w
From: "Merlin Moncure" <merlin.moncure@rcsonline.com>
To: "Kelly Burkhart" <kelly@tradebotsystems.com>
Cc: <pgsql-performance@postgresql.org>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.051 required=5 tests=[AWL=0.051]
X-Spam-Score: 0.051
X-Spam-Level: 
X-Archive-Number: 200510/473
X-Sequence-Number: 15241

Kelly wrote:
> We are running some performance tests in which we are attempting to
> insert about 100,000,000 rows in a database at a sustained rate.
About
> 50M rows in, our performance drops dramatically.
>=20
> This test is with data that we believe to be close to what we will
> encounter in production.  However in tests with purely generated,
> sequential data, we did not notice this slowdown.  I'm trying to
figure
> out what patterns in the "real" data may be causing us problems.
>=20
> I have log,data and indexes on separate LUNs on an EMC SAN.  Prior to
> slowdown, each partition is writing at a consistent rate.  Index
> partition is reading at a much lower rate.  At the time of slowdown,
> index partition read rate increases, all write rates decrease.  CPU
> utilization drops.
>=20
> The server is doing nothing aside from running the DB.  It is a dual
> opteron (dual core, looks like 4 cpus) with 4GB RAM.  shared_buffers =
=3D
> 32768.  fsync =3D off.  Postgres version is 8.1.b4.  OS is SuSE
Enterprise
> server 9.
>=20
> My leading hypothesis is that one indexed column may be leading to our
> issue.  The column in question is a varchar(12) column which is
non-null
> in about 2% of the rows.  The value of this column is 5 characters
which
> are the same for every row, followed by a 7 character zero filled base
> 36 integer.  Thus, every value of this field will be exactly 12 bytes
> long, and will be substantially the same down to the last bytes.
>=20
> Could this pattern be pessimal for a postgresql btree index?  I'm
> running a test now to see if I can verify, but my runs take quite a
long
> time...
>=20
> If this sounds like an unlikely culprit how can I go about tracking
down
> the issue?

well, can you defer index generation until after loading the set (or use
COPY?)

if that index is causing the problem, you may want to consider setting
up partial index to exclude null values.

One interesting thing to do would be to run your inserting process until
slowdown happens, stop the process, and reindex the table and then
resume it, and see if this helps.

Merlin




From pgsql-performance-owner@postgresql.org  Mon Oct 31 13:51:49 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 9DBE0DB4C1
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 31 Oct 2005 13:51:48 -0400 (AST)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 23901-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 31 Oct 2005 17:51:46 +0000 (GMT)
Received: from tbmail.tradebot.com
	(Tradebot-Systems-1096753.cust-rtr.swbell.net [68.90.170.2])
	by svr1.postgresql.org (Postfix) with ESMTP id 4D9E8DB4FF
	for <pgsql-performance@postgresql.org>;
	Mon, 31 Oct 2005 13:51:45 -0400 (AST)
Received: from 192.168.200.29 ([192.168.200.29]) by tbmail.tradebot.com
	([192.168.1.50]) with Microsoft Exchange Server HTTP-DAV ;
	Mon, 31 Oct 2005 17:51:46 +0000
Received: from krb06 by TBMAIL; 31 Oct 2005 11:51:46 -0600
Subject: Re: 8.x index insert performance
From: Kelly Burkhart <kelly@tradebotsystems.com>
To: Merlin Moncure <merlin.moncure@rcsonline.com>
Cc: pgsql-performance@postgresql.org
In-Reply-To: <6EE64EF3AB31D5448D0007DD34EEB3417DD725@Herge.rcsinc.local>
References: <6EE64EF3AB31D5448D0007DD34EEB3417DD725@Herge.rcsinc.local>
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Date: Mon, 31 Oct 2005 11:51:46 -0600
Message-Id: <1130781106.7026.46.camel@krb06.tradebot.com>
Mime-Version: 1.0
X-Mailer: Evolution 2.2.1 
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.024 required=5 tests=[AWL=0.023,
	UNPARSEABLE_RELAY=0.001]
X-Spam-Score: 0.024
X-Spam-Level: 
X-Archive-Number: 200510/474
X-Sequence-Number: 15242

On Mon, 2005-10-31 at 12:32 -0500, Merlin Moncure wrote:
> well, can you defer index generation until after loading the set (or use
> COPY?)

I cannot defer index generation.

We are using the copy API.  Copying 10000 rows in a batch.

> 
> if that index is causing the problem, you may want to consider setting
> up partial index to exclude null values.

This is a single column index.  I assumed that null column values were
not indexed.  Is my assumption incorrect?

-K

From pgsql-performance-owner@postgresql.org  Mon Oct 31 15:02:28 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 203E4DB568
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 31 Oct 2005 15:02:27 -0400 (AST)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 54036-08
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 31 Oct 2005 19:02:25 +0000 (GMT)
Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.200])
	by svr1.postgresql.org (Postfix) with ESMTP id 69E79DB566
	for <pgsql-performance@postgresql.org>;
	Mon, 31 Oct 2005 15:02:25 -0400 (AST)
Received: by xproxy.gmail.com with SMTP id i30so1041347wxd
	for <pgsql-performance@postgresql.org>;
	Mon, 31 Oct 2005 11:02:26 -0800 (PST)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;
	h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references;
	b=tgUC+f/aA4TSK54n3cm13WMgMmVTL0xVliRwQBJiaxvNiuplY7D+RpoD3Pa7TMXSra3PK829hxhdeI1UyvVwSPcsbBMBfaLKWIhAfar0o1mHrmDhQxucq9HDPNNfWg/6IcXS5CS1TeUps4BdbdaCpu8PRxG7xL2P6DZ5rQ6esN0=
Received: by 10.64.233.6 with SMTP id f6mr431882qbh;
	Mon, 31 Oct 2005 11:02:26 -0800 (PST)
Received: by 10.64.151.6 with HTTP; Mon, 31 Oct 2005 11:02:26 -0800 (PST)
Message-ID: <b41c75520510311102t31a6eal@mail.gmail.com>
Date: Mon, 31 Oct 2005 20:02:26 +0100
From: Claus Guttesen <kometen@gmail.com>
To: Kelly Burkhart <kelly@tradebotsystems.com>
Subject: Re: 8.x index insert performance
Cc: pgsql-performance@postgresql.org
In-Reply-To: <1130778725.7026.33.camel@krb06.tradebot.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
References: <1130778725.7026.33.camel@krb06.tradebot.com>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0 required=5 tests=[none]
X-Spam-Score: 0
X-Spam-Level: 
X-Archive-Number: 200510/475
X-Sequence-Number: 15243

> We are running some performance tests in which we are attempting to
> insert about 100,000,000 rows in a database at a sustained rate.  About
> 50M rows in, our performance drops dramatically.
>
> This test is with data that we believe to be close to what we will
> encounter in production.  However in tests with purely generated,
> sequential data, we did not notice this slowdown.  I'm trying to figure
> out what patterns in the "real" data may be causing us problems.
>
> I have log,data and indexes on separate LUNs on an EMC SAN.  Prior to
> slowdown, each partition is writing at a consistent rate.  Index
> partition is reading at a much lower rate.  At the time of slowdown,
> index partition read rate increases, all write rates decrease.  CPU
> utilization drops.

I'm doing some test-inserts (albeit with much fewer records) into
8.0.4 (on FreeBSD 6.0 RC1) and the import-time decreased three-fold
when I increased the below mentioned values:

shared_buffers =3D 8192
commit_delay =3D 100000
commit_siblings =3D 1000

When I increased shared_buffers the kernel needed minor tweaking.

regards
Claus

From pgsql-performance-owner@postgresql.org  Mon Oct 31 15:13:35 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 7775FDB598
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 31 Oct 2005 15:13:33 -0400 (AST)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 62922-04
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 31 Oct 2005 19:13:31 +0000 (GMT)
Received: from Herge.rcsinc.local (mail.rcsonline.com [70.89.208.142])
	by svr1.postgresql.org (Postfix) with ESMTP id 31C95DB596
	for <pgsql-performance@postgresql.org>;
	Mon, 31 Oct 2005 15:13:31 -0400 (AST)
X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0
Content-class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Subject: Re: 8.x index insert performance
Date: Mon, 31 Oct 2005 14:13:29 -0500
Message-ID: <6EE64EF3AB31D5448D0007DD34EEB3417DD72D@Herge.rcsinc.local>
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
Thread-Topic: [PERFORM] 8.x index insert performance
Thread-Index: AcXeQ8OAwNyZx/DSRr2FBr5GX29I/QACu8DQ
From: "Merlin Moncure" <merlin.moncure@rcsonline.com>
To: "Kelly Burkhart" <kelly@tradebotsystems.com>
Cc: <pgsql-performance@postgresql.org>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.051 required=5 tests=[AWL=0.051]
X-Spam-Score: 0.051
X-Spam-Level: 
X-Archive-Number: 200510/476
X-Sequence-Number: 15244

> > if that index is causing the problem, you may want to consider
setting
> > up partial index to exclude null values.
>=20
> This is a single column index.  I assumed that null column values were
> not indexed.  Is my assumption incorrect?
>=20
> -K
It turns out it is, or it certainly seems to be.  I didn't know that :).
So partial index will probably not help for null exclusion...

would be interesting to see if you are getting swaps (check pg_tmp) when
performance breaks down.  That is an easy fix, bump work_mem.

Merlin

From pgsql-performance-owner@postgresql.org  Mon Oct 31 15:52:50 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 17186DB52D
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 31 Oct 2005 15:52:49 -0400 (AST)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 78053-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 31 Oct 2005 19:52:46 +0000 (GMT)
Received: from mail.envyfinancial.com (unknown [206.248.142.186])
	by svr1.postgresql.org (Postfix) with ESMTP id 4EF85DB565
	for <pgsql-performance@postgresql.org>;
	Mon, 31 Oct 2005 15:52:47 -0400 (AST)
Received: from localhost (localhost.localdomain [127.0.0.1])
	by mail.envyfinancial.com (Postfix) with ESMTP id CB5102343A;
	Mon, 31 Oct 2005 14:35:47 -0500 (EST)
Received: from mail.envyfinancial.com ([127.0.0.1])
	by localhost (mark.mielke.cc [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 02757-08; Mon, 31 Oct 2005 14:35:47 -0500 (EST)
Received: by mail.envyfinancial.com (Postfix, from userid 500)
	id 80D8A23436; Mon, 31 Oct 2005 14:35:47 -0500 (EST)
Date: Mon, 31 Oct 2005 14:35:47 -0500
From: mark@mark.mielke.cc
To: Merlin Moncure <merlin.moncure@rcsonline.com>
Cc: Kelly Burkhart <kelly@tradebotsystems.com>,
	pgsql-performance@postgresql.org
Subject: Re: 8.x index insert performance
Message-ID: <20051031193547.GA3311@mark.mielke.cc>
References: <6EE64EF3AB31D5448D0007DD34EEB3417DD725@Herge.rcsinc.local>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <6EE64EF3AB31D5448D0007DD34EEB3417DD725@Herge.rcsinc.local>
User-Agent: Mutt/1.4.2.1i
X-Virus-Scanned: amavisd-new at mail.envyfinancial.com
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.375 required=5 tests=[AWL=-0.175,
 NO_REAL_NAME=0.55]
X-Spam-Score: 0.375
X-Spam-Level: 
X-Archive-Number: 200510/477
X-Sequence-Number: 15245

On Mon, Oct 31, 2005 at 12:32:03PM -0500, Merlin Moncure wrote:
> if that index is causing the problem, you may want to consider setting
> up partial index to exclude null values.

Hey all.

Pardon my ignorance. :-)

I've been trying to figure out whether null values are indexed or not from
the documentation. I was under the impression, that null values are not
stored in the index. Occassionally, though, I then see a suggestion such
as the above, that seems to indicate to me that null values *are* stored
in the index, allowing for the 'exclude null values' to have effect?

Which is it? :-)

Thanks,
mark

-- 
mark@mielke.cc / markm@ncf.ca / markm@nortel.com     __________________________
.  .  _  ._  . .   .__    .  . ._. .__ .   . . .__  | Neighbourhood Coder
|\/| |_| |_| |/    |_     |\/|  |  |_  |   |/  |_   | 
|  | | | | \ | \   |__ .  |  | .|. |__ |__ | \ |__  | Ottawa, Ontario, Canada

  One ring to rule them all, one ring to find them, one ring to bring them all
                       and in the darkness bind them...

                           http://mark.mielke.cc/


From pgsql-performance-owner@postgresql.org  Mon Oct 31 16:27:35 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 54B55DB470
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 31 Oct 2005 16:27:33 -0400 (AST)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 90000-03
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 31 Oct 2005 20:27:31 +0000 (GMT)
Received: from Herge.rcsinc.local (mail.rcsonline.com [70.89.208.142])
	by svr1.postgresql.org (Postfix) with ESMTP id 859C8DB2FD
	for <pgsql-performance@postgresql.org>;
	Mon, 31 Oct 2005 16:27:30 -0400 (AST)
X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0
Content-class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Subject: Re: 8.x index insert performance
Date: Mon, 31 Oct 2005 15:27:31 -0500
Message-ID: <6EE64EF3AB31D5448D0007DD34EEB3417DD730@Herge.rcsinc.local>
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
Thread-Topic: [PERFORM] 8.x index insert performance
Thread-Index: AcXeVIwYYpSRWENzSlOASAgCfmWHHAABKvHw
From: "Merlin Moncure" <merlin.moncure@rcsonline.com>
To: <mark@mark.mielke.cc>
Cc: <pgsql-performance@postgresql.org>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.05 required=5 tests=[AWL=0.050]
X-Spam-Score: 0.05
X-Spam-Level: 
X-Archive-Number: 200510/478
X-Sequence-Number: 15246

> On Mon, Oct 31, 2005 at 12:32:03PM -0500, Merlin Moncure wrote:
> > if that index is causing the problem, you may want to consider
setting
> > up partial index to exclude null values.
>=20
> Hey all.
>=20
> Pardon my ignorance. :-)
>=20
> I've been trying to figure out whether null values are indexed or not
from
> the documentation. I was under the impression, that null values are
not
> stored in the index. Occassionally, though, I then see a suggestion
such
> as the above, that seems to indicate to me that null values *are*
stored
> in the index, allowing for the 'exclude null values' to have effect?
>=20
> Which is it? :-)

I think I'm the ignorant one...do explain on any lookup on an indexed
field where the field value is null and you get a seqscan.

Merlin

From pgsql-performance-owner@postgresql.org  Mon Oct 31 16:30:33 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id ADBD2DB527
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 31 Oct 2005 16:30:29 -0400 (AST)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 88261-10
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 31 Oct 2005 20:30:27 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id 56B40DB2FD
	for <pgsql-performance@postgresql.org>;
	Mon, 31 Oct 2005 16:30:28 -0400 (AST)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j9VKUTHP018648;
	Mon, 31 Oct 2005 15:30:29 -0500 (EST)
To: mark@mark.mielke.cc
Cc: Merlin Moncure <merlin.moncure@rcsonline.com>,
	Kelly Burkhart <kelly@tradebotsystems.com>,
	pgsql-performance@postgresql.org
Subject: Re: 8.x index insert performance 
In-reply-to: <20051031193547.GA3311@mark.mielke.cc> 
References: <6EE64EF3AB31D5448D0007DD34EEB3417DD725@Herge.rcsinc.local>
	<20051031193547.GA3311@mark.mielke.cc>
Comments: In-reply-to mark@mark.mielke.cc
	message dated "Mon, 31 Oct 2005 14:35:47 -0500"
Date: Mon, 31 Oct 2005 15:30:29 -0500
Message-ID: <18647.1130790629@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.006 required=5 tests=[AWL=0.006]
X-Spam-Score: 0.006
X-Spam-Level: 
X-Archive-Number: 200510/479
X-Sequence-Number: 15247

mark@mark.mielke.cc writes:
> I've been trying to figure out whether null values are indexed or not from
> the documentation. I was under the impression, that null values are not
> stored in the index.

You're mistaken, at least with regard to btree indexes.

			regards, tom lane

From pgsql-performance-owner@postgresql.org  Mon Oct 31 16:59:53 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id EF830DB5AB
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 31 Oct 2005 16:59:51 -0400 (AST)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 98742-07
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 31 Oct 2005 20:59:49 +0000 (GMT)
Received: from tbmail.tradebot.com
	(Tradebot-Systems-1096753.cust-rtr.swbell.net [68.90.170.2])
	by svr1.postgresql.org (Postfix) with ESMTP id 247A4DB577
	for <pgsql-performance@postgresql.org>;
	Mon, 31 Oct 2005 16:59:49 -0400 (AST)
Received: from 192.168.200.29 ([192.168.200.29]) by tbmail.tradebot.com
	([192.168.1.50]) with Microsoft Exchange Server HTTP-DAV ;
	Mon, 31 Oct 2005 20:59:51 +0000
Received: from krb06 by TBMAIL; 31 Oct 2005 14:59:51 -0600
Subject: Re: 8.x index insert performance
From: Kelly Burkhart <kelly@tradebotsystems.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: mark@mark.mielke.cc, Merlin Moncure <merlin.moncure@rcsonline.com>,
	pgsql-performance@postgresql.org
In-Reply-To: <18647.1130790629@sss.pgh.pa.us>
References: <6EE64EF3AB31D5448D0007DD34EEB3417DD725@Herge.rcsinc.local>
	<20051031193547.GA3311@mark.mielke.cc> <18647.1130790629@sss.pgh.pa.us>
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Date: Mon, 31 Oct 2005 14:59:51 -0600
Message-Id: <1130792391.7026.55.camel@krb06.tradebot.com>
Mime-Version: 1.0
X-Mailer: Evolution 2.2.1 
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.022 required=5 tests=[AWL=0.021,
	UNPARSEABLE_RELAY=0.001]
X-Spam-Score: 0.022
X-Spam-Level: 
X-Archive-Number: 200510/480
X-Sequence-Number: 15248

On Mon, 2005-10-31 at 15:30 -0500, Tom Lane wrote:
> mark@mark.mielke.cc writes:
> > I've been trying to figure out whether null values are indexed or not from
> > the documentation. I was under the impression, that null values are not
> > stored in the index.
> 
> You're mistaken, at least with regard to btree indexes.

Ha!  So I'm creating an index 98% full of nulls!  Looks like this is
easily fixed with partial indexes.

-K

From pgsql-performance-owner@postgresql.org  Mon Oct 31 17:01:36 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 92583DB556
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 31 Oct 2005 17:01:35 -0400 (AST)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 26064-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 31 Oct 2005 21:01:33 +0000 (GMT)
Received: from Herge.rcsinc.local (mail.rcsonline.com [70.89.208.142])
	by svr1.postgresql.org (Postfix) with ESMTP id B3681DB527
	for <pgsql-performance@postgresql.org>;
	Mon, 31 Oct 2005 17:01:33 -0400 (AST)
X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0
Content-class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Subject: Re: 8.x index insert performance 
Date: Mon, 31 Oct 2005 16:01:34 -0500
Message-ID: <6EE64EF3AB31D5448D0007DD34EEB3417DD731@Herge.rcsinc.local>
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
Thread-Topic: [PERFORM] 8.x index insert performance 
Thread-Index: AcXeWfGg51vuxzAGTWe9XOk6Oul93wAAh+wA
From: "Merlin Moncure" <merlin.moncure@rcsonline.com>
To: "Tom Lane" <tgl@sss.pgh.pa.us>
Cc: <pgsql-performance@postgresql.org>,
	"Kelly Burkhart" <kelly@tradebotsystems.com>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.049 required=5 tests=[AWL=0.049]
X-Spam-Score: 0.049
X-Spam-Level: 
X-Archive-Number: 200510/481
X-Sequence-Number: 15249

> mark@mark.mielke.cc writes:
> > I've been trying to figure out whether null values are indexed or
not
> from
> > the documentation. I was under the impression, that null values are
not
> > stored in the index.
>=20
> You're mistaken, at least with regard to btree indexes.

hmm. I tried several different ways to filter/extract null values from
an indexed key and got a seq scan every time.  The only way I could
query for/against null values was to convert to bool via function.

However I did a partial exclusion on a 1% non null value really big
table and index size dropped as expected.

Merlin

From pgsql-performance-owner@postgresql.org  Mon Oct 31 17:03:56 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 252A7DB5B3
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 31 Oct 2005 17:03:55 -0400 (AST)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 28160-02
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 31 Oct 2005 21:03:52 +0000 (GMT)
Received: from koolancexeon.g2switchworks.com (mail.g2switchworks.com
	[63.87.162.25])
	by svr1.postgresql.org (Postfix) with ESMTP id 515D8DB5B1
	for <pgsql-performance@postgresql.org>;
	Mon, 31 Oct 2005 17:03:53 -0400 (AST)
Received: mail.g2switchworks.com 10.10.1.8 from 10.10.1.37 10.10.1.37 via HTTP
	with MS-WebStorage 6.5.6944
Received: from state.g2switchworks.com by mail.g2switchworks.com;
	31 Oct 2005 15:03:53 -0600
Subject: Re: 8.x index insert performance
From: Scott Marlowe <smarlowe@g2switchworks.com>
To: Merlin Moncure <merlin.moncure@rcsonline.com>
Cc: Kelly Burkhart <kelly@tradebotsystems.com>,
	pgsql-performance@postgresql.org
In-Reply-To: <6EE64EF3AB31D5448D0007DD34EEB3417DD72D@Herge.rcsinc.local>
References: <6EE64EF3AB31D5448D0007DD34EEB3417DD72D@Herge.rcsinc.local>
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Message-Id: <1130792605.15018.21.camel@state.g2switchworks.com>
Mime-Version: 1.0
X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) 
Date: Mon, 31 Oct 2005 15:03:53 -0600
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.008 required=5 tests=[AWL=0.007,
	UNPARSEABLE_RELAY=0.001]
X-Spam-Score: 0.008
X-Spam-Level: 
X-Archive-Number: 200510/482
X-Sequence-Number: 15250

On Mon, 2005-10-31 at 13:13, Merlin Moncure wrote:
> > > if that index is causing the problem, you may want to consider
> setting
> > > up partial index to exclude null values.
> > 
> > This is a single column index.  I assumed that null column values were
> > not indexed.  Is my assumption incorrect?
> > 
> > -K
> It turns out it is, or it certainly seems to be.  I didn't know that :).
> So partial index will probably not help for null exclusion...
> 
> would be interesting to see if you are getting swaps (check pg_tmp) when
> performance breaks down.  That is an easy fix, bump work_mem.

OK, here's the issue in a nutshell.

NULLS, like everything else, are indexed.  HOWEVER, there's no way for
them to be used by a normal query, since =NULL is not a legal
construct.  So, you can't do something like:

select * from sometable where somefield = NULL

because you won't get any answers, since nothing can equal NULL and

select * from sometable where somefield IS NULL won't work because IS is
not a nomally indexible operator.

Which is why you can create two indexes on a table to get around this
like so:

create index iname1 on table (field) where field IS NULL

and

create index iname2 on table (field) where field IS NOT NULL

And then the nulls are indexable by IS / IS NOT NULL.

From pgsql-performance-owner@postgresql.org  Mon Oct 31 17:08:13 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 0A954DB577
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 31 Oct 2005 17:08:12 -0400 (AST)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 19038-09
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 31 Oct 2005 21:08:09 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id A6E1EDB527
	for <pgsql-performance@postgresql.org>;
	Mon, 31 Oct 2005 17:08:10 -0400 (AST)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j9VL8Cwc018971;
	Mon, 31 Oct 2005 16:08:12 -0500 (EST)
To: "Merlin Moncure" <merlin.moncure@rcsonline.com>
Cc: pgsql-performance@postgresql.org,
	"Kelly Burkhart" <kelly@tradebotsystems.com>
Subject: Re: 8.x index insert performance 
In-reply-to: <6EE64EF3AB31D5448D0007DD34EEB3417DD731@Herge.rcsinc.local> 
References: <6EE64EF3AB31D5448D0007DD34EEB3417DD731@Herge.rcsinc.local>
Comments: In-reply-to "Merlin Moncure" <merlin.moncure@rcsonline.com>
	message dated "Mon, 31 Oct 2005 16:01:34 -0500"
Date: Mon, 31 Oct 2005 16:08:12 -0500
Message-ID: <18970.1130792892@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.006 required=5 tests=[AWL=0.006]
X-Spam-Score: 0.006
X-Spam-Level: 
X-Archive-Number: 200510/483
X-Sequence-Number: 15251

"Merlin Moncure" <merlin.moncure@rcsonline.com> writes:
>> You're mistaken, at least with regard to btree indexes.

> hmm. I tried several different ways to filter/extract null values from
> an indexed key and got a seq scan every time.

I said they were stored, not that you could query against them ;-)
IS NULL isn't considered an indexable operator, mainly because it's
not an operator at all in the strict sense of the word; and our index
access APIs only support querying on indexable operators.

The reason they're stored is that they have to be in order to make
multi-column indexes work right.  I suppose we could special-case
single-column indexes, but we don't.  In any case, it's more likely
that someone would one day get around to making IS NULL an indexable
operator than that we'd insert a special case like that.

			regards, tom lane

From pgsql-performance-owner@postgresql.org  Mon Oct 31 17:10:58 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 6D188DB57A
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 31 Oct 2005 17:10:57 -0400 (AST)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 28843-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 31 Oct 2005 21:10:55 +0000 (GMT)
Received: from Herge.rcsinc.local (mail.rcsonline.com [70.89.208.142])
	by svr1.postgresql.org (Postfix) with ESMTP id EC519DB575
	for <pgsql-performance@postgresql.org>;
	Mon, 31 Oct 2005 17:10:55 -0400 (AST)
X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0
Content-class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Subject: Re: 8.x index insert performance
Date: Mon, 31 Oct 2005 16:10:57 -0500
Message-ID: <6EE64EF3AB31D5448D0007DD34EEB3417DD732@Herge.rcsinc.local>
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
Thread-Topic: [PERFORM] 8.x index insert performance
Thread-Index: AcXeXp5QsA/c2Y7xTtSH+0mL7GgDxQAACFzQ
From: "Merlin Moncure" <merlin.moncure@rcsonline.com>
To: "Scott Marlowe" <smarlowe@g2switchworks.com>
Cc: <pgsql-performance@postgresql.org>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.049 required=5 tests=[AWL=0.049]
X-Spam-Score: 0.049
X-Spam-Level: 
X-Archive-Number: 200510/484
X-Sequence-Number: 15252

> select * from sometable where somefield IS NULL won't work because IS
is
> not a nomally indexible operator.

Ah, I didn't know that.  So there is no real reason not to exclude null
values from all your indexes :).  Reading Tom's recent comments
everything is clear now.

Instead of using your two index approach I prefer to:
create function nullidx(anyelement) returns boolean as $$ select $1 is
null; $$ language
sql immutable;

create index on t(nullidx(f)); -- etc

Merlin

From pgsql-performance-owner@postgresql.org  Mon Oct 31 17:18:47 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id 1D576DB509
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 31 Oct 2005 17:18:47 -0400 (AST)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 37899-03
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 31 Oct 2005 21:18:45 +0000 (GMT)
Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130])
	by svr1.postgresql.org (Postfix) with ESMTP id D7F9DDB4E8
	for <pgsql-performance@postgresql.org>;
	Mon, 31 Oct 2005 17:18:45 -0400 (AST)
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j9VLIlha019066;
	Mon, 31 Oct 2005 16:18:47 -0500 (EST)
To: Kelly Burkhart <kelly@tradebotsystems.com>
Cc: mark@mark.mielke.cc, Merlin Moncure <merlin.moncure@rcsonline.com>,
	pgsql-performance@postgresql.org
Subject: Re: 8.x index insert performance 
In-reply-to: <1130792391.7026.55.camel@krb06.tradebot.com> 
References: <6EE64EF3AB31D5448D0007DD34EEB3417DD725@Herge.rcsinc.local>
	<20051031193547.GA3311@mark.mielke.cc>
	<18647.1130790629@sss.pgh.pa.us>
	<1130792391.7026.55.camel@krb06.tradebot.com>
Comments: In-reply-to Kelly Burkhart <kelly@tradebotsystems.com>
	message dated "Mon, 31 Oct 2005 14:59:51 -0600"
Date: Mon, 31 Oct 2005 16:18:47 -0500
Message-ID: <19065.1130793527@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.006 required=5 tests=[AWL=0.006]
X-Spam-Score: 0.006
X-Spam-Level: 
X-Archive-Number: 200510/485
X-Sequence-Number: 15253

Kelly Burkhart <kelly@tradebotsystems.com> writes:
> Ha!  So I'm creating an index 98% full of nulls!  Looks like this is
> easily fixed with partial indexes.

Still, though, it's not immediately clear why you'd be seeing a severe
dropoff in insert performance after 50M rows.  Even though there are
lots of nulls, I don't see why they'd behave any worse for insert speed
than real data.  One would like to think that the insert speed would
follow a nice O(log N) rule.

Are you doing the inserts all in one transaction, or several?  If
several, could you get a gprof profile of inserting the same number of
rows (say a million or so) both before and after the unexpected dropoff
occurs?

			regards, tom lane

From pgsql-performance-owner@postgresql.org  Mon Oct 31 19:16:59 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id AAE51DB5B4
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 31 Oct 2005 19:16:56 -0400 (AST)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 84721-05
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 31 Oct 2005 23:16:53 +0000 (GMT)
Received: from floppy.pyrenet.fr (floppy.pyrenet.fr [194.116.145.2])
	by svr1.postgresql.org (Postfix) with ESMTP id C1797DB5AD
	for <pgsql-performance@postgresql.org>;
	Mon, 31 Oct 2005 19:16:53 -0400 (AST)
Received: by floppy.pyrenet.fr (Postfix, from userid 106)
	id 2817431059; Tue,  1 Nov 2005 00:16:53 +0100 (MET)
From: "PostgreSQL" <martin@portant.com>
X-Newsgroups: pgsql.performance
Subject: 8.1beta3 performance
Date: Mon, 31 Oct 2005 17:16:46 -0600
Organization: Hub.Org Networking Services
Lines: 10
Message-ID: <dk68ku$2lqa$1@news.hub.org>
X-Complaints-To: usenet@news.hub.org
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
X-RFC2646: Format=Flowed; Original
To: pgsql-performance@postgresql.org
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0 required=5 tests=[none]
X-Spam-Score: 0
X-Spam-Level: 
X-Archive-Number: 200510/486
X-Sequence-Number: 15254

We're running 8.1beta3 on one server and are having ridiculous performance 
issues.  This is a 2 cpu Opteron box and both processors are staying at 98 
or 99% utilization processing not-that-complex queries.  Prior to the 
upgrade, our I/O wait time was about 60% and cpu utilization rarely got very 
high, now I/O wait time is at or near zero.

I'm planning to go back to 8.0 tonight or tomorrow night but thought I'd 
check the pqsql-performance prophets before I gave it up. 



From pgsql-performance-owner@postgresql.org  Mon Oct 31 20:13:27 2005
X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org
Received: from localhost (av.hub.org [200.46.204.144])
	by svr1.postgresql.org (Postfix) with ESMTP id C8BCDDB5C4
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Mon, 31 Oct 2005 20:13:25 -0400 (AST)
Received: from svr1.postgresql.org ([200.46.204.71])
	by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024)
	with ESMTP id 17376-03
	for <pgsql-performance-postgresql.org@localhost.postgresql.org>;
	Tue,  1 Nov 2005 00:13:22 +0000 (GMT)
Received: from mail.envyfinancial.com (unknown [206.248.142.186])
	by svr1.postgresql.org (Postfix) with ESMTP id 9F2F6DB5C3
	for <pgsql-performance@postgresql.org>;
	Mon, 31 Oct 2005 20:13:23 -0400 (AST)
Received: from localhost (localhost.localdomain [127.0.0.1])
	by mail.envyfinancial.com (Postfix) with ESMTP id 15F1623453;
	Mon, 31 Oct 2005 18:57:10 -0500 (EST)
Received: from mail.envyfinancial.com ([127.0.0.1])
	by localhost (mark.mielke.cc [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 06426-05; Mon, 31 Oct 2005 18:57:09 -0500 (EST)
Received: by mail.envyfinancial.com (Postfix, from userid 500)
	id C185F23436; Mon, 31 Oct 2005 18:57:09 -0500 (EST)
Date: Mon, 31 Oct 2005 18:57:09 -0500
From: mark@mark.mielke.cc
To: Merlin Moncure <merlin.moncure@rcsonline.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: 8.x index insert performance
Message-ID: <20051031235709.GA6393@mark.mielke.cc>
References: <6EE64EF3AB31D5448D0007DD34EEB3417DD730@Herge.rcsinc.local>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <6EE64EF3AB31D5448D0007DD34EEB3417DD730@Herge.rcsinc.local>
User-Agent: Mutt/1.4.2.1i
X-Virus-Scanned: amavisd-new at mail.envyfinancial.com
X-Virus-Scanned: by amavisd-new at hub.org
X-Spam-Status: No, score=0.379 required=5 tests=[AWL=-0.171,
 NO_REAL_NAME=0.55]
X-Spam-Score: 0.379
X-Spam-Level: 
X-Archive-Number: 200510/487
X-Sequence-Number: 15255

On Mon, Oct 31, 2005 at 03:27:31PM -0500, Merlin Moncure wrote:
> > On Mon, Oct 31, 2005 at 12:32:03PM -0500, Merlin Moncure wrote:
> > > if that index is causing the problem, you may want to consider setting
> > > up partial index to exclude null values.
> > Hey all.
> > Pardon my ignorance. :-)
> > I've been trying to figure out whether null values are indexed or not from
> > the documentation. I was under the impression, that null values are not
> > stored in the index. Occassionally, though, I then see a suggestion such
> > as the above, that seems to indicate to me that null values *are* stored
> > in the index, allowing for the 'exclude null values' to have effect?
> > Which is it? :-)
> I think I'm the ignorant one...do explain on any lookup on an indexed
> field where the field value is null and you get a seqscan.

Nahhh... I think the documentation could use more explicit or obvious
explanation. Or, I could have checked the source code to see. In any case,
I expect we aren't the only ones that lacked confidence.

Tom was kind enough to point out that null values are stored. I expect
that the seqscan is used if the null values are not selective enough,
the same as any other value that isn't selective enough.

Now we can both have a little more confidence! :-)

Cheers,
mark

-- 
mark@mielke.cc / markm@ncf.ca / markm@nortel.com     __________________________
.  .  _  ._  . .   .__    .  . ._. .__ .   . . .__  | Neighbourhood Coder
|\/| |_| |_| |/    |_     |\/|  |  |_  |   |/  |_   | 
|  | | | | \ | \   |__ .  |  | .|. |__ |__ | \ |__  | Ottawa, Ontario, Canada

  One ring to rule them all, one ring to find them, one ring to bring them all
                       and in the darkness bind them...

                           http://mark.mielke.cc/