Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(postgres): map saturated session-mode pooler to a friendly message (#64082)

Tom Owers289dd86f8100
diff --git a/posthog/temporal/data_imports/sources/postgres/source.py b/posthog/temporal/data_imports/sources/postgres/source.py
index 6390232c93b8..ed6541f50a46 100644
--- a/posthog/temporal/data_imports/sources/postgres/source.py
+++ b/posthog/temporal/data_imports/sources/postgres/source.py
@@ -71,6 +71,21 @@ PostgresErrors = {
# transient mid-stream drop in the streaming path (`_CONNECTION_DROPPED_ERROR_SUBSTRINGS`) and
# must stay retryable there.
"server closed the connection unexpectedly": "Your database closed the connection unexpectedly while connecting. This usually means the host or port is wrong, the server requires SSL/TLS, or a connection pooler, firewall, or SSH tunnel dropped the connection. Check your host, port, and SSL settings.",
+ # Supabase/Supavisor reports a saturated session-mode pooler as
+ # "FATAL: (EMAXCONNSESSION) max clients reached in session mode - max clients are limited to
+ # pool_size: <n>". Every client slot the pooler exposes is in use, so it refuses new connections
+ # until one frees up — a config/capacity condition on the customer's pooler, not a PostHog bug.
+ # Map it to an actionable message so credential validation stops surfacing it as captured error
+ # noise. The volatile pool_size number and the "(EMAXCONNSESSION)" code prefix are excluded from
+ # the match. NB: this is intentionally NOT added to `get_non_retryable_errors` — pooler
+ # saturation is transient (it clears once connections are returned to the pool), so the streaming
+ # path must keep retrying it. See `test_transient_connection_errors_are_retryable`.
+ "max clients reached in session mode": (
+ "Your database's connection pooler has no free client connections "
+ '("max clients reached in session mode"). Raise the pooler\'s client limit (for example '
+ "increase pool_size, or switch it to transaction mode) or reduce the number of concurrent "
+ "connections to your database, then try again."
+ ),
}
diff --git a/posthog/temporal/data_imports/sources/postgres/test_postgres.py b/posthog/temporal/data_imports/sources/postgres/test_postgres.py
index d44946c4b409..2d9b51178b2c 100644
--- a/posthog/temporal/data_imports/sources/postgres/test_postgres.py
+++ b/posthog/temporal/data_imports/sources/postgres/test_postgres.py
@@ -1343,6 +1343,17 @@ class TestValidateCredentialsErrorMapping:
"or port is wrong, the server requires SSL/TLS, or a connection pooler, firewall, or SSH tunnel "
"dropped the connection. Check your host, port, and SSL settings.",
),
+ # Supabase/Supavisor session-mode pooler with no free client slots. The pool_size number
+ # is volatile, so the match is on the stable "max clients reached in session mode" phrase.
+ (
+ 'connection failed: connection to server at "52.45.94.125", port 5432 failed: '
+ "FATAL: (EMAXCONNSESSION) max clients reached in session mode - max clients are "
+ "limited to pool_size: 15",
+ "Your database's connection pooler has no free client connections (\"max clients "
+ "reached in session mode\"). Raise the pooler's client limit (for example increase "
+ "pool_size, or switch it to transaction mode) or reduce the number of concurrent "
+ "connections to your database, then try again.",
+ ),
# Unmapped errors fall back to the generic message.
(
"some brand new failure",