29

I installed PostgreSQL 10.1 under a CentOS 7.3 environment.

The service is started (postmaster.pid file present under /var/lib/pgsql/10/data), but I need to reload configuration or restart the server following a change in pg_hba.conf.

However, trying different commands, I get the following:

pg_ctl reload -D /var/lib/pgsql/10/data
bash: pg_ctl: command not found

service postgresql reload
Redirecting to /bin/systemctl reload postgresql.service
Failed to reload postgresql.service: Unit not found.
Sébastien Clément
  • 1,805
  • 3
  • 18
  • 28

6 Answers6

55

I found out that you need to specify the exact name for the PostgreSQL service, which you can find under the list of services, using systemctl (also see this post):

systemctl list-units|grep postgresql
postgresql-10.service                                                                     loaded active running   PostgreSQL 10 database server

Then you can use service:

service postgresql-10.service reload

or

service postgresql-10.service restart

Alternatively, you can use the systemctl command:

/bin/systemctl reload postgresql-10.service

or

/bin/systemctl restart postgresql-10.service
Sébastien Clément
  • 1,805
  • 3
  • 18
  • 28
7

If you have sudogoer as a role in postgresql, you can alternatively use:

sudo systemctl restart postgresql
usr
  • 187
  • 2
  • 7
  • 2
    This is wrong, the unit is called postgresql-10 – Gaius May 04 '18 at 13:57
  • This is not wrong. It works for me. Also here's further proof: https://linode.com/docs/databases/postgresql/how-to-install-postgresql-relational-databases-on-centos-7/#peer-authentication – usr May 04 '18 at 14:03
  • The .service file can be called anything you want. It's usually located at /usr/lib/systemd/system and can be renamed as you please. If you customize it though, it's recommended to move it to /etc/systemd/system – medley56 Aug 14 '18 at 16:43
1
$ sudo systemctl restart postgresql-10

Or better:

$ /usr/pgsql-10/bin/pg_ctl reload

Or first (one-time):

    $ sudo ln -s /usr/pgsql-10/bin/pg_ctl /usr/bin/pg_ctl

and then (every time):

    $ pg_ctl reload

Note: pg_ctl cannot be run as root.

Mir-Ismaili
  • 131
  • 1
  • 6
0

I don't know how your service file is set up so I can't debug your systemd command. It's possible that it's named something different as Sebastien suggests.

As for pg_ctl, that is a result of the installation not adding the directory to the path. (There are reasons for this mentioned in the comments here). There are a few different ways to solve but I recommend just adding /usr/pgsql-x.x/bin to the path of the postgres user. Just add PATH=$PATH:/usr/pgsql-x.x/bin to the postgres user's .bash_profile and you should be good to go.

medley56
  • 173
  • 8
0

You may also use (PostgresSQL 11 running on MX Linux (Debian 9, Stretch))-

/etc/init.d/postgresql status

/etc/init.d/postgresql stop

/etc/init.d/postgresql restart
usr
  • 187
  • 2
  • 7
Lucky
  • 1
0

Make sure /sbin is part of your path if running the service and systemctl commands.

Laurenz Albe
  • 51,298
  • 4
  • 39
  • 69