【问题标题】:Postgresql version 13 psql: error: could not connect to server: could not connect to server: No such file or directoryPostgresql 版本 13 psql:错误:无法连接到服务器:无法连接到服务器:没有这样的文件或目录
【发布时间】:2020-10-31 17:51:36
【问题描述】:

我目前正在使用 Rails 6 应用程序和 Postgresql。我在运行rails db:create 时遇到了问题。这个错误似乎在我更新brew upgrade 后发生了我收到以下错误:

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?

我正在运行 Mac OS Mojave,并将 postgresq 更新到版本 13。

$ postgres --version
postgres (PostgreSQL) 13.0

我猜这就是我遇到问题的原因,我注意到在其他一些帖子中运行 brew postgresql-upgrade-database 可能是解决此问题的方法,但是当我运行命令时,我得到:

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

但是当我导航到postgres 时,我可以看到.old 文件,如下图所示:

另外,如果我尝试连接到psql,我会收到一个错误

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

我还看到服务正在运行:

$ 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

可能是什么问题?

【问题讨论】:

  • 你试过重启吗?听起来它只是不听。试试这个:telnet localhost 5432。如果它失败了,它肯定没有在那个端口上运行。另外,检查/var/log/postgres 是否有任何错误。无论如何,值得先尝试重新启动。
  • Trying ::1... telnet: connect to address ::1: Connection refused Trying 127.0.0.1... telnet: connect to address 127.0.0.1: Connection refused telnet: Unable to connect to remote host

标签: ruby-on-rails postgresql macos-mojave


【解决方案1】:

这已经帮我解决了

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

然后运行

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

关注PostgreSQL with Homebrew on Mac了解更多详情

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-08
    • 2018-01-14
    • 2017-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-17
    相关资源
    最近更新 更多