Skip to content
← Back to activity

Immutable solution version

Postgres connection pooling not working

Version 2

Complete solution

Shows how to fix postgres connection pooling not working. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

Set persistence.datastores.*.sql.maxConns and maxIdleConns explicitly. 1. cluster with 2k shards (I assume that's the culprit) 1. use Postgres v97 plugin (actual Postgres is v14, we still have to upgrade the plugin) 1.

Steps

  1. cluster with 2k shards (I assume that's the culprit)

    1. use Postgres v97 plugin (actual Postgres is v14, we still have to upgrade the plugin)

    1.

  2. [tdeebswihart (contributor)]: The CPU/GC load from constant connection and TLS cert recreation comes from sqlx pool defaults (max 2 idle conns, unbounded pool). Set persistence.datastores.*.sql.maxConns and maxIdleConns explicitly. The reporter confirmed connection handling dropped out of the profiles after configuring it.

When to use

You are seeing this: Issue temporalio/temporal#4975 (closed, 13 comments): ## Expected Behavior Connections rarely getting opened Use this skill when you run into "Postgres connection pooling not working".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

Versions mentioned in the source: v1.20. If you are on something much newer or older, the details may have shifted.

Why this happens

The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.

Evidence

In gh:temporalio/temporal#4975 (Temporal), the issue reported was: Issue temporalio/temporal#4975 (closed, 13 comments): ## Expected Behavior Connections rarely getting opened

Actual Behavior

50% of all CPU load (4 cores) just from opening new connections

[image]

Steps to Reproduce the Problem

  1. cluster with 2k shards (I assume that's the culprit)
  2. use Postgres v97 plugin (actual Postgres is v14, we still have to upgrade the plugin)

1.

Specifications

  • Version: v1.20
  • Platform: Linux, AWS, EKS The verified resolution from the thread: [tdeebswihart (contributor)]: The CPU/GC load from constant connection and TLS cert recreation comes from sqlx pool defaults (max 2 idle conns, unbounded pool). Set persistence.datastores.*.sql.maxConns and maxIdleConns explicitly. The reporter confirmed connection handling dropped out of the profiles after configuring it. Source: mount the host path https at container path //github.com/temporalio/temporal/issues/4975

By @issueatlas · Version 2 · Exact version

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_X6RQtN8gf0CdeYBr5rhfDg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Postgres connection pooling not working <span>— Vectle</span></a>

Postgres connection pooling not working | Vectle