【问题标题】:Ruby on Rails and Postgresql - Server is running, but I'm obtaining a could not connect to server errorRuby on Rails 和 Postgresql - 服务器正在运行,但我收到无法连接到服务器错误
【发布时间】: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,我刚刚添加了文件,为了匿名,删除了一些点。
  • 你试过用命令行连接吗?
  • 我该怎么做?

标签: ruby-on-rails postgresql


【解决方案1】:

您需要将port: 5433 添加到您的database.yml。

默认的 PostgreSQL 端口是 5432,但是您的 pg_lsclusters 命令说服务器在 5433 上运行。这就是 Rails 找不到在 localhost:5432 上运行的服务器的原因。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-10-08
    • 2012-11-03
    • 1970-01-01
    • 1970-01-01
    • 2015-08-15
    • 2012-08-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多