Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mac OSX Lion Postgres does not accept connections on /tmp/.s.PGSQL.5432

I'm getting a common Mac OSX error for Homebrew installations of Postgres,

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

This is apparently due to there being multiple installs on the system. However, the usual steps are not resolving things.

I can successfully start Postgres and running:

ps auxw | grep post

returns ..

euanmillar       847   0.0  0.0  2432768    588 s000  R+   11:19am   0:00.00 grep postgres
euanmillar       845   0.0  0.0  2439324    448   ??  Ss   11:19am   0:00.00 postgres:
stats collector process
euanmillar       844   0.0  0.0  2443176   1520   ??  Ss   11:19am   0:00.00 postgres:
autovacuum launcher process
euanmillar       843   0.0  0.0  2443044    544   ??  Ss   11:19am   0:00.00 postgres: wal writer process
euanmillar       842   0.0  0.0  2443044    584   ??  Ss   11:19am   0:00.00 postgres: writer process
euanmillar       841   0.0  0.0  2443044    596   ??  Ss   11:19am   0:00.00 postgres: checkpointer process
euanmillar       839   0.0  0.0  2443044   3616 s000  S    11:19am   0:00.02 /us

so it looks like postgres is running.

I have commented in the following lines in postgresql.conf

port = 5432
unix_socket_directory = '/var/pgsql_socket'
unix_socket_permissions = 0777

and in var/pgsql_socket/ I do have a hidden file .s.PGSQL.5432

I have tried solutions to many of the posts here. This one especially seems similar:

https://dba.stackexchange.com/questions/21587/postgresql-is-running-locally-but-i-cannot-connect-why

But the difference is that I do have a '/var/pgsql_socket' directory which is CHOWN-ed to everyone. I have used Homebrew to completely remove and re-install Postgres and still I have the same issue.

like image 625
Euan Millar Avatar asked Jun 21 '13 16:06

Euan Millar


People also ask

How do I run PostgreSQL port 5432?

How do I connect to postgres port 5432? If you are trying to connect to a Postgres instance on the same host as your terminal, you can run lsof -p :5432 which will show which, if any, processes are listening on that port. The postgres process should be connected there.

What port is Postgres running on Mac?

This will start up a postgres server hosted locally on port 5432. The server will be run out of the directory /usr/local/var/postgres . This will connect to the server and access the postgres database.

Can't connect to Postgres server?

“Could not connect to server: Connection refused” To be sure that PostgreSQL is running, you can also restart it with systemctl restart postgresql. If this does not fix the problem, the most likely cause of this error is that PostgreSQL is not configured to allow TCP/IP connections.


3 Answers

You need to remove the postmaster.pid, which should be in the following path: /usr/local/var/postgres/postmaster.pid

like image 182
Iman Avatar answered Nov 09 '22 21:11

Iman


A simpler solution is to locate where the socket actually is vs where it's expected to be. In my case, I ran:

$ locate PGSQL.5432
/private/var/pgsql_socket/.s.PGSQL.5432
/private/var/pgsql_socket/.s.PGSQL.5432.lock

Then just symlink the expected socket location to the actual socket location.

$ ln -s /private/var/pgsql_socket/.s.PGSQL.5432 /tmp/.s.PGSQL.5432
like image 29
Matt Dressel Avatar answered Nov 09 '22 22:11

Matt Dressel


For me, i removed postmaster.pid in /usr/local/var/postgres. fixed me right up.

like image 26
courtsimas Avatar answered Nov 09 '22 22:11

courtsimas