Re: Proposal: Track last-used timestamp for index usage - Mailing list pgsql-hackers

From SATYANARAYANA NARLAPURAM
Subject Re: Proposal: Track last-used timestamp for index usage
Date
Msg-id CAHg+QDdoo0u+WWuHYOnKn+ygYrg87yufiPUS_X+=0BrUEM3JYw@mail.gmail.com
Whole thread
In response to Proposal: Track last-used timestamp for index usage  (Raghav Mittal <mittalr086@gmail.com>)
List pgsql-hackers
Hi Raghav,

On Tue, Mar 31, 2026 at 7:23 PM Raghav Mittal <mittalr086@gmail.com> wrote:
Hi all,

I’ve been exploring index usage statistics in PostgreSQL and noticed that
pg_stat_user_indexes only provides cumulative counters (idx_scan), but not
recency information.

Problem:
- Counters reset on restart or pg_stat_reset()
- No way to determine when an index was last used
- Makes it hard to safely identify unused indexes

Proposal:
Introduce lightweight tracking of last-used timestamp for indexes.

Could you elaborate the problem trying to solve here? As you mentioned idx_scan already tracks the usage. Periodic snapshots should provide the usage over a period of time. What is the purpose of exact timestamp?

Thanks,
Satya

pgsql-hackers by date:

Previous
From: Sami Imseih
Date:
Subject: Re: Add pg_stat_autovacuum_priority
Next
From: Sami Imseih
Date:
Subject: Re: Refactor query normalization into core query jumbling