PostgreSQL configuration: changing connection limit with max_connections

  • Last updated: Nov 13, 2024
  • Views: 7
  • Author: Admin

To tune the performance and ensure stable operation of PostgreSQL, it is sometimes necessary to change the max_connections parameter, which determines the maximum number of simultaneous connections to the database. The max_connections parameter is important because it allows you to optimize the use of server resources and prevent system overload. Too low a value can result in users not being able to connect to the database, while too high a value can result in excessive resource consumption and reduced performance.

In this article we will look at how to correctly change the value of the max_connections parameter.

The article on the page is based on my many years of experience with this technology and is presented to you as a short instruction, but if you want to get acquainted with it in more detail, then I recommend that you go to the official documentation on PostgreSQL.

 

Contents of the article:

  1. Current max_connections values.
  2. Change max_connections in postgresql.conf.
  3. Restart the database.
  4. Checking the result.

 

1. Current max_connections values.

Before changing the max_connections parameter values, let's see what the maximum number of connections to the database is currently set to. To check, use the sql command:

psql> SHOW max_connections;

postgresql max connection

As we can see, at the moment the maximum number of connections to the database is set to 400.


 

2. Change max_connections in postgresql.conf.

You need to change the max_connections parameter values ​​in the postgresql.conf configuration file. Find the postgresql.conf file, open it and find the max_connections parameter and change it to the value we need for the normal operation of our service.

$. sudo vim $PG_HOME/postgresql.conf

postgresql max connection

Change the values ​​from 400 to 500, then save and close the file.


 

3. Restart the database.

The max_connections variable is static, so you need to restart the database.

$. pg_ctl restart


 

4. Checking the result.

After we have changed the max_connections values ​​from 400 to 500 and restarted the database, we can check the result. Repeat the first step:

psql> SHOW max_connections;

postgresql max connection

As we can see, everything worked out, the max_connections value is successfully applied.


 

As a result, today we looked at how to correctly change the maximum number of connections to the PostgreSQL database using the max_connections parameter.

 

SIMILAR ARTICLES