Skip to content

Instantly share code, notes, and snippets.

@AtulKsol
Last active December 22, 2022 05:10
Show Gist options
  • Save AtulKsol/17a34c3f22a4c13506e75ce1549770c2 to your computer and use it in GitHub Desktop.
Save AtulKsol/17a34c3f22a4c13506e75ce1549770c2 to your computer and use it in GitHub Desktop.
Postgres on OSX with homebrew not running

Postgres on OSX with homebrew not running [tested in mac]

Fix for following issue:

$ psql
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"?

Running postgres might work but not necessarily and can throw following error:

pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
pg_ctl: another server might be running; trying to start server anyway

So here's a quick fix.

  1. Check the log
$ tail -f /usr/local/var/postgres/server.log
FATAL:  lock file "postmaster.pid" already exists
HINT:  Is another postmaster (PID 326) running in data directory "/usr/local/var/postgres"?
FATAL:  lock file "postmaster.pid" already exists
HINT:  Is another postmaster (PID 326) running in data directory "/usr/local/var/postgres"?
  1. Delete the PID file.
$ rm /usr/local/var/postgres/postmaster.pid
  1. Run pg_ctl manually
$ pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
  1. Make sure it's running
$ ps x | grep postgres

This should appear from the output above

8352   ??  S      0:00.02 /usr/local/opt/postgresql/bin/postgres -D /usr/local/var/postgres -r /usr/local/var/postgres/server.log
8354   ??  Ss     0:00.00 postgres: checkpointer process
8355   ??  Ss     0:00.03 postgres: writer process
8356   ??  Ss     0:00.01 postgres: wal writer process
8357   ??  Ss     0:00.00 postgres: autovacuum launcher process
8358   ??  Ss     0:00.00 postgres: stats collector process

Also, this also happens to other processes like mongodb or anything that relies on PID files.

Start Postgres in system StartUp

brew services start postgresql
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist 
@protectroot-com
Copy link

Obrigado! Gracias!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment