Re: Postgres index usage

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Dirschel, Steve" <steve(dot)dirschel(at)thomsonreuters(dot)com>
Cc: "pgsql-performance(at)lists(dot)postgresql(dot)org" <pgsql-performance(at)lists(dot)postgresql(dot)org>
Subject: Re: Postgres index usage
Date: 2024-08-07 17:36:50
Message-ID: 2056002.1723052210@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

"Dirschel, Steve" <steve(dot)dirschel(at)thomsonreuters(dot)com> writes:
> I queried that table for a specific index and idx_scan is 0. I
> queried pg_statio_all_indexes and can see idx_blks_read and
> idx_blks_hit have numbers in there. If the index is not being used
> then what it causing idx_blks_read and idx_blks_hit to increase over
> time? I'm wondering if those increase due to DML on the table.

Yes, I think that's the case: index updates will cause the per-block
counters to advance, but only an index search will increment idx_scan.

I'd recommend testing this theory for yourself in an idle database,
though. It's not impossible that Aurora works differently from
community PG.

Another thing to keep in mind is that in versions before PG 15,
the statistics subsystem is (by design) unreliable and might sometimes
miss events under load. This effect isn't big enough to invalidate
a conclusion that an index with idx_scan = 0 isn't being used, but
it's something to keep in mind when running small tests that are
only expected to record a few events.

regards, tom lane

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Greg Sabino Mullane 2024-08-07 18:18:46 Re: Postgres index usage
Previous Message Dirschel, Steve 2024-08-07 17:23:35 RE: Postgres index usage