1

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?

ogirginc
  • 4,948
  • 3
  • 31
  • 45

1 Answers1

3

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.

ogirginc
  • 4,948
  • 3
  • 31
  • 45
  • 1
    Another (better) option to solve `icu4c` issue: https://stackoverflow.com/a/56418438/534943 – Styx Jun 29 '19 at 08:53
  • @Styx if you were able to switch to `61.2` version, that was because you already had it. Unfortunately, reinstalling with xarging only installs the latest version, not the dependent one. (To see it yourself, use `brew cleanup` before reinstalling. You should get the "Error: icu4c does not have a version `61.2` in the Cellar. icu4c installed versions: `64.2`" error.) – ogirginc Jun 29 '19 at 12:01