Re: Sequential scan being used despite indexes - Mailing list pgsql-performance

From Michael Fuhr
Subject Re: Sequential scan being used despite indexes
Date
Msg-id 20060201050828.GA6681@winnie.fuhr.org
Whole thread Raw
In response to Re: Sequential scan being used despite indexes  (James Russell <internationalhobo@gmail.com>)
List pgsql-performance
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

pgsql-performance by date:

Previous
From: Christopher Kings-Lynne
Date:
Subject: Re: Sequential scan being used despite indexes
Next
From: Tom Lane
Date:
Subject: Re: partitioning and locking problems