我想知道如何在与AWS上的RDS数据库连接的Rails 6应用程序中解决以下错误:
在5.000秒内无法从池中获得连接 (等待5.075秒);所有池连接都在使用中
到目前为止,我已经尝试过:
谢谢。
答案 0 :(得分:0)
我建议您通过此链接https://devcenter.heroku.com/articles/forked-pg-connections。至少要验证Postgres服务器可以处理的活动连接数限制。
如果使用Unicorn前叉服务器模型,则可以在挂钩之前/之后进行配置,以正常打开和关闭数据库连接。
before_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
Process.kill 'QUIT', Process.pid
end
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
end
after_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to sent QUIT'
end
defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection(
Rails.application.config.database_configuration[Rails.env]
)
end