: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(postgres): treat pooler login failures as non-retryable (#63727)
Tom Owers28824e70916f
diff --git a/posthog/temporal/data_imports/sources/postgres/source.py b/posthog/temporal/data_imports/sources/postgres/source.pyindex 7ce7e882207e..c316dc83b36a 100644--- a/posthog/temporal/data_imports/sources/postgres/source.py+++ b/posthog/temporal/data_imports/sources/postgres/source.py@@ -241,6 +241,22 @@ class PostgresSource(SQLSource[PostgresSourceConfig], SSHTunnelMixin, ValidateDa"SSLRequiredError": None,"SSL/TLS connection is required": None,"Could not establish session to SSH gateway": None,+ # Surfaced by a connection pooler (e.g. PgBouncer) as a psycopg ProtocolViolation when+ # the pooler has *repeatedly* failed to log in to the backend database within its+ # server_login_retry window (full message: "server login has been failing, cached+ # error: <reason> (server_login_retry)"). By the time this is returned the backend is in+ # a sustained failure state — unreachable, refusing connections, or rejecting the+ # pooler's credentials — so it is not a one-off transient blip; retrying the whole sync+ # just hits the same wall. Matches the stable pooler signature; the cached <reason>+ # ("connect timeout", etc.) and the trailing "(server_login_retry)" suffix vary and are+ # excluded.+ "server login has been failing": (+ "Your database's connection pooler (for example PgBouncer) reported that it has "+ 'repeatedly failed to connect to the backend database ("server login has been '+ 'failing"). This usually means the database is unreachable, refusing connections, or '+ "the pooler's credentials for the database are wrong. Check that the database is "+ "running and reachable from your pooler, then re-enable the sync."+ ),# `offset_chunking` retries a Postgres standby recovery conflict ("canceling statement# due to conflict with recovery") 30 times in-process with backoff + chunk-size# reduction before raising this. The conflict comes from the customer's read replicadiff --git a/posthog/temporal/data_imports/sources/postgres/test_postgres.py b/posthog/temporal/data_imports/sources/postgres/test_postgres.pyindex 96fbc6bc22ad..e9ba964370ce 100644--- a/posthog/temporal/data_imports/sources/postgres/test_postgres.py+++ b/posthog/temporal/data_imports/sources/postgres/test_postgres.py@@ -261,6 +261,8 @@ class TestPostgresSourceNonRetryableErrors:# "Tenant or user not found connection to server" / "FATAL: Tenant or user not found"# patterns don't substring-match this, so it needs its own key.'connection failed: connection to server at "52.45.94.125", port 6543 failed: FATAL: (ENOTFOUND) tenant/user postgres.hksbxxtlcfeyyalgveif not found',+ "ProtocolViolation: server login has been failing, cached error: connect timeout (server_login_retry)",+ "server login has been failing, cached error: connection refused (server_login_retry)",],)def test_permanent_connection_errors_are_non_retryable(self, source, error_msg):