Installed PostgreSQL 10 by a normal user.

Enabled and started its service:

sudo systemctl start postgresql-10
sudo systemctl enable postgresql-10

Then login with postgres user:

sudo su - postgres

Add this setting to .bash_profile file:

export PATH=$PATH:/usr/pgsql-10/bin/

Restart PostgreSQL by pg_ctl:

-bash-4.2$ pg_ctl restart

Then 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-10

It 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.
Description=PostgreSQL 10 database server



# Note: avoid inserting whitespace in these Environment= lines, or you may
# break postgresql-setup.

# Location of database directory

# Where to send early-startup messages from the server (before the logging
# options of postgresql.conf take effect)
# This is normally controlled by the global default set by systemd
# StandardOutput=syslog

# Disable OOM kill on the postmaster

ExecStartPre=/usr/pgsql-10/bin/postgresql-10-check-db-dir ${PGDATA}
ExecStart=/usr/pgsql-10/bin/postmaster -D ${PGDATA}
ExecReload=/bin/kill -HUP $MAINPID

# Do not set any timeout value, so that systemd will not kill postmaster
# during crash recovery.

  • the systemd service can vary per distro. Can you include it in your question with systemctl cat postgresql-10.service? It may have some hints on how they interact. Does journalctl -u postgresql-10 show any hints? How about systemctl status postgresql-10?
    – danblack
    Mar 2, 2020 at 2:59
  • @danblack I added postgresql-10 service's content to the question. I stoped its service by pg_ctl stop and systemctl start PostgreSQL-10, it can start.
    – rawmain
    Mar 2, 2020 at 3:14

1 Answer 1


If you start the server manually using 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.

  • Would the sequence of steps to correct a situation where the server was started manually with pg_ctl be: stop the server with pg_ctl, start the server with systemctl?
    – dw8547
    Mar 2, 2020 at 8:34
  • 2
    Yes, that's what I would recommend. Mar 2, 2020 at 8:39
  • A very good practice!
    – rawmain
    Mar 2, 2020 at 11:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.