Re: BUG #15801: pg_stat_database update stats_reset only by pg_stat_reset
On Mon, May 13, 2019 at 07:15:47AM +0000, PG Bug reporting form wrote:
> only update pg_stat_database column stats_reset.
> stat_reset shuld update when all the column is reset.
These two functions reset statistics for a single table, and what you
are looking at are the database-level statistics.
On Mon, May 13, 2019 at 12:46 PM PG Bug reporting form <[hidden email]> wrote:
only update pg_stat_database column stats_reset.
stat_reset shuld update when all the column is reset.
pg_stat_reset_single_table_counters resets the stats of a single table. From your example, it resets the following stats:
select * from pg_stat_all_tables where relid='lzzhang_tab'::regclass::oid;
It'll not reset the database statistics.
It seems from the code in pgstat_recv_resetsinglecounter that whenever any individual object inside the database is reset, the stats_reset of pg_stat_database view is updated. This behaviour got introduced by the following commit:
Track last time for statistics reset on databases and bgwriter
Tracks one counter for each database, which is reset whenever
the statistics for any individual object inside the database is
reset, and one counter for the background writer.
So, the behaviour seems to be intentional. But, the documents of pg_stat_database doesn't convey this behaviour properly.
stats_resettimestamp with time zoneTime at which these statistics were last reset
IMHO, the actual behaviour is stats_reset is the time at which either any pg_stat_database statistic of a database is updated or any statistic of any object inside the database is updated.