/tmp/.s.PGSQL.5432?

/tmp/.s.PGSQL.5432 is the Unix socket.

It is time the year to figure out the answer of:

PG::ConnectionBad: 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"?

Check if Postgres started:

ps aux | grep postgres

I’ve collected all possible answers, try any of these combinations. Good luck!

brew services restart postgresql

This main postgres process exit but did not clear this file so postgres thought it already started, remove this file:

rm /usr/local/var/postgres/postmaster.pid

then brew services restart postgresql.

2019 ✅

Could be there is no default database:

initdb --locale=C -E UTF-8 $HOMEBREW_PREFIX/var/postgres
pg_ctl -D $HOMEBREW_PREFIX/var/postgres -l logfile start

2020 ✅

If you recently brew upgrade then maybe you need this:

brew postgresql-upgrade-database

Article with more details

2020 ✅

Restart your computer.

Try bin/postgres-broke.

2020-06-16 11:36:26.805 [6532] LOG:  database system is ready to accept connections
2020-06-16 11:36:50.010 [6846] WARNING:  SET LOCAL can only be used in transaction blocks
2020-06-16 11:36:50.010 [6846] WARNING:  SET LOCAL can only be used in transaction blocks
dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.64.dylib
  Referenced from: /usr/local/opt/postgresql/bin/postgres
  Reason: image not found
dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.64.dylib
  Referenced from: /usr/local/opt/postgresql/bin/postgres
  Reason: image not found
dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.64.dylib
  Referenced from: /usr/local/opt/postgresql/bin/postgres
  Reason: image not found

Reinstall:

$ brew uninstall --force postgresql
$ brew install postgresql

You recently brew upgrade, PostgreSQL’s dependency icu4c is broken. Try this command:

initdb --locale=C -E UTF-8 $HOMEBREW_PREFIX/postgres

If you get something similar to:

dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.66.dylib
  Referenced from: /usr/local/Cellar/postgresql/12.3/bin/postgres
  Reason: image not found
no data was returned by command ""/usr/local/Cellar/postgresql/12.3/bin/postgres" -V"
initdb: error: The program "postgres" is needed by initdb but was not found in the
same directory as "/usr/local/Cellar/postgresql/12.3/bin/initdb".
Check your installation.

or

dyld[9404]: Library not loaded: /opt/homebrew/opt/icu4c/lib/libicui18n.69.dylib
  Referenced from: /opt/homebrew/Cellar/postgresql/14.1_1/bin/postgres
  Reason: tried: '/opt/homebrew/opt/icu4c/lib/libicui18n.69.dylib' (no such file), '/usr/local/lib/libicui18n.69.dylib' (no such file), '/usr/lib/libicui18n.69.dylib' (no such file), '/opt/homebrew/Cellar/icu4c/70.1/lib/libicui18n.69.dylib' (no such file), '/usr/local/lib/libicui18n.69.dylib' (no such file), '/usr/lib/libicui18n.69.dylib' (no such file)
no data was returned by command ""/opt/homebrew/Cellar/postgresql/14.1_1/bin/postgres" -V"
initdb: error: The program "postgres" is needed by initdb but was not found in the
same directory as "/opt/homebrew/Cellar/postgresql/14.1_1/bin/initdb".
Check your installation.

Reinstall icu4c:

brew reinstall icu4c

$ brew services start postgres
Bootstrap failed: 5: Input/output error
Try re-running the command as root for richer errors.
Error: Failure while executing; `/bin/launchctl bootstrap gui/501 /Library/LaunchAgents/homebrew.mxcl.postgresql.plist` exited with 5.

$ sudo /bin/launchctl bootstrap gui/501 /Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Password:
/Library/LaunchAgents/homebrew.mxcl.postgresql.plist: service already bootstrapped
Bootstrap failed: 37: Operation already in progress

$ brew services restart postgresql
==> Successfully stopped `postgresql` (label: homebrew.mxcl.postgresql)
==> Successfully started `postgresql` (label: homebrew.mxcl.postgresql)