From 0a20ff54f5e66158930d5328f89f087d4e9ab400 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Tue, 13 Sep 2022 11:05:07 -0400 Subject: Split up guc.c for better build speed and ease of maintenance. guc.c has grown to be one of our largest .c files, making it a bottleneck for compilation. It's also acquired a bunch of knowledge that'd be better kept elsewhere, because of our not very good habit of putting variable-specific check hooks here. Hence, split it up along these lines: * guc.c itself retains just the core GUC housekeeping mechanisms. * New file guc_funcs.c contains the SET/SHOW interfaces and some SQL-accessible functions for GUC manipulation. * New file guc_tables.c contains the data arrays that define the built-in GUC variables, along with some already-exported constant tables. * GUC check/assign/show hook functions are moved to the variable's home module, whenever that's clearly identifiable. A few hard- to-classify hooks ended up in commands/variable.c, which was already a home for miscellaneous GUC hook functions. To avoid cluttering a lot more header files with #include "guc.h", I also invented a new header file utils/guc_hooks.h and put all the GUC hook functions' declarations there, regardless of their originating module. That allowed removal of #include "guc.h" from some existing headers. The fallout from that (hopefully all caught here) demonstrates clearly why such inclusions are best minimized: there are a lot of files that, for example, were getting array.h at two or more levels of remove, despite not having any connection at all to GUCs in themselves. There is some very minor code beautification here, such as renaming a couple of inconsistently-named hook functions and improving some comments. But mostly this just moves code from point A to point B and deals with the ensuing needs for #include adjustments and exporting a few functions that previously weren't exported. Patch by me, per a suggestion from Andres Freund; thanks also to Michael Paquier for the idea to invent guc_funcs.c. Discussion: https://postgr.es/m/587607.1662836699@sss.pgh.pa.us --- src/backend/tcop/postgres.c | 53 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'src/backend/tcop/postgres.c') diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c index c6ca3b5b3d4..35eff28bd36 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -67,6 +67,7 @@ #include "tcop/pquery.h" #include "tcop/tcopprot.h" #include "tcop/utility.h" +#include "utils/guc_hooks.h" #include "utils/lsyscache.h" #include "utils/memutils.h" #include "utils/ps_status.h" @@ -3505,6 +3506,58 @@ assign_max_stack_depth(int newval, void *extra) max_stack_depth_bytes = newval_bytes; } +/* + * GUC check_hook for client_connection_check_interval + */ +bool +check_client_connection_check_interval(int *newval, void **extra, GucSource source) +{ + if (!WaitEventSetCanReportClosed() && *newval != 0) + { + GUC_check_errdetail("client_connection_check_interval must be set to 0 on this platform."); + return false; + } + return true; +} + +/* + * GUC check_hook for log_parser_stats, log_planner_stats, log_executor_stats + * + * This function and check_log_stats interact to prevent their variables from + * being set in a disallowed combination. This is a hack that doesn't really + * work right; for example it might fail while applying pg_db_role_setting + * values even though the final state would have been acceptable. However, + * since these variables are legacy settings with little production usage, + * we tolerate that. + */ +bool +check_stage_log_stats(bool *newval, void **extra, GucSource source) +{ + if (*newval && log_statement_stats) + { + GUC_check_errdetail("Cannot enable parameter when \"log_statement_stats\" is true."); + return false; + } + return true; +} + +/* + * GUC check_hook for log_statement_stats + */ +bool +check_log_stats(bool *newval, void **extra, GucSource source) +{ + if (*newval && + (log_parser_stats || log_planner_stats || log_executor_stats)) + { + GUC_check_errdetail("Cannot enable \"log_statement_stats\" when " + "\"log_parser_stats\", \"log_planner_stats\", " + "or \"log_executor_stats\" is true."); + return false; + } + return true; +} + /* * set_debug_options --- apply "-d N" command line option -- cgit v1.2.3