繁体   English   中英

使用 Postgres 的 Rails 应用程序中的连接池错误

[英]Connection pool error in Rails application with Postgres

当我的 Rails 应用程序部署在 AWS ECS 中时,我遇到了问题。 许多请求以200结束,但也有一些(比如说 50)以500结束。 日志说:

ActiveRecord::ConnectionNotEstablished (No connection pool with 'primary' found.)

我将我的池(在database.yml配置中)更改为 15,还将 RAILS_MAX_THREADS 设置为 15,实际上它现在很少发生,但问题仍然存在。

我在这里想念什么?

Ruby 版本:2.6.6 Postgres:11.5

数据库.yml:

production:
  adapter: postgresql
  encoding: utf8
  database: <%= ENV['DB_NAME'] %>
  username: <%= ENV['DB_USERNAME'] %>
  password: <%= ENV['DB_PASSWORD'] %>
  host: <%= ENV['DB_HOSTNAME'] %>
  port: <%= ENV['DB_PORT'] %>
  pool: 25

尝试并使用它在默认情况下具有通用值,然后根据 env 具有其他环境的单独值,这可以基于环境变量:

default: &default
  adapter:  postgresql
  encoding: unicode
  port:     <%= ENV.fetch("POSTGRESQL_PORT", "5432") %>
  pool:     <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  username: <%= ENV['POSTGRESQL_USER_NAME'] %>
  password: <%= ENV.fetch("POSTGRESQL_PASSWORD", "somepassword") %>
  host:     <%= ENV['POSTGRESQL_HOST'] %>

development:
  <<: *default
  database: <%= ENV['POSTGRESQL_DB'] %>-development
  host: db

production:
  <<: *default
  database: <%= ENV['POSTGRESQL_DB'] %>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM