PostgreSQL无法连接到:处理请求时出现意外错误:无法连接到服务器:没有此类文件或目录

时间:2017-09-14 13:38:26

标签: ruby-on-rails postgresql amazon-web-services amazon-ec2

我面临一个非常奇怪的问题,下面是亚马逊EC2上的PostgreSQL错误:

Unexpected error while processing request: 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"?

    /bundle/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:671:in `initialize'
    /bundle/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:671:in `new'
    /bundle/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:671:in `connect'
    /bundle/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:217:in `initialize'
    /bundle/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:37:in `new'
    /bundle/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:37:in `postgresql_connection'

我能够从ssh通过psql命令登录到AWS EC2实例,但是当它使用我的rails应用程序时它无法正常工作,可能是什么问题?

我正在使用AWS + EC2 + Docker + RDS进行我的应用部署。

的database.yml

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

development:
  <<: *default
  database: <%= Figaro.env.rds_db_name || Figaro.env.database_name %>
  host: <%= Figaro.env.rds_hostname || Figaro.env.database_host %>
  port: <%= Figaro.env.rds_port || Figaro.env.database_port %>
  username: <%= Figaro.env.rds_username || Figaro.env.database_username %>
  password: <%= Figaro.env.rds_password || Figaro.env.database_password %>

test:
  <<: *default
  database: cluetap_test

dev:
  <<: *default
  database: <%= Figaro.env.database_name %>

staging:
  <<: *default
  database: <%= Figaro.env.rds_db_name || Figaro.env.database_name %>
  host: <%= Figaro.env.rds_hostname || Figaro.env.database_host %>
  port: <%= Figaro.env.rds_port || Figaro.env.database_port %>
  username: <%= Figaro.env.rds_username || Figaro.env.database_username %>
  password: <%= Figaro.env.rds_password || Figaro.env.database_password %>

production:
  <<: *default
  database: <%= Figaro.env.rds_db_name || Figaro.env.database_name %>
  host: <%= Figaro.env.rds_hostname || Figaro.env.database_host %>
  port: <%= Figaro.env.rds_port || Figaro.env.database_port %>
  username: <%= Figaro.env.rds_username || Figaro.env.database_username %>
  password: <%= Figaro.env.rds_password || Figaro.env.database_password %>

1 个答案:

答案 0 :(得分:0)

这是安全组的一个问题,所以我更新了它,然后它运行正常。