[英]Ruby on Rails and Postgresql - Server is running, but I'm obtaining a could not connect to server error
QUESTION: PostgreSQL server is running, but when I run rake db:migrate, I obtain a ConnectionBad: could not connect to server error. 问题:PostgreSQL服务器正在运行,但是当我运行rake db:migrate时,我得到一个ConnectionBad:无法连接到服务器错误。 What can I do to fix this error?
我该如何解决该错误?
Update - Database.yml file 更新-Database.yml文件
I've removed some points in the file for anonymity. 我已经删除了文件中的一些匿名性。
default: &default
adapter: postgresql
pool: 5
timeout: 5000
development:
adapter: postgresql
encoding: unicode
database: db_development
pool: 5
username:
password:
test:
adapter: postgresql
encoding: unicode
database: db_test
pool: 5
username:
password:
production:
adapter: postgresql
encoding: unicode
database: db_production
pool: 5
username:
password:
I've looked through the API and tried to implement the answers, but nothing is working on my end. 我查看了API并尝试实现了答案,但最终没有任何结果。
When I run pg_lsclusters
, I'm told: 当我运行
pg_lsclusters
,被告知:
Ver Cluster Port Status Owner Data directory Log file
10 main 5433 online postgres /var/lib/postgresql/10/main
/var/log/postgresql/postgresql-10-main.log
So it's online, I usually start the server as sudo service postgresql start
. 所以它是在线的,我通常以
sudo service postgresql start
来启动服务器。
However, when I try and run rake db:migrate
, I get the error: 但是,当我尝试运行
rake db:migrate
,出现错误:
PG::ConnectionBad: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
I haven't encountered this error before, is it possible I have uninstalled postgresql wrongly? 我以前没有遇到过此错误,可能我错误地卸载了postgresql吗?
I did it as: sudo apt-get update
sudo apt-get install postgresql postgresql-contrib libpq-dev
gem install pg
我这样做是:
sudo apt-get update
sudo apt-get install postgresql postgresql-contrib libpq-dev
gem install pg
And in the Ruby on Rails app: 在Ruby on Rails应用中:
bundle install
bundle update
bundle install
bundle update
Everything installed perfectly, so I just don't know what I have done wrong, given I've done those steps before on another computer and it works fine for it. 一切都安装完美,所以我只是不知道自己做错了什么,因为我之前已经在另一台计算机上完成了这些步骤,并且可以正常工作。
You need to add port: 5433
to your database.yml. 您需要在数据库
port: 5433
添加port: 5433
。
The default PostgreSQL port is 5432, but your pg_lsclusters
command says the server is running on 5433. This is why Rails can't find a server running on localhost:5432. PostgreSQL的默认端口是5432,但是您的
pg_lsclusters
命令说服务器正在5433上运行。这就是为什么Rails找不到运行在localhost:5432上的服务器的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.