background

Sorry, too many clients already. Sorry, too many clients already. The number of connections to the PG library is full. Think we have a lot of application development environment Shared this a PG library, so often the number of connections filled, simply a don the development environment of PG library up the maximum number of connections is finished, it is to develop the library, and bring up afterward, also avoided after the link count filled, affect developers work fluency.

The modification process

View the maximum number of connections

Log in to the PG library in your development environment and run the following command to check the current maximum number of connections to the database:

show max_connections;
Copy the code

View the path to the pg library configuration file for max_connections

To develop the PG library in the environment, run the following command:

select name, setting, boot_val, reset_val, sourcefile from pg_settings where name = 'max_connections'; -- name = name of the configuration item -- setting = value of the configuration item -- boot_val = Initialization of the configuration item value -- sourcefile = path of the configuration file where the configuration item residesCopy the code

Modify the target configuration file

In the previous step we found the path to the PG library configuration file for the maximum number of links. Just change the value of max_connections in the corresponding configuration file. However, when I logged in to the server where the PG library is located, there was no configuration file of the PG library in the specified path, and I was immediately dumbfounded. On second thought, our PG library seems to be started with a Docker container

docker ps
Copy the code

Sure enough, I saw the PG library container in action. It’s convenient to know that the PG library is started as a Docker container. There are two ways to modify the PG library configuration file:

  1. Log in to the container and modify the PG database configuration file obtained in the previous step
docker exec-it {container ID} /bin/bashCopy the code

However, there may be no vi, vim and other text editing tools in the Docker container. 2. If the target configuration file cannot be directly modified in the container, we can use the docker inspect command to check the directory mounted by the target container on the host, go to the host to find the target PG library configuration file and modify it directly.

Docker inspect containers {id} | grep Mounts - A 20Copy the code

Restart the PG library

Because our PG library is started by docker container, it is ok to directly restart the corresponding Docker container, and the command is as follows:

Docker restart docker restartCopy the code

If the PG library is a common application, run the PG library restart command on the server:

pg_ctl reload
Copy the code

validation

Log in to the PG library and run the following command to see if the value of the maximum number of connections has been changed to the value we just configured:

show max_connections;
Copy the code

reference

PG database Check the current number of connections and the maximum number of connections postgresQL Modify the maximum number of connections Configure docker: How to check the mount directory of a container Docker general operations — start, stop, restart a container instance