postgresql_16:4.13.2.19 pg_stat_all_indexes
PostgreSQL 16 > Server Administration > Monitoring Database Activity > The Cumulative Statistics System > pg_stat_all_indexes
The pg_stat_all_indexes view will contain one row for each index in the current database, showing statistics about accesses to that specific index. The pg_stat_user_indexes and pg_stat_sys_indexes views contain the same information, but filtered to only show user and system indexes respectively.
| Column Type Description | | --- | | relid oid OID of the table for this index | | indexrelid oid OID of this index | | schemaname name Name of the schema this index is in | | relname name Name of the table for this index | | indexrelname name Name of this index | | idx_scan bigint Number of index scans initiated on this index | | last_idx_scan timestamp with time zone The time of the last scan on this index, based on the most recent transaction stop time | | idx_tup_read bigint Number of index entries returned by scans on this index | | idx_tup_fetch bigint Number of live table rows fetched by simple index scans using this index |
Indexes can be used by simple index scans, “bitmap” index scans, and the optimizer. In a bitmap scan the output of several indexes can be combined via AND or OR rules, so it is difficult to associate individual heap row fetches with specific indexes when a bitmap scan is used. Therefore, a bitmap scan increments the pg_stat_all_indexes.idx_tup_read count(s) for the index(es) it uses, and it increments the pg_stat_all_tables.idx_tup_fetch count for the table, but it does not affect pg_stat_all_indexes.idx_tup_fetch. The optimizer also accesses indexes to check for supplied constants whose values are outside the recorded range of the optimizer statistics because the optimizer statistics might be stale.
Note
The idx_tup_read and idx_tup_fetch counts can be different even without any use of bitmap scans, because idx_tup_read counts index entries retrieved from the index while idx_tup_fetch counts live rows fetched from the table. The latter will be less if any dead or not-yet-committed rows are fetched using the index, or if any heap fetches are avoided by means of an index-only scan.