PG错误无法连接到服务器:连接被拒绝服务器是否在端口5432上运行?

时间:2014-06-20 18:14:46

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

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

  

PG :: ERROR无法连接到服务器:连接被拒绝服务器是否在主机“localhost”上运行   (:1)并接受端口5432上的TCP / IP连接?无法连接到服务器:连接
  拒绝服务器是否在主机“localhost”(127.0.0.1)上运行并接受端口5432上的TCP / IP连接?无法连接到服务器:连接被拒绝服务器是否在主机“localhost”(fe80 :: 1)上运行并接受端口5432上的TCP / IP连接?

这是一份清单,以及我尝试的事项清单;

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

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

  10. 在更新计算机之前,我仍然可以在我的机器上开始/完成的其他项目上工作。

  11. 当我从终端运行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"?

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

    更新

    感谢this问题,只需为Mac下载 Postgres.app 即可解决所有问题。现在一切都很好。

2 个答案:

答案 0 :(得分:12)

这比您想象的要容易,因为如果您更新了Mac,那么进程正在运行,但此处postmaster.pid缺少/usr/local/var/postgres/文件。所以你需要为postgres开始创建postmaster.pid的过程。

如果正在进行,那么 -

手动停止:

pg_ctl -D /usr/local/var/postgres stop -s -m fast

手动启动:

pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start

现在一切正常......

答案 1 :(得分:1)

在命令行中运行

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