#DevOps

Postgres 连接池:PgBouncer 还是连接复用?

由@yanghx发起讨论 · 发布于 2026年7月30日 · 更新于 2026年8月3日

Serverless / Edge 场景下,每个请求一个 Postgres 连接会很快打满 max_connections。两个主流方案:PgBouncer(transaction pooling)和应用层连接池(如 Prisma 的 pgbouncer 模式、postgres.js 的 pool)。

我的实践:

  • 长连接服务(Node 后端)→ 应用层 pool 足够。
  • Serverless(每实例短生命周期)→ 必须 PgBouncer,且要 transaction 模式。
  • Prisma 在 PgBouncer transaction 模式下要开 ?pgbouncer=true。

注意 transaction 模式下不能用 prepared statements,某些 ORM 要关。

大家的 Postgres 连接池都怎么搭?

回复

暂时没有回复。

Related

相关推荐