Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 43190B5DBD9 for ; Fri, 14 Oct 2011 01:37:56 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 86835-03 for ; Fri, 14 Oct 2011 04:37:50 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id E75F1B5DBD8 for ; Fri, 14 Oct 2011 01:37:49 -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 p9E4bmTn013426; Fri, 14 Oct 2011 00:37:48 -0400 (EDT) To: Svetlin Manavski cc: pgsql-performance@postgresql.org Subject: Re: Join over two tables of 50K records takes 2 hours In-reply-to: References: Comments: In-reply-to Svetlin Manavski message dated "Wed, 12 Oct 2011 09:55:46 +0100" Date: Fri, 14 Oct 2011 00:37:48 -0400 Message-ID: <13425.1318567068@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.404 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RP_MATCHES_RCVD=-0.504 X-Spam-Level: X-Archive-Number: 201110/136 X-Sequence-Number: 45358 Svetlin Manavski writes: > I am running 9.03 with the settings listed below. I have a prohibitively > slow query in an application which has an overall good performance: It's slow because the planner is choosing a nestloop join on the strength of its estimate that there's only a half dozen rows to be joined. You need to figure out why those rowcount estimates are so bad. I suspect that you've shot yourself in the foot by raising autovacuum_analyze_threshold so high --- most likely, none of those tables have ever gotten analyzed. And what's with the high autovacuum_naptime setting? You might need to increase default_statistics_target too, but first see if a manual ANALYZE makes things better. regards, tom lane