Since I'm using CONN_MAX_AGE: 300
on my Django servers, request fail with errors because PostgreSQL exceeds the max_connections
limit (which is 100 by default).
What is the best strategy to solve this? I've tried using pgpool2, but this didn't solve the problem at all. Now the connections were queued by pgpool 2 (letting the sites wait forever, and cause a gateway timeout in the end).
I expected that using pgpool would reduce the number of idle connections going to PostgreSQL, not cause the same issue again.
These are the settings I've used:
pgpool2:
num_init_children = 32 # are so many workers needed?
max_pool = 10 # default is 4
postgres:
max_connections = 400 # upgraded from default 100
uWSGI/Django:
- all workers have 20 threads.
- there are 10 workers in total with all sites combined.
The VPS is an 8core Linode @ 2.27GHz with 2GB ram.