繁体   English   中英

ActiveRecord :: ConnectionNotEstablished - 没有X的连接池

[英]ActiveRecord::ConnectionNotEstablished - No connection pool for X

我无法按照需要在heroku上托管我的sinatra / ruby​​应用程序。 我摆弄了一些试图解决这个问题的设置,但到目前为止还没有结果。

ActiveRecord::ConnectionNotEstablished - No connection pool for User:
2015-06-25T14:26:11.736854+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:566:in `retrieve_connection'
2015-06-25T14:26:11.736856+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.1/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
2015-06-25T14:26:11.736858+00:00 app[web.1]:    /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.1/lib/active_record/connection_handling.rb:87:in `connection'

用户是我的ActiveRecords表之一,应用程序失败,因为我尝试查询它。

我使用sinatra与puma备份。 这是我的Procfile:

web: ruby app/my-server.rb -s puma

我还在检查有多少打开的连接使用:

select count(*) from pg_stat_activity where pid <> pg_backend_pid()  and usename = current_user; 

但它每次都说0。

我正在主持应用程序的免费计划和开发计划的herokupostgres。

我还注意到,在短时间内有2次快速调用api时会出现问题。 就像只有1个,而不是5个连接可用,因为第一次呼叫成功,第二次呼叫失败。 在我的database.yml中,我将池设置为5。

我在Rails 4.2.1和Postgres 9.4上

这是我的database.yml以及:

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

production:
  <<: *default
  host: my_db_address
  port: 5432
  database: my_db_name
  username: my_db_user_name
  password: my_db_password

< test and development ommited >

我是否会错过一些配置或免费的heroku计划窒息?

请检查您的sinatra应用程序如何建立连接

configure :production, :development do
  db = URI.parse(ENV['DATABASE_URL'] || 'postgres://localhost/mydb')
  pool = ENV["DB_POOL"] || ENV['MAX_THREADS'] || 5
  ActiveRecord::Base.establish_connection(
        adapter:  db.scheme == 'postgres' ? 'postgresql' : db.scheme,
        host:      db.host,
        username:  db.user,
        password:  db.password,
        database:  db.path[1..-1],
        encoding:  'utf8',
        pool:      pool
  )
end

确保您对池有适当的设置,同时确保您有DB_POOLMAX_THREADS的heroku配置。

heroku config:set DB_POOL=5

要么

heroku config:set MAX_THREADS=5

暂无
暂无

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

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