Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1htzUf-00084F-NX for pgsql-hackers@arkaria.postgresql.org; Sat, 03 Aug 2019 19:15:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1htzTe-0002rX-NZ for pgsql-hackers@arkaria.postgresql.org; Sat, 03 Aug 2019 19:14:02 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1htzTe-0002o3-F2 for pgsql-hackers@lists.postgresql.org; Sat, 03 Aug 2019 19:14:02 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1htzTW-0008SD-LW for pgsql-hackers@postgresql.org; Sat, 03 Aug 2019 19:14:01 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x73JDmPm016338; Sat, 3 Aug 2019 15:13:48 -0400 From: Tom Lane To: Ian Barwick cc: Tomas Vondra , Amit Kapila , Stephen Frost , Robert Haas , "pgsql-hackers@postgresql.org" Subject: Re: [PATCH] Stop ALTER SYSTEM from making bad assumptions In-reply-to: References: <20372.1561134638@sss.pgh.pa.us> <20190621164028.GO2480@tamriel.snowman.net> <21353.1561136112@sss.pgh.pa.us> <20190624185647.GW2480@tamriel.snowman.net> <15032.1561403529@sss.pgh.pa.us> <20190624192014.GB2480@tamriel.snowman.net> <56aff4f3-dec8-f462-7feb-0938411b04a6@2ndquadrant.com> <20190802222254.qsvqjtkwte464lu3@development> <31697.1564784856@sss.pgh.pa.us> Comments: In-reply-to Ian Barwick message dated "Sat, 03 Aug 2019 07:39:27 +0900" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <16080.1564859244.0@sss.pgh.pa.us> Date: Sat, 03 Aug 2019 15:13:48 -0400 Message-ID: <16337.1564859628@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <16080.1564859244.1@sss.pgh.pa.us> Ian Barwick writes: > On 8/3/19 7:27 AM, Tom Lane wrote: >> Tomas Vondra writes: >>> The main issue however is that no code was written yet. >> Seems like it ought to be relatively simple ... but I didn't look. > The patch I originally sent does exactly this. Ah, you did send a patch, but that tries to maintain the existing behavior of replacing the last occurrence in-place. I think it's simpler and more sensible to just make a sweep to delete all matches, and then append the new setting (if any) at the end, as attached. A more aggressive patch would try to de-duplicate the entire list, not just the current target entry ... but I'm not really excited about doing that in a back-patchable bug fix. I looked at the TAP test you proposed and couldn't quite convince myself that it was worth the trouble. A new test within an existing suite would likely be fine, but a whole new src/test/ subdirectory just for pg.auto.conf seems a bit much. (Note that the buildfarm and possibly the MSVC scripts would have to be taught about each such subdirectory.) At the same time, we lack any better place to put such a test :-(. Maybe it's time for a "miscellaneous TAP tests" subdirectory? regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="alter-system-remove-dup-entries-1.patch"; charset="us-ascii" Content-ID: <16080.1564859244.2@sss.pgh.pa.us> Content-Description: alter-system-remove-dup-entries-1.patch Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index fc46360..12abbb2 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -7850,40 +7850,37 @@ replace_auto_config_value(ConfigVariable **head_p,= ConfigVariable **tail_p, const char *name, const char *value) { ConfigVariable *item, + *next, *prev =3D NULL; = - /* Search the list for an existing match (we assume there's only one) */ - for (item =3D *head_p; item !=3D NULL; item =3D item->next) + /* + * Remove any existing match(es) for "name". Normally there'd be at mos= t + * one, but if external tools have modified the config file, there could + * be more. + */ + for (item =3D *head_p; item !=3D NULL; item =3D next) { + next =3D item->next; if (strcmp(item->name, name) =3D=3D 0) { - /* found a match, replace it */ - pfree(item->value); - if (value !=3D NULL) - { - /* update the parameter value */ - item->value =3D pstrdup(value); - } + /* found a match, delete it */ + if (prev) + prev->next =3D next; else - { - /* delete the configuration parameter from list */ - if (*head_p =3D=3D item) - *head_p =3D item->next; - else - prev->next =3D item->next; - if (*tail_p =3D=3D item) - *tail_p =3D prev; + *head_p =3D next; + if (next =3D=3D NULL) + *tail_p =3D prev; = - pfree(item->name); - pfree(item->filename); - pfree(item); - } - return; + pfree(item->value); + pfree(item->name); + pfree(item->filename); + pfree(item); } - prev =3D item; + else + prev =3D item; } = - /* Not there; no work if we're trying to delete it */ + /* Done if we're trying to delete it */ if (value =3D=3D NULL) return; = ------- =_aaaaaaaaaa0--