travisbeck
PPrisma
•Created by travisbeck on 12/18/2024 in #help-and-questions
Prisma with pgbouncer behind a load balancer
Hi friends! We are running prisma with pgbouncer behind an AWS network load balancer to handle multiple pgbouncer instances. This generally is working great.
Our problem though is that when we bring up new pgbouncer instances, existing web app processes only use it for new connections (not existing ones) and so load is only actually evenly balanced after a server restart.
Ideally I would want a way to set an idle connection timeout in Prisma in our application so that connections would get recycled if they're not being used, but I don't see any option for that. In fact the only thing that I've found that's related to this is this reference to Zombie connections which implies that Prisma can't do this, but not why it can't.
There is a client_idle_timeout option in pgbouncer that can disconnect idle clients on pgbouncer's side but the docs say this should only be used for network problems.
It seems like one of the main benefits of using pgbouncer is cheap connection setup cost, so this feels like a pretty normal thing in this case despite the fact that it's normally a good idea to set up connections once and leave them for the life of the process. Have any of you run into this? Is the right way to do this to set the client_idle_timeout in pgbouncer? Is there an idle connection timeout in PrismaClient that I'm not seeing? Thanks for the help!
7 replies