29

Running postgreSQL 9.4.5_2 currently

I have tried

pg_ctl stop -W -t 1 -s -D /usr/local/var/postgres -m f

Normally no news is good news but after I will run

pg_ctl status -D /usr/local/var/postgres 

and get pg_ctl: server is running (PID: 536)

I have also tried

pg_ctl restart -w -D /usr/local/var/postgres -c -m i

Response message is:

waiting for server to shut down.......................... failed
pg_ctl: server does not shut down

I've also checked my /Library/LaunchDaemons/ to see why the service is starting at login but no luck so far. Anyone have any ideas on where I should check next? Force quit in the activity monitor also isn't helping me any.

Andre Figueiredo
  • 12,930
  • 8
  • 48
  • 74
Andrew M
  • 1,083
  • 2
  • 12
  • 15

9 Answers9

37

Sadly none of the previous answers help me, it worked for me with:

brew services stop postgresql

Cheers

lgargantini
  • 519
  • 4
  • 5
21

Restart it with

sudo -u postgres pg_ctl -D /Library/PostgreSQL/11/data stop
Ben Butterworth
  • 22,056
  • 10
  • 114
  • 167
Rajeev
  • 339
  • 2
  • 12
  • 8
    This is great, but one note - your command assumes you are in the same directory as the `pg_ctl` binary. Usually whatever install process you went through to get Postgres onto your machine puts that binary on a directory in your path. So what probably works more universally is `sudo -u postgres pg_ctl -D /Library/PostgreSQL/11/data stop` – Yu Chen Feb 15 '20 at 02:00
  • 3
    Good solution. But not `./pg_ctl`. Please use `pg_ctl`. – Allen Haley Feb 26 '20 at 14:24
  • 2
    It doesn't work if your path is on a user directory (e.g. in `~/` because of permission issues. Run `cd /` to avoid file permissions issues when you switch the postgres user, which doesn't have access to your user home directory. – Ben Butterworth Mar 07 '23 at 15:09
18

Tried sudo and su but no such luck. Just found this gui

https://github.com/MaccaTech/postgresql-mac-preferences

If anyone can help with the terminal commands that would be very much appreciated, but till then the gui will get the job done.

Andrew M
  • 1,083
  • 2
  • 12
  • 15
13

Had the same issue, I had installed postgres locally and wanted to wrap in a docker container instead.

I solved it pretty radically by 1) uninstalling postgres 2) kill the leftover process on postgres port. If you don't un-install the process restarts and grabs the port again - look at your Brewfile form brew bundle dump to check for a restart_service: true flag.

I reasoned that, as I am using containers, I should not need the local one anyway, but !! attention this will remove postgres from your system.

brew uninstall postgres
...
lsof -i :5432 # this to find the PID for the process
kill - 9 <the PID you found at previous command> 

Note: if you still want to used psql you can brew install libpq, and add psql to your PATH (the command output shows you what to add to your .zshrc, or similar)

Andrea C
  • 329
  • 4
  • 6
8

you can stop the server using this command

{pg_ctl -D /usr/local/var/postgres stop -s -m fast}
Andre Figueiredo
  • 12,930
  • 8
  • 48
  • 74
jrad
  • 111
  • 1
  • 3
2

Adding onto the solutions already stated :

if you decide to use the pg_ctl command, ensure that you are executing the command as a user with the permissions to access the databases/database server.

this means :

  • the current logged in user on your terminal should have those permissions

or

  • first run :
$ sudo su <name_of_database_user>

pg_ctl -D /Library/PostgreSQL/<version_here>/data/ stop

the same goes for the start command.

credit : https://gist.github.com/kingbin/9435292 (essentially hosted a file with the commands on github, saved me some time :^) )

Sir_A.D
  • 21
  • 4
2

I had a stray docker container running Postgres that I had forgotten about.

BWStearns
  • 2,567
  • 2
  • 19
  • 33
2

Another possible scenario is when you installed PostgreSQL via UI, the command to find the process is:

netstat -vanp tcp | grep 5432

Then you kill the PID

kill -9 PID_FROM_netstat
Cesar Celis
  • 166
  • 1
  • 4
  • 8
1

I just installed Postgres 15 on OS X Ventura and also could not figure out how to stop it. The following worked:

sudo -u postgres /Library/PostgreSQL/15/bin/pg_ctl -D /Library/PostgreSQL/15/data stop
Greg S
  • 466
  • 3
  • 5