【问题标题】:Rails local server doesnt run : could not connect to server: Connection refusedRails 本地服务器未运行:无法连接到服务器:连接被拒绝
【发布时间】:2016-11-18 16:46:37
【问题描述】:

我的本​​地服务器不再适用于我的 rails 应用程序。我收到以下错误消息:

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?
could not connect to server: Connection refused
    Is the server running on host "localhost" (::1) and accepting
    TCP/IP connections on port 5432?

我去检查我的数据库日志。这是最后几行:

STATEMENT:  CREATE DATABASE starsetmetiers_development;
ERROR:  unrecognized configuration parameter "idle_in_transaction_session_timeout"
STATEMENT:  SET idle_in_transaction_session_timeout = 0;

ERROR:  unrecognized configuration parameter "row_security"
STATEMENT:  SET row_security = off;

FATAL:  database "stars_metiers_development" does not exist
FATAL:  database "stars_metiers_development" does not exist
LOG:  received smart shutdown request
LOG:  autovacuum launcher shutting down
LOG:  shutting down
LOG:  database system is shut down

我最近销毁了我的开发数据库并通过提取生产数据库重新创建了一个。我认为它在我的 database.yml 文件中被正确引用:

default: &default
  adapter: postgresql
  encoding: unicode
  host: localhost
  # For details on connection pooling, see rails configuration guide
  # http://guides.rubyonrails.org/configuring.html#database-pooling
  pool: 5

development:
  <<: *default
  database: starsetmetiers_development

我不明白这个错误来自哪里(我也没有在我的 postgres 文件夹中找到 postmaster.pid 文件)。 我该如何解决这个问题?

当我尝试运行 rails c 时收到此错误消息

/Users/davidgeismar/.rbenv/versions/2.0.0-p576/lib/ruby/2.0.0/irb/completion.rb:9:in `require': dlopen(/Users/davidgeismar/.rbenv/versions/2.0.0-p576/lib/ruby/2.0.0/x86_64-darwin14.5.0/readline.bundle, 9): Library not loaded: /usr/local/opt/readline/lib/libreadline.6.dylib (LoadError)
  Referenced from: /Users/davidgeismar/.rbenv/versions/2.0.0-p576/lib/ruby/2.0.0/x86_64-darwin14.5.0/readline.bundle
  Reason: image not found - /Users/davidgeismar/.rbenv/versions/2.0.0-p576/lib/ruby/2.0.0/x86_64-darwin14.5.0/readline.bundle
    from /Users/davidgeismar/.rbenv/versions/2.0.0-p576/lib/ruby/2.0.0/irb/completion.rb:9:in `<top (required)>'
    from /Users/davidgeismar/.rbenv/versions/2.0.0-p576/lib/ruby/gems/2.0.0/gems/railties-4.1.8/lib/rails/commands/console.rb:3:in `require'
    from /Users/davidgeismar/.rbenv/versions/2.0.0-p576/lib/ruby/gems/2.0.0/gems/railties-4.1.8/lib/rails/commands/console.rb:3:in `<top (required)>'
    from /Users/davidgeismar/.rbenv/versions/2.0.0-p576/lib/ruby/gems/2.0.0/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:128:in `require'
    from /Users/davidgeismar/.rbenv/versions/2.0.0-p576/lib/ruby/gems/2.0.0/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:128:in `require_command!'
    from /Users/davidgeismar/.rbenv/versions/2.0.0-p576/lib/ruby/gems/2.0.0/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:59:in `console'
    from /Users/davidgeismar/.rbenv/versions/2.0.0-p576/lib/ruby/gems/2.0.0/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
    from /Users/davidgeismar/.rbenv/versions/2.0.0-p576/lib/ruby/gems/2.0.0/gems/railties-4.1.8/lib/rails/commands.rb:17:in `<top (required)>'
    from ./bin/rails:4:in `require'
    from ./bin/rails:4:in `<main>'

【问题讨论】:

  • 看起来你的 posgres 服务器要么没有监听 localhost,要么根本没有运行。
  • @SergioTulentsev 你有什么建议我应该做/检查?

标签: ruby-on-rails localserver connection-refused


【解决方案1】:

参数 idle_in_transaction_session_timeout 是 9.6 中的新参数 - 我认为您正在尝试将 9.6 备份上传到 Postgres 的早期版本。

我如下注释掉了转储的顶部,并在我遇到问题时让它工作。如果有机会,您可能想更新 Postgres。

SET statement_timeout = 0;
SET lock_timeout = 0;
-- SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SET check_function_bodies = false;
SET client_min_messages = warning;
-- SET row_security = off;

【讨论】:

    【解决方案2】:

    您缺少 readline 依赖项,因为您的错误输出中的这一行显示:

    Library not loaded: /usr/local/opt/readline/lib/libreadline
    

    你可以解决这个问题

    $ brew install readline
    

    【讨论】:

      【解决方案3】:

      无法连接到服务器:连接被拒绝 服务器是否在主机“localhost”(127.0.0.1)上运行并接受 端口 5432 上的 TCP/IP 连接?

      上述错误的原因是您的 postgresql 服务器没有运行。因此,请按照您的操作系统运行它,如下所示:

      Ubuntu:sudo service postgresql start
      Fedora:systemctl 启动 postgresql
      Windows:net start postgresql-9.x.x

      【讨论】:

        猜你喜欢
        • 2013-04-14
        • 2020-12-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-11-15
        • 2011-12-29
        • 2013-11-18
        • 2019-02-20
        相关资源
        最近更新 更多