【发布时间】:2019-03-15 11:46:25
【问题描述】:
问题:PostgreSQL 服务器正在运行,但是当我运行 rake db:migrate 时,我得到一个 ConnectionBad: could not connect to server 错误。我该如何解决这个错误?
更新 - Database.yml 文件
为了匿名,我删除了文件中的一些点。
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:
我查看了 API 并尝试实现答案,但没有任何效果。
当我运行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
所以它在线,我通常以sudo service postgresql start启动服务器。
但是,当我尝试运行 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"?
我之前没有遇到过这个错误,是不是我错误地卸载了postgresql?
我是这样做的:
sudo apt-get update
sudo apt-get install postgresql postgresql-contrib libpq-dev
gem install pg
在 Ruby on Rails 应用程序中:
bundle install
bundle update
一切都安装得很好,所以我只是不知道我做错了什么,因为我之前在另一台计算机上完成了这些步骤并且它工作正常。
【问题讨论】:
-
请附上你的database.yml文件的内容
-
嗨 hd1,我刚刚添加了文件,为了匿名,删除了一些点。
-
你试过用命令行连接吗?
-
我该怎么做?