Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wef86-004w0o-0S for pgsql-hackers@arkaria.postgresql.org; Tue, 30 Jun 2026 20:32:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wef84-00A0mD-2T for pgsql-hackers@arkaria.postgresql.org; Tue, 30 Jun 2026 20:32:24 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wef84-00A0m5-1K for pgsql-hackers@lists.postgresql.org; Tue, 30 Jun 2026 20:32:24 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wef80-0000000153c-0Vpk for pgsql-hackers@lists.postgresql.org; Tue, 30 Jun 2026 20:32:24 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.18.1/8.18.1) with ESMTP id 65UKWFdd3006314; Tue, 30 Jun 2026 16:32:15 -0400 From: Tom Lane To: pgsql-hackers@lists.postgresql.org cc: Jobin Augustine Subject: Improving display of octal GUCs MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <3006298.1782851521.0@sss.pgh.pa.us> Date: Tue, 30 Jun 2026 16:32:15 -0400 Message-ID: <3006313.1782851535@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3006298.1782851521.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable It's customary to write the values of unix_socket_permissions and a few other GUCs in octal. However, we implemented that via show_hooks, which don't affect any pg_settings columns except the current value. So you get results like this: regression=3D# SELECT name,setting,min_val,max_val,boot_val,reset_val FROM pg_settings WHERE name IN ('data_directory_mode', 'log_file_mode', 'unix_socket_permis= sions'); name | setting | min_val | max_val | boot_val | reset_= val = -------------------------+---------+---------+---------+----------+-------= ---- data_directory_mode | 0700 | 0 | 511 | 448 | 448 log_file_mode | 0600 | 0 | 511 | 384 | 384 unix_socket_permissions | 0777 | 0 | 511 | 511 | 511 (3 rows) That's always been a niggling annoyance, and we recently got a bug report complaining about it [1]. So here's an attempt to improve matters: regression=3D# SELECT name,setting,min_val,max_val,boot_val,reset_val FROM pg_settings WHERE name IN ('data_directory_mode', 'log_file_mode', 'unix_socket_permis= sions'); name | setting | min_val | max_val | boot_val | reset_= val = -------------------------+---------+---------+---------+----------+-------= ---- data_directory_mode | 0700 | 0000 | 0777 | 0700 | 0700 log_file_mode | 0600 | 0000 | 0777 | 0600 | 0600 unix_socket_permissions | 0777 | 0000 | 0777 | 0777 | 0777 (3 rows) Details in the draft commit message. regards, tom lane [1] https://www.postgresql.org/message-id/flat/19540-e641040b089ab768%40po= stgresql.org ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name*0="v1-0001-Improve-display-of-GUCs-that-are-customarily-writ.p"; name*1="atch"; charset="us-ascii" Content-ID: <3006298.1782851521.2@sss.pgh.pa.us> Content-Description: v1-0001-Improve-display-of-GUCs-that-are-customarily-writ.patch Content-Transfer-Encoding: quoted-printable =46rom 22dfabe82b9118aa3c95000f43b9204e2f266b6f Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Tue, 30 Jun 2026 16:18:35 -0400 Subject: [PATCH v1] Improve display of GUCs that are customarily written i= n octal. A few integer-valued GUCs representing Unix file permission masks are customarily written and shown in octal. However, we implemented the "shown" part via show_hook functions, which is problematic because it only affects display of the current value. It's confusing that, for example, the pg_settings view renders the current value in octal but the min, max, reset, and boot values in decimal. To improve matters, get rid of these custom show_hooks in favor of inventing a per-GUC flag GUC_SHOW_IN_OCTAL, which can be inspected in appropriate places. I've implemented that in places that respond to units flags, but not in places that don't, such as GetConfigOption(). It's tempting to consider going further, in particular adjusting input parsing so that we read the values of these variables in octal even without a leading zero. I've refrained from doing so here because I'm afraid that it'd break more usages than it fixes, but perhaps there's a case to be made for that. Bug: #19540 Reported-by: Jobin Augustine Author: Tom Lane Discussion: https://postgr.es/m/19540-e641040b089ab768@postgresql.org --- src/backend/commands/variable.c | 40 ----------------- src/backend/utils/misc/README | 6 +++ src/backend/utils/misc/guc.c | 53 +++++++++++++++++------ src/backend/utils/misc/guc_funcs.c | 15 +++++-- src/backend/utils/misc/guc_parameters.dat | 7 ++- src/include/utils/guc.h | 1 + src/include/utils/guc_hooks.h | 3 -- src/test/regress/expected/guc.out | 14 ++++++ src/test/regress/sql/guc.sql | 7 +++ 9 files changed, 82 insertions(+), 64 deletions(-) diff --git a/src/backend/commands/variable.c b/src/backend/commands/variab= le.c index 8afd252fc8c..dd41cd51755 100644 --- a/src/backend/commands/variable.c +++ b/src/backend/commands/variable.c @@ -1171,46 +1171,6 @@ assign_io_combine_limit(int newval, void *extra) io_combine_limit =3D Min(io_max_combine_limit, newval); } = -/* - * These show hooks just exist because we want to show the values in octa= l. - */ - -/* - * GUC show_hook for data_directory_mode - */ -const char * -show_data_directory_mode(void) -{ - static char buf[12]; - - snprintf(buf, sizeof(buf), "%04o", data_directory_mode); - return buf; -} - -/* - * GUC show_hook for log_file_mode - */ -const char * -show_log_file_mode(void) -{ - static char buf[12]; - - snprintf(buf, sizeof(buf), "%04o", Log_file_mode); - return buf; -} - -/* - * GUC show_hook for unix_socket_permissions - */ -const char * -show_unix_socket_permissions(void) -{ - static char buf[12]; - - snprintf(buf, sizeof(buf), "%04o", Unix_socket_permissions); - return buf; -} - = /* * These check hooks do nothing more than reject non-default settings diff --git a/src/backend/utils/misc/README b/src/backend/utils/misc/README index 85d97d29b67..09195e61520 100644 --- a/src/backend/utils/misc/README +++ b/src/backend/utils/misc/README @@ -115,6 +115,12 @@ This hook allows variable-specific computation of the= value displayed by SHOW (and other SQL features for showing GUC variable values). The return value can point to a static buffer, since show functions are not used reentrantly. +Note that the show_hook only controls display of the variable's current +value, not its auxiliary values such as min, max, or reset value. +Therefore it is unwise to format the output significantly differently +than the way that those values will be displayed. (As an example, +don't use a show_hook to display a file mode value in octal; instead +set the GUC_SHOW_IN_OCTAL flag.) = = Saving/Restoring GUC Variable Values diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index 774bbc9be5f..21c9ccec1e2 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -3067,20 +3067,37 @@ parse_and_validate_value(const struct config_gener= ic *record, if (newval->intval < conf->min || newval->intval > conf->max) { const char *unit =3D get_config_unit_name(record->flags); - const char *unitspace; = if (unit) - unitspace =3D " "; + { + ereport(elevel, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("%d %s is outside the valid range for parameter \"%s\" (%= d %s .. %d %s)", + newval->intval, unit, + record->name, + conf->min, unit, + conf->max, unit))); + } + else if (record->flags & GUC_SHOW_IN_OCTAL) + { + ereport(elevel, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("0%03o is outside the valid range for parameter \"%s\" (0= %03o .. 0%03o)", + newval->intval, + record->name, + conf->min, + conf->max))); + } else - unit =3D unitspace =3D ""; - - ereport(elevel, - (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("%d%s%s is outside the valid range for parameter \"%s\" (%= d%s%s .. %d%s%s)", - newval->intval, unitspace, unit, - record->name, - conf->min, unitspace, unit, - conf->max, unitspace, unit))); + { + ereport(elevel, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("%d is outside the valid range for parameter \"%s\" (%d .= . %d)", + newval->intval, + record->name, + conf->min, + conf->max))); + } return false; } = @@ -5393,7 +5410,7 @@ ShowGUCOption(const struct config_generic *record, b= ool use_units) = if (conf->show_hook) val =3D conf->show_hook(); - else + else if (use_units && (record->flags & GUC_UNIT)) { /* * Use int64 arithmetic to avoid overflows in units @@ -5402,7 +5419,7 @@ ShowGUCOption(const struct config_generic *record, b= ool use_units) int64 result =3D *conf->variable; const char *unit; = - if (use_units && result > 0 && (record->flags & GUC_UNIT)) + if (result > 0) convert_int_from_base_unit(result, record->flags & GUC_UNIT, &result, &unit); @@ -5413,6 +5430,16 @@ ShowGUCOption(const struct config_generic *record, = bool use_units) result, unit); val =3D buffer; } + else if (record->flags & GUC_SHOW_IN_OCTAL) + { + snprintf(buffer, sizeof(buffer), "0%03o", *conf->variable); + val =3D buffer; + } + else + { + snprintf(buffer, sizeof(buffer), "%d", *conf->variable); + val =3D buffer; + } } break; = diff --git a/src/backend/utils/misc/guc_funcs.c b/src/backend/utils/misc/g= uc_funcs.c index e2c2919484e..0e75c903003 100644 --- a/src/backend/utils/misc/guc_funcs.c +++ b/src/backend/utils/misc/guc_funcs.c @@ -682,24 +682,31 @@ GetConfigOptionValues(const struct config_generic *c= onf, const char **values) case PGC_INT: { const struct config_int *lconf =3D &conf->_int; + const char *fmt; + + /* choose display format */ + if (conf->flags & GUC_SHOW_IN_OCTAL) + fmt =3D "0%03o"; + else + fmt =3D "%d"; = /* min_val */ - snprintf(buffer, sizeof(buffer), "%d", lconf->min); + snprintf(buffer, sizeof(buffer), fmt, lconf->min); values[9] =3D pstrdup(buffer); = /* max_val */ - snprintf(buffer, sizeof(buffer), "%d", lconf->max); + snprintf(buffer, sizeof(buffer), fmt, lconf->max); values[10] =3D pstrdup(buffer); = /* enumvals */ values[11] =3D NULL; = /* boot_val */ - snprintf(buffer, sizeof(buffer), "%d", lconf->boot_val); + snprintf(buffer, sizeof(buffer), fmt, lconf->boot_val); values[12] =3D pstrdup(buffer); = /* reset_val */ - snprintf(buffer, sizeof(buffer), "%d", lconf->reset_val); + snprintf(buffer, sizeof(buffer), fmt, lconf->reset_val); values[13] =3D pstrdup(buffer); } break; diff --git a/src/backend/utils/misc/guc_parameters.dat b/src/backend/utils= /misc/guc_parameters.dat index 3c1e6b31bf8..a1d0de57547 100644 --- a/src/backend/utils/misc/guc_parameters.dat +++ b/src/backend/utils/misc/guc_parameters.dat @@ -599,12 +599,11 @@ { name =3D> 'data_directory_mode', type =3D> 'int', context =3D> 'PGC_INT= ERNAL', group =3D> 'PRESET_OPTIONS', short_desc =3D> 'Shows the mode of the data directory.', long_desc =3D> 'The parameter value is a numeric mode specification in = the form accepted by the chmod and umask system calls. (To use the customa= ry octal format the number must start with a 0 (zero).)', - flags =3D> 'GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE | GUC_RUNTIME_COMP= UTED', + flags =3D> 'GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE | GUC_RUNTIME_COMP= UTED | GUC_SHOW_IN_OCTAL', variable =3D> 'data_directory_mode', boot_val =3D> '0700', min =3D> '0000', max =3D> '0777', - show_hook =3D> 'show_data_directory_mode', }, = { name =3D> 'data_sync_retry', type =3D> 'bool', context =3D> 'PGC_POSTMA= STER', group =3D> 'ERROR_HANDLING_OPTIONS', @@ -1707,11 +1706,11 @@ { name =3D> 'log_file_mode', type =3D> 'int', context =3D> 'PGC_SIGHUP', = group =3D> 'LOGGING_WHERE', short_desc =3D> 'Sets the file permissions for log files.', long_desc =3D> 'The parameter value is expected to be a numeric mode sp= ecification in the form accepted by the chmod and umask system calls. (To = use the customary octal format the number must start with a 0 (zero).)', + flags =3D> 'GUC_SHOW_IN_OCTAL', variable =3D> 'Log_file_mode', boot_val =3D> '0600', min =3D> '0000', max =3D> '0777', - show_hook =3D> 'show_log_file_mode', }, = { name =3D> 'log_filename', type =3D> 'string', context =3D> 'PGC_SIGHUP'= , group =3D> 'LOGGING_WHERE', @@ -3295,11 +3294,11 @@ { name =3D> 'unix_socket_permissions', type =3D> 'int', context =3D> 'PGC= _POSTMASTER', group =3D> 'CONN_AUTH_SETTINGS', short_desc =3D> 'Sets the access permissions of the Unix-domain socket.= ', long_desc =3D> 'Unix-domain sockets use the usual Unix file system perm= ission set. The parameter value is expected to be a numeric mode specifica= tion in the form accepted by the chmod and umask system calls. (To use the= customary octal format the number must start with a 0 (zero).)', + flags =3D> 'GUC_SHOW_IN_OCTAL', variable =3D> 'Unix_socket_permissions', boot_val =3D> '0777', min =3D> '0000', max =3D> '0777', - show_hook =3D> 'show_unix_socket_permissions', }, = { name =3D> 'update_process_title', type =3D> 'bool', context =3D> 'PGC_S= USET', group =3D> 'PROCESS_TITLE', diff --git a/src/include/utils/guc.h b/src/include/utils/guc.h index dc406d6651a..4ad1aacae67 100644 --- a/src/include/utils/guc.h +++ b/src/include/utils/guc.h @@ -228,6 +228,7 @@ typedef enum 0x002000 /* can't set in PG_AUTOCONF_FILENAME */ #define GUC_RUNTIME_COMPUTED 0x004000 /* delay processing in 'postgres = -C' */ #define GUC_ALLOW_IN_PARALLEL 0x008000 /* allow setting in parallel mode= */ +#define GUC_SHOW_IN_OCTAL 0x010000 /* show integer variable in octal *= / = #define GUC_UNIT_KB 0x01000000 /* value is in kilobytes */ #define GUC_UNIT_BLOCKS 0x02000000 /* value is in blocks */ diff --git a/src/include/utils/guc_hooks.h b/src/include/utils/guc_hooks.h index 307f4fbaefe..c2d70e949c9 100644 --- a/src/include/utils/guc_hooks.h +++ b/src/include/utils/guc_hooks.h @@ -46,7 +46,6 @@ extern void assign_client_encoding(const char *newval, v= oid *extra); extern bool check_cluster_name(char **newval, void **extra, GucSource sou= rce); extern bool check_commit_ts_buffers(int *newval, void **extra, GucSource source); -extern const char *show_data_directory_mode(void); 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); @@ -77,7 +76,6 @@ 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 bool check_log_stats(bool *newval, void **extra, GucSource source)= ; extern bool check_log_timezone(char **newval, void **extra, GucSource sou= rce); extern void assign_log_timezone(const char *newval, void *extra); @@ -171,7 +169,6 @@ extern bool check_transaction_deferrable(bool *newval,= void **extra, GucSource s extern bool check_transaction_isolation(int *newval, void **extra, GucSou= rce source); extern bool check_transaction_read_only(bool *newval, void **extra, GucSo= urce source); extern void assign_transaction_timeout(int newval, void *extra); -extern const char *show_unix_socket_permissions(void); extern bool check_wal_buffers(int *newval, void **extra, GucSource source= ); extern bool check_wal_consistency_checking(char **newval, void **extra, GucSource source); diff --git a/src/test/regress/expected/guc.out b/src/test/regress/expected= /guc.out index 3fa2562f231..0c18fc94e31 100644 --- a/src/test/regress/expected/guc.out +++ b/src/test/regress/expected/guc.out @@ -928,6 +928,20 @@ SELECT query_id IS NOT NULL AS qid_set FROM pg_stat_a= ctivity = RESET track_activities; RESET compute_query_id; +-- Test GUC_SHOW_IN_OCTAL +SELECT name, min_val, max_val, boot_val +FROM pg_settings +WHERE name IN ('data_directory_mode', 'log_file_mode', + 'unix_socket_permissions'); + name | min_val | max_val | boot_val = +-------------------------+---------+---------+---------- + data_directory_mode | 0000 | 0777 | 0700 + log_file_mode | 0000 | 0777 | 0600 + unix_socket_permissions | 0000 | 0777 | 0777 +(3 rows) + +ALTER SYSTEM SET log_file_mode =3D 0640; -- decimal, so out of range +ERROR: 01200 is outside the valid range for parameter "log_file_mode" (0= 000 .. 0777) -- Test GUC categories and flag patterns SELECT pg_settings_get_flags(NULL); pg_settings_get_flags = diff --git a/src/test/regress/sql/guc.sql b/src/test/regress/sql/guc.sql index dfb843fd3ae..e78b4af3a3a 100644 --- a/src/test/regress/sql/guc.sql +++ b/src/test/regress/sql/guc.sql @@ -365,6 +365,13 @@ SELECT query_id IS NOT NULL AS qid_set FROM pg_stat_a= ctivity RESET track_activities; RESET compute_query_id; = +-- Test GUC_SHOW_IN_OCTAL +SELECT name, min_val, max_val, boot_val +FROM pg_settings +WHERE name IN ('data_directory_mode', 'log_file_mode', + 'unix_socket_permissions'); +ALTER SYSTEM SET log_file_mode =3D 0640; -- decimal, so out of range + -- Test GUC categories and flag patterns SELECT pg_settings_get_flags(NULL); SELECT pg_settings_get_flags('does_not_exist'); -- = 2.52.0 ------- =_aaaaaaaaaa0--