X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 587C69DCAAF for ; Wed, 1 Feb 2006 01:08:39 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 52913-03 for ; Wed, 1 Feb 2006 01:08:38 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by postgresql.org (Postfix) with ESMTP id CF9769DC85C for ; Wed, 1 Feb 2006 01:08:36 -0400 (AST) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id k1158TbW037854 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 31 Jan 2006 22:08:32 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.4/8.13.4) with ESMTP id k1158S7m006911; Tue, 31 Jan 2006 22:08:28 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.4/8.13.4/Submit) id k1158SVA006910; Tue, 31 Jan 2006 22:08:28 -0700 (MST) (envelope-from mfuhr) Date: Tue, 31 Jan 2006 22:08:28 -0700 From: Michael Fuhr To: James Russell Cc: "Joshua D. Drake" , pgsql-performance@postgresql.org Subject: Re: Sequential scan being used despite indexes Message-ID: <20060201050828.GA6681@winnie.fuhr.org> References: <3a3a16930601311914w5bd7d1d0hde7b4e495e0deb27@mail.gmail.com> <43E02B2F.9070202@commandprompt.com> <20060201035803.GA6324@winnie.fuhr.org> <3a3a16930601312033w2e4e3186k8f502e5b8c2cc6f2@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3a3a16930601312033w2e4e3186k8f502e5b8c2cc6f2@mail.gmail.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.115 required=5 tests=[AWL=0.115] X-Spam-Score: 0.115 X-Spam-Level: X-Archive-Number: 200602/4 X-Sequence-Number: 16990 On Wed, Feb 01, 2006 at 01:33:08PM +0900, James Russell wrote: > Reading about this issue further in the FAQ, it seems that I should ensure > that Postgres has adequate and accurate information about the tables in > question by regularly running VACUUM ANALYZE, something I don't do > currently. Many people use a cron job (or the equivalent) to run VACUUM ANALYZE at regular intervals; some also use the pg_autovacuum daemon, which is a contrib module in 8.0 and earlier and part of the backend as of 8.1. How often to vacuum/analyze depends on usage. Once per day is commonly cited, but busy tables might need it more often than that. Just recently somebody had a table that could have used vacuuming every five minutes or less (all records were updated every 30 seconds); pg_autovacuum can be useful in such cases. > I disabled SeqScan as per the FAQ, and it indeed was a lot slower so > Postgres was making the right choice in this case. The planner might be making the right choice given the statistics it has, but it's possible that better statistics would lead to a different plan, perhaps one where an index scan would be faster. What happens if you run VACUUM ANALYZE on all the tables, then run the query again with EXPLAIN ANALYZE? -- Michael Fuhr