我最近更新了我的机器(运行 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 ;
- PostgreSQL 版本为 9.3.4
- 我通过 HomeBrew 安装了它
- 我的 database.yml 文件中有
host: localhost
- Rails 版本 4.1.1,ruby 2.0.0p247(2013-06-27 修订版 41674)[x86_64-darwin12.5.0]
- 运行
brew uninstall postgresql
然后brew install postgresql
- 试图访问我的 postgres.conf 文件,但不允许通过 PGAdmin 和命令行访问
运行
locate pg_hba.conf
并且终端将其输出;WARNING: The locate database (/var/db/locate.database) does not exist.
我也尝试过使用 rails 4.0,但我仍然遇到问题
我仍然可以在我的计算机上处理在我更新计算机之前启动/完成的其他项目。
当我从终端运行
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/