Received: from localhost (unknown [200.46.204.184]) by developer.postgresql.org (Postfix) with ESMTP id 518722E0037 for ; Wed, 23 Apr 2008 17:43:24 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 87747-04 for ; Wed, 23 Apr 2008 17:43:17 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by developer.postgresql.org (Postfix) with ESMTP id 8C5742E002C for ; Wed, 23 Apr 2008 17:43:20 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id m3NKgpJi016713; Wed, 23 Apr 2008 16:42:51 -0400 (EDT) To: Brian Cox cc: pgsql-general@postgresql.org Subject: Re: query performance In-reply-to: <480F8FFF.8080904@ca.com> References: <480F8FFF.8080904@ca.com> Comments: In-reply-to Brian Cox message dated "Wed, 23 Apr 2008 12:37:35 -0700" Date: Wed, 23 Apr 2008 16:42:51 -0400 Message-ID: <16712.1208983371@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200804/1186 X-Sequence-Number: 132155 Brian Cox writes: > I have a largish (pg_dump output is 4G) database. The query: > select count(*) from some-table > was taking 120 secs to report that there were 151,000+ rows. > This seemed very slow. This db gets vacuum'd regularly (at least once > per day). I also did a manual 'vacuum analyze', but after it completed, > the query ran no faster. However, after dumping the database and > recreating it from the backup, the same query takes 2 secs. > Why the dramatic decrease? Presumably, the table was really bloated (lots of unused space). > Would 'vacuum full' have achieved the > same performance improvements? It would've compacted the table all right, but probably left the indexes worse off. > Is there anything else that needs to be done > regularly to prevent this performance degradation? I suspect that your FSM settings are too low, causing free space found by VACUUM to be forgotten about. You might also need to consider vacuuming more than once a day (there's a tradeoff between how often you vacuum and how much FSM space you need). regards, tom lane