158

I have PostgreSQL 9.3 and 9.4 installed on my Linux Mint machine.

How can I restart PostgreSQL 9.4?

A method to restart both versions together is also fine.

catch23
  • 17,519
  • 42
  • 144
  • 217
Tony Joseph
  • 1,802
  • 2
  • 14
  • 17
  • Have you searched the web? http://www.codeproject.com/Articles/898303/Installing-and-Configuring-PostgreSQL-on-Linux-Min – kometen Jan 21 '16 at 07:49
  • I suggest migrating your data to 9.4 and remove the 9.3 installation afterwards. – Jan Henke Jan 21 '16 at 07:49
  • 1
    @kometen The referenced article doesn't provide a way to selectively start and stop each and every single instance. – EnzoR Jan 21 '16 at 09:44
  • @JanHenke I wouldn't suggest anything outside the scope of the question. Anyway, v9.5 is the current stable version. – EnzoR Jan 21 '16 at 09:45
  • @Enzo He said he has both version running in parallel. So I just suggested migrating to the newer of the two, which would also fix the problem, as there would be only one postgresql left. – Jan Henke Jan 21 '16 at 15:01
  • I also have 2 versions (used to be 3) in order to be able to support 2 different setups. – EnzoR Jan 21 '16 at 16:02
  • `systemctl restart postgresql` worked for me: it restarted _both_ of my installed running versions. – John1024 Feb 02 '20 at 20:44
  • This answer solves the problem in latest versions https://stackoverflow.com/a/67754783/5084088 – Jenison Gracious May 29 '21 at 19:05

8 Answers8

237

Try this as root (maybe you can use sudo or su):

/etc/init.d/postgresql restart

Without any argument the script also gives you a hint on how to restart a specific version

[Uqbar@Feynman ~] /etc/init.d/postgresql
Usage: /etc/init.d/postgresql {start|stop|restart|reload|force-reload|status} [version ...]

Similarly, in case you have it, you can also use the service tool:

[Uqbar@Feynman ~] service postgresql
Usage: /etc/init.d/postgresql {start|stop|restart|reload|force reload|status} [version ...]

Please, pay attention to the optional [version ...] trailing argument. That's meant to allow you, the user, to act on a specific version, in case you were running multiple ones. So you can restart version X while keeping version Y and Z untouched and running.

Finally, in case you are running systemd, then you can use systemctl like this:

[Uqbar@Feynman ~] systemctl status postgresql
● postgresql.service - PostgreSQL database server
   Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2017-11-14 12:33:35 CET; 7min ago
...

You can replace status with stop, start or restart as well as other actions. Please refer to the documentation for full details. In order to operate on multiple concurrent versions, the syntax is slightly different. For example to stop v12 and reload v13 you can run:

systemctl stop postgresql-12.service
systemctl reload postgresql-13.service

Thanks to @Jojo for pointing me to this very one. Finally Keep in mind that root permissions may be needed for non-informative tasks as in the other cases seen earlier.

EnzoR
  • 3,107
  • 2
  • 22
  • 25
67

You can also restart postgresql by using this command, should work on both the versions:

sudo service postgresql restart
Martin Zeitler
  • 1
  • 19
  • 155
  • 216
Aditi Gupta
  • 876
  • 7
  • 5
  • For me, if already running, this doesn't appear to do anything. (doing "restart" instead of start in there does appear to work) – omgponies Aug 11 '20 at 03:40
25

On Windows :

1-Open Run Window by Winkey + R

2-Type services.msc

3-Search Postgres service based on version installed.

4-Click stop, start or restart the service option.

On Linux :

sudo systemctl restart postgresql

also instead of "restart" you can replace : stop or status.

Sobhan
  • 1,280
  • 1
  • 18
  • 31
  • OP says "I have Postgresql 9.3 and 9.4 installed on my Linux Mint machine."... Linux ... Now Windows! – EnzoR Oct 25 '21 at 11:55
  • @EnzoR my answer covers both Linux and Windows!!! is it wrong?? maybe someone need it :) do not take it hard dude – Sobhan Oct 25 '21 at 11:58
  • Not taking it hard. I The OP is about Linux and about 2 versions at the same time. Your answer is about Windows and Linux and only one default version. I simply say your answer is not hitting the spot. – EnzoR Oct 26 '21 at 12:54
8

This should work:

sudo systemctl stop postgresql

sudo systemctl start postgresql

Shailesh
  • 2,116
  • 4
  • 28
  • 48
3

The right way to restart postgres server is to use

pg_ctl restart -D /home/postgres/postgresdbdata/

pg_ctl is usually found in location usr/local/pgsql/bin/pg_ctl if u dont have it added to your path.

Documentation can be found here https://www.postgresql.org/docs/13/app-pg-ctl.html This has more details on Start,Stop,Restart,etc of the postgres server.

Jenison Gracious
  • 486
  • 4
  • 13
1

You can firstly check for the postgress process running

ps -ef | grep post

You might need to use (post|pg) on the grep side, to discover the process for the Postgres service running on your machine, it might depend on your OS.

And you can just kill the child process since most of this process should restart automatically.

sudo kill $pid_of_the_child_process
Aecio Levy
  • 149
  • 1
  • 8
0

macOS:

  1. On the top left of the MacOS menu bar you have the Postgres Icon
  2. Click on it this opens a drop down menu
  3. Click on Stop -> than click on start
sogu
  • 2,738
  • 5
  • 31
  • 90
  • On macOS you have a top menu bar that generally stores that clock, search icon,... and some running mini apps that you can open up. And there you can see the elephant icon as well for postgres. – sogu Oct 19 '20 at 11:00
  • I use macOS Mojave 10.14.6 and the top menu doesn't show such an icon. But my database manager shows the Postgres server is active. – Agent47 Oct 19 '20 at 11:10
  • OP says "I have Postgresql 9.3 and 9.4 installed on my Linux Mint machine."... Linux ... Now macOS! – EnzoR Oct 25 '21 at 11:56
0

With below shown steps I managed to restart Postgres server which located at /database/pgsql directory and initially was started by another user

  • find out the owner of the postgres directory.
    ls -l /database/pgsql
    in my case owner was postgres user.

  • set Postgres data directory path, otherwise restart gives error about missing data directory path
    export PGDATA='/database/pgsql/data'

  • restart Postgres server with the following command.
    sudo -u postgres -E /database/pgsql/bin/pg_ctl restart
    -u runs command as postgres user -E includes current user environment variables so PGDATA variable value is visible to the command. to run command sudo permission needed.

Namig Hajiyev
  • 1,117
  • 15
  • 16