I recently installed a Pgbouncer because our database received lots of connexions. (web / api activities). The problem is : apparently, the pgb doesn't keep opened connexions in his pool to reuse them after. I think this is what's happen because :
- when checking in the database (select .. from pg_stat_activity) I see that the number of connection grow with trafic, but just after a rush period it decrease a lot. (and the whole happen with the 1800 seconds I set for server_lifetime
- when I query 'show pools' within pgbouncer database, I can see 'active sv' increase, but after working on them, I don't see lots of 'sv idle' , remaining there, until next trafic spike.
Could something explain why the connections are not kept in 'sv idle' ? how can I 'debug' / test it futherly to identify what could be wrong ?
I set the pbgouncer like this :
- server_lifetime = 1800
- server_idle_timeout = 1800
- max_client_conn = 5000
- default_pool_size = 1500
- min_pool_size = 50
- pool_mode = transaction
(I tried with pool_mode = session with same behaviour)
The script open connection like this :
$co = new PDO($dsn, $user, $pwd);
$co->exec('SET statement_timeout TO 10000;');
$co->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$co->setAttribute(PDO::ATTR_PERSISTENT, true);
and after querying the database, perform a PDO::closeCursor()