Skip to content

Commit fce2ce7

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 a0b808b commit fce2ce7

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
@@ -484,6 +484,7 @@ replace_guc_value(char **lines, const char *guc_name, const char *guc_value,
484484
for (i = 0; lines[i]; i++)
485485
{
486486
const char *where;
487+
const char *namestart;
487488

488489
/*
489490
* Look for a line assigning to guc_name. Typically it will be
@@ -494,15 +495,19 @@ replace_guc_value(char **lines, const char *guc_name, const char *guc_value,
494495
where = lines[i];
495496
while (*where == '#' || isspace((unsigned char) *where))
496497
where++;
497-
if (strncmp(where, guc_name, namelen) != 0)
498+
if (pg_strncasecmp(where, guc_name, namelen) != 0)
498499
continue;
500+
namestart = where;
499501
where += namelen;
500502
while (isspace((unsigned char) *where))
501503
where++;
502504
if (*where != '=')
503505
continue;
504506

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

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

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

202+
# Make sure multiple invocations of -c parameters are added case insensitive
203+
command_ok(
204+
[
205+
'initdb', '-cwork_mem=128',
206+
'-cWork_Mem=256', '-cWORK_MEM=512',
207+
"$tempdir/dataY"
208+
],
209+
'multiple -c options with different case');
210+
211+
my $conf = slurp_file("$tempdir/dataY/postgresql.conf");
212+
ok($conf !~ qr/^WORK_MEM = /m, "WORK_MEM should not be configured");
213+
ok($conf !~ qr/^Work_Mem = /m, "Work_Mem should not be configured");
214+
ok($conf =~ qr/^work_mem = 512/m, "work_mem should be in config");
215+
202216
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