agora inbox for pgsql-committers@postgresql.org  
help / color / mirror / Atom feed
pgsql: Rework pgstat_write_statsfile() in combination with to_serialize
2+ messages / 1 participants
[nested] [flat]

* pgsql: Rework pgstat_write_statsfile() in combination with to_serialize
@ 2026-07-15 01:53  Michael Paquier <michael@paquier.xyz>
  0 siblings, 0 replies; 2+ messages in thread

From: Michael Paquier @ 2026-07-15 01:53 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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(-)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* pgsql: Rework pgstat_write_statsfile() in combination with to_serialize
@ 2026-07-15 01:53  Michael Paquier <michael@paquier.xyz>
  0 siblings, 0 replies; 2+ messages in thread

From: Michael Paquier @ 2026-07-15 01:53 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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

Details
-------
https://git.postgresql.org/pg/commitdiff/0892319c65e7d7458ee8fb902618491aaa0e4734

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(-)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2026-07-15 01:53 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-07-15 01:53 pgsql: Rework pgstat_write_statsfile() in combination with to_serialize Michael Paquier <michael@paquier.xyz>
2026-07-15 01:53 pgsql: Rework pgstat_write_statsfile() in combination with to_serialize Michael Paquier <michael@paquier.xyz>

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