PostgreSQL pg_stat_all_indexes table 中的统计信息存储了多长时间?

How long are stats in PostgreSQL's pg_stat_all_indexes table stored?

我使用 PostgreSQL 11.1,我正在尝试从 pg_stat_all_indexes table 收集有关索引使用情况的信息,以确定是否可以删除特定索引 - 根据 Index size/usage statistics https://wiki.postgresql.org/wiki/Index_Maintenance 中的部分。

我注意到那里的信息随着时间的推移发生了显着变化(从几千次索引命中到 0),而且我在文档或 table 本身中都找不到关于这些统计生命周期的信息。这让我很担心,因为我想确定,我要做出的关于删除索引的决定是基于足够长一段时间内的统计数据。

有什么方法可以检查这些统计信息在 pg_stat_all_indexes table 中存储了多长时间?

Quote from the manual

When the server shuts down cleanly, a permanent copy of the statistics data is stored in the pg_stat subdirectory, so that statistics can be retained across server restarts. When recovery is performed at server start [...], all statistics counters are reset

(强调我的)

如果您想重置统计数据以获得基线,您可以使用pg_stat_reset()然后比较从那一点开始的值(例如通过存储每日快照并比较天数之间的差异)