Ruby-on-rails 服务器是否在主机“localhost”(::1) 上运行并接受端口 5432 上的 TCP/IP 连接?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37307346/
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
Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432?
提问by Thibaud Clement
Before anything, please note that I have found several similar questions on Stack Overflow and articles all over the web, but none of those helped me fix my issue:
在此之前,请注意,我在 Stack Overflow 和网络上的文章中发现了几个类似的问题,但这些问题都没有帮助我解决问题:
- PG Error could not connect to server: Connection refused Is the server running on port 5432?
- PG::ConnectionBad - could not connect to server: Connection refused
- psql: could not connect to server: Connection refused
Now, here is the issue:
现在,这里是问题:
- I have a Rails app that works like a charm.
- With my collaborator, we use GitHub to work together.
- We have a
masterand anmvpbranches. - I recently updated my
gitversion with Homebrew (Mac). - We use Foreman to start our app locally.
- 我有一个非常棒的 Rails 应用程序。
- 与我的合作者一起,我们使用 GitHub 一起工作。
- 我们有一个
master和一个mvp分支。 - 我最近
git用 Homebrew (Mac)更新了我的版本。 - 我们使用 Foreman 在本地启动我们的应用程序。
Now, when I try to launch the app locally, I get the following error:
现在,当我尝试在本地启动应用程序时,出现以下错误:
PG::ConnectionBad at /
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?
I tried to reboot my computers several times.
我多次尝试重新启动计算机。
I also checked the content of /usr/local/var/postgres:
我还检查了以下内容/usr/local/var/postgres:
PG_VERSION pg_dynshmem pg_multixact pg_snapshots pg_tblspc postgresql.conf
base pg_hba.conf pg_notify pg_stat pg_twophase postmaster.opts
global pg_ident.conf pg_replslot pg_stat_tmp pg_xlog server.log
pg_clog pg_logical pg_serial pg_subtrans postgresql.auto.conf
As you can see, there is no postmaster.pidfile in there.
如您所见,那里没有postmaster.pid文件。
Any idea how I could fix this?
知道我该如何解决这个问题吗?
采纳答案by Graham Slick
You most likely ran out of battery and your postgresql server didn't shutdown correctly.
您很可能没电了,并且您的 postgresql 服务器没有正确关闭。
The easiest workaround is to download the official postgresql app and launch it: it will force the server to start (http://postgresapp.com/)
最简单的解决方法是下载官方 postgresql 应用程序并启动它:它会强制服务器启动(http://postgresapp.com/)
回答by user8376606
run postgres -D /usr/local/var/postgresand you should see something like:
运行 postgres -D /usr/local/var/postgres,您应该会看到如下内容:
FATAL: lock file "postmaster.pid" already exists
HINT: Is another postmaster (PID 379) running in data directory "/usr/local/var/postgres"?
Then run kill -9 PIDin HINT
然后kill -9 PID在 HINT 中运行
And you should be good to go.
你应该很高兴去。
回答by Nishant
Most likely it's because your system shutdown unexpectedly
很可能是因为您的系统意外关闭
Try
尝试
postgres -D /usr/local/var/postgres
You might see
你可能会看到
FATAL: lock file "postmaster.pid" already exists HINT: Is another postmaster (PID 449) running in data directory "/usr/local/var/postgres"?
FATAL: lock file "postmaster.pid" already exists HINT: Is another postmaster (PID 449) running in data directory "/usr/local/var/postgres"?
Then try
然后试试
kill -9 PID
example
例子
kill -9 419
And it should start postgres normally
它应该正常启动 postgres
回答by Shiva89
It might be as simple as the postgresql service is down. Try running:
可能就像 postgresql 服务关闭一样简单。尝试运行:
sudo service postgresql start
which fixed the issue for me.
这为我解决了这个问题。
回答by Tan
This worked in my case:
这在我的情况下有效:
brew uninstall postgresql
rm -fr /usr/local/var/postgres/
brew install postgresql
回答by Talha Meh
I had almost just as same error with my Ruby on Rails application running postgresql(mac). This worked for me:
我的 Ruby on Rails 应用程序在运行 postgresql(mac) 时遇到了几乎同样的错误。这对我有用:
brew services restart postgresql
回答by Aman Kumar
This can be as pid file created for postgress have not been deleted due to unexpected shutdown. So to fix this, remove this pid file.
这可能是因为为 postgress 创建的 pid 文件由于意外关闭而没有被删除。因此,要解决此问题,请删除此 pid 文件。
Find the postgres data directory. On a MAC using homebrew it is
/usr/local/var/postgres/, other systems it might be/usr/var/postgres/Remove pid file
rm postmaster.pid
Restart postgress. On Mac,
brew services restart postgresql
找到 postgres 数据目录。在使用自制软件的 MAC 上
/usr/local/var/postgres/,它可能是其他系统/usr/var/postgres/删除pid文件
rm postmaster.pid
重新启动 postgress。在 Mac 上,
brew 服务重启 postgresql
回答by techdreams
I resolved the issue via this command
我通过这个命令解决了这个问题
pg_ctl -D /usr/local/var/postgres start
At times, you might get this error
有时,您可能会收到此错误
pg_ctl: another server might be running; trying to start server anyway
So, try running the following command and then run the first command given above.
因此,尝试运行以下命令,然后运行上面给出的第一个命令。
pg_ctl -D /usr/local/var/postgres stop
回答by Tomasz Bartkowiak
For Dockerusers: In my case it was caused by excessive docker image size. You can remove unused data using prunecommand:
对于Docker用户:在我的情况下,它是由过大的Docker图像大小引起的。您可以使用prune命令删除未使用的数据:
docker system prune --all --force --volumes
Warning:as per manual (docker system prune --help):
警告:根据手册 ( docker system prune --help):
This will remove:
- all stopped containers
- all networks not used by at least one container
- all dangling images
- all dangling build cache
这将删除:
- 所有停止的容器
- 至少一个容器未使用的所有网络
- 所有悬垂的图像
- 所有悬空构建缓存
回答by sogu
It also gives the same error if you just stop your PostgreSQL app. You just need to start it again. (PostgreSQL 11)
如果您只是停止 PostgreSQL 应用程序,它也会出现相同的错误。你只需要重新开始。(PostgreSQL 11)

