diff options
Diffstat (limited to 'src/backend/commands/extension.c')
-rw-r--r-- | src/backend/commands/extension.c | 40 |
1 files changed, 13 insertions, 27 deletions
diff --git a/src/backend/commands/extension.c b/src/backend/commands/extension.c index 5da5981726c..3af15dd38bb 100644 --- a/src/backend/commands/extension.c +++ b/src/backend/commands/extension.c @@ -774,9 +774,7 @@ execute_extension_script(Oid extensionOid, ExtensionControlFile *control, const char *schemaName, Oid schemaOid) { char *filename; - char *save_client_min_messages, - *save_log_min_messages, - *save_search_path; + int save_nestlevel; StringInfoData pathbuf; ListCell *lc; @@ -808,22 +806,20 @@ execute_extension_script(Oid extensionOid, ExtensionControlFile *control, * so that we won't spam the user with useless NOTICE messages from common * script actions like creating shell types. * - * We use the equivalent of SET LOCAL to ensure the setting is undone upon - * error. + * We use the equivalent of a function SET option to allow the setting to + * persist for exactly the duration of the script execution. guc.c also + * takes care of undoing the setting on error. */ - save_client_min_messages = - pstrdup(GetConfigOption("client_min_messages", false, false)); + save_nestlevel = NewGUCNestLevel(); + if (client_min_messages < WARNING) (void) set_config_option("client_min_messages", "warning", PGC_USERSET, PGC_S_SESSION, - GUC_ACTION_LOCAL, true, 0); - - save_log_min_messages = - pstrdup(GetConfigOption("log_min_messages", false, false)); + GUC_ACTION_SAVE, true, 0); if (log_min_messages < WARNING) (void) set_config_option("log_min_messages", "warning", PGC_SUSET, PGC_S_SESSION, - GUC_ACTION_LOCAL, true, 0); + GUC_ACTION_SAVE, true, 0); /* * Set up the search path to contain the target schema, then the schemas @@ -832,10 +828,9 @@ execute_extension_script(Oid extensionOid, ExtensionControlFile *control, * * Note: it might look tempting to use PushOverrideSearchPath for this, * but we cannot do that. We have to actually set the search_path GUC in - * case the extension script examines or changes it. + * case the extension script examines or changes it. In any case, the + * GUC_ACTION_SAVE method is just as convenient. */ - save_search_path = pstrdup(GetConfigOption("search_path", false, false)); - initStringInfo(&pathbuf); appendStringInfoString(&pathbuf, quote_identifier(schemaName)); foreach(lc, requiredSchemas) @@ -849,7 +844,7 @@ execute_extension_script(Oid extensionOid, ExtensionControlFile *control, (void) set_config_option("search_path", pathbuf.data, PGC_USERSET, PGC_S_SESSION, - GUC_ACTION_LOCAL, true, 0); + GUC_ACTION_SAVE, true, 0); /* * Set creating_extension and related variables so that @@ -910,18 +905,9 @@ execute_extension_script(Oid extensionOid, ExtensionControlFile *control, CurrentExtensionObject = InvalidOid; /* - * Restore GUC variables for the remainder of the current transaction. - * Again use SET LOCAL, so we won't affect the session value. + * Restore the GUC variables we set above. */ - (void) set_config_option("search_path", save_search_path, - PGC_USERSET, PGC_S_SESSION, - GUC_ACTION_LOCAL, true, 0); - (void) set_config_option("client_min_messages", save_client_min_messages, - PGC_USERSET, PGC_S_SESSION, - GUC_ACTION_LOCAL, true, 0); - (void) set_config_option("log_min_messages", save_log_min_messages, - PGC_SUSET, PGC_S_SESSION, - GUC_ACTION_LOCAL, true, 0); + AtEOXact_GUC(true, save_nestlevel); } /* |