pg_conftool mistakes regular comments for commented config options
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
postgresql-common (Ubuntu) |
Fix Released
|
Medium
|
Athos Ribeiro | ||
Bionic |
Won't Fix
|
Low
|
Athos Ribeiro | ||
Focal |
Won't Fix
|
Low
|
Athos Ribeiro | ||
Jammy |
Fix Committed
|
Low
|
Athos Ribeiro | ||
Kinetic |
Fix Committed
|
Low
|
Athos Ribeiro | ||
Lunar |
Fix Released
|
Medium
|
Athos Ribeiro |
Bug Description
[ Impact ]
pg_conftool mistakes regular comments starting with a configuration option for actual commented configuration options.
While the issue does not impact any software features or its usability, it may lead to the deletion of useful comments or documentation in configuration files.
[ Test Plan ]
The proposed change includes new tests to cover the most basic cases the regular expression was failing to deal with.
On top of that, we can verify the fix by
0) Installing postgresql-
1) appending
# test_config this is just a comment
to the /etc/postgresql
2) running
pg_conftool /etc/postgresql
3) checking that the end of the file contains
# test_config this is just a comment
test_config = on
for fixed versions of the package, instead of just
test_config = on
as it happens for affected versions.
[ Where problems could occur ]
While the changed regular expression is being tested during autopkgtest runs, the proposed patch may change its parsing behavior for unaccounted use cases. If this happens, we will need to cover such cases and propose further fixes.
[ Other info ]
We already submitted a fix to Debian in https:/
Note that while lunar has one specific documentation line affected by this issue (as described below), the other affected series would only have this issue manifested for user specific crafted comments, AFAICT. This is why all SRUs for this bug are marked as low priority, differently from the lunar one.
[ Original report ]
While configuring Postgres for our Docker containers running Ubuntu/Postgres15 (new deployment) we have found a peculiar problem.
When setting the "logging_collector = on/off" we have found pg_conftool uncomments the incorrect line, please note this does not happen to any other line, but very well may as we do not change all default settings.
Here is an excerpt for /etc/postgresql
Default install:
-------
446 # eventlog, depending on platform.
447 # csvlog and jsonlog require
448 # logging_collector to be on.
449
450 # This is used when logging to stderr:
451 #logging_collector = off # Enable capturing of stderr, jsonlog,
452 # and csvlog into log files. Required
453 # to be on for csvlogs and jsonlogs.
-------
Please note this ONLY happens on PG15 which happens to have comments on line 447/448 in a separate line placing "logging_collector" in the start of the sentence.
When running:
-------
# pg_conftool /etc/postgresql
-------
It will modify the postgresql.conf but not how you would think it would; after setting logging_collector to on:
-------
447 # csvlog and jsonlog require
448 logging_collector on
449
450 # This is used when logging to stderr:
451 #logging_collector = off # Enable capturing of stderr, jsonlog,
452 # and csvlog into log files. Required
453 # to be on for csvlogs and jsonlogs.
-------
The incorrect line was uncommented (448), it should have uncommented line 451.
Looking into the source code for pg_conftool we found the regex used for parsing postgresql.conf is the problem, it recognizes line 448 as a valid setting line when it is indeed a comment:
-------
448 # logging_collector to be on
-------
Here is the snip for file ".\postgresql-
-------
my $found = 0;
# first, search for an uncommented setting
for (my $i=0; $i <= $#lines; ++$i) {
if ($lines[$i] =~ /^\s*($
$lines[$i] =~ /^\s*($
$lines[$i] = "$1$2$value$3\n";
$found = 1;
last;
}
}
# now check if the setting exists as a comment; if so, change that instead
# of appending
if (!$found) {
for (my $i=0; $i <= $#lines; ++$i) {
if ($lines[$i] =~ /^\s*#\
$lines[$i] =~ /^\s*#\
$lines[$i] = "$1$2$value$3\n";
$found = 1;
last;
}
}
-------
Related branches
- git-ubuntu bot: Approve
- Bryce Harrington (community): Approve
- Canonical Server Reporter: Pending requested
-
Diff: 107 lines (+26/-2)3 files modifiedPgCommon.pm (+2/-2)
debian/changelog (+6/-0)
t/005_PgCommon.t (+18/-0)
- git-ubuntu bot: Approve
- Bryce Harrington (community): Approve
- Canonical Server Reporter: Pending requested
-
Diff: 107 lines (+26/-2)3 files modifiedPgCommon.pm (+2/-2)
debian/changelog (+6/-0)
t/005_PgCommon.t (+18/-0)
- git-ubuntu bot: Approve
- Bryce Harrington (community): Approve
- Canonical Server Reporter: Pending requested
-
Diff: 138 lines (+31/-5)5 files modifiedPgCommon.pm (+2/-2)
debian/changelog (+7/-0)
debian/control (+2/-1)
debian/rules (+2/-2)
t/005_PgCommon.t (+18/-0)
- git-ubuntu bot: Approve
- Bryce Harrington (community): Approve
- Canonical Server Reporter: Pending requested
-
Diff: 107 lines (+26/-2)3 files modifiedPgCommon.pm (+2/-2)
debian/changelog (+6/-0)
t/005_PgCommon.t (+18/-0)
- git-ubuntu bot: Approve
- Sergio Durigan Junior (community): Approve
- Canonical Server Reporter: Pending requested
-
Diff: 121 lines (+28/-3)4 files modifiedPgCommon.pm (+2/-2)
debian/changelog (+6/-0)
debian/control (+2/-1)
t/005_PgCommon.t (+18/-0)
Changed in postgresql-common (Ubuntu): | |
assignee: | nobody → Athos Ribeiro (athos-ribeiro) |
description: | updated |
Changed in postgresql-common (Ubuntu Jammy): | |
status: | New → Triaged |
assignee: | nobody → Athos Ribeiro (athos-ribeiro) |
Changed in postgresql-common (Ubuntu Kinetic): | |
status: | New → Triaged |
Changed in postgresql-common (Ubuntu Focal): | |
status: | New → Triaged |
Changed in postgresql-common (Ubuntu Bionic): | |
status: | New → Triaged |
assignee: | nobody → Athos Ribeiro (athos-ribeiro) |
Changed in postgresql-common (Ubuntu Focal): | |
assignee: | nobody → Athos Ribeiro (athos-ribeiro) |
Changed in postgresql-common (Ubuntu Kinetic): | |
assignee: | nobody → Athos Ribeiro (athos-ribeiro) |
importance: | Undecided → Low |
Changed in postgresql-common (Ubuntu Jammy): | |
importance: | Undecided → Low |
Changed in postgresql-common (Ubuntu Focal): | |
importance: | Undecided → Low |
Changed in postgresql-common (Ubuntu Bionic): | |
importance: | Undecided → Low |
description: | updated |
Changed in postgresql-common (Ubuntu Lunar): | |
status: | Triaged → Fix Released |
tags: | removed: server-todo |
Thanks for the bug report and suggested fix.
I've confirmed the behavior occurs as described, in a lunar lxc container:
root@triage- lunar:/ home/bryce# pg_conftool /etc/postgresql /15/main/ postgresql. conf set logging_collector on lunar:/ home/bryce# grep logging_collector /etc/postgresql /15/main/ postgresql. conf lunar:/ home/bryce#
root@triage-
logging_collector on
#logging_collector = off # Enable capturing of stderr, jsonlog,
# These are only used if logging_collector is on:
root@triage-