Limit connection numbers with pgbouncer
-
30-09-2020 - |
Question
So I have this pgbouncer config:
[databases]
my_db = host=10.10.10.10
my_db_with_conn_limit = host=10.10.10.10 dbname=my_db pool_size=55
max_client_conn = 300
default_pool_size = 65
reserve_pool_size = 5
reserve_pool_timeout = 1
And the goal is to limit the number of connections from a specific app - when the db name is database_with_conn_limit, only 55 connections are allowed.
Basically, the apps are identical, but I want one to be limited in connections and the other one grab as many as it wants.
- Is this a correct setup?
- Or should I specify pool_size for my_db, too, giving it all Postgres has minus 55?
Solution
You don't have to "specify pool_size
for my_db, too".
But your config won't limit the number of connections though. You need to limit max_db_connections
for that like here:
[databases]
my_db = host=10.10.10.10
my_db_with_conn_limit = host=10.10.10.10 dbname=my_db pool_size=55 max_db_connections=55
Otherwise you limit the number of sessions in pool, but not the number of connections...
You can also just set different limits per database+user pair instead (which I believe is more common practice).
Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange