Steven Aguilar
Steven Aguilar

Reputation: 3057

Postgresql version 13 psql: error: could not connect to server: could not connect to server: No such file or directory

I'm currently working with a Rails 6 application and Postgresql. I been having issues when I run rails db:create. This error seem to happen after I updated brew upgrade I get the following error:

rails aborted!
PG::ConnectionBad: 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?

I'm running Mac OS Mojave and I updated postgresq to version 13.

$ postgres --version
postgres (PostgreSQL) 13.0

I'm guessing this is why I have issues, I noticed in some of the other posts that running brew postgresql-upgrade-database might be a FIX to this problem, however when I run the command I get:

$ brew postgresql-upgrade-database
Error: No such file or directory @ rb_sysopen - /usr/local/var/postgres/PG_VERSION

But I can see the .old file when I navigate to postgres as shown in the image below: enter image description here

Also, if I tried connecting to psql I get an error

$ psql
psql: error: could not connect to server: 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 also see that the service is running:

$ ps -ef | grep postgres
  501 48733  5971   0  1:23PM ttys011    0:00.31 /usr/local/Cellar/macvim/8.2-166_1/MacVim.app/Contents/MacOS/Vim /usr/local/var/postgres/
  501 52975  5971   0  1:54PM ttys011    0:00.01 grep postgres

What can the issue be?

Upvotes: 3

Views: 3646

Answers (1)

Steven Aguilar
Steven Aguilar

Reputation: 3057

this fixed it for me

initdb `brew --prefix`/var/postgres/data -E utf8

and then running

pg_ctl -D /usr/local/var/postgres/data -l logfile start

Follow PostgreSQL with Homebrew on Mac for more detail

Upvotes: 3

Related Questions