How to restart PostgreSQL server under CentOS 7
-
11-10-2020 - |
Question
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.
Solution
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
OTHER TIPS
If you have sudogoer as a role in postgresql, you can alternatively use:
sudo systemctl restart postgresql
$ 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.
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.
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
Make sure /sbin
is part of your path if running the service
and systemctl
commands.