简体   繁体   English

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

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

I can't make my sinatra/ruby app hosted on heroku works as desired. 我无法按照需要在heroku上托管我的sinatra / ruby​​应用程序。 I fiddled with some setup trying to resolve this issue but so far no results. 我摆弄了一些试图解决这个问题的设置,但到目前为止还没有结果。

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'

User is one of my ActiveRecords table and the app fails because I try to query it. 用户是我的ActiveRecords表之一,应用程序失败,因为我尝试查询它。

I use sinatra with puma backup. 我使用sinatra与puma备份。 Here is my Procfile: 这是我的Procfile:

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

I was also checking how many open connections there is using: 我还在检查有多少打开的连接使用:

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

but its says 0 every time. 但它每次都说0。

I'm hosting the app on free plan and dev plan of herokupostgres. 我正在主持应用程序的免费计划和开发计划的herokupostgres。

I also noticed that the problem occurs when there are 2 quick calls to api at short interval of time. 我还注意到,在短时间内有2次快速调用api时会出现问题。 Like there was only 1, not 5 connections available, because 1st call succeds and the second one fails. 就像只有1个,而不是5个连接可用,因为第一次呼叫成功,第二次呼叫失败。 In my database.yml I setup pool to 5. 在我的database.yml中,我将池设置为5。

I'm on Rails 4.2.1 and Postgres 9.4 我在Rails 4.2.1和Postgres 9.4上

Here is my database.yml aswell: 这是我的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 >

Do I miss some configuration or does free heroku plan chokes on it? 我是否会错过一些配置或免费的heroku计划窒息?

Please check how your sinatra app established the connection 请检查您的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

Make sure you have proper settings for pool, also make sure you have a heroku config for DB_POOL or MAX_THREADS . 确保您对池有适当的设置,同时确保您有DB_POOLMAX_THREADS的heroku配置。

heroku config:set DB_POOL=5

or 要么

heroku config:set MAX_THREADS=5

暂无
暂无

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

相关问题 ActiveRecord::ConnectionNotEstablished: ActiveRecord::Base with mongoid 没有连接池 - ActiveRecord::ConnectionNotEstablished: No connection pool for ActiveRecord::Base with mongoid ActiveRecord::ConnectionNotEstablished(未找到“主”连接池。) - ActiveRecord::ConnectionNotEstablished (No connection pool with 'primary' found.) ROR - ActiveRecord::ConnectionNotEstablished: PublicActivity::ORM::ActiveRecord::Activity 没有连接池 - ROR - ActiveRecord::ConnectionNotEstablished: No connection pool for PublicActivity::ORM::ActiveRecord::Activity `retrieve_connection&#39;:没有模型的连接池(ActiveRecord :: ConnectionNotEstablished) - `retrieve_connection': No connection pool for Model (ActiveRecord::ConnectionNotEstablished) 呈现结果时,ActiveRecord::ConnectionNotEstablished(未找到具有“主要”的连接池。) - ActiveRecord::ConnectionNotEstablished (No connection pool with 'primary' found.) when rendering results ActiveRecord::ConnectionNotEstablished:在登台时找不到“阅读”角色的“主要”连接池 - ActiveRecord::ConnectionNotEstablished: No connection pool with 'primary' found for the 'reading' role on staging ActiveRecord :: ConnectionNotEstablished(ActiveRecord :: ConnectionNotEstablished) - ActiveRecord::ConnectionNotEstablished (ActiveRecord::ConnectionNotEstablished) ActiveRecord :: ConnectionNotEstablished - ActiveRecord::ConnectionNotEstablished ActiveRecord::ConnectionNotEstablished 错误 - ActiveRecord::ConnectionNotEstablished error [help] ActiveRecord :: ConnectionNotFounded - [help]ActiveRecord::ConnectionNotEstablished
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM