patternsqlMinor
Why PostgreSQL's service are different between system service and pg_ctl?
Viewed 0 times
postgresqlwhypg_ctlaresystemdifferentservicebetweenand
Problem
Installed PostgreSQL 10 by a normal user.
Enabled and started its service:
Then login with
Add this setting to
Restart PostgreSQL by
Then exit to normal user and check postgresql's status again, it failed. Even use this way to restart can't success:
It always
But if I use
These 2 ways aren't controlling the same process?
Add postgresql-10 service content
```
$ sudo systemctl cat postgresql-10.service
# /usr/lib/systemd/system/postgresql-10.service
# It's not recommended to modify this file in-place, because it will be
# overwritten during package upgrades. If you want to customize, the
# best way is to create a file "/etc/systemd/system/postgresql-10.service",
# containing
# .include /usr/lib/systemd/system/postgresql-10.service
# ...make your changes here...
# For more info about custom unit files, see
# http://fedoraproject.org/wiki/Systemd#How_do_I_customize_a_unit_file.2F_add_a_custom_unit_file.3F
# Note: changing PGDATA will typically require adjusting SELinux
# configuration as well.
# Note: do not use a PGDATA pathname containing spaces, or you will
# break postgresql-setup.
[Unit]
Description=PostgreSQL 10 database server
Documentation=https://www.postgresql.org/docs/10/static/
After=syslog.target
After=network.target
[Service]
Type=notify
User=postgres
Group=postgres
# Note: avoid inserting whitespace in these Environment= lines, or you may
# break postgresql-setup.
# Location of database directory
Environment=PGDATA=/var/lib/pgsql/10/data/
# Where to send early-startup messages from the server (before the logging
# options of postgres
Enabled and started its service:
sudo systemctl start postgresql-10
sudo systemctl enable postgresql-10Then login with
postgres user:sudo su - postgresAdd this setting to
.bash_profile file:export PATH=$PATH:/usr/pgsql-10/bin/Restart PostgreSQL by
pg_ctl:-bash-4.2$ pg_ctl restartThen exit to normal user and check postgresql's status again, it failed. Even use this way to restart can't success:
sudo systemctl restart postgresql-10
sudo systemctl stop postgresql-10It always
failed.But if I use
postgres user to test restart, stop, start, all of them can success.These 2 ways aren't controlling the same process?
Add postgresql-10 service content
```
$ sudo systemctl cat postgresql-10.service
# /usr/lib/systemd/system/postgresql-10.service
# It's not recommended to modify this file in-place, because it will be
# overwritten during package upgrades. If you want to customize, the
# best way is to create a file "/etc/systemd/system/postgresql-10.service",
# containing
# .include /usr/lib/systemd/system/postgresql-10.service
# ...make your changes here...
# For more info about custom unit files, see
# http://fedoraproject.org/wiki/Systemd#How_do_I_customize_a_unit_file.2F_add_a_custom_unit_file.3F
# Note: changing PGDATA will typically require adjusting SELinux
# configuration as well.
# Note: do not use a PGDATA pathname containing spaces, or you will
# break postgresql-setup.
[Unit]
Description=PostgreSQL 10 database server
Documentation=https://www.postgresql.org/docs/10/static/
After=syslog.target
After=network.target
[Service]
Type=notify
User=postgres
Group=postgres
# Note: avoid inserting whitespace in these Environment= lines, or you may
# break postgresql-setup.
# Location of database directory
Environment=PGDATA=/var/lib/pgsql/10/data/
# Where to send early-startup messages from the server (before the logging
# options of postgres
Solution
If you start the server manually using
It will happily try to start the server, which will fail (because the server is already running), and it cannot stop the server, because it does not know it is running.
So always use
pg_ctl, systemd doesn't know about it.It will happily try to start the server, which will fail (because the server is already running), and it cannot stop the server, because it does not know it is running.
So always use
systemctl when starting and stopping the service. Reloading with pg_ctl reload is fine.Context
StackExchange Database Administrators Q#260956, answer score: 6
Revisions (0)
No revisions yet.