Postgres.app Could not start on port 5432

Viewed 127340

I'm using http://postgresapp.com. In the menubar it gives the error " Could not start on port 5432." Similarly if I try to start the server from the terminal, I get:

psql: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

I also ran pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start and got the output server starting but still get the same errors when connecting to psql.

26 Answers

If you are running your server on a macOS machine and installed Postgres through Homebrew, you can stop the current instance like this:

brew services stop postgresql

Then click the Elephant in the native menu-bar at the top of the screen and it should successfully startup.

If you've installed Postgres via another method (for example, from www.postgresql.org) and it's starting automatically at startup, you can prevent that Postgres from starting via the following:

sudo launchctl unload /Library/LaunchDaemons/com.edb.launchd.postgresql-X.X.plist  
sudo rm -f /Library/LaunchDaemons/com.edb.launchd.postgresql-X.X.plist  

TIP: use tab to autocomplete after the com.edb.launchd part to figure out what version is loading.

Restart Postgres.app and you should be good to go.

(from http://forums.enterprisedb.com/posts/list/1831.page;jsessionid=70621DC48C99EDE663A6A594B05F1A02#6782)

This command is a one-liner that instantly kills all PostgresSQL processes.

sudo kill -kill $(sudo lsof -t -i :5432)

This fixed all my problems on Mac OSX Mojave 10.14.1.

I generally face this issue on my mac, and this fixes it for me always

rm /usr/local/var/postgres/postmaster.pid
brew services restart postgresql

Hope this is helpful

For those using mac, this code worked for me like charm.

sudo pkill -u postgres

Netstat, ps aux, etc ... none showed 5432 in use. Checked /Library. Found PG9.6 old install still there. Did rm -rf and bang. Version 11 works fine.

I was losing my mind over this problem! i kept running

lsof -i | grep 5432

and nothing was showing up! finally i ran it using sudo and a potgres client showed up. so if anyone else has tried the lsof and went nowhere, try it with sudo.

sudo lsof -i | grep 5432

and then

sudo kill <the_pid_from_postgresql_found_from_lsof>

I had this same issue and mine was caused by some configuration issues I was having. Clearing the user configurations and reinstalling postgres in brew worked for me!

brew uninstall postgresql
rm -rf /usr/local/var/postgres

Related