ruby-on-rails - 升级到 OSX Mavericks 后修复 postgresql

标签 ruby-on-rails ruby macos postgresql osx-mavericks

最近升级到 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 中设置 host: 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 安装,因为 Mavericks 将添加新版本的 postgres。我如何找到它所在的位置?它很可能是用自制软件安装的,但我不确定。

最佳答案

如果你是通过自制软件安装的,试试这个(来自 brew info postgresql )

launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

这将重新加载它。 Postgress.app 我默认不会找到你的数据库(你需要将它指向 PGDATA 目录,并且你可能会遇到版本冲突(如果你运行 9.2 而 postgress.app 是 9.3,转储/restore 将是按顺序。

从评论中提取。

好的,看来您已经安装了 9.2.3,我会这样做。

postgres -D /usr/local/var/postgres 

然后将它们全部备份。 pg_dumpall > ~/mydatabases.dump

杀死 postgres

一个brew reinstall postgresql , 但警告这将使您从 9.2.39.3.1 .然后重新导入所有数据库 psql < mydatabaes.dump .确保按照 launchctl 内容的卸载/加载说明进行操作,到那时你应该会很好。您还可以考虑使用 postgress.app 并将您的数据库导入该应用程序,但无论如何您都需要备份/转储数据库。

关于ruby-on-rails - 升级到 OSX Mavericks 后修复 postgresql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19565708/

相关文章:

objective-c - 向使用 BWToolkit 的 App Store 提交应用程序

ruby-on-rails - 渲染json并返回

ruby-on-rails - Dashing 仪表板和 batman.js 绑定(bind)

ruby - 如何在案例中使用 "break"...而在 Ruby 中

linux - 涉及当前系统时间的 bash 别名

objective-c - 我的应用程序的 [NSHTTPCookieStorage setCookie] 破坏了浏览器的 cookie?

ruby-on-rails - bundle 安装返回 "Could not locate Gemfile"

ruby-on-rails - 如何使用 Gmail Api 获取邮件列表?

ruby - 数组中的符号 (Ruby)

ruby - 如何在 rspec 中 stub rand?