50

How to restart PostgreSQL via ssh console?

When i search this thing on SO I only find: postgres, ubuntu how to restart service on startup? get stuck on clustering after instance reboot

Ismail Yavuz
  • 6,727
  • 6
  • 29
  • 50

4 Answers4

128
sudo service postgresql restart
Ismail Yavuz
  • 6,727
  • 6
  • 29
  • 50
12
systemctl restart postgresql@<postgres_version>-<cluster_name>.service

By default cluster_name = 'main', run this command to list all the clusters you have :

ls /var/lib/postgresql/

if you want to know whether the postgresql is running try this command :

systemctl status postgresql@<postgres_version>-<cluster_version>.service
aarona
  • 35,986
  • 41
  • 138
  • 186
aziz aziz
  • 173
  • 8
  • 1
    There seems to be two daemons around `postgresql` and `postgresql@XX-main` any idea or reference to what's the difference? – lowercase00 Mar 29 '22 at 20:35
7

My postgresql service is named postgresql-9.5; in case you get "postgresql: unrecognized service" you can find its name with

sudo service --status-all | grep postgresql

and then proceed as per the accepted answer.

JL_SO
  • 1,742
  • 1
  • 25
  • 38
  • I got this awk: fatal: cannot open file `/etc/mongod.conf' for reading (No such file or directory) – Rajan Verma - Aarvy Dec 24 '19 at 04:50
  • @Aarvy, were you running the command as sudo? There is a reference to mongod.conf in your /etc/init.d/mongod file. Regardless of this you can also run this command to see the name of your postgres service: `ls -lrt /etc/init.d/postgres*` – JL_SO Jan 24 '20 at 15:43
0

The problem is with your remote configuration

sudo nano /etc/postgresql/13/main/postgresql.conf 

Uncomment line 59 and change the Listen address to accept connections within your networks. *

#Listen on all interfaces

listen_addresses = '*'

#Listen on specified private IP address

listen_addresses = '192.168.10.11`