From 749c78d0afcdb1a9a96b28e366ef11b1b500ee79 Mon Sep 17 00:00:00 2001 From: Thomas Munro Date: Wed, 3 Apr 2019 07:57:25 +1300 Subject: [PATCH] When restoring GUCs in parallel workers, show an error context. Otherwise it can be hard to see where an error is coming from, when the parallel worker sets all the GUCs that it received from the leader. Discussion: https://postgr.es/m/15726-6d67e4fa14f027b3%40postgresql.org --- src/backend/utils/misc/guc.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index cd5a65be75b..da635915fc3 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -10035,6 +10035,16 @@ read_gucstate_binary(char **srcptr, char *srcend, void *dest, Size size) *srcptr += size; } +static void +guc_restore_error_context_callback(void *arg) +{ + char **pair = (char **) arg; + + if (pair) + errcontext("while setting parameter \"%s\" to \"%s\"", + pair[0], pair[1]); +} + /* * RestoreGUCState: * Reads the GUC state at the specified address and updates the GUCs with the @@ -10053,6 +10063,7 @@ RestoreGUCState(void *gucstate) char *srcend; Size len; int i; + ErrorContextCallback error_context_callback; /* See comment at can_skip_gucvar(). */ for (i = 0; i < num_guc_variables; i++) @@ -10065,9 +10076,16 @@ RestoreGUCState(void *gucstate) srcptr += sizeof(len); srcend = srcptr + len; + /* If the GUC value check fails, we want errors to show the GUC name */ + error_context_callback.callback = guc_restore_error_context_callback; + error_context_callback.previous = error_context_stack; + error_context_callback.arg = NULL; + error_context_stack = &error_context_callback; + while (srcptr < srcend) { int result; + char *pair[2]; varname = read_gucstate(&srcptr, srcend); varvalue = read_gucstate(&srcptr, srcend); @@ -10082,6 +10100,9 @@ RestoreGUCState(void *gucstate) read_gucstate_binary(&srcptr, srcend, &varscontext, sizeof(varscontext)); + pair[0] = varname; + pair[1] = varvalue; + error_context_callback.arg = &pair[0]; result = set_config_option(varname, varvalue, varscontext, varsource, GUC_ACTION_SET, true, ERROR, true); if (result <= 0) @@ -10090,7 +10111,10 @@ RestoreGUCState(void *gucstate) errmsg("parameter \"%s\" could not be set", varname))); if (varsourcefile[0]) set_config_sourcefile(varname, varsourcefile, varsourceline); + error_context_callback.arg = NULL; } + + error_context_stack = error_context_callback.previous; } /* -- 2.21.0