]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Rework pgstat_write_statsfile() in combination with to_serialized_data REL_19_STABLE github/REL_19_STABLE
authorMichael Paquier <michael@paquier.xyz>
Wed, 15 Jul 2026 01:35:19 +0000 (10:35 +0900)
committerMichael Paquier <michael@paquier.xyz>
Wed, 15 Jul 2026 01:35:19 +0000 (10:35 +0900)
commit0892319c65e7d7458ee8fb902618491aaa0e4734
tree7e0a463f4485f5c77764bbdcaee8adf5e72597d6
parent31d04313c1163497f4c6f4f64fad2359cbbab149
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
src/backend/utils/activity/pgstat.c
src/include/utils/pgstat_internal.h
src/test/modules/test_custom_stats/test_custom_var_stats.c