Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id DBA6D632DDC for ; Mon, 4 Jan 2010 17:01:09 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 02148-03 for ; Mon, 4 Jan 2010 21:00:55 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from outbound.afilias.info (outbound.afilias.info [69.46.124.26]) by mail.postgresql.org (Postfix) with ESMTP id 12AC1632A55 for ; Mon, 4 Jan 2010 17:00:58 -0400 (AST) Received: from ms5.yyz2.afilias-ops.info ([10.50.129.111] helo=smtp.afilias.info) by outbound.afilias.info with esmtp (Exim 4.69) (envelope-from ) id 1NRu2r-0002n2-7k; Mon, 04 Jan 2010 21:00:57 +0000 Received: from tor-gateway.afilias.info ([199.15.87.4] helo=[10.10.46.12]) by smtp.afilias.info with esmtpsa (SSLv3:AES256-SHA:256) (Exim 4.69) (envelope-from ) id 1NRu2r-0004c3-42; Mon, 04 Jan 2010 21:00:57 +0000 Subject: Re: DB is slow until DB is reloaded From: Brad Nicholson To: Madison Kelly Cc: Gary Doades , pgsql-performance@postgresql.org In-Reply-To: <4B425555.6020709@alteeve.com> References: <4B423D22.7040803@alteeve.com> <4B424215.70605@pinpointresearch.com> <4B424FF6.40207@alteeve.com> <4B425222.7070905@gpdnet.co.uk> <4B425555.6020709@alteeve.com> Content-Type: text/plain Date: Mon, 04 Jan 2010 16:00:56 -0500 Message-Id: <1262638856.29852.4.camel@bnicholson-desktop> Mime-Version: 1.0 X-Mailer: Evolution 2.26.1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.45 tagged_above=-10 required=5 tests=AWL=-2.553, BAYES_40=-0.185, FH_DATE_PAST_20XX=3.188 X-Spam-Level: X-Archive-Number: 201001/14 X-Sequence-Number: 36894 On Mon, 2010-01-04 at 15:53 -0500, Madison Kelly wrote: > Gary Doades wrote: > > From your queries it definitely looks like its your stats that are the > > problem. When the stats get well out of date the planner is choosing a > > hash join because it thinks thousands of rows are involved where as only > > a few are actually involved. Thats why, with better stats, the second > > query is using a loop join over very few rows and running much quicker. > > > > Therefore it's ANALYZE you need to run as well as regular VACUUMing. > > There should be no need to VACUUM FULL at all as long as you VACUUM and > > ANALYZE regularly. Once a day may be enough, but you don't say how long > > it takes your database to become "slow". > > > > You can VACUUM either the whole database (often easiest) or individual > > tables if you know in more detail what the problem is and that only > > certain tables need it. > > > > Setting up autovacuum may well be sufficient. > > > > Cheers, > > Gary. > > That explains things, thank you! > > For the record; It was taking a few months for the performance to become > intolerable. I've added CLUSTER -> ANALYZE -> VACUUM to my nightly > routine and dropped the VACUUM FULL call. I'll see how this works. I think you are going down the wrong route here - you should be looking at preventative maintenance instead of fixing it after its broken. Ensure that autovacuum is running for the database (assuming that you are on a relatively modern version of PG), and possibly tune it to be more aggressive (we can help). This will ensure that the condition never comes up. ps - if you do go with the route specify, no need to VACUUM after the CLUSTER. CLUSTER gets rid of the dead tuples - nothing for VACUUM to do. -- Brad Nicholson 416-673-4106 Database Administrator, Afilias Canada Corp.