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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24333317/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 01:30:23  来源:igfitidea点击:

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

rubymacospostgresqlruby-on-rails-4

提问by user3749994

I recently updated my machine (MacBook Pro running Mountain Lion) and ever since then, whenever I set up a rails project, my machine craps out and cannot connect to PG. Currently, this is the error I am getting when I try to go to localhost;

我最近更新了我的机器(运行 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?

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

Here is a checklist, and list of things I have tried;

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

  1. PostgreSQL version is 9.3.4
  2. I have it installed through HomeBrew
  3. I have host: localhostin my database.yml file
  4. Rails version 4.1.1, ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.5.0]
  5. Ran brew uninstall postgresqlthen brew install postgresql
  6. Tried to access my postgres.conf file but wasn't allowed through PGAdmin and command line
  7. Ran locate pg_hba.confand terminal shot this out;

    WARNING: The locate database (/var/db/locate.database) does not exist.
    
  8. I have also tried using rails 4.0 but I still get the problem

  9. I can still work on other projects on my machine that were started/finished before I updated my computer.

  10. When I run psqlfrom my terminal I get 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"?

  1. PostgreSQL 版本是 9.3.4
  2. 我是通过 HomeBrew 安装的
  3. host: localhost在我的 database.yml 文件中
  4. Rails 版本 4.1.1,ruby 2.0.0p247(2013-06-27 修订版 41674)[x86_64-darwin12.5.0]
  5. brew uninstall postgresqlbrew install postgresql
  6. 试图访问我的 postgres.conf 文件,但不允许通过 PGAdmin 和命令行
  7. Ranlocate pg_hba.conf和终端机把它拍出来了;

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

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

  10. 当我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"?

I am really lost here, and am not sure what else to do. Any help would be much appreciated.

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

UPDATE:

更新:

Thanks to thisquestion, all was resolved by simply downloading Postgres.appfor Mac. Everything works great now.

由于这个问题,只需下载适用于 Mac 的Postgres.app即可解决所有问题。现在一切都很好。

回答by Nikhil Thombare

This is quite easy than your think because If you update your mac then process is running but postmaster.pidfile is missing from /usr/local/var/postgres/here. so you need to start process for postgres which create postmaster.pid.

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

If progress is running then -

如果进度正在运行,则 -

Stop manually:

手动停止:

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

Start manually:

手动启动:

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

now all are working...

现在所有人都在工作......

回答by Evelin Ponce

Run in your command line

在命令行中运行

postgres -D /usr/local/var/postgres

If the result is like the next one

如果结果像下一个

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.

Run

brew postgresql-upgrade-database

Based in this post

基于这篇文章