Re: INSERT/UPDATE statements sometimes choosing not to use PK index? - Mailing list pgsql-general

From Tom Lane
Subject Re: INSERT/UPDATE statements sometimes choosing not to use PK index?
Date
Msg-id 32040.1383054311@sss.pgh.pa.us
Whole thread Raw
In response to INSERT/UPDATE statements sometimes choosing not to use PK index?  (Matt <bsg075@gmail.com>)
Responses Re: INSERT/UPDATE statements sometimes choosing not to use PK index?
List pgsql-general
Matt <bsg075@gmail.com> writes:
> In most cases, EXPLAIN and runtime tell me the index is utilized. However,
> sometime on back to back runs (5 minute intervals) the runtime explodes and
> EXPLAIN shows me that the PK index is not used, as both the staging table
> and destination table a sequentially scanned.

You haven't explained what you do with the "staging table", but maybe you
need to ANALYZE it after you've loaded fresh data into it.  The stats for
the main table are presumably somewhat stable, but the stats for the
staging table maybe not.  The apparent correlation to consecutive runs
lends some support to this theory, as that would reduce the time window
for auto-ANALYZE to fix it for you.

            regards, tom lane


pgsql-general by date:

Previous
From: Chris Travers
Date:
Subject: Re: json datatype and table bloat?
Next
From: Rahila Syed
Date:
Subject: Increasing CPU usage of PostgreSQL