Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rPhRi-00DUgV-1k for pgsql-hackers@arkaria.postgresql.org; Tue, 16 Jan 2024 11:17:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rPhRg-0031q9-On for pgsql-hackers@arkaria.postgresql.org; Tue, 16 Jan 2024 11:17:28 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rPhRg-0031q0-EF for pgsql-hackers@lists.postgresql.org; Tue, 16 Jan 2024 11:17:28 +0000 Received: from smtp.outgoing.loopia.se ([93.188.3.37]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rPhRd-0026ZL-OZ for pgsql-hackers@lists.postgresql.org; Tue, 16 Jan 2024 11:17:27 +0000 Received: from s807.loopia.se (localhost [127.0.0.1]) by s807.loopia.se (Postfix) with ESMTP id 9C3752FE0C5B for ; Tue, 16 Jan 2024 12:17:24 +0100 (CET) Received: from s934.loopia.se (unknown [172.22.191.6]) by s807.loopia.se (Postfix) with ESMTP id 8C9CD2E28900; Tue, 16 Jan 2024 12:17:24 +0100 (CET) Received: from s472.loopia.se (unknown [172.22.191.5]) by s934.loopia.se (Postfix) with ESMTP id 8A9AF7CEA5D; Tue, 16 Jan 2024 12:17:24 +0100 (CET) X-Virus-Scanned: amavisd-new at amavis.loopia.se X-Spam-Flag: NO X-Spam-Score: -1.01 X-Spam-Level: X-Spam-Status: No, score=-1.01 tagged_above=-999 required=6.2 tests=[ALL_TRUSTED=-1, T_SCC_BODY_TEXT_LINE=-0.01] autolearn=disabled Received: from s980.loopia.se ([172.22.191.5]) by s472.loopia.se (s472.loopia.se [172.22.190.12]) (amavisd-new, port 10024) with LMTP id Ck3PNOBHkTdv; Tue, 16 Jan 2024 12:17:24 +0100 (CET) X-Loopia-Auth: user X-Loopia-User: daniel@yesql.se X-Loopia-Originating-IP: 89.255.232.193 Received: from smtpclient.apple (customer-89-255-232-193.stosn.net [89.255.232.193]) (Authenticated sender: daniel@yesql.se) by s980.loopia.se (Postfix) with ESMTPSA id EB24E2201627; Tue, 16 Jan 2024 12:17:23 +0100 (CET) From: Daniel Gustafsson Message-Id: <405F4FB5-81DF-4554-9E44-8C73E98200B2@yesql.se> Content-Type: multipart/mixed; boundary="Apple-Mail=_51A4FA87-25F8-4B0D-98C6-46E9B462734F" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.4\)) Subject: Re: initdb's -c option behaves wrong way? Date: Tue, 16 Jan 2024 12:17:23 +0100 In-Reply-To: <20230928.164904.2153358973162534034.horikyota.ntt@gmail.com> Cc: pgsql-hackers@lists.postgresql.org To: Kyotaro Horiguchi References: <20230928.164904.2153358973162534034.horikyota.ntt@gmail.com> X-Mailer: Apple Mail (2.3696.120.41.1.4) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_51A4FA87-25F8-4B0D-98C6-46E9B462734F Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii > On 28 Sep 2023, at 09:49, Kyotaro Horiguchi = wrote: > I noticed that -c option of initdb behaves in an unexpected > manner. Identical variable names with variations in letter casing are > treated as distinct variables. >=20 > $ initdb -cwork_mem=3D100 -cWORK_MEM=3D1000 -cWork_mem=3D2000 > The original intention was apparently to overwrite the existing > line. Furthermore, I surmise that preserving the original letter > casing is preferable. Circling back to an old thread, I agree that this seems odd and the = original thread [0] makes no mention of it being intentional. The patch seems fine to me, the attached version is rebased, pgindented = and has a test case added. -- Daniel Gustafsson [0] = https://www.postgresql.org/message-id/flat/2844176.1674681919%40sss.pgh.pa= .us --Apple-Mail=_51A4FA87-25F8-4B0D-98C6-46E9B462734F Content-Disposition: attachment; filename=v2-0001-Make-initdb-c-option-case-insensitive.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="v2-0001-Make-initdb-c-option-case-insensitive.patch" Content-Transfer-Encoding: quoted-printable =46rom=20cbdfe0eefbd2707401f542e3e5a4e08c7202a77c=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20Daniel=20Gustafsson=20= =0ADate:=20Tue,=2016=20Jan=202024=2012:02:21=20= +0100=0ASubject:=20[PATCH=20v2]=20Make=20initdb=20-c=20option=20case=20= insensitive=0A=0AWhen=20a=20-c=20option=20specifies=20a=20GUC=20name=20= to=20replace=20using=20different=0Acase=20than=20the=20existing=20= parameter=20it=20was=20added=20as=20a=20new=20parameter=0Arather=20than=20= replacing=20the=20existing.=20=20This=20makes=20-c=20replacements=0Acase=20= insensitive=20such=20that=20-cWORK_MEM=20will=20update=20the=20value=20= of=0Awork_mem=20in=20the=20config.=0A=0AReported-by:=20Kyotaro=20= Horiguchi=20=0ADiscussion:=20= https://postgr.es/m/20230928.164904.2153358973162534034.horikyota.ntt@gmai= l.com=0A---=0A=20src/bin/initdb/initdb.c=20=20=20=20=20=20=20=20|=2046=20= ++++++++++++++++++++++------------=0A=20src/bin/initdb/t/001_initdb.pl=20= |=2012=20+++++++++=0A=202=20files=20changed,=2042=20insertions(+),=2016=20= deletions(-)=0A=0Adiff=20--git=20a/src/bin/initdb/initdb.c=20= b/src/bin/initdb/initdb.c=0Aindex=20ac409b0006..aa858ece8a=20100644=0A= ---=20a/src/bin/initdb/initdb.c=0A+++=20b/src/bin/initdb/initdb.c=0A@@=20= -471,20=20+471,14=20@@=20replace_guc_value(char=20**lines,=20const=20= char=20*guc_name,=20const=20char=20*guc_value,=0A=20=09int=09=09=09= namelen=20=3D=20strlen(guc_name);=0A=20=09PQExpBuffer=20newline=20=3D=20= createPQExpBuffer();=0A=20=09int=09=09=09i;=0A+=09const=20char=20*where;=0A= +=09const=20char=20*pname;=0A=20=0A-=09/*=20prepare=20the=20replacement=20= line,=20except=20for=20possible=20comment=20and=20newline=20*/=0A=20=09= if=20(mark_as_comment)=0A=20=09=09appendPQExpBufferChar(newline,=20'#');=0A= -=09appendPQExpBuffer(newline,=20"%s=20=3D=20",=20guc_name);=0A-=09if=20= (guc_value_requires_quotes(guc_value))=0A-=09=09= appendPQExpBuffer(newline,=20"'%s'",=20escape_quotes(guc_value));=0A-=09= else=0A-=09=09appendPQExpBufferStr(newline,=20guc_value);=0A=20=0A=20=09= for=20(i=20=3D=200;=20lines[i];=20i++)=0A=20=09{=0A-=09=09const=20char=20= *where;=0A-=0A=20=09=09/*=0A=20=09=09=20*=20Look=20for=20a=20line=20= assigning=20to=20guc_name.=20=20Typically=20it=20will=20be=0A=20=09=09=20= *=20preceded=20by=20'#',=20but=20that=20might=20not=20be=20the=20case=20= if=20a=20-c=20switch=0A@@=20-494,15=20+488,32=20@@=20= replace_guc_value(char=20**lines,=20const=20char=20*guc_name,=20const=20= char=20*guc_value,=0A=20=09=09where=20=3D=20lines[i];=0A=20=09=09while=20= (*where=20=3D=3D=20'#'=20||=20isspace((unsigned=20char)=20*where))=0A=20=09= =09=09where++;=0A-=09=09if=20(strncmp(where,=20guc_name,=20namelen)=20!=3D= =200)=0A+=09=09if=20(strncasecmp(where,=20guc_name,=20namelen)=20!=3D=20= 0)=0A=20=09=09=09continue;=0A+=0A+=09=09pname=20=3D=20where;=0A=20=09=09= where=20+=3D=20namelen;=0A=20=09=09while=20(isspace((unsigned=20char)=20= *where))=0A=20=09=09=09where++;=0A-=09=09if=20(*where=20!=3D=20'=3D')=0A= -=09=09=09continue;=0A=20=0A-=09=09/*=20found=20it=20--=20append=20the=20= original=20comment=20if=20any=20*/=0A+=09=09/*=20assume=20there's=20only=20= one=20match=20*/=0A+=09=09if=20(*where=20=3D=3D=20'=3D')=0A+=09=09=09= break;=0A+=09}=0A+=0A+=09if=20(lines[i])=0A+=09{=0A+=09=09/*=20Found=20= it,=20rewrite=20the=20line=20preserving=20the=20original=20comment=20if=20= any=20*/=0A+=09=09appendPQExpBuffer(newline,=20"%.*s=20=3D=20",=20= namelen,=20pname);=0A+=09=09if=20(guc_value_requires_quotes(guc_value))=0A= +=09=09=09appendPQExpBuffer(newline,=20"'%s'",=20= escape_quotes(guc_value));=0A+=09=09else=0A+=09=09=09= appendPQExpBufferStr(newline,=20guc_value);=0A+=0A+=09=09/*=0A+=09=09=20= *=20Body=20of=20line=20has=20been=20completed,=20now=20continue=20with=20= potential=0A+=09=09=20*=20indentation=20and=20comment.=0A+=09=09=20*/=0A=20= =09=09where=20=3D=20strrchr(where,=20'#');=0A=20=09=09if=20(where)=0A=20=09= =09{=0A@@=20-549,16=20+560,19=20@@=20replace_guc_value(char=20**lines,=20= const=20char=20*guc_name,=20const=20char=20*guc_value,=0A=20=0A=20=09=09= free(lines[i]);=0A=20=09=09lines[i]=20=3D=20newline->data;=0A-=0A-=09=09= break;=09=09=09=09=09/*=20assume=20there's=20only=20one=20match=20*/=0A=20= =09}=0A-=0A-=09if=20(lines[i]=20=3D=3D=20NULL)=0A+=09else=0A=20=09{=0A=20= =09=09/*=0A=20=09=09=20*=20No=20match,=20so=20append=20a=20new=20entry.=20= =20(We=20rely=20on=20the=20bootstrap=20server=0A=20=09=09=20*=20to=20= complain=20if=20it's=20not=20a=20valid=20GUC=20name.)=0A=20=09=09=20*/=0A= +=09=09appendPQExpBuffer(newline,=20"%s=20=3D=20",=20guc_name);=0A+=09=09= if=20(guc_value_requires_quotes(guc_value))=0A+=09=09=09= appendPQExpBuffer(newline,=20"'%s'",=20escape_quotes(guc_value));=0A+=09=09= else=0A+=09=09=09appendPQExpBufferStr(newline,=20guc_value);=0A+=0A=20=09= =09appendPQExpBufferChar(newline,=20'\n');=0A=20=09=09lines=20=3D=20= pg_realloc_array(lines,=20char=20*,=20i=20+=202);=0A=20=09=09lines[i++]=20= =3D=20newline->data;=0Adiff=20--git=20a/src/bin/initdb/t/001_initdb.pl=20= b/src/bin/initdb/t/001_initdb.pl=0Aindex=2003376cc0f7..1c048bba8e=20= 100644=0A---=20a/src/bin/initdb/t/001_initdb.pl=0A+++=20= b/src/bin/initdb/t/001_initdb.pl=0A@@=20-199,4=20+199,16=20@@=20= command_fails(=0A=20command_fails([=20'initdb',=20'--no-sync',=20= '--set',=20'foo=3Dbar',=20"$tempdir/dataX"=20],=0A=20=09'fails=20for=20= invalid=20--set=20option');=0A=20=0A+#=20Make=20sure=20multiple=20= invocations=20of=20-c=20parameters=20are=20added=20case=20insensitive=0A= +command_ok(=0A+=09[=0A+=09=09'initdb',=20'-cwork_mem=3D128',=20= '-cWork_Mem=3D256',=20'-cWORK_MEM=3D512',=0A+=09=09"$tempdir/dataX"=0A+=09= ],=0A+=09'multiple=20-c=20options=20with=20different=20case');=0A+=0A+my=20= $conf=20=3D=20slurp_file("$tempdir/dataX/postgresql.conf");=0A+ok($conf=20= =3D~=20qr/^work_mem=20=3D=20512/m,=20"work_mem=20configured");=0A= +ok($conf=20!~=20qr/^WORK_MEM=20=3D=20512/m,=20"WORK_MEM=20should=20not=20= be=20in=20config");=0A+=0A=20done_testing();=0A--=20=0A2.32.1=20(Apple=20= Git-133)=0A=0A= --Apple-Mail=_51A4FA87-25F8-4B0D-98C6-46E9B462734F--