: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): stop retrying an explicit pg_hba.conf rejection (#123473)
Tom Owers1eee66127dfb
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/source.pyindex 5773fa0fbcec..7e653b52a5de 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/source.py@@ -928,6 +928,17 @@ class PostgresSource('("no pg_hba.conf entry for host"). Add an entry that permits the connecting host, '"user, and database (over SSL or otherwise), then re-enable the sync."),+ # The matching sibling of the entry above: a pg_hba.conf line *does* match the connecting+ # host/user/database, but its auth method is explicitly "reject" — "FATAL: pg_hba.conf+ # rejects connection for host <host>, user <user>, database <database>, SSL encryption"+ # (and its "no encryption" sibling). Same administrator-authored rule, same permanence:+ # every retry reaches the same explicit rejection until the customer changes the rule.+ # Match the stable prefix and exclude the volatile host/user/database.+ "pg_hba.conf rejects connection for host": (+ "Your PostgreSQL server's pg_hba.conf explicitly rejects this connection "+ '("pg_hba.conf rejects connection for host"). Update the matching rule to allow the '+ "connecting host, user, and database (over SSL or otherwise), then re-enable the sync."+ ),"could not translate host name": _DNS_RESOLUTION_ERROR,"timeout expired connection to server at": None,"password authentication failed for user": _INVALID_CREDENTIALS_ERROR,diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/test_postgres.py b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/test_postgres.pyindex ac2ece4171c4..6198efa783da 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/test_postgres.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/test_postgres.py@@ -894,6 +894,40 @@ class TestPostgresSourceNonRetryableErrors:assert friendly, "Missing pg_hba.conf entry error should surface an actionable message"assert "pg_hba.conf" in friendly[0]+ @pytest.mark.parametrize(+ "error_msg",+ [+ # Raw psycopg message: a pg_hba.conf line matches the host/user/database but its auth+ # method is "reject", the explicit-rule sibling of "no pg_hba.conf entry for host" above.+ # libpq concatenates the SSL and no-encryption attempts when sslmode=prefer retries after+ # the SSL attempt is rejected; the host/user/database are volatile, the phrase is stable.+ 'connection failed: connection to server at "203.0.113.10", port 5432 failed: FATAL: '+ 'pg_hba.conf rejects connection for host "10.9.8.7", user "reporting_ro", database '+ '"analytics", SSL encryption\nconnection to server at "203.0.113.10", port 5432 failed: '+ 'FATAL: pg_hba.conf rejects connection for host "10.9.8.7", user "reporting_ro", '+ 'database "analytics", no encryption',+ # Temporal-wrapped message (what the workflow-level check sees) — carries the class name.+ 'OperationalError: connection failed: connection to server at "10.0.0.5", port 5432 '+ 'failed: FATAL: pg_hba.conf rejects connection for host "10.0.0.5", user "postgres", '+ 'database "app", no encryption',+ ],+ )+ def test_pg_hba_conf_rejects_connection_is_non_retryable(self, source, error_msg):+ non_retryable = source.get_non_retryable_errors()+ is_non_retryable = any(pattern in error_msg for pattern in non_retryable.keys())+ assert is_non_retryable, f"Explicit pg_hba.conf rejection should be non-retryable: {error_msg}"++ def test_pg_hba_conf_rejects_connection_returns_friendly_message(self, source):+ non_retryable = source.get_non_retryable_errors()+ error_msg = (+ 'connection failed: connection to server at "203.0.113.10", port 5432 failed: FATAL: '+ 'pg_hba.conf rejects connection for host "10.9.8.7", user "reporting_ro", database '+ '"analytics", no encryption'+ )+ friendly = [reason for pattern, reason in non_retryable.items() if pattern in error_msg and reason]+ assert friendly, "Explicit pg_hba.conf rejection should surface an actionable message"+ assert "pg_hba.conf" in friendly[0]+@pytest.mark.parametrize("error_msg,expected_fragment",[