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

PG Error could not connect to server: Connection refused Is the server running on port 5432?

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

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?

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

  • 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和命令行
  • Ran locate pg_hba.conf然后终端出局了;

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

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

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

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

    更新:

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


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

    如果进展正在运行 -

    手动停止:

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

    手动启动:

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

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


    在命令行中运行

    1
    postgres -D /usr/local/var/postgres

    如果结果像下一个

    1
    2
    3
    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.

    1
    brew postgresql-upgrade-database

    基于这篇文章