3

Steps to recreate error:

  • brew uninstall postgresql
  • brew prune
  • brew install postgresql
  • run postgresql start commands
  • psql

yields:

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

Suggested fixes I have tried that don't work:

create missing symbolic link:

  • sudo mkdir /var/pgsql_socket/
  • sudo ln -s /private/tmp/.s.PGSQL.5432 /var/pgsql_socket/

remove postmaster.pid file (same link as above):

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

create potentially "cleaned up" directories from upgrade:

  • mkdir -p /usr/local/var/postgres/{pg_tblspc,pg_twophase,pg_stat_tmp}/ touch /usr/local/var/postgres/{pg_tblspc,pg_twophase,pg_stat_tmp}/.keep

Related GitHub issue

Edit 1:

This article correctly speculates that there are multiple versions of postgres in use, and which pg_ctl must be specified (below). Strangely, there are two directories in /usr/local/var: postgre & postgres. If anybody knows which settings to update to use the proper pg_ctl command directly, I would appreciate it!

/usr/local/Cellar/postgresql/9.3.5_1/bin/pg_ctl -D /usr/local/var/postgre start

Community
  • 1
  • 1
b_archer
  • 317
  • 3
  • 11
  • I'm getting similar issues in Yosemite, but reading through your description I suspect when you ran the start commands you neglected to copy the last character of a command ending in postgres like `postgres -D /usr/local/var/postgres` and somehow created an extraneous `postgre`. – Strand McCutchen Dec 19 '14 at 23:30
  • this post solution worked for me `https://medium.com/@bitadj/completely-uninstall-and-reinstall-psql-on-osx-551390904b86` – STEEL Sep 25 '18 at 16:29

1 Answers1

8

I ran into the same issue and after looking at the log file I found one directory was missing:

$ tail /usr/local/var/postgres/server.log
FATAL:  could not open directory "pg_tblspc": No such file or directory

Then I did $ mkdir /usr/local/var/postgres/pg_tblspc, restarted PostgreSQL and got:

$ tail /usr/local/var/postgres/server.log
FATAL:  could not open directory "pg_replslot": No such file or directory

After redoing the process may times I eneded up creating the following directories and then successfully started PostgreSQL:

/usr/local/var/postgres/pg_tblspc
/usr/local/var/postgres/pg_replslot
/usr/local/var/postgres/pg_twophase
/usr/local/var/postgres/pg_logical
/usr/local/var/postgres/pg_logical/mappings

I hope this helps.

danypype
  • 443
  • 4
  • 10
  • I had a similar issue on Windows when trying to restore from a raw data backup. Your solution worked for me. – ksl Mar 21 '17 at 11:58
  • Worked for me as well (using Mac OSX Catalina, Homebrew and Postgresql 12.3). There were a few additional folders & files to add but the same idea. – jjkl Jul 09 '20 at 18:21