pgsql: Fix assertion failure when updating stats_fetch_consistency in a - Mailing list pgsql-committers

From Michael Paquier
Subject pgsql: Fix assertion failure when updating stats_fetch_consistency in a
Date
Msg-id E1pwZVr-001MLY-Vt@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Fix assertion failure when updating stats_fetch_consistency in a transaction

An update of the GUC stats_fetch_consistency in a transaction would be
able to trigger an assertion when doing cache->snapshot.  In this case,
when retrieving a pgstat entry after the switch, a new snapshot would be
rebuilt, confusing pgstat_build_snapshot() because a snapshot is already
cached with an unexpected mode ("cache").

In order to fix this problem, this commit adds a flag to force a
snapshot clear each time this GUC is changed.  Some tests are added to
check, while on it.

Some optimizations in avoiding the snapshot clear should be possible
depending on what is cached and the current GUC value, I guess, but this
solution is simple, and ensures that the state of the cache is updated
each time a new pgstat entry is fetched, hence being consistent with the
level wanted by the client that has set the GUC.

Note that cache->none and snapshot->none would not cause issues, as
fetching a pgstat entry would be retrieved from shared memory on the
second attempt, however a snapshot would still be cached.  Similarly,
none->snapshot and none->cache would build a new snapshot on the second
fetch attempt.  Finally, snapshot->cache would cache a new snapshot on
the second attempt.

Reported-by: Alexander Lakhin
Author: Kyotaro Horiguchi
Discussion: https://postgr.es/m/17804-2a118cd046f2d0e5@postgresql.org
backpatch-through: 15

Branch
------
REL_15_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/ccd21e1cfa11fa4f39d01d95cf119beae9cf4d20

Modified Files
--------------
doc/src/sgml/config.sgml            |  5 ++--
src/backend/utils/activity/pgstat.c | 34 ++++++++++++++++++++-
src/backend/utils/misc/guc.c        |  2 +-
src/include/pgstat.h                |  2 ++
src/test/regress/expected/stats.out | 59 +++++++++++++++++++++++++++++++++++++
src/test/regress/sql/stats.sql      | 20 +++++++++++++
6 files changed, 118 insertions(+), 4 deletions(-)


pgsql-committers by date:

Previous
From: Michael Paquier
Date:
Subject: pgsql: Document values of stats_fetch_consistency in postgresql.conf.sa
Next
From: Peter Eisentraut
Date:
Subject: pgsql: Add missing gettext triggers