Db connections are not removed when established from aws lambda
Hi team, we are running in aws lambdas and setting up a connection like this:
This db is reused between invocations in lambda. Current executions never get above 25 in aws, and there's concurrency limits set on that, however in neon dashboard it's seen the db connection count approaches 100. how is that possible? Is there a way to counteract this?

6 Replies
correct-apricot•6mo ago
This is using node-postgres driver, right?
You might also want to set the max pool connections. It's possible that each pool in each is holding ~4 connections
other-emeraldOP•6mo ago
correct-apricot•6mo ago
Ah, ok
other-emeraldOP•6mo ago
right that makes sense and in lambda that's wasteful, looking into how to do this. Also just switched to -pooled
is it possible that this Pool is holding 4 connections?
Do you mean adding this
max here?correct-apricot•6mo ago
That would work, although I would be a little bit careful. There might be some reason why your lambda creates more connections that would then break if it cannot create more than 1
So, make sure to test it
other-emeraldOP•6mo ago
thanks! I don't see a reason why aws lambda would attempt to use multiple db connections in a normal, non-exotic usage. As lambda is not able to handle multiple requests concurrently