Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between connection pooling and max_connections?

Tags:

People also ask

What is the difference between connection and connection pool?

When an application requests a connection from the connection pool, the Pool assigns an available connection. If an unused connection exists, the pool return it. Otherwise, if there is no available connection, the Pool will create a new connection and assigns it to the application as an active connection.

What is Max_connections?

max_connections is a global variable that can have a minimum value of 1 and a maximum value of 100000. However, It has always been commonly known that settings max_connections to an insanely high value is not too good for performance. Generations of system administrators have followed this rule.

What is connection pool?

Connection pooling means that connections are reused rather than created each time a connection is requested. To facilitate connection reuse, a memory cache of database connections, called a connection pool, is maintained by a connection pooling module as a layer on top of any standard JDBC driver product.

What is connection pooling used for?

Using connection pools helps to both alleviate connection management overhead and decrease development tasks for data access. Each time an application attempts to access a backend store (such as a database), it requires resources to create, maintain, and release a connection to that datastore.


I am using Postgres with Sequelize as the ORM / query interface. Recently we started hitting some errors:

SequelizeConnectionError: remaining connection slots are reserved for non-replication superuser connections

Looking into it, the problem seems to be related to the connection limits set for Postgres, but I was having some trouble figuring out how to relate the client-side pooling settings with the Postgres settings:

On my postgres 9.4 database (on Amazon RDS), my max_connections is defaulted to 26:

SELECT name, setting FROM pg_settings WHERE name='max_connections';
+-----------------+---------+
| name            | setting |
+-----------------+---------+
| max_connections | 26      |
+-----------------+---------+

In Sequelize, I have my pool set to:

pool: {
  max: 10,
  min: 0,
  idle: 10000
},

Some questions:

  • In general how does the pool relate to max_connections?
  • Does each connection in the pool take 1 count out of the max_connections?
  • Does this mean that the pool max must always be smaller than the max_connections?
  • Would lowering the idle timeout on the pool help free connections faster?