Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f1bf619

Browse files
committed
Fix ALTER SYSTEM to cope with duplicate entries in postgresql.auto.conf.
ALTER SYSTEM itself normally won't make duplicate entries (although up till this patch, it was possible to confuse it by writing case variants of a GUC's name). However, if some external tool has appended entries to the file, that could result in duplicate entries for a single GUC name. In such a situation, ALTER SYSTEM did exactly the wrong thing, because it replaced or removed only the first matching entry, leaving the later one(s) still there and hence still determining the active value. This patch fixes that by making ALTER SYSTEM sweep through the file and remove all matching entries, then (if not ALTER SYSTEM RESET) append the new setting to the end. This means entries will be in order of last setting rather than first setting, but that shouldn't hurt anything. Also, make the comparisons case-insensitive so that the right things happen if you do, say, ALTER SYSTEM SET "TimeZone" = 'whatever'. This has been broken since ALTER SYSTEM was invented, so back-patch to all supported branches. Ian Barwick, with minor mods by me Discussion: https://postgr.es/m/aed6cc9f-98f3-2693-ac81-52bb0052307e@2ndquadrant.com
1 parent 9c02cf5 commit f1bf619

File tree

1 file changed

+22
-25
lines changed
  • src/backend/utils/misc

1 file changed

+22
-25
lines changed

src/backend/utils/misc/guc.c

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7837,40 +7837,37 @@ replace_auto_config_value(ConfigVariable **head_p, ConfigVariable **tail_p,
78377837
const char *name, const char *value)
78387838
{
78397839
ConfigVariable *item,
7840+
*next,
78407841
*prev = NULL;
78417842

7842-
/* Search the list for an existing match (we assume there's only one) */
7843-
for (item = *head_p; item != NULL; item = item->next)
7843+
/*
7844+
* Remove any existing match(es) for "name". Normally there'd be at most
7845+
* one, but if external tools have modified the config file, there could
7846+
* be more.
7847+
*/
7848+
for (item = *head_p; item != NULL; item = next)
78447849
{
7845-
if (strcmp(item->name, name) == 0)
7850+
next = item->next;
7851+
if (guc_name_compare(item->name, name) == 0)
78467852
{
7847-
/* found a match, replace it */
7848-
pfree(item->value);
7849-
if (value != NULL)
7850-
{
7851-
/* update the parameter value */
7852-
item->value = pstrdup(value);
7853-
}
7853+
/* found a match, delete it */
7854+
if (prev)
7855+
prev->next = next;
78547856
else
7855-
{
7856-
/* delete the configuration parameter from list */
7857-
if (*head_p == item)
7858-
*head_p = item->next;
7859-
else
7860-
prev->next = item->next;
7861-
if (*tail_p == item)
7862-
*tail_p = prev;
7857+
*head_p = next;
7858+
if (next == NULL)
7859+
*tail_p = prev;
78637860

7864-
pfree(item->name);
7865-
pfree(item->filename);
7866-
pfree(item);
7867-
}
7868-
return;
7861+
pfree(item->name);
7862+
pfree(item->value);
7863+
pfree(item->filename);
7864+
pfree(item);
78697865
}
7870-
prev = item;
7866+
else
7867+
prev = item;
78717868
}
78727869

7873-
/* Not there; no work if we're trying to delete it */
7870+
/* Done if we're trying to delete it */
78747871
if (value == NULL)
78757872
return;
78767873

0 commit comments

Comments
 (0)