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 3e51b278d). Discussion: https://postgr.es/m/20230928.164904.2153358973162534034.horikyota.ntt@gmail.com
This commit is contained in:
parent
a0b808baef
commit
fce2ce797c
@ -484,6 +484,7 @@ replace_guc_value(char **lines, const char *guc_name, const char *guc_value,
|
|||||||
for (i = 0; lines[i]; i++)
|
for (i = 0; lines[i]; i++)
|
||||||
{
|
{
|
||||||
const char *where;
|
const char *where;
|
||||||
|
const char *namestart;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Look for a line assigning to guc_name. Typically it will be
|
* 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,
|
|||||||
where = lines[i];
|
where = lines[i];
|
||||||
while (*where == '#' || isspace((unsigned char) *where))
|
while (*where == '#' || isspace((unsigned char) *where))
|
||||||
where++;
|
where++;
|
||||||
if (strncmp(where, guc_name, namelen) != 0)
|
if (pg_strncasecmp(where, guc_name, namelen) != 0)
|
||||||
continue;
|
continue;
|
||||||
|
namestart = where;
|
||||||
where += namelen;
|
where += namelen;
|
||||||
while (isspace((unsigned char) *where))
|
while (isspace((unsigned char) *where))
|
||||||
where++;
|
where++;
|
||||||
if (*where != '=')
|
if (*where != '=')
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* found it -- append the original comment if any */
|
/* found it -- let's use the canonical casing shown in the file */
|
||||||
|
memcpy(&newline->data[mark_as_comment ? 1 : 0], namestart, namelen);
|
||||||
|
|
||||||
|
/* now append the original comment if any */
|
||||||
where = strrchr(where, '#');
|
where = strrchr(where, '#');
|
||||||
if (where)
|
if (where)
|
||||||
{
|
{
|
||||||
|
@ -199,4 +199,18 @@ command_fails(
|
|||||||
command_fails([ 'initdb', '--no-sync', '--set', 'foo=bar', "$tempdir/dataX" ],
|
command_fails([ 'initdb', '--no-sync', '--set', 'foo=bar', "$tempdir/dataX" ],
|
||||||
'fails for invalid --set option');
|
'fails for invalid --set option');
|
||||||
|
|
||||||
|
# Make sure multiple invocations of -c parameters are added case insensitive
|
||||||
|
command_ok(
|
||||||
|
[
|
||||||
|
'initdb', '-cwork_mem=128',
|
||||||
|
'-cWork_Mem=256', '-cWORK_MEM=512',
|
||||||
|
"$tempdir/dataY"
|
||||||
|
],
|
||||||
|
'multiple -c options with different case');
|
||||||
|
|
||||||
|
my $conf = slurp_file("$tempdir/dataY/postgresql.conf");
|
||||||
|
ok($conf !~ qr/^WORK_MEM = /m, "WORK_MEM should not be configured");
|
||||||
|
ok($conf !~ qr/^Work_Mem = /m, "Work_Mem should not be configured");
|
||||||
|
ok($conf =~ qr/^work_mem = 512/m, "work_mem should be in config");
|
||||||
|
|
||||||
done_testing();
|
done_testing();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user