Proposal: Track last-used timestamp for index usage
Proposal: Track last-used timestamp for index usage
От:
Raghav Mittal <mittalr086@gmail.com>
Дата:
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.
Possible approach:
- Mark index usage in executor (cheap signal)
- Background worker periodically updates last_used_at
- Avoids overhead in query execution path
Questions:
1. Has this problem been explored before?
2. Are there known concerns with adding timestamp tracking to stats?
3. Would this be acceptable as an extension vs core feature?
Happy to prototype this if there’s interest.
Thanks!
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.
Possible approach:
- Mark index usage in executor (cheap signal)
- Background worker periodically updates last_used_at
- Avoids overhead in query execution path
Questions:
1. Has this problem been explored before?
2. Are there known concerns with adding timestamp tracking to stats?
3. Would this be acceptable as an extension vs core feature?
Happy to prototype this if there’s interest.
Thanks!
Re: Proposal: Track last-used timestamp for index usage
От:
SATYANARAYANA NARLAPURAM <satyanarlapuram@gmail.com>
Дата:
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
Re: Proposal: Track last-used timestamp for index usage
От:
Sami Imseih <samimseih@gmail.com>
Дата:
Hi, > 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. pg_stat_user_indexes.last_idx_scan and pg_stat_all_tableslast_seq_scan have been around since v16. See [1] Is that what you are looking for? [1] [https://www.postgresql.org/docs/devel/monitoring-stats.html#MONITORING-PG-STAT-ALL-INDEXES-VIEW] -- Sami Imseih Amazon Web Services (AWS)