Problem
- running out of database connections in prod leading to errors like this;
Error:
Invalid `prisma.queryRaw()` invocation:
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: 5)
at Object.request (/usr/src/app/node_modules/@prisma/client/runtime/index.js:45629:15)
at async Proxy._request (/usr/src/app/node_modules/@prisma/client/runtime/index.js:46456:18)
Situation
- multiple API containers running in Google Cloud Run running node/express/prisma API
- using Supabase's hosted postgres. In supabase Settings > Database, Connection Pooling is enabled.
- in db connection string, using
:6543/postgres?pgbouncer=true
Attempt to diagnose
in supabase, Database > Roles, I can see a list of roles and the number of connections for each.
pgBouncerhas 0 and the role which my application uses has several.If I query
pg_stat_activity, I can see connections for theusenamewhich is used by my application, andclient_addrvalues representing ip addresses for a couple of different container instances. Are these "forwarded on" frompgBouncer? or have they bypassedpgBouncerentirely?
I am not familiar with what either of these should look like if I were using pgBouncer correctly so it's hard for me to tell what's going on.
I assume this means that I either haven't configured pgBouncer correctly, or I'm not connecting to it properly, or both. I'd be really grateful if someone could point out how I could either check or fix my connection to pgBouncer and clarify what I should see in pg_stat_activity if I was correctly connected to pgBouncer. Thanks.