10

I recently updated my machine (MacBook Pro running Mountain Lion) and ever since then, whenever I set up a rails project, my machine craps out and cannot connect to PG. Currently, this is the error I am getting when I try to go to localhost;

PG::ERROR could not connect to server: Connection refused Is the server running on host "localhost"
(::1) and accepting TCP/IP connections on port 5432? could not connect to server: Connection
refused Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432? could not connect to server: Connection refused Is the server running on host "localhost" (fe80::1) and accepting TCP/IP connections on port 5432?

Here is a checklist, and list of things I have tried;

  1. PostgreSQL version is 9.3.4
  2. I have it installed through HomeBrew
  3. I have host: localhost in my database.yml file
  4. Rails version 4.1.1, ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.5.0]
  5. Ran brew uninstall postgresql then brew install postgresql
  6. Tried to access my postgres.conf file but wasn't allowed through PGAdmin and command line
  7. Ran locate pg_hba.conf and terminal shot this out;

    WARNING: The locate database (/var/db/locate.database) does not exist.
    
  8. I have also tried using rails 4.0 but I still get the problem

  9. I can still work on other projects on my machine that were started/finished before I updated my computer.

  10. When I run psql from my terminal I get 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"?

I am really lost here, and am not sure what else to do. Any help would be much appreciated.

UPDATE:

Thanks to this question, all was resolved by simply downloading Postgres.app for Mac. Everything works great now.

Community
  • 1
  • 1
user3749994
  • 315
  • 2
  • 8
  • 18

2 Answers2

22

This is quite easy than your think because If you update your mac then process is running but postmaster.pid file is missing from /usr/local/var/postgres/ here. so you need to start process for postgres which create postmaster.pid.

If progress is running then -

Stop manually:

pg_ctl -D /usr/local/var/postgres stop -s -m fast

Start manually:

pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start

now all are working...

maja
  • 14,242
  • 14
  • 72
  • 106
Nikhil Thombare
  • 872
  • 1
  • 8
  • 24
13

Run in your command line

postgres -D /usr/local/var/postgres

If the result is like the next one

LOG:  skipping missing configuration file "/usr/local/var/postgres/postgresql.auto.conf"
FATAL:  database files are incompatible with server
DETAIL:  The data directory was initialized by PostgreSQL version 10, which is not compatible with this version 11.

Run

brew postgresql-upgrade-database

Based in this post

Evelin Ponce
  • 826
  • 1
  • 9
  • 25
  • Thank you for this. Hit the same issue after I installed an unrelated package. Homebrew updated PG and DB files became incompatible. – Jan Klimo Oct 20 '20 at 06:19