Sidekiq - could not obtain a database connection within 5.000 seconds

I set database pool to sidekiq concurrency and now it works for me.

bundle exec sidekiq -c 10

in my database.yml

development:
  adapter: postgresql
  ...
  host: localhost
  pool: 10

The probem is related to the fact that database pool should be 'sidekiq_concurrency' + 2. If you put this into your sidekiq initializer you will solve the problem in general:

Sidekiq.configure_server do |config|
     config = ActiveRecord::Base.configurations[Rails.env] ||
         Rails.application.config.database_configuration[Rails.env]
     config['pool'] = Sidekiq.options[:concurrency] + 2
     ActiveRecord::Base.establish_connection(config)
     Rails.logger.debug("Connection Pool size for Sidekiq Server is now: #{ActiveRecord::Base.connection.pool.instance_variable_get('@size')}")
end