agora inbox for pgsql-committers@postgresql.org
help / color / mirror / Atom feedFrom: Michael Paquier <michael@paquier.xyz>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Rework pgstat_write_statsfile() in combination with to_serialize
Date: Wed, 15 Jul 2026 01:53:54 +0000
Message-ID: <E1wjoor-000DwF-1w@gemulon.postgresql.org> (raw)
Rework pgstat_write_statsfile() in combination with to_serialized_data
Contrary to the from_serialized_data callback used by the pgstats reads
at startup, the to_serialized_data callback used for the pgstats writes
matched with pgstat_write_statsfile(), by not returning a boolean
status, expecting a ferror() failure to deal with the discard of the
stats file should an error happen while writing the stats. This was
slightly confusing designed this way.
Things are changed in this commit with:
- to_serialized_data now returns a boolean status on a write failure.
pgstat_write_statsfile() detects that and switches to failure mode
instead of continuing to process the entries to write, speeding up the
shutdown.
- pgstat_write_statsfile() now uses STATS_DISCARD if a failure happens,
to let the registered callbacks directly know that something is wrong,
and that things need to be cleaned up. This gives a better error path
detection for custom stats kinds. For example, they do not have to rely
solely on the expectation of an ferror() for an auxiliary file.
This new set of behaviors matches with what is already done in
pgstat_read_statsfile() for the finish() callback (DISCARD on failure,
READ on success) and the from_serialized_data with a status returned.
Author: Sami Imseih <samimseih@gmail.com>
Discussion: https://postgr.es/m/CAA5RZ0sMgOvuhpb2P=KSJOjgjC6AfUu+GYcu9mHar-y_Xtd=Pg@mail.gmail.com
Backpatch-through: 19
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/572c3b2ddf8c90303d57bf33add4dcbf1b30b866
Modified Files
--------------
src/backend/utils/activity/pgstat.c | 34 ++++++++++++++++++----
src/include/utils/pgstat_internal.h | 5 ++--
.../test_custom_stats/test_custom_var_stats.c | 29 +++++++++++-------
3 files changed, 49 insertions(+), 19 deletions(-)
view thread (2+ messages) latest in thread
Message-ID: <E1wjoor-000DwF-1w@gemulon.postgresql.org>
Permalink: ../E1wjoor-000DwF-1w@gemulon.postgresql.org/
Also on: postgresql.org/message-id/E1wjoor-000DwF-1w@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: Rework pgstat_write_statsfile() in combination with to_serialize
In-Reply-To: <E1wjoor-000DwF-1w@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 agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox