Commit 41e461d3 authored by Tom Lane's avatar Tom Lane

Improve define_custom_variable's handling of pre-existing settings.

Arrange for any problems with pre-existing settings to be reported as
WARNING not ERROR, so that we don't undesirably abort the loading of the
incoming add-on module.  The bad setting is just discarded, as though it
had never been applied at all.  (This requires a change in the API of
set_config_option.  After some thought I decided the most potentially
useful addition was to allow callers to just pass in a desired elevel.)

Arrange to restore the complete stacked state of the variable, rather than
cheesily reinstalling only the active value.  This ensures that custom GUCs
will behave unsurprisingly even when the module loading operation occurs
within nested subtransactions that have changed the active value.  Since a
module load could occur as a result of, eg, a PL function call, this is not
an unlikely scenario.
parent fa56a0c3
...@@ -253,11 +253,8 @@ tsa_set_curcfg(PG_FUNCTION_ARGS) ...@@ -253,11 +253,8 @@ tsa_set_curcfg(PG_FUNCTION_ARGS)
name = DatumGetCString(DirectFunctionCall1(regconfigout, name = DatumGetCString(DirectFunctionCall1(regconfigout,
ObjectIdGetDatum(arg0))); ObjectIdGetDatum(arg0)));
set_config_option("default_text_search_config", name, SetConfigOption("default_text_search_config", name,
PGC_USERSET, PGC_USERSET, PGC_S_SESSION);
PGC_S_SESSION,
GUC_ACTION_SET,
true);
PG_RETURN_VOID(); PG_RETURN_VOID();
} }
...@@ -271,11 +268,8 @@ tsa_set_curcfg_byname(PG_FUNCTION_ARGS) ...@@ -271,11 +268,8 @@ tsa_set_curcfg_byname(PG_FUNCTION_ARGS)
name = text_to_cstring(arg0); name = text_to_cstring(arg0);
set_config_option("default_text_search_config", name, SetConfigOption("default_text_search_config", name,
PGC_USERSET, PGC_USERSET, PGC_S_SESSION);
PGC_S_SESSION,
GUC_ACTION_SET,
true);
PG_RETURN_VOID(); PG_RETURN_VOID();
} }
......
...@@ -816,14 +816,14 @@ execute_extension_script(Oid extensionOid, ExtensionControlFile *control, ...@@ -816,14 +816,14 @@ execute_extension_script(Oid extensionOid, ExtensionControlFile *control,
if (client_min_messages < WARNING) if (client_min_messages < WARNING)
(void) set_config_option("client_min_messages", "warning", (void) set_config_option("client_min_messages", "warning",
PGC_USERSET, PGC_S_SESSION, PGC_USERSET, PGC_S_SESSION,
GUC_ACTION_LOCAL, true); GUC_ACTION_LOCAL, true, 0);
save_log_min_messages = save_log_min_messages =
pstrdup(GetConfigOption("log_min_messages", false, false)); pstrdup(GetConfigOption("log_min_messages", false, false));
if (log_min_messages < WARNING) if (log_min_messages < WARNING)
(void) set_config_option("log_min_messages", "warning", (void) set_config_option("log_min_messages", "warning",
PGC_SUSET, PGC_S_SESSION, PGC_SUSET, PGC_S_SESSION,
GUC_ACTION_LOCAL, true); GUC_ACTION_LOCAL, true, 0);
/* /*
* Set up the search path to contain the target schema, then the schemas * Set up the search path to contain the target schema, then the schemas
...@@ -849,7 +849,7 @@ execute_extension_script(Oid extensionOid, ExtensionControlFile *control, ...@@ -849,7 +849,7 @@ execute_extension_script(Oid extensionOid, ExtensionControlFile *control,
(void) set_config_option("search_path", pathbuf.data, (void) set_config_option("search_path", pathbuf.data,
PGC_USERSET, PGC_S_SESSION, PGC_USERSET, PGC_S_SESSION,
GUC_ACTION_LOCAL, true); GUC_ACTION_LOCAL, true, 0);
/* /*
* Set creating_extension and related variables so that * Set creating_extension and related variables so that
...@@ -915,13 +915,13 @@ execute_extension_script(Oid extensionOid, ExtensionControlFile *control, ...@@ -915,13 +915,13 @@ execute_extension_script(Oid extensionOid, ExtensionControlFile *control,
*/ */
(void) set_config_option("search_path", save_search_path, (void) set_config_option("search_path", save_search_path,
PGC_USERSET, PGC_S_SESSION, PGC_USERSET, PGC_S_SESSION,
GUC_ACTION_LOCAL, true); GUC_ACTION_LOCAL, true, 0);
(void) set_config_option("client_min_messages", save_client_min_messages, (void) set_config_option("client_min_messages", save_client_min_messages,
PGC_USERSET, PGC_S_SESSION, PGC_USERSET, PGC_S_SESSION,
GUC_ACTION_LOCAL, true); GUC_ACTION_LOCAL, true, 0);
(void) set_config_option("log_min_messages", save_log_min_messages, (void) set_config_option("log_min_messages", save_log_min_messages,
PGC_SUSET, PGC_S_SESSION, PGC_SUSET, PGC_S_SESSION,
GUC_ACTION_LOCAL, true); GUC_ACTION_LOCAL, true, 0);
} }
/* /*
......
...@@ -2779,7 +2779,7 @@ RI_Initial_Check(Trigger *trigger, Relation fk_rel, Relation pk_rel) ...@@ -2779,7 +2779,7 @@ RI_Initial_Check(Trigger *trigger, Relation fk_rel, Relation pk_rel)
snprintf(workmembuf, sizeof(workmembuf), "%d", maintenance_work_mem); snprintf(workmembuf, sizeof(workmembuf), "%d", maintenance_work_mem);
(void) set_config_option("work_mem", workmembuf, (void) set_config_option("work_mem", workmembuf,
PGC_USERSET, PGC_S_SESSION, PGC_USERSET, PGC_S_SESSION,
GUC_ACTION_LOCAL, true); GUC_ACTION_LOCAL, true, 0);
if (SPI_connect() != SPI_OK_CONNECT) if (SPI_connect() != SPI_OK_CONNECT)
elog(ERROR, "SPI_connect failed"); elog(ERROR, "SPI_connect failed");
...@@ -2868,7 +2868,7 @@ RI_Initial_Check(Trigger *trigger, Relation fk_rel, Relation pk_rel) ...@@ -2868,7 +2868,7 @@ RI_Initial_Check(Trigger *trigger, Relation fk_rel, Relation pk_rel)
snprintf(workmembuf, sizeof(workmembuf), "%d", old_work_mem); snprintf(workmembuf, sizeof(workmembuf), "%d", old_work_mem);
(void) set_config_option("work_mem", workmembuf, (void) set_config_option("work_mem", workmembuf,
PGC_USERSET, PGC_S_SESSION, PGC_USERSET, PGC_S_SESSION,
GUC_ACTION_LOCAL, true); GUC_ACTION_LOCAL, true, 0);
return true; return true;
} }
......
...@@ -238,7 +238,7 @@ ProcessConfigFile(GucContext context) ...@@ -238,7 +238,7 @@ ProcessConfigFile(GucContext context)
/* Now we can re-apply the wired-in default (i.e., the boot_val) */ /* Now we can re-apply the wired-in default (i.e., the boot_val) */
if (set_config_option(gconf->name, NULL, if (set_config_option(gconf->name, NULL,
context, PGC_S_DEFAULT, context, PGC_S_DEFAULT,
GUC_ACTION_SET, true) > 0) GUC_ACTION_SET, true, 0) > 0)
{ {
/* Log the change if appropriate */ /* Log the change if appropriate */
if (context == PGC_SIGHUP) if (context == PGC_SIGHUP)
...@@ -293,7 +293,7 @@ ProcessConfigFile(GucContext context) ...@@ -293,7 +293,7 @@ ProcessConfigFile(GucContext context)
scres = set_config_option(item->name, item->value, scres = set_config_option(item->name, item->value,
context, PGC_S_FILE, context, PGC_S_FILE,
GUC_ACTION_SET, true); GUC_ACTION_SET, true, 0);
if (scres > 0) if (scres > 0)
{ {
/* variable was updated, so log the change if appropriate */ /* variable was updated, so log the change if appropriate */
......
This diff is collapsed.
...@@ -315,7 +315,7 @@ extern bool parse_int(const char *value, int *result, int flags, ...@@ -315,7 +315,7 @@ extern bool parse_int(const char *value, int *result, int flags,
extern bool parse_real(const char *value, double *result); extern bool parse_real(const char *value, double *result);
extern int set_config_option(const char *name, const char *value, extern int set_config_option(const char *name, const char *value,
GucContext context, GucSource source, GucContext context, GucSource source,
GucAction action, bool changeVal); GucAction action, bool changeVal, int elevel);
extern char *GetConfigOptionByName(const char *name, const char **varname); extern char *GetConfigOptionByName(const char *name, const char **varname);
extern void GetConfigOptionByNum(int varnum, const char **values, bool *noshow); extern void GetConfigOptionByNum(int varnum, const char **values, bool *noshow);
extern int GetNumConfigOptions(void); extern int GetNumConfigOptions(void);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment