ruby - PG错误无法连接到服务器: Connection refused Is the server running on port 5432?

标签 ruby macos postgresql ruby-on-rails-4

我最近更新了我的机器(运行 Mountain Lion 的 MacBook Pro),从那时起,每当我设置一个 Rails 项目时,我的机器就会崩溃并且无法连接到 PG。目前,这是我尝试访问本地主机时遇到的错误;

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?

这是一个 list ,以及我尝试过的事情的 list ;

  1. PostgreSQL 版本为 9.3.4
  2. 我通过 HomeBrew 安装了它
  3. 我的 database.yml 文件中有 host: localhost
  4. Rails 版本 4.1.1,ruby 2.0.0p247(2013-06-27 修订版 41674)[x86_64-darwin12.5.0]
  5. 运行 brew uninstall postgresql 然后 brew install postgresql
  6. 试图访问我的 postgres.conf 文件,但不允许通过 PGAdmin 和命令行访问
  7. 运行 locate pg_hba.conf 并且终端将其输出;

    WARNING: The locate database (/var/db/locate.database) does not exist.
    
  8. 我也尝试过使用 rails 4.0,但我仍然遇到问题

  9. 我仍然可以在我的计算机上处​​理在我更新计算机之前启动/完成的其他项目。

  10. 当我从终端运行 psql 时,我得到 psql:无法连接到服务器:没有那个文件或目录 服务器是否在本地运行并接受 Unix 域套接字“/tmp/.s.PGSQL.5432”上的连接?

我真的迷失在这里,不知道还能做什么。任何帮助将不胜感激。

更新:

感谢this问题,只需下载适用于 Mac 的 Postgres.app 即可解决所有问题。现在一切正常。

最佳答案

在命令行中运行

postgres -D /usr/local/var/postgres

如果结果和下一个一样

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.

运行

brew postgresql-upgrade-database

基于此post

关于ruby - PG错误无法连接到服务器: Connection refused Is the server running on port 5432?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24333317/

相关文章:

objective-c - 如何将 STDOUT 重定向到 NSTextView?

macos - macOS 中/usr/local/lib/dtrace 目录的意义是什么?

postgresql - 在数据库管理中使用 View 而不是表是一种好的编程习惯吗

ruby - 错误 : Error installing ffi: ERROR: Failed to build gem native extension

ruby-on-rails - Ruby on Rails : allow the user to enter a new information, 或单击下拉菜单选择现有信息

objective-c - 增强 Cocoa(和/或 Carbon)中的 OS X 保存对话框

sql - Postgresql 单引号转义

postgresql - 在 PostgreSQL 中存储不区分大小写的 varchar

ruby - Sinatra:运行 rspec 测试时记录噪音

jquery - Rack 抛出 EOFError(错误的内容正文)