Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Database connection timeout error in postgresql

Currently am running backgroud jobs with sidekiq, while running its giving "ActiveRecord::ConnectionTimeoutError".

This is my current database.yml file,

production:
  adapter: postgresql
  encoding: unicode
  database: app_production
  username: password
  password:
  host: app.domain.com
  pool: 25

This is is my sidekiq.yml file,

production:
    concurrency: 25
    timeout: 300

While running its giving connection timeout error

This error was am getting in the backgroud,

could not obtain a database connection within 5 seconds (waited 5.82230675 seconds). The max pool size is currently 25; consider increasing it.
like image 839
SaravanaKumAr Avatar asked Feb 06 '14 14:02

SaravanaKumAr


People also ask

What is connection timeout in PostgreSQL?

connectTimeout = int. The timeout value used for socket connect operations. If connecting to the server takes longer than this value, the connection is broken. The timeout is specified in seconds and a value of zero means that it's disabled.

What is connection limit in PostgreSQL?

PostgreSQL Connection Limits 15 connections are reserved for the superuser to maintain the state and integrity of your database, and 100 connections are available for you and your applications. If the number of connections to the database exceeds the 100-connection limit, new connections fail and return an error.

Can't connect to server connection timed out psycopg2?

If Django/psycopg2 have the correct domain name or IP address for the PostgreSQL server, and the correct port, the most common explanation for "Connection timed out" is that a firewall (typically on the PostgreSQL server) is filtering that traffic.


1 Answers

Maximum number of connections allowed to your postgres database is 25. But you have set your concurrency for sidekiq as 25. So if you have all the concurrent threads for sidekiq running, you will not have any database connection available for your app server.

Either reduce the sidekiq concurrency or increase the pool size(I recommend increasing the pool size).

Postgres allows 100 concurrent connections by default

like image 155
usha Avatar answered Sep 30 '22 15:09

usha