PG ConnectionBad (could not connect to server No such file or directory)

 3 years ago
source link: https://fuzzyblog.io/blog/postgres/2020/04/08/pg-connectionbad-could-not-connect-to-server-no-such-file-or-directory.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

PG ConnectionBad (could not connect to server No such file or directory)

Apr 8, 2020


I've recently had the situation where my personal development box (OSX Mojave, Rails, Postgres) has become unstable with, at times, multiple crashes per day. I logged in this morning and found myself getting errors like this:

PG::ConnectionBad (could not connect to server: No such file or directory)

I did some digging and even though Postgres appeared to be running to brew, it was a false positive due to a leftover postmaster.pd file. Here was the fix:

  1. First make sure that postgres isn't running use ps i.e. **ps auwwx grep post**.
  2. Delete the file: /usr/local/var/postgres/postmaster.pid i.e. rm /usr/local/var/postgres/postmaster.pid
  3. At this point brew will, foolishly and oddly, still think Postgres is running so do do a brew restart postgres

Here's a handy Stack Overflow reference.

Note: Make absolutely sure that postgres is NOT running before you delete postmaster.pid or you risk serious database corruption / data loss.

Posted In: #postgres

About Joyk

Aggregate valuable and interesting links.
Joyk means Joy of geeK