aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2016-05-25 17:48:15 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2016-05-25 17:48:15 -0400
commitb2355a29c69c90b9987cc3a8884b8ed3396842e9 (patch)
treeaa0749d31b6cbc9527f29efe504f6128dbb65ecc
parentaf6555b80c7b5f9827a58c5872a723d5660897ae (diff)
downloadpostgresql-b2355a29c69c90b9987cc3a8884b8ed3396842e9.tar.gz
postgresql-b2355a29c69c90b9987cc3a8884b8ed3396842e9.zip
Ensure that backends see up-to-date statistics for shared catalogs.
Ever since we split the statistics collector's reports into per-database files (commit 187492b6c2e8cafc), backends have been seeing stale statistics for shared catalogs. This is because the inquiry message only prompts the collector to write the per-database file for the requesting backend's own database. Stats for shared catalogs are in a separate file for "DB 0", which didn't get updated. In normal operation this was partially masked by the fact that the autovacuum launcher would send an inquiry message at least once per autovacuum_naptime that asked for "DB 0"; so the shared-catalog stats would never be more than a minute out of date. However the problem becomes very obvious with autovacuum disabled, as reported by Peter Eisentraut. To fix, redefine the semantics of inquiry messages so that both the specified DB and DB 0 will be dumped. (This might seem a bit inefficient, but we have no good way to know whether a backend's transaction will look at shared-catalog stats, so we have to read both groups of stats whenever we request stats. Sending two inquiry messages would definitely not be better.) Back-patch to 9.3 where the bug was introduced. Report: <56AD41AC.1030509@gmx.net>
-rw-r--r--src/backend/postmaster/pgstat.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c
index ab018c47414..7f64949ea02 100644
--- a/src/backend/postmaster/pgstat.c
+++ b/src/backend/postmaster/pgstat.c
@@ -5351,7 +5351,16 @@ pgstat_db_requested(Oid databaseid)
{
slist_iter iter;
- /* Check the databases if they need to refresh the stats. */
+ /*
+ * If any requests are outstanding at all, we should write the stats for
+ * shared catalogs (the "database" with OID 0). This ensures that
+ * backends will see up-to-date stats for shared catalogs, even though
+ * they send inquiry messages mentioning only their own DB.
+ */
+ if (databaseid == InvalidOid && !slist_is_empty(&last_statrequests))
+ return true;
+
+ /* Search to see if there's an open request to write this database. */
slist_foreach(iter, &last_statrequests)
{
DBWriteRequest *req = slist_container(DBWriteRequest, next, iter.cur);