Dreaded "psql: could not connect to server: No such file" error with Homebrew/OSX

Viewed 2180

I've just restarted OSX (Sierra 10.12.6) and when I try to run psql (which previously worked fine) I get the dreaded:

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

Trying brew services restart postgresql does not help, and brew services start postgresql claims the service is already running.

Yet ps auxw | grep postgres reveals no Postgres processes are running. Has Homebrew got confused?

which psql shows /usr/local/bin/psql.

Here's what I've tried...

psql -h localhost makes no difference.

I've run brew uninstall --force postgresql followed by brew install postgresql, which makes no difference. I've also tried doing the same after a brew doctor and brew update, which again makes no difference.

I've seen advice to delete the postmaster.pid file, but there is no such file in /usr/local/var/postgres/. There also doesn't appear to be a server.log file in that directory.

Running locate PGSQL.5432 shows no files.

I am the owner of the /usr/local/var/postgres directory, with drwxr-xr-x permissions.

It's possible I might have installed KyngChaos postgres at some point in the past.

I've checked the .plist file indicated in the output of brew services list (~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist), it shows the following:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>KeepAlive</key>
  <true/>
  <key>Label</key>
  <string>homebrew.mxcl.postgresql</string>
  <key>ProgramArguments</key>
  <array>
    <string>/usr/local/opt/postgresql/bin/postgres</string>
    <string>-D</string>
    <string>/usr/local/var/postgres</string>
  </array>
  <key>RunAtLoad</key>
  <true/>
  <key>WorkingDirectory</key>
  <string>/usr/local</string>
  <key>StandardErrorPath</key>
  <string>/usr/local/var/log/postgres.log</string>
</dict>
</plist>

I'm very keen not to have to delete all my postgres databases if possible, because I'm currently in a remote location with nowhere to back them up!

0 Answers
Related