pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Christopher Kings-Lynne <chriskl@familyhealth.com.au>
To: Logan Bowers <logan@datacurrent.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Neil Conway <neilc@samurai.com>
Cc: sean@chittenden.org
Cc: pgsql-performance@postgresql.org
Subject: Re: postgresql meltdown on PlanetMath.org
Date: Tue, 18 Mar 2003 10:44:01 +0800
Message-ID: <088d01c2ecf8$3bf742e0$6500a8c0@fhp.internal> (raw)
References: <20030316060125.GD19570@vt.edu>
	<3E741B93.1090203@joeconway.com>
	<20030316075206.GE19570@vt.edu>
	<Pine.LNX.4.53.0303170059580.8767@neo.magick.org>
	<20030317061011.GH23355@perrin.int.nxad.com>
	<33137.130.15.224.150.1047881939.squirrel@mailbox.samurai.com>
	<495.1047882860@sss.pgh.pa.us>
	<Pine.LNX.4.53.0303171845190.8636@neo.magick.org>

> I'm running this db on a celeron 450Mhz with 256MB RAM and a 60GB HDD
> (7200 rpm).  For the most part I have the db running "well enough."  Over
> time however, I find that performance degrades, the count(*) above is an
> example of a command that does worse over time.  It gets run once an hour
> for stats collection.  When I first migrated the db to v7.3.1 it would
> take about 5-10 seconds (which it is close to now after a VACUUM FULL) but
> after a few weeks it would take over a minute of really intense HDD
> activity.  Also of note is that when I first loaded the data it would
> cache very well with the query taking maybe taking 15 seconds if I had
> just started the db after reboot, but when it was in its "slow" state
> repeating the query didn't noticably use the disk less (nor did it take
> less time).

To speed up your COUNT(*), how about doing this:

Create a separate table to hold a single integer.

Add a trigger after insert on your table to increment the counter in the
other table
Add a trigger after delete on your table to decrement the counter in the
other table.

That way you always have an O(1) count...

Chris




view thread (39+ messages)  latest in thread

Message-ID: <088d01c2ecf8$3bf742e0$6500a8c0@fhp.internal>
Permalink:  ../088d01c2ecf8$3bf742e0$6500a8c0@fhp.internal/
Also on:    postgresql.org/message-id/088d01c2ecf8$3bf742e0$6500a8c0@fhp.internal

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-performance@postgresql.org
  Cc: chriskl@familyhealth.com.au, logan@datacurrent.com, tgl@sss.pgh.pa.us, neilc@samurai.com, sean@chittenden.org
  Subject: Re: postgresql meltdown on PlanetMath.org
  In-Reply-To: <088d01c2ecf8$3bf742e0$6500a8c0@fhp.internal>
  References: <20030316060125.GD19570@vt.edu> <3E741B93.1090203@joeconway.com> <20030316075206.GE19570@vt.edu> <Pine.LNX.4.53.0303170059580.8767@neo.magick.org> <20030317061011.GH23355@perrin.int.nxad.com> <33137.130.15.224.150.1047881939.squirrel@mailbox.samurai.com> <495.1047882860@sss.pgh.pa.us> <Pine.LNX.4.53.0303171845190.8636@neo.magick.org> <088d01c2ecf8$3bf742e0$6500a8c0@fhp.internal>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox