Set the maximum number of Postgres connections Error [How to Solve]

The Postgres version of this tutorial case is 12

Problem Description:

psycopg2.OperationalError: FATAL: sorry, too many clients already on

In the morning, I found that the python back-end service I maintained reported an error. Baidu found that the default maximum concurrency of Postgres was only 100, which led to this problem

Modify tutorial:

cd /var/lib/postgresql/12/main
vi postgresql.auto.conf

Add the following line of code to the file to set the maximum number of connections to 800, the default is 100
max_connections = 800

Restart the service
service postgresql restart

The following is the SQL command to check whether the modification is successful:

# Show the maximum number of connections to the current database
show max_connections;

# Show the number of users currently connected to the data
SELECT COUNT(*) from pg_stat_activity;

# Show details of the current connection, very slow, don't use it
SELECT * FROM pg_stat_activity;

The effect is similar, which indicates that the setting is successful

Read More: