diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c index 893b66107ef..f4ea96fbb32 100644 --- a/src/backend/postmaster/pgstat.c +++ b/src/backend/postmaster/pgstat.c @@ -3721,9 +3721,20 @@ pgstat_read_statsfile(Oid onlydb, bool permanent) { ereport(pgStatRunningInCollector ? LOG : WARNING, (errmsg("corrupted statistics file \"%s\"", statfile))); + memset(&globalStats, 0, sizeof(globalStats)); goto done; } + /* + * In the collector, disregard the timestamp we read from the permanent + * stats file; we should be willing to write a temp stats file immediately + * upon the first request from any backend. This only matters if the old + * file's timestamp is less than PGSTAT_STAT_INTERVAL ago, but that's not + * an unusual scenario. + */ + if (pgStatRunningInCollector) + globalStats.stats_timestamp = 0; + /* * We found an existing collector stats file. Read it and put all the * hashtable entries into place.