X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 9EA0A536F6 for ; Thu, 14 Apr 2005 08:53: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 16123-10 for ; Thu, 14 Apr 2005 11:53:14 +0000 (GMT) Received: from krogh.officenet.no (unknown [128.39.244.194]) by svr1.postgresql.org (Postfix) with ESMTP id BD9B4536ED for ; Thu, 14 Apr 2005 08:53:12 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by krogh.officenet.no (Postfix) with ESMTP id 75A5F2A1CF8; Thu, 14 Apr 2005 13:53:15 +0200 (CEST) From: Andreas Joseph Krogh Organization: OfficeNet AS To: Richard Huxton Subject: Re: Very low performance on table with only 298 rows Date: Thu, 14 Apr 2005 13:53:12 +0200 User-Agent: KMail/1.8 Cc: pgsql-sql@postgresql.org References: <200504141248.21783.andreak@officenet.no> <425E53C7.5080604@archonet.com> In-Reply-To: <425E53C7.5080604@archonet.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200504141353.14022.andreak@officenet.no> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200504/188 X-Sequence-Number: 21081 On Thursday 14 April 2005 13:28, Richard Huxton wrote: > Andreas Joseph Krogh wrote: > > nbeweb=3D> EXPLAIN select count(*) from onp_web_index; > > QUERY PLAN > > -----------------------------------------------------------------------= =2D- > >---- Hi all. > > I have a problem with a table which only has 298 rows in it. A select > > count(*) takes forever and CTRL-C also takes a long time canceling the > > query. There are only 298 rows in the table when count(*) returns. How > > come it takes such a long time counting only 298 rows? Here is EXPLAIN > > ANALYZE: > > > > nbeweb=3D> EXPLAIN ANALYZE select count(*) from onp_web_index; > > QUERY PLAN > > -----------------------------------------------------------------------= =2D- > >---------------------------------------------------------- Aggregate=20 > > (cost=3D205759.52..205759.52 rows=3D1 width=3D0) (actual > > time=3D179748.910..179748.913 rows=3D1 loops=3D1) > > -> Seq Scan on onp_web_index (cost=3D0.00..205455.41 rows=3D121641 > > width=3D0) (actual time=3D179735.956..179747.821 rows=3D298 loops=3D1) > > Total runtime: 179748.993 ms > > Why does PG think you have 121641 rows in this table? > How often do you vacuum it? > How often do you analyse it? > Does "vacuum full verbose" show a lot of dead rows being removed? > > I'm suspecting a *lot* of dead rows need to be removed. I vacuum the whole database every sunday with the command: VACUUM ANALYZE Do I need to issue a VACUUM FULL? I've never VACUUM FULL'ed it.. I have other much larger tables which take lot less time to count(*). Cant = it=20 be that this table is hosed somehow? Note: I have a column of type tsvector= =20 in there, cat it be that this column causes some unexpected trouble? I'm issuing a VACUUM FULL verbose now... =2D-=20 Andreas Joseph Krogh Senior Software Developer / Manager gpg public_key: http://dev.officenet.no/~andreak/public_key.asc =2D-----------------------+---------------------------------------------+ OfficeNet AS | The most difficult thing in the world is to | Hoffsveien 17 | know how to do a thing and to watch | PO. Box 425 Sk=F8yen | somebody else doing it wrong, without | 0213 Oslo | comment. | NORWAY | | Phone : +47 22 13 01 00 | | Direct: +47 22 13 10 03 | | Mobile: +47 909 56 963 | | =2D-----------------------+---------------------------------------------+