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): treat SASL authentication failure as non-retryable (#64373)

Tom Owersa12b75f6752c
diff --git a/posthog/temporal/data_imports/sources/postgres/source.py b/posthog/temporal/data_imports/sources/postgres/source.py
index ed6541f50a46..37c9bac11485 100644
--- a/posthog/temporal/data_imports/sources/postgres/source.py
+++ b/posthog/temporal/data_imports/sources/postgres/source.py
@@ -210,6 +210,21 @@ class PostgresSource(SQLSource[PostgresSourceConfig], SSHTunnelMixin, ValidateDa
"and the connection details are correct, then re-enable the sync."
),
"error received from server in SCRAM exchange: Wrong password": None,
+ # The server (commonly Supabase's Supavisor transaction pooler on port 6543) rejects the
+ # SASL/SCRAM credential exchange with "FATAL: SASL authentication failed" instead of
+ # PostgreSQL's "password authentication failed for user" — so none of the password keys
+ # above substring-match it and Temporal keeps retrying a credential mismatch that only the
+ # customer can fix. It surfaces alone via `str(e)`: when `options` is rejected first, the
+ # no-`options` reconnect raises this and the "unsupported startup parameter: options"
+ # error is only its chained context (which `str(e)` drops). Auth rejection is
+ # deterministic, never a transient blip, so stop retrying.
+ "SASL authentication failed": (
+ "Your database rejected the credentials during authentication "
+ '("SASL authentication failed"). This usually means the username or password is '
+ "wrong. Some connection poolers (for example Supabase's transaction pooler) also "
+ "require a pooler-specific username such as postgres.<project-ref>. Check your "
+ "credentials, then re-enable the sync."
+ ),
"could not translate host name": None,
"timeout expired connection to server at": None,
"password authentication failed for user": None,
diff --git a/posthog/temporal/data_imports/sources/postgres/test_postgres.py b/posthog/temporal/data_imports/sources/postgres/test_postgres.py
index 2d9b51178b2c..accdfa941323 100644
--- a/posthog/temporal/data_imports/sources/postgres/test_postgres.py
+++ b/posthog/temporal/data_imports/sources/postgres/test_postgres.py
@@ -349,6 +349,35 @@ class TestPostgresSourceNonRetryableErrors:
assert "password authentication failed for user" not in error_msg
assert any(pattern in error_msg for pattern in non_retryable.keys())
+ @pytest.mark.parametrize(
+ "error_msg",
+ [
+ # Supabase's Supavisor transaction pooler (port 6543) rejects bad credentials with
+ # "FATAL: SASL authentication failed" rather than PostgreSQL's "password authentication
+ # failed for user". When `options` is rejected first, this is the message that propagates
+ # via str(e) (the options error is only the chained context). Host/port are volatile.
+ 'connection failed: connection to server at "52.57.91.216", port 6543 failed: FATAL: SASL authentication failed connection to server at "52.57.91.216", port 6543 failed: FATAL: SASL authentication failed',
+ 'OperationalError: connection failed: connection to server at "10.0.0.1", port 6543 failed: FATAL: SASL authentication failed',
+ ],
+ )
+ def test_sasl_authentication_failed_is_non_retryable(self, source, error_msg):
+ # The PostgreSQL "password authentication failed for user" key doesn't substring-match the
+ # pooler's SASL wording, so confirm the dedicated key recognises it independent of host/port.
+ non_retryable = source.get_non_retryable_errors()
+ assert "SASL authentication failed" in non_retryable
+ assert "password authentication failed for user" not in error_msg
+ assert any(pattern in error_msg for pattern in non_retryable.keys())
+
+ def test_sasl_authentication_failed_returns_friendly_message(self, source):
+ non_retryable = source.get_non_retryable_errors()
+ error_msg = (
+ 'connection failed: connection to server at "52.57.91.216", port 6543 failed: '
+ "FATAL: SASL authentication failed"
+ )
+ friendly = [reason for pattern, reason in non_retryable.items() if pattern in error_msg and reason]
+ assert friendly, "SASL authentication failure should surface an actionable message"
+ assert "credentials" in friendly[0]
+
def test_supavisor_enotfound_tenant_user_uses_new_key(self, source):
# The older tenant/user patterns don't cover the newer "(ENOTFOUND) tenant/user" wording,
# so confirm it's specifically the new key that recognises this message.