From 7c01e2c39ca6f0d9edfe02a8f51cd2e4a3b452bc Mon Sep 17 00:00:00 2001
From: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Date: Wed, 25 Feb 2026 15:48:14 +0530
Subject: [PATCH v20260724 4/7] Pass use_units parameter to GucShowHook
 functions

ShowGUCOption() prints the value of a GUC variable with units if the variable
has a unit and the caller passes use_units as true. However when a GUC variable
has a show_hook associated with it, the show_hook does not receive use_units
parameter. Hence a show_hook cannot determine whether to show the value with
units or not. This was not a problem until now because all the GUC variables
with show_hook were either didn't have any units associated with them or their
show_hook used a fixed unit to print the value of the variable.

shared_buffers is a GUC variable whose value is shows in different units based
on the GUC variable's value.  With shared buffer pool resizing, we want to show
the pending size of the buffer pool, if any with appropriate units. We do this
using a show_hook, which needs use_units input. This commit adds use_units
parameter to GucShowHook and passes it from ShowGUCOption(). The actual commit
which uses this new parameter will be in a followup commit.

Author: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Reported by: Palak Chaturvedi <chaturvedipalak1911@gmail.com>
---
 src/backend/access/transam/xlog.c |  8 ++++----
 src/backend/commands/variable.c   | 14 +++++++-------
 src/backend/executor/instrument.c |  2 +-
 src/backend/libpq/pqcomm.c        |  8 ++++----
 src/backend/utils/misc/guc.c      | 10 +++++-----
 src/include/access/xlog.h         |  2 +-
 src/include/utils/guc.h           |  2 +-
 src/include/utils/guc_hooks.h     | 30 +++++++++++++++---------------
 8 files changed, 38 insertions(+), 38 deletions(-)

diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 26e4929e167..a4057223cf7 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -4975,7 +4975,7 @@ SetLocalDataChecksumState(uint32 data_checksum_version)
 
 /* guc hook */
 const char *
-show_data_checksums(void)
+show_data_checksums(bool use_units)
 {
 	return get_checksum_state_string(LocalDataChecksumState);
 }
@@ -5211,7 +5211,7 @@ InitializeWalConsistencyChecking(void)
  * GUC show_hook for archive_command
  */
 const char *
-show_archive_command(void)
+show_archive_command(bool use_units)
 {
 	if (XLogArchivingActive())
 		return XLogArchiveCommand;
@@ -5223,7 +5223,7 @@ show_archive_command(void)
  * GUC show_hook for in_hot_standby
  */
 const char *
-show_in_hot_standby(void)
+show_in_hot_standby(bool use_units)
 {
 	/*
 	 * We display the actual state based on shared memory, so that this GUC
@@ -5238,7 +5238,7 @@ show_in_hot_standby(void)
  * GUC show_hook for effective_wal_level
  */
 const char *
-show_effective_wal_level(void)
+show_effective_wal_level(bool use_units)
 {
 	if (wal_level == WAL_LEVEL_MINIMAL)
 		return "minimal";
diff --git a/src/backend/commands/variable.c b/src/backend/commands/variable.c
index 8afd252fc8c..491c8aa392d 100644
--- a/src/backend/commands/variable.c
+++ b/src/backend/commands/variable.c
@@ -389,7 +389,7 @@ assign_timezone(const char *newval, void *extra)
  * show_timezone: GUC show_hook for timezone
  */
 const char *
-show_timezone(void)
+show_timezone(bool use_units)
 {
 	const char *tzn;
 
@@ -462,7 +462,7 @@ assign_log_timezone(const char *newval, void *extra)
  * show_log_timezone: GUC show_hook for log_timezone
  */
 const char *
-show_log_timezone(void)
+show_log_timezone(bool use_units)
 {
 	const char *tzn;
 
@@ -674,7 +674,7 @@ assign_random_seed(double newval, void *extra)
 }
 
 const char *
-show_random_seed(void)
+show_random_seed(bool use_units)
 {
 	return "unavailable";
 }
@@ -1031,7 +1031,7 @@ assign_role(const char *newval, void *extra)
 }
 
 const char *
-show_role(void)
+show_role(bool use_units)
 {
 	/*
 	 * Check whether SET ROLE is active; if not return "none".  This is a
@@ -1179,7 +1179,7 @@ assign_io_combine_limit(int newval, void *extra)
  * GUC show_hook for data_directory_mode
  */
 const char *
-show_data_directory_mode(void)
+show_data_directory_mode(bool use_units)
 {
 	static char buf[12];
 
@@ -1191,7 +1191,7 @@ show_data_directory_mode(void)
  * GUC show_hook for log_file_mode
  */
 const char *
-show_log_file_mode(void)
+show_log_file_mode(bool use_units)
 {
 	static char buf[12];
 
@@ -1203,7 +1203,7 @@ show_log_file_mode(void)
  * GUC show_hook for unix_socket_permissions
  */
 const char *
-show_unix_socket_permissions(void)
+show_unix_socket_permissions(bool use_units)
 {
 	static char buf[12];
 
diff --git a/src/backend/executor/instrument.c b/src/backend/executor/instrument.c
index ffbcd572133..d4c8373336a 100644
--- a/src/backend/executor/instrument.c
+++ b/src/backend/executor/instrument.c
@@ -423,7 +423,7 @@ assign_timing_clock_source(int newval, void *extra)
 }
 
 const char *
-show_timing_clock_source(void)
+show_timing_clock_source(bool use_units)
 {
 	switch (timing_clock_source)
 	{
diff --git a/src/backend/libpq/pqcomm.c b/src/backend/libpq/pqcomm.c
index aaae7214f13..b69bff03f09 100644
--- a/src/backend/libpq/pqcomm.c
+++ b/src/backend/libpq/pqcomm.c
@@ -1972,7 +1972,7 @@ assign_tcp_keepalives_idle(int newval, void *extra)
  * GUC show_hook for tcp_keepalives_idle
  */
 const char *
-show_tcp_keepalives_idle(void)
+show_tcp_keepalives_idle(bool use_units)
 {
 	/* See comments in assign_tcp_keepalives_idle */
 	static char nbuf[16];
@@ -1995,7 +1995,7 @@ assign_tcp_keepalives_interval(int newval, void *extra)
  * GUC show_hook for tcp_keepalives_interval
  */
 const char *
-show_tcp_keepalives_interval(void)
+show_tcp_keepalives_interval(bool use_units)
 {
 	/* See comments in assign_tcp_keepalives_idle */
 	static char nbuf[16];
@@ -2018,7 +2018,7 @@ assign_tcp_keepalives_count(int newval, void *extra)
  * GUC show_hook for tcp_keepalives_count
  */
 const char *
-show_tcp_keepalives_count(void)
+show_tcp_keepalives_count(bool use_units)
 {
 	/* See comments in assign_tcp_keepalives_idle */
 	static char nbuf[16];
@@ -2041,7 +2041,7 @@ assign_tcp_user_timeout(int newval, void *extra)
  * GUC show_hook for tcp_user_timeout
  */
 const char *
-show_tcp_user_timeout(void)
+show_tcp_user_timeout(bool use_units)
 {
 	/* See comments in assign_tcp_keepalives_idle */
 	static char nbuf[16];
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index 774bbc9be5f..1a5a168bc1a 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -5381,7 +5381,7 @@ ShowGUCOption(const struct config_generic *record, bool use_units)
 				const struct config_bool *conf = &record->_bool;
 
 				if (conf->show_hook)
-					val = conf->show_hook();
+					val = conf->show_hook(use_units);
 				else
 					val = *conf->variable ? "on" : "off";
 			}
@@ -5392,7 +5392,7 @@ ShowGUCOption(const struct config_generic *record, bool use_units)
 				const struct config_int *conf = &record->_int;
 
 				if (conf->show_hook)
-					val = conf->show_hook();
+					val = conf->show_hook(use_units);
 				else
 				{
 					/*
@@ -5421,7 +5421,7 @@ ShowGUCOption(const struct config_generic *record, bool use_units)
 				const struct config_real *conf = &record->_real;
 
 				if (conf->show_hook)
-					val = conf->show_hook();
+					val = conf->show_hook(use_units);
 				else
 				{
 					double		result = *conf->variable;
@@ -5446,7 +5446,7 @@ ShowGUCOption(const struct config_generic *record, bool use_units)
 				const struct config_string *conf = &record->_string;
 
 				if (conf->show_hook)
-					val = conf->show_hook();
+					val = conf->show_hook(use_units);
 				else if (*conf->variable && **conf->variable)
 					val = *conf->variable;
 				else
@@ -5459,7 +5459,7 @@ ShowGUCOption(const struct config_generic *record, bool use_units)
 				const struct config_enum *conf = &record->_enum;
 
 				if (conf->show_hook)
-					val = conf->show_hook();
+					val = conf->show_hook(use_units);
 				else
 					val = config_enum_lookup_by_value(record, *conf->variable);
 			}
diff --git a/src/include/access/xlog.h b/src/include/access/xlog.h
index 4dd98624204..ee15b4cbb16 100644
--- a/src/include/access/xlog.h
+++ b/src/include/access/xlog.h
@@ -255,7 +255,7 @@ extern bool DataChecksumsInProgressOn(void);
 extern void SetDataChecksumsOnInProgress(void);
 extern void SetDataChecksumsOn(void);
 extern void SetDataChecksumsOff(void);
-extern const char *show_data_checksums(void);
+extern const char *show_data_checksums(bool use_units);
 extern const char *get_checksum_state_string(uint32 state);
 extern void InitLocalDataChecksumState(void);
 extern void SetLocalDataChecksumState(uint32 data_checksum_version);
diff --git a/src/include/utils/guc.h b/src/include/utils/guc.h
index 8057d7870ad..2a6e2ed18b3 100644
--- a/src/include/utils/guc.h
+++ b/src/include/utils/guc.h
@@ -192,7 +192,7 @@ typedef void (*GucRealAssignHook) (double newval, void *extra);
 typedef void (*GucStringAssignHook) (const char *newval, void *extra);
 typedef void (*GucEnumAssignHook) (int newval, void *extra);
 
-typedef const char *(*GucShowHook) (void);
+typedef const char *(*GucShowHook) (bool use_units);
 
 /*
  * Miscellaneous
diff --git a/src/include/utils/guc_hooks.h b/src/include/utils/guc_hooks.h
index 6a76f8d5ed6..df048517a0f 100644
--- a/src/include/utils/guc_hooks.h
+++ b/src/include/utils/guc_hooks.h
@@ -28,7 +28,7 @@
 extern bool check_application_name(char **newval, void **extra,
 								   GucSource source);
 extern void assign_application_name(const char *newval, void *extra);
-extern const char *show_archive_command(void);
+extern const char *show_archive_command(bool use_units);
 extern bool check_autovacuum_work_mem(int *newval, void **extra,
 									  GucSource source);
 extern bool check_vacuum_buffer_usage_limit(int *newval, void **extra,
@@ -46,7 +46,7 @@ extern void assign_client_encoding(const char *newval, void *extra);
 extern bool check_cluster_name(char **newval, void **extra, GucSource source);
 extern bool check_commit_ts_buffers(int *newval, void **extra,
 									GucSource source);
-extern const char *show_data_directory_mode(void);
+extern const char *show_data_directory_mode(bool use_units);
 extern bool check_datestyle(char **newval, void **extra, GucSource source);
 extern void assign_datestyle(const char *newval, void *extra);
 extern bool check_debug_io_direct(char **newval, void **extra, GucSource source);
@@ -61,11 +61,11 @@ extern bool check_default_text_search_config(char **newval, void **extra, GucSou
 extern void assign_default_text_search_config(const char *newval, void *extra);
 extern bool check_default_with_oids(bool *newval, void **extra,
 									GucSource source);
-extern const char *show_effective_wal_level(void);
+extern const char *show_effective_wal_level(bool use_units);
 extern bool check_huge_page_size(int *newval, void **extra, GucSource source);
 extern void assign_io_method(int newval, void *extra);
 extern bool check_io_max_concurrency(int *newval, void **extra, GucSource source);
-extern const char *show_in_hot_standby(void);
+extern const char *show_in_hot_standby(bool use_units);
 extern bool check_locale_messages(char **newval, void **extra, GucSource source);
 extern void assign_locale_messages(const char *newval, void *extra);
 extern bool check_locale_monetary(char **newval, void **extra, GucSource source);
@@ -77,11 +77,11 @@ extern void assign_locale_time(const char *newval, void *extra);
 extern bool check_log_destination(char **newval, void **extra,
 								  GucSource source);
 extern void assign_log_destination(const char *newval, void *extra);
-extern const char *show_log_file_mode(void);
+extern const char *show_log_file_mode(bool use_units);
 extern bool check_log_stats(bool *newval, void **extra, GucSource source);
 extern bool check_log_timezone(char **newval, void **extra, GucSource source);
 extern void assign_log_timezone(const char *newval, void *extra);
-extern const char *show_log_timezone(void);
+extern const char *show_log_timezone(bool use_units);
 extern void assign_maintenance_io_concurrency(int newval, void *extra);
 extern void assign_io_max_combine_limit(int newval, void *extra);
 extern void assign_io_combine_limit(int newval, void *extra);
@@ -97,7 +97,7 @@ extern bool check_primary_slot_name(char **newval, void **extra,
 									GucSource source);
 extern bool check_random_seed(double *newval, void **extra, GucSource source);
 extern void assign_random_seed(double newval, void *extra);
-extern const char *show_random_seed(void);
+extern const char *show_random_seed(bool use_units);
 extern bool check_recovery_prefetch(int *new_value, void **extra,
 									GucSource source);
 extern void assign_recovery_prefetch(int new_value, void *extra);
@@ -118,7 +118,7 @@ extern bool check_recovery_target_xid(char **newval, void **extra,
 extern void assign_recovery_target_xid(const char *newval, void *extra);
 extern bool check_role(char **newval, void **extra, GucSource source);
 extern void assign_role(const char *newval, void *extra);
-extern const char *show_role(void);
+extern const char *show_role(bool use_units);
 extern bool check_restrict_nonsystem_relation_kind(char **newval, void **extra,
 												   GucSource source);
 extern void assign_restrict_nonsystem_relation_kind(const char *newval, void *extra);
@@ -143,32 +143,32 @@ extern void assign_synchronous_commit(int newval, void *extra);
 extern void assign_syslog_facility(int newval, void *extra);
 extern void assign_syslog_ident(const char *newval, void *extra);
 extern void assign_tcp_keepalives_count(int newval, void *extra);
-extern const char *show_tcp_keepalives_count(void);
+extern const char *show_tcp_keepalives_count(bool use_units);
 extern void assign_tcp_keepalives_idle(int newval, void *extra);
-extern const char *show_tcp_keepalives_idle(void);
+extern const char *show_tcp_keepalives_idle(bool use_units);
 extern void assign_tcp_keepalives_interval(int newval, void *extra);
-extern const char *show_tcp_keepalives_interval(void);
+extern const char *show_tcp_keepalives_interval(bool use_units);
 extern void assign_tcp_user_timeout(int newval, void *extra);
-extern const char *show_tcp_user_timeout(void);
+extern const char *show_tcp_user_timeout(bool use_units);
 extern bool check_temp_buffers(int *newval, void **extra, GucSource source);
 extern bool check_temp_tablespaces(char **newval, void **extra,
 								   GucSource source);
 extern void assign_temp_tablespaces(const char *newval, void *extra);
 extern bool check_timezone(char **newval, void **extra, GucSource source);
 extern void assign_timezone(const char *newval, void *extra);
-extern const char *show_timezone(void);
+extern const char *show_timezone(bool use_units);
 extern bool check_timezone_abbreviations(char **newval, void **extra,
 										 GucSource source);
 extern void assign_timezone_abbreviations(const char *newval, void *extra);
 extern void assign_timing_clock_source(int newval, void *extra);
 extern bool check_timing_clock_source(int *newval, void **extra, GucSource source);
-extern const char *show_timing_clock_source(void);
+extern const char *show_timing_clock_source(bool use_units);
 extern bool check_transaction_buffers(int *newval, void **extra, GucSource source);
 extern bool check_transaction_deferrable(bool *newval, void **extra, GucSource source);
 extern bool check_transaction_isolation(int *newval, void **extra, GucSource source);
 extern bool check_transaction_read_only(bool *newval, void **extra, GucSource source);
 extern void assign_transaction_timeout(int newval, void *extra);
-extern const char *show_unix_socket_permissions(void);
+extern const char *show_unix_socket_permissions(bool use_units);
 extern bool check_wal_buffers(int *newval, void **extra, GucSource source);
 extern bool check_wal_consistency_checking(char **newval, void **extra,
 										   GucSource source);
-- 
2.34.1

