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. See pgstat_read_db_statsfile_timestamp. I have observed this while reviewing Sawada-San's patch related to logical replication stats [1].
I think 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. The attached patch by Sawada-San will fix this issue. As the chances of this the problem is rare and nobody has reported any issue related to this, so it might be okay not to backpatch this. Thoughts? [1] - https://www.postgresql.org/message-id/CAA4eK1JBqQh9cBKjO-nKOOE%3D7f6ONDCZp0TJZfn4VsQqRZ%2BuYA%40mail.gmail.com -- With Regards, Amit Kapila.
v1-0001-Fix-inconsistency-in-determining-the-timestamp-of.patch
Description: Binary data