pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix assertion failure when updating stats_fetch_consistency in a
Date: Wed, 10 May 2023 02:25:08 +0000
Message-ID: <E1pwZVr-001MLX-VK@gemulon.postgresql.org> (raw)

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
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/605994651b6a4209b418cb09d3c223ca269f7cfc

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



view thread (7+ messages)

Message-ID: <E1pwZVr-001MLX-VK@gemulon.postgresql.org>
Permalink:  ../E1pwZVr-001MLX-VK@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1pwZVr-001MLX-VK@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: michael@paquier.xyz, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Fix assertion failure when updating stats_fetch_consistency in a
  In-Reply-To: <E1pwZVr-001MLX-VK@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox