简体   繁体   English

Ruby on Rails和Postgresql-服务器正在运行,但我收到一个无法连接服务器的错误

[英]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.

相关问题 Ruby on Rails-运行服务器时出错 - Ruby on Rails - error running server PostgreSQL 错误:无法连接到数据库模板1:无法连接到服务器: - PostgreSQL error: could not connect to database template1: could not connect to server: Appfog + Rails 3 + Postgresql + IronWorker =>无法连接到服务器:连接超时(PG :: Error) - Appfog + Rails 3 + Postgresql + IronWorker => could not connect to server: Connection timed out (PG::Error) Postgresql 版本 13 psql:错误:无法连接到服务器:无法连接到服务器:没有这样的文件或目录 - Postgresql version 13 psql: error: could not connect to server: could not connect to server: No such file or directory Cloud9中的postgresql错误“无法连接到服务器:连接被拒绝” - postgresql error in Cloud9 “could not connect to server: Connection refused” Ruby on Rails连接到服务器问题 - Ruby on Rails connect to server issues 在rails上连接Ruby中的Sql server - Connect Sql server in Ruby on rails Ruby on Rails:Heroku服务器上的JQuery自动完成功能(可能是SQL,PostgreSql错误) - Ruby on rails: JQuery autocomplete on heroku server (SQL, PostgreSql error probably) Ruby on Rails / PostgreSQL - 启动服务器时库未加载错误 - Ruby on Rails / PostgreSQL - Library not loaded error when starting server Ruby on Rails服务器错误 - Ruby on Rails server error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM