Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7c88443

Browse files
committed
Fix another oversight in logging of changes in postgresql.conf settings.
We were using GetConfigOption to collect the old value of each setting, overlooking the possibility that it didn't exist yet. This does happen in the case of adding a new entry within a custom variable class, as exhibited in bug #6097 from Maxim Boguk. To fix, add a missing_ok parameter to GetConfigOption, but only in 9.1 and HEAD --- it seems possible that some third-party code is using that function, so changing its API in a minor release would cause problems. In 9.0, create a near-duplicate function instead.
1 parent ec19465 commit 7c88443

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

src/backend/commands/extension.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -813,14 +813,14 @@ execute_extension_script(Oid extensionOid, ExtensionControlFile *control,
813813
* error.
814814
*/
815815
save_client_min_messages =
816-
pstrdup(GetConfigOption("client_min_messages", false));
816+
pstrdup(GetConfigOption("client_min_messages", false, false));
817817
if (client_min_messages < WARNING)
818818
(void) set_config_option("client_min_messages", "warning",
819819
PGC_USERSET, PGC_S_SESSION,
820820
GUC_ACTION_LOCAL, true);
821821

822822
save_log_min_messages =
823-
pstrdup(GetConfigOption("log_min_messages", false));
823+
pstrdup(GetConfigOption("log_min_messages", false, false));
824824
if (log_min_messages < WARNING)
825825
(void) set_config_option("log_min_messages", "warning",
826826
PGC_SUSET, PGC_S_SESSION,
@@ -835,7 +835,7 @@ execute_extension_script(Oid extensionOid, ExtensionControlFile *control,
835835
* but we cannot do that. We have to actually set the search_path GUC in
836836
* case the extension script examines or changes it.
837837
*/
838-
save_search_path = pstrdup(GetConfigOption("search_path", false));
838+
save_search_path = pstrdup(GetConfigOption("search_path", false, false));
839839

840840
initStringInfo(&pathbuf);
841841
appendStringInfoString(&pathbuf, quote_identifier(schemaName));

src/backend/utils/misc/guc-file.l

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,9 @@ ProcessConfigFile(GucContext context)
306306
/* In SIGHUP cases in the postmaster, report changes */
307307
if (context == PGC_SIGHUP && !IsUnderPostmaster)
308308
{
309-
const char *preval = GetConfigOption(item->name, false);
309+
const char *preval = GetConfigOption(item->name, true, false);
310310

311-
/* string variables could be NULL; treat that as empty */
311+
/* If option doesn't exist yet or is NULL, treat as empty string */
312312
if (!preval)
313313
preval = "";
314314
/* must dup, else might have dangling pointer below */
@@ -323,7 +323,7 @@ ProcessConfigFile(GucContext context)
323323

324324
if (pre_value)
325325
{
326-
const char *post_value = GetConfigOption(item->name, false);
326+
const char *post_value = GetConfigOption(item->name, true, false);
327327

328328
if (!post_value)
329329
post_value = "";

src/backend/utils/misc/guc.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5838,8 +5838,11 @@ SetConfigOption(const char *name, const char *value,
58385838

58395839

58405840
/*
5841-
* Fetch the current value of the option `name'. If the option doesn't exist,
5842-
* throw an ereport and don't return.
5841+
* Fetch the current value of the option `name', as a string.
5842+
*
5843+
* If the option doesn't exist, return NULL if missing_ok is true (NOTE that
5844+
* this cannot be distinguished from a string variable with a NULL value!),
5845+
* otherwise throw an ereport and don't return.
58435846
*
58445847
* If restrict_superuser is true, we also enforce that only superusers can
58455848
* see GUC_SUPERUSER_ONLY variables. This should only be passed as true
@@ -5849,16 +5852,21 @@ SetConfigOption(const char *name, const char *value,
58495852
* valid until the next call to configuration related functions.
58505853
*/
58515854
const char *
5852-
GetConfigOption(const char *name, bool restrict_superuser)
5855+
GetConfigOption(const char *name, bool missing_ok, bool restrict_superuser)
58535856
{
58545857
struct config_generic *record;
58555858
static char buffer[256];
58565859

58575860
record = find_option(name, false, ERROR);
58585861
if (record == NULL)
5862+
{
5863+
if (missing_ok)
5864+
return NULL;
58595865
ereport(ERROR,
58605866
(errcode(ERRCODE_UNDEFINED_OBJECT),
5861-
errmsg("unrecognized configuration parameter \"%s\"", name)));
5867+
errmsg("unrecognized configuration parameter \"%s\"",
5868+
name)));
5869+
}
58625870
if (restrict_superuser &&
58635871
(record->flags & GUC_SUPERUSER_ONLY) &&
58645872
!superuser())

src/include/utils/guc.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,8 @@ extern void DefineCustomEnumVariable(
296296

297297
extern void EmitWarningsOnPlaceholders(const char *className);
298298

299-
extern const char *GetConfigOption(const char *name, bool restrict_superuser);
299+
extern const char *GetConfigOption(const char *name, bool missing_ok,
300+
bool restrict_superuser);
300301
extern const char *GetConfigOptionResetString(const char *name);
301302
extern void ProcessConfigFile(GucContext context);
302303
extern void InitializeGUCOptions(void);

0 commit comments

Comments
 (0)