How to start and stop PostgreSQL server?

1. On MacOS:

If you installed PostgreSQL via Homebrew:

  • To start manually: pg_ctl -D /usr/local/var/postgres start
  • To stop manually: pg_ctl -D /usr/local/var/postgres stop
  • To start PostgreSQL server now and relaunch at login:
    brew services start postgresql
  • And stop PostgreSQL: brew services stop postgresql

2. On Windows:

First, you need to find the PostgreSQL database directory, it can be something like C:\Program Files\PostgreSQL\10.4\data. Then open Command Prompt and execute this command:

  • To start the server: pg_ctl -D "C:\Program Files\PostgreSQL\9.6\data" start
  • To stop the server: pg_ctl -D "C:\Program Files\PostgreSQL\9.6\data" stop
  • To restart the server: pg_ctl -D "C:\Program Files\PostgreSQL\9.6\data" restart

3. On Linux:

  • Start the PostgreSQL server: sudo service postgresql start
  • Stop the PostgreSQL server: sudo service postgresql stop

Link reference:

https://tableplus.com/blog/2018/10/how-to-start-stop-restart-postgresql-server.html