BUG #17469: postgresql-11.service file not configured to match setup/initdb options specified

Started by PG Bug reporting formalmost 4 years ago6 messagesbugs
Jump to latest
#1PG Bug reporting form
noreply@postgresql.org

The following bug has been logged on the website:

Bug reference: 17469
Logged by: Joe Hebert
Email address: jhebert@micron.com
PostgreSQL version: 11.11
Operating system: RHEL 8.5
Description:

The following command was used to initialize the database (separate issue
with postgresql-11-setup not working):
/usr/pgsql-11/bin/initdb -A password -E utf8 -D /postgres/data/datafiles -X
/postgres/tranlog

Initialization completed successfully.

Then ran: sudo systemctl enable postgresql-11
Result: Created symlink
/etc/systemd/system/multi-user.target.wants/postgresql-11.service â
/usr/lib/systemd/system/postgresql-11.service.

Then ran: sudo systemctl start postgresql-11
Result:
Job for postgresql-11.service failed because the control process exited with
error code.
See "systemctl status postgresql-11.service" and "journalctl -xe" for
details.

sudo systemctl status postgresql-11
â postgresql-11.service - PostgreSQL 11 database server
Loaded: loaded (/usr/lib/systemd/system/postgresql-11.service; enabled;
vendor preset: disabled)
Active: failed (Result: exit-code) since Wed 2022-04-27 16:19:40 MDT; 28s
ago
Docs: https://www.postgresql.org/docs/11/static/
Process: 147756 ExecStartPre=/usr/pgsql-11/bin/postgresql-11-check-db-dir
${PGDATA} (code=exited, status=1/FAILURE)

Apr 27 16:19:40 systemd[1]: Starting PostgreSQL 11 database server...
Apr 27 16:19:40 systemd[1]: postgresql-11.service: Control process exited,
code=exited status=1
Apr 27 16:19:40 systemd[1]: postgresql-11.service: Failed with result
'exit-code'.
Apr 27 16:19:40 systemd[1]: Failed to start PostgreSQL 11 database
server.

After researching further, I reviewed file
/usr/lib/systemd/system/postgresql-11.service
and found the following offending line:
Environment=PGDATA=/var/lib/pgsql/11/data/

Which should have been set to /postgres/data/datafiles based in the option
provided to the initdb command.

Work-around: sudo systemctl edit --full postgresql-11
replaced the content, fixing the incorrect path
Result: PostgreSQL instance started successfully

If this is not considered a bug, please consider addressing this as an
enhancement. As a side note, I tried the "sudo systemctl edit" command
without the --full option to only override the one line, however, the issue
still persisted and required a wholesale replacement of the
postgresql-11.service file.

#2David G. Johnston
david.g.johnston@gmail.com
In reply to: PG Bug reporting form (#1)
Re: BUG #17469: postgresql-11.service file not configured to match setup/initdb options specified

On Thu, Apr 28, 2022 at 4:42 PM PG Bug reporting form <
noreply@postgresql.org> wrote:

The following bug has been logged on the website:

Bug reference: 17469
Logged by: Joe Hebert
Email address: jhebert@micron.com
PostgreSQL version: 11.11
Operating system: RHEL 8.5
Description:

After researching further, I reviewed file
/usr/lib/systemd/system/postgresql-11.service
and found the following offending line:
Environment=PGDATA=/var/lib/pgsql/11/data/

Which should have been set to /postgres/data/datafiles based in the option
provided to the initdb command.

I'm curious to know where you got the idea that initdb integrated with
systemd. I'm under the impression it doesn't. PostgreSQL core doesn't
generally deal with such platform-specific concerns (i.e., it isn't a
feature enhancement we would consider).

If you go against the conventions of your packaged distribution (or do not
avail yourself of its tooling) you have to do the customizations yourself.

David J.

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: PG Bug reporting form (#1)
Re: BUG #17469: postgresql-11.service file not configured to match setup/initdb options specified

PG Bug reporting form <noreply@postgresql.org> writes:

After researching further, I reviewed file
/usr/lib/systemd/system/postgresql-11.service
and found the following offending line:
Environment=PGDATA=/var/lib/pgsql/11/data/
Which should have been set to /postgres/data/datafiles based in the option
provided to the initdb command.

Hmm. initdb knows nothing about systemd unit files, and would not
have the permissions to modify them even if it did know, since it
doesn't run as root.

If this is not considered a bug, please consider addressing this as an
enhancement.

This isn't really a matter for the core Postgres distribution, because not
one of the files you mention is part of the core Postgres distribution.
You could take it up with whoever produces the package you are using.

My guess is that the packager will say that manual invocation of initdb
isn't the right way in their package and you should use some wrapper
script instead --- in which case you could move on to why the wrapper
script isn't adequately documented or how it lacks some functionality
you need. But this list isn't well positioned to help you.

regards, tom lane

#4Joe Hebert (jhebert)
jhebert@micron.com
In reply to: David G. Johnston (#2)
RE: [EXT] Re: BUG #17469: postgresql-11.service file not configured to match setup/initdb options specified

Micron Confidential

Hi David,

Thanks for your response. Initially I was attempting to use sudo to initialize the DB per the sample commands provided at the following web page:

https://www.postgresql.org/download/linux/redhat/

From the recommended script on that page:
# Optionally initialize the database and enable automatic start:
sudo /usr/pgsql-11/bin/postgresql-11-setup initdb
sudo systemctl enable postgresql-11

Due to encountering error "failed to find PGDATA setting in /postgres/data/datafiles.service", it looked like I had encountered bug #15108</messages/by-id/152094313655.1225.9005657715834235284@wrigleys.postgresql.org&gt;, which led me to use initdb instead of postgresql-11-setup per Sergei's recommendation. Below are the actual commands I used, which were successful:

/usr/pgsql-11/bin/initdb -A ldap -E utf8 -D /postgres/data/datafiles -X /postgres/tranlog
sudo systemctl enable postgresql-11

Anyway, since the above recommended commands were to be run with sudo, I presumed the systemctl template for postgresql would have been generated with the -D option value I provided embedded in the PGDATA environment variable in the template (/usr/lib/systemd/system/postgresql-11.service). However, after realizing that I could not use sudo with initdb, it makes sense that it would not integrate with the postgresql-11.service template.

I guess I am not sure where that template file comes from (and which process generates it), but it would be nice if we didn't have to edit the template every time we install. On my side, finding a way to edit the file (sudo systemctl edit --full postgresql-11) in an automated way (for unattended installs) may be problematic.

Hopefully this helps explain the path I took and my thought process.

Joe

Micron Confidential
From: David G. Johnston <david.g.johnston@gmail.com>
Sent: Thursday, April 28, 2022 5:58 PM
To: Joe Hebert (jhebert) <jhebert@micron.com>; PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>
Subject: [EXT] Re: BUG #17469: postgresql-11.service file not configured to match setup/initdb options specified

CAUTION: EXTERNAL EMAIL. Do not click links or open attachments unless you recognize the sender and were expecting this message.

On Thu, Apr 28, 2022 at 4:42 PM PG Bug reporting form <noreply@postgresql.org<mailto:noreply@postgresql.org>> wrote:
The following bug has been logged on the website:

Bug reference: 17469
Logged by: Joe Hebert
Email address: jhebert@micron.com<mailto:jhebert@micron.com>
PostgreSQL version: 11.11
Operating system: RHEL 8.5
Description:

After researching further, I reviewed file
/usr/lib/systemd/system/postgresql-11.service
and found the following offending line:
Environment=PGDATA=/var/lib/pgsql/11/data/

Which should have been set to /postgres/data/datafiles based in the option
provided to the initdb command.

I'm curious to know where you got the idea that initdb integrated with systemd. I'm under the impression it doesn't. PostgreSQL core doesn't generally deal with such platform-specific concerns (i.e., it isn't a feature enhancement we would consider).

If you go against the conventions of your packaged distribution (or do not avail yourself of its tooling) you have to do the customizations yourself.

David J.

#5Devrim GÜNDÜZ
devrim@gunduz.org
In reply to: PG Bug reporting form (#1)
Re: BUG #17469: postgresql-11.service file not configured to match setup/initdb options specified

Hi,

On Thu, 2022-04-28 at 23:18 +0000, PG Bug reporting form wrote:

Bug reference:      17469
Logged by:          Joe Hebert
Email address:      jhebert@micron.com
PostgreSQL version: 11.11
Operating system:   RHEL 8.5
Description:       

The following command was used to initialize the database (separate
issue with postgresql-11-setup not working):

What is the problem with that setup script?

Regards,
--
Devrim Gündüz
Open Source Solution Architect, Red Hat Certified Engineer
Twitter: @DevrimGunduz , @DevrimGunduzTR

#6Joe Hebert (jhebert)
jhebert@micron.com
In reply to: Devrim GÜNDÜZ (#5)
RE: [EXT] Re: BUG #17469: postgresql-11.service file not configured to match setup/initdb options specified

Micron Confidential

Hi Devrim,

I have attached a previous response which has more details. Those details should probably be added to the case notes.

Thanks,

Joe

Micron Confidential

-----Original Message-----
From: Devrim Gündüz <devrim@gunduz.org>
Sent: Sunday, May 15, 2022 7:07 PM
To: Joe Hebert (jhebert) <jhebert@micron.com>; pgsql-bugs@lists.postgresql.org
Subject: [EXT] Re: BUG #17469: postgresql-11.service file not configured to match setup/initdb options specified

CAUTION: EXTERNAL EMAIL. Do not click links or open attachments unless you recognize the sender and were expecting this message.