summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Paquier2025-03-08 01:56:30 +0000
committerMichael Paquier2025-03-08 01:56:30 +0000
commit9a8dd2c5a6d9d2538444c156e6b273b1b4f4e3a4 (patch)
tree88132b555c12f20c12ebb8a742d475f5cd545102
parent8e167e618893b59ee45317c43055002ba71f955b (diff)
Improve check for detection of pending data in backend statistics
The callback pgstat_backend_have_pending_cb() is used as a way for pg_stat_report() to detect if there is any pending data for backend statistics. It did not include a check based on pgstat_tracks_backend_bktype(), that discards processes whose backend types do not support backend statistics. The logic is not a problem on HEAD, as processes that do not support backend statistics cannot touch PendingBackendStats, so the callback would always report that there is no pending data in this case. However, we would run into trouble once backend statistics include portions of pending stats that are not always zeroed, like pgWalUsage. There is no reason for pgstat_backend_have_pending_cb() to not check for pgstat_tracks_backend_bktype(), anyway, and this pattern is safer in the long run, so let's update the code to do so. While on it, this commit adds a proper initialization to PendingBackendStats. Author: Bertrand Drouvot <[email protected]> Co-authored-by: Michael Paquier <[email protected]> Discussion: https://postgr.es/m/[email protected]
-rw-r--r--src/backend/utils/activity/pgstat_backend.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/backend/utils/activity/pgstat_backend.c b/src/backend/utils/activity/pgstat_backend.c
index a9343b7b59e..6efbb650aa8 100644
--- a/src/backend/utils/activity/pgstat_backend.c
+++ b/src/backend/utils/activity/pgstat_backend.c
@@ -36,7 +36,7 @@
* reported within critical sections so we use static memory in order to avoid
* memory allocation.
*/
-static PgStat_BackendPending PendingBackendStats;
+static PgStat_BackendPending PendingBackendStats = {0};
/*
* Utility routines to report I/O stats for backends, kept here to avoid
@@ -222,6 +222,9 @@ pgstat_flush_backend(bool nowait, bits32 flags)
bool
pgstat_backend_have_pending_cb(void)
{
+ if (!pgstat_tracks_backend_bktype(MyBackendType))
+ return false;
+
return (!pg_memory_is_all_zeros(&PendingBackendStats,
sizeof(struct PgStat_BackendPending)));
}