I'm working with a tech stack of Prisma ORM and Postgres on Supabase with PgBouncer enabled. We're also using Google Cloud Run to deploy our Node/Express API.
When looking through logs for production, you will see occurances of the same errors being raised again and again. One such example looks like:
Timed out fetching a new connection from the connection pool. More info: http://pris.ly/d/connection-pool (Current connection pool timeout: 10, connection limit: 1)
I've read up on this page: https://www.prisma.io/docs/concepts/components/prisma-client/working-with-prismaclient/connection-pool.
The timeout of 10 seconds is the Prisma connection pool default and the connection limit of 1 is set via the query parameter of the connection string I use,
postgresql://[USER]:[PASSWORD]@localhost:[PORT]/[NAME]?pgbouncer=true&connection_limit=1
, given from the docs also: https://www.prisma.io/docs/guides/performance-and-optimization/connection-management/configure-pg-bouncer.
This was done because we thought multiple instances of our API containers would hog the connections to PgBouncer.
My question is:
- Have I set up PgBouncer correctly, and if not, how can I look into setting it up properly?
- As I'm trying to use PgBouncer, does that make my messing around with the
connection_limit
query parameter pointless? Should I just get rid of that? - How can I stop these timeouts from occurring?
What I've tried:
- Removing the
connection_limit
- this seemed to have little to no effect. - Reviewing Supabase -> Database -> Roles for connections - of the 60 max connections I see pgbouncer in the list with connections - so I assume this means pgbouncer is working?
- Looking through
pg_stat_activity
- I'm seeing 2 different client addresses across multiple processes, almost all idle (I assume because pgbouncer is managing them?) - I'm thinking of increasing the pool timeout from the default of 10, but I don't really want to do that.