From e8d281545ef5c944b119e525ca2c7fc761565cbf Mon Sep 17 00:00:00 2001 From: Amit Kapila Date: Tue, 8 Sep 2020 11:14:49 +0530 Subject: [PATCH v1] Fix inconsistency in determining the timestamp of the db statfile. We use the timestamp of the global statfile if we are not able to determine it for a particular database either because the entry for that database doesn't exist or there is an error while reading the specific database entry. This was not taken care of while reading other entries like ArchiverStats or SLRUStats. This can only happen if due to some reason the statfile got corrupt or we have some bug in stats writing code, the chances of both are rare and even if that happens we will use stale statistics. As the chances of this problem are rare and nobody has reported any issue, so decided not to backpatch it. Reported-By: Amit Kapila Author: Sawada Masahiko --- src/backend/postmaster/pgstat.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c index 5f4b168fd1..3c14e646e8 100644 --- a/src/backend/postmaster/pgstat.c +++ b/src/backend/postmaster/pgstat.c @@ -5620,6 +5620,9 @@ pgstat_read_db_statsfile_timestamp(Oid databaseid, bool permanent, return false; } + /* By default, we're going to return the timestamp of the global file. */ + *ts = myGlobalStats.stats_timestamp; + /* * Read archiver stats struct */ @@ -5629,7 +5632,7 @@ pgstat_read_db_statsfile_timestamp(Oid databaseid, bool permanent, ereport(pgStatRunningInCollector ? LOG : WARNING, (errmsg("corrupted statistics file \"%s\"", statfile))); FreeFile(fpin); - return false; + return true; } /* @@ -5640,12 +5643,9 @@ pgstat_read_db_statsfile_timestamp(Oid databaseid, bool permanent, ereport(pgStatRunningInCollector ? LOG : WARNING, (errmsg("corrupted statistics file \"%s\"", statfile))); FreeFile(fpin); - return false; + return true; } - /* By default, we're going to return the timestamp of the global file. */ - *ts = myGlobalStats.stats_timestamp; - /* * We found an existing collector stats file. Read it and look for a * record for the requested database. If found, use its timestamp. -- 2.28.0.windows.1