Skip to content

Commit b78f4d2

Browse files
committed
Fix initdb's -c option to treat the GUC name case-insensitively.
The backend treats GUC names case-insensitively, so this code should too. This avoids ending up with a confusing set of redundant entries in the generated postgresql.conf file. Per report from Kyotaro Horiguchi. Back-patch to v16 where this feature was added (in commit 3e51b27). Discussion: https://postgr.es/m/20230928.164904.2153358973162534034.horikyota.ntt@gmail.com
1 parent 896bd6d commit b78f4d2

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/bin/initdb/initdb.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,7 @@ replace_guc_value(char **lines, const char *guc_name, const char *guc_value,
482482
for (i = 0; lines[i]; i++)
483483
{
484484
const char *where;
485+
const char *namestart;
485486

486487
/*
487488
* Look for a line assigning to guc_name. Typically it will be
@@ -492,15 +493,19 @@ replace_guc_value(char **lines, const char *guc_name, const char *guc_value,
492493
where = lines[i];
493494
while (*where == '#' || isspace((unsigned char) *where))
494495
where++;
495-
if (strncmp(where, guc_name, namelen) != 0)
496+
if (pg_strncasecmp(where, guc_name, namelen) != 0)
496497
continue;
498+
namestart = where;
497499
where += namelen;
498500
while (isspace((unsigned char) *where))
499501
where++;
500502
if (*where != '=')
501503
continue;
502504

503-
/* found it -- append the original comment if any */
505+
/* found it -- let's use the canonical casing shown in the file */
506+
memcpy(&newline->data[mark_as_comment ? 1 : 0], namestart, namelen);
507+
508+
/* now append the original comment if any */
504509
where = strrchr(where, '#');
505510
if (where)
506511
{

src/bin/initdb/t/001_initdb.pl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,18 @@
187187
command_fails([ 'initdb', '--no-sync', '--set', 'foo=bar', "$tempdir/dataX" ],
188188
'fails for invalid --set option');
189189

190+
# Make sure multiple invocations of -c parameters are added case insensitive
191+
command_ok(
192+
[
193+
'initdb', '-cwork_mem=128',
194+
'-cWork_Mem=256', '-cWORK_MEM=512',
195+
"$tempdir/dataY"
196+
],
197+
'multiple -c options with different case');
198+
199+
my $conf = slurp_file("$tempdir/dataY/postgresql.conf");
200+
ok($conf !~ qr/^WORK_MEM = /m, "WORK_MEM should not be configured");
201+
ok($conf !~ qr/^Work_Mem = /m, "Work_Mem should not be configured");
202+
ok($conf =~ qr/^work_mem = 512/m, "work_mem should be in config");
203+
190204
done_testing();

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy