Reputation: 5270
I have previously installed Postgresql on Mac with Homebrew.
When I try to access database, keep getting the error below:
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"?
Is there a way to get a better error message compared to the one I am getting from psql
?
Upvotes: 1
Views: 1977
Reputation: 5270
Yes.
Unfortunately, when a Homebrew service starts, it can fail silently without you realising.
To confirm this is your case too, run:
brew services list
You should see PostgreSQL's status as started
. However, the colour is yellow, not green (can be a bit hard to see depending on your colour scheme).
Yellow means; the actual status is unknown
not started
!
To make a meaning out of the unknown
status, use pg_ctl
to start PostgreSQL server:
# For Intel
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
# For M1:
pg_ctl -D /opt/homebrew/var/postgresql@11 start
This command should output the real issue:
dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.63.dylib
Referenced from: /usr/local/Cellar/postgresql/10.6_1/bin/postgres
Reason: image not found
no data was returned by command ""/usr/local/Cellar/postgresql/10.6_1/bin/postgres" -V"
The program "postgres" is needed by pg_ctl but was not found in the
same directory as "/usr/local/Cellar/postgresql/10.6_1/bin/pg_ctl".
Check your installation.
For the example above, the problem was icu4c
lib's version.
Upvotes: 3