【发布时间】:2013-11-03 03:31:59
【问题描述】:
最近升级到 OSX Mavericks 后,我的 Rails 应用程序的数据库连接中断。
当我尝试从数据库中获取时,服务器返回以下错误:
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?
could not connect to server: Connection refused
Is the server running on host "localhost" (fe80::1) and accepting
TCP/IP connections on port 5432?
当尝试运行 psql 我得到:
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"?
我已经尝试了互联网上提供的许多解决方案。这样重新安装 pg gem 并在我的 database.yml 中设置主机:localhost。我的 /usr/local/var/postgres/pg_hba.conf 文件说:
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication RyanKing trust
#host replication RyanKing 127.0.0.1/32 trust
#host replication RyanKing ::1/128 trust
哪个 psql 返回:/usr/local/bin/psql
这个有什么解决办法吗?一些解决方案建议我需要将我的 $PATH 更改为我以前的 postgres 安装,因为新版本的 postgres 将与 Mavericks 一起添加。我如何找到它的位置?很有可能它是用自制软件安装的,但我不确定。
【问题讨论】:
-
你是如何在 localhost 上安装 postgresql 的?它似乎没有运行,(
netstat -na | grep 5432检查它是否在监听。但是知道你是如何安装它的将有助于弄清楚如何让它重新启动。 -
netstat -na | grep 5432不返回任何内容。我不记得我是如何安装它的。可能是自制的。 -
PostgreSQL 应该是 Apple 最近在 Mac OS 上安装的。您可能正在搭载该安装,如果安装操作系统升级破坏了它,这似乎很可能。如果您自己安装,它应该不会损坏。
标签: ruby-on-rails ruby macos postgresql osx-mavericks