---
title: "Comment by Mihai_LeanZero on \"Postgres connection pooling: why your app runs out of connections under load\" | Hashnode"
description: "Good rundown, and the PgBouncer transaction-mode tradeoff is the part people usually skip over. One thing worth adding to the \"ORMs that don't clean up\" cause:"
url: "https://hashnode.com/posts/postgres-connection-pooling-why-your-app-runs-out-of-connections-under-load/6ab27f79094f9bcfd63c8e1a/comment/6ab284eae69a4757cff9e530"
---

[Discussion](https://hashnode.com/posts/postgres-connection-pooling-why-your-app-runs-out-of-connections-under-load/6ab27f79094f9bcfd63c8e1a)

Comment [Postgres connection pooling: why your app runs out of connections under load](https://hashnode.com/posts/postgres-connection-pooling-why-your-app-runs-out-of-connections-under-load/6ab27f79094f9bcfd63c8e1a)

[Mihai\_LeanZero](https://hashnode.com/@mihaileanzero)

[Sep 22](https://hashnode.com/posts/postgres-connection-pooling-why-your-app-runs-out-of-connections-under-load/6ab27f79094f9bcfd63c8e1a/comment/6ab284eae69a4757cff9e530)

Good rundown, and the PgBouncer transaction-mode tradeoff is the part people usually skip over. One thing worth adding to the "ORMs that don't clean up" cause: even with an in-app pool in place, a request that opens a transaction and then does slow I/O before committing (an external API call, a retry loop, a queue publish) still holds a real Postgres backend the whole time, and PgBouncer in transaction mode can't reclaim it either since it's mid-transaction from its point of view. We rely on idle\_in\_transaction\_session\_timeout on the Postgres side to kill those automatically rather than trusting every code path to clean up on its own, and pg\_stat\_activity filtered on state = 'idle in transaction' is usually the fastest way to find which endpoint is actually the culprit before guessing at pool sizes.

[Amit Shukla](https://hashnode.com/@amitshuklabag)

[Oct 2](https://hashnode.com/posts/postgres-connection-pooling-why-your-app-runs-out-of-connections-under-load/6ab27f79094f9bcfd63c8e1a/comment/6ab284eae69a4757cff9e530#reply-6abfe116570249a66b3ae514)

Great addition, and a sneaky one, because the pool looks healthy while one slow endpoint holds a backend hostage. Agree on setting idle\_in\_transaction\_session\_timeout as the backstop. The real fix is usually moving the API call or queue publish outside the transaction, but the timeout catches the paths nobody remembers. Your pg\_stat\_activity query is the first thing I'd run too.
