aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/backend/utils/misc/guc.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index f88386f0486..eca51a7c4eb 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -9595,6 +9595,21 @@ read_gucstate_binary(char **srcptr, char *srcend, void *dest, Size size)
}
/*
+ * Callback used to add a context message when reporting errors that occur
+ * while trying to restore GUCs in parallel workers.
+ */
+static void
+guc_restore_error_context_callback(void *arg)
+{
+ char **error_context_name_and_value = (char **) arg;
+
+ if (error_context_name_and_value)
+ errcontext("while setting parameter \"%s\" to \"%s\"",
+ error_context_name_and_value[0],
+ error_context_name_and_value[1]);
+}
+
+/*
* RestoreGUCState:
* Reads the GUC state at the specified address and updates the GUCs with the
* values read from the GUC state.
@@ -9612,6 +9627,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++)
@@ -9624,9 +9640,16 @@ RestoreGUCState(void *gucstate)
srcptr += sizeof(len);
srcend = srcptr + len;
+ /* If the GUC value check fails, we want errors to show useful context. */
+ 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 *error_context_name_and_value[2];
varname = read_gucstate(&srcptr, srcend);
varvalue = read_gucstate(&srcptr, srcend);
@@ -9641,6 +9664,9 @@ RestoreGUCState(void *gucstate)
read_gucstate_binary(&srcptr, srcend,
&varscontext, sizeof(varscontext));
+ error_context_name_and_value[0] = varname;
+ error_context_name_and_value[1] = varvalue;
+ error_context_callback.arg = &error_context_name_and_value[0];
result = set_config_option(varname, varvalue, varscontext, varsource,
GUC_ACTION_SET, true, ERROR, true);
if (result <= 0)
@@ -9649,7 +9675,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;
}
/*