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
PG Error could not connect to server: Connection refused Is the server running on port 5432?
提问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;
这是一个清单,以及我尝试过的事情的清单;
- PostgreSQL version is 9.3.4
- I have it installed through HomeBrew
- I have
host: localhost
in my database.yml file - Rails version 4.1.1, ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.5.0]
- Ran
brew uninstall postgresql
thenbrew install postgresql
- Tried to access my postgres.conf file but wasn't allowed through PGAdmin and command line
Ran
locate pg_hba.conf
and terminal shot this out;WARNING: The locate database (/var/db/locate.database) does not exist.
I have also tried using rails 4.0 but I still get the problem
I can still work on other projects on my machine that were started/finished before I updated my computer.
When I run
psql
from my terminal I getpsql: 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"?
- PostgreSQL 版本是 9.3.4
- 我是通过 HomeBrew 安装的
- 我
host: localhost
在我的 database.yml 文件中 - 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
和终端机把它拍出来了;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"?
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.pid
file 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
基于这篇文章