pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Koen De Groote <kdg.dev@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Index no longer being used, destroying and recreating it restores use.
Date: Thu, 4 Jun 2020 09:29:27 -0700
Message-ID: <0ac3b92f-d4da-5b10-ac11-a73b4c4116a3@aklaver.com> (raw)
In-Reply-To: <CAGbX52FL1ihuw9kWB8a2J2QPofgfDhykBENJaoyVEfTTPOvpkw@mail.gmail.com>
References: <CAGbX52FL1ihuw9kWB8a2J2QPofgfDhykBENJaoyVEfTTPOvpkw@mail.gmail.com>

On 6/4/20 8:37 AM, Koen De Groote wrote:
> Greetings,
> 
> The following is using version 11.2 of PostgreSQL.
> 
> I've got a table with about 30 million rows and a particular index that 
> up until recently was actively being used.
> 
> And then it stopped being used and the query that the index was made 
> for, is now doing sequential scans.

Did you ANALYZE the table at that point?

> 
> Deleting the index and creating it again, seems to fix the problem. The 
> new index, which is identical in composition, is being used and the 
> query in question no longer uses sequential scans.
> 
> 
> It's the exact same query and the index is identical in composition. Yet 
> after a while the database stops using it. I'd like to find out why that 
> is and how to prevent it.
> 
> 
> Also, I'm assuming this is the correct list for such a question?
> 
> 
> In the past, I had asked this somewhere else, but then no longer had 
> time to spend on it: https://dba.stackexchange.com/questions/264237/
> 
> Some data I gathered then:
> 
>  1. Size of the index not being used is 101MB.
>  2. Size of the index being used is 16MB.
> 
> The query takes the form of:
> 
> "select * from myTable where bool1 = true and bool2 = false and 
> timestamp <= ('timestampField'::timestamp without time zone) order by 
> stringField asc, id asc limit 100 offset 30000;"
> 
> 30000 is an example value.
> #
> 
> Here is the "explain analyze" for index used: 
> https://explain.depesz.com/s/H5X9y
> 
> #
> 
> Here is the "explain analyze" for index not used: 
> https://explain.depesz.com/s/n6bP
> 
> 
> And I'm frankly stumped.An index growing from 16MB to 101MB isn't that 
> big of an increase, I would think? Is that the reason it's no longer 
> being used? Or is something else going on here?
> 
> The entire database, in which this table belongs, undergoes a "vacuum 
> analyze" every single night, which takes about 8 minutes. Do I perhaps 
> need to do something additional in terms of cleanup/maintenance?
> 
> I've tried altering statistics, to very large values even, but no 
> changes there either.
> 
> Any help or suggestion would be appreciated.
> 
> Kind regards,
> Koen De Groote
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com





view thread (17+ messages)  latest in thread

Message-ID: <0ac3b92f-d4da-5b10-ac11-a73b4c4116a3@aklaver.com>
Permalink:  ../0ac3b92f-d4da-5b10-ac11-a73b4c4116a3@aklaver.com/
Also on:    postgresql.org/message-id/0ac3b92f-d4da-5b10-ac11-a73b4c4116a3@aklaver.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: adrian.klaver@aklaver.com, kdg.dev@gmail.com
  Subject: Re: Index no longer being used, destroying and recreating it restores use.
  In-Reply-To: <0ac3b92f-d4da-5b10-ac11-a73b4c4116a3@aklaver.com>
  References: <CAGbX52FL1ihuw9kWB8a2J2QPofgfDhykBENJaoyVEfTTPOvpkw@mail.gmail.com> <0ac3b92f-d4da-5b10-ac11-a73b4c4116a3@aklaver.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox