【问题标题】:1 [Ubuntu] Configuring Postgresql to talk to Rails App, stuck with no idea what to try next1 [Ubuntu] 配置 Postgresql 与 Rails 应用程序对话,不知道下一步该尝试什么
【发布时间】:2016-08-18 04:24:47
【问题描述】:

嗨,

我正在设置一个新的 Acer-571 Chromebook,通过 Crouton 运行 Ubuntu,主要用于 Rails 开发。

我已经在 rails 中安装了 postgresql 和 pg gem。当我以用户 postgres 登录时,我创建了一个超级用户 brett,以及一个名为 brett 的数据库。

我可以验证 postgresql 正在运行:

brett@localhost:~/Downloads/lcba/config$ service  postgresql status
Running clusters: 9.1/main 

brett@localhost:~/Downloads/lcba/config$ pg_lsclusters 
Version Cluster   Port Status Owner    Data directory                     Log file
9.1     main      5432 online postgres /var/lib/postgresql/9.1/main       /var/log/postgresql/postgresql-9.1-main.log

我已将我的 database.yml 文件配置为发布到(我认为是)我创建的正确用户和数据库:

default: &default
  adapter: postgresql
  encoding: unicode
  pool: 5

development:
  <<: *default
  database: brett
  host: localhost
  post: 5432
  password: brett_pass
  host: localhost

test:
  <<: *default
  database: brett_test
  host: localhost
  post: 5432
  database: brett
  password: brett_pass

我启动我的 Rails 服务器,并前往 localhost:3000,并在有关 pg 连接的日志中收到以下错误消息:

  Started GET "/" for ::1 at 2016-04-24 15:11:35 -0700

PG::Error (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"?
):
  activerecord (4.2.0) lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `initialize'
  activerecord (4.2.0) lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `new'
  activerecord (4.2.0) lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `connect'
  activerecord (4.2.0) lib/active_record/connection_adapters/postgresql_adapter.rb:242:in `initialize'
  activerecord (4.2.0) lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `new'
  activerecord (4.2.0) lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `postgresql_connection'
  activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:436:in `new_connection'
  activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:446:in `checkout_new_connection'
  activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
  activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
  /home/brett/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
  activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
  activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
  /home/brett/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
  activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
  activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:565:in `retrieve_connection'
  activerecord (4.2.0) lib/active_record/connection_handling.rb:113:in `retrieve_connection'
  activerecord (4.2.0) lib/active_record/connection_handling.rb:87:in `connection'
  activerecord (4.2.0) lib/active_record/migration.rb:384:in `connection'
  activerecord (4.2.0) lib/active_record/migration.rb:371:in `call'
  actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
  activesupport (4.2.0) lib/active_support/callbacks.rb:88:in `_run_callbacks'
  activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_call_callbacks'
  activesupport (4.2.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (4.2.0) lib/action_dispatch/middleware/reloader.rb:73:in `call'
  actionpack (4.2.0) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
  web-console (2.0.0.beta3) lib/action_dispatch/debug_exceptions.rb:18:in `middleware_call'
  web-console (2.0.0.beta3) lib/action_dispatch/debug_exceptions.rb:13:in `call'
  actionpack (4.2.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.2.0) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.2.0) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `block in tagged'
  activesupport (4.2.0) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `tagged'
  railties (4.2.0) lib/rails/rack/logger.rb:20:in `call'
  actionpack (4.2.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
  rack (1.6.4) lib/rack/runtime.rb:18:in `call'
  activesupport (4.2.0)  lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
  rack (1.6.4) lib/rack/lock.rb:17:in `call'
  actionpack (4.2.0) lib/action_dispatch/middleware/static.rb:113:in `call'
  rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
  railties (4.2.0) lib/rails/engine.rb:518:in `call'
  railties (4.2.0) lib/rails/application.rb:164:in `call'
  rack (1.6.4) lib/rack/content_length.rb:15:in `call'
  puma (2.11.1) lib/puma/server.rb:507:in `handle_request'
  puma (2.11.1) lib/puma/server.rb:375:in `process_client'
  puma (2.11.1) lib/puma/server.rb:262:in `block in run'
  puma (2.11.1) lib/puma/thread_pool.rb:104:in `block in spawn_thread'

有人对正确的方向有任何想法或指示吗?在过去的两天里,我一直试图让 postgresql 工作,但无济于事。准备好并愿意提供所需的任何信息或控制台输出。谢谢。

【问题讨论】:

标签: ruby-on-rails ruby postgresql ubuntu


【解决方案1】:

更新:我继续尝试多种解决方案,直到我注意到我的本地主机仍然抛出此错误,无论是否运行 rails 服务器。我发现该进程发生在端口上并将其杀死,然后 postgres 随后能够通过一些小的修改进行连接。

如果遇到 pg 连接错误,请检查端口上的幽灵进程!

【讨论】:

    【解决方案2】:

    在您的配置中,将所有记录的 post 修复为 port

    development:
      <<: *default
      database: brett
      host: localhost
      port: 5432
    

    【讨论】:

    • 另外,也许你应该添加 username: 为好
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-05
    • 2019-04-15
    • 1970-01-01
    • 2014-02-28
    • 2020-06-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多