: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 syncs pg_hba.conf permanently rejects (#100122)
Tom Owers16f0d95fc2a0
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 e7dd8e40f119..d43f2415cd9b 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@@ -500,6 +500,19 @@ class PostgresSource(SQLSource[PostgresSourceConfig], SSHTunnelMixin, ValidateDa"through PAM (for example against the system password database or LDAP), and it ""rejected the username or password. Check your credentials, then re-enable the sync."),+ # Postgres's host-based access control (pg_hba.conf) rejects the connecting host/user/+ # database combination outright, before password auth is even attempted: "FATAL: no+ # pg_hba.conf entry for host <host>, user <user>, database <database>, SSL encryption"+ # (and its "no encryption" sibling, when sslmode=prefer retries without TLS after the+ # SSL attempt is rejected the same way). This is the server administrator's own access+ # rule, not a transient condition — every retry reaches the same rule until the customer+ # adds a matching pg_hba.conf entry. Match the stable prefix and exclude the volatile+ # host/user/database.+ "no pg_hba.conf entry for host": (+ "Your PostgreSQL server's pg_hba.conf doesn't have a rule allowing this connection "+ '("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."+ ),"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 cddffc43008b..beebaf9a2819 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@@ -729,6 +729,39 @@ class TestPostgresSourceNonRetryableErrors:assert friendly, "Invalid SSL-negotiation response should surface an actionable message"assert "host and port" in friendly[0]+ @pytest.mark.parametrize(+ "error_msg",+ [+ # Raw psycopg message (what the activity-level check sees via str(e)). libpq concatenates+ # the SSL and no-encryption attempts into one message when sslmode=prefer retries after the+ # SSL attempt is rejected; the host/user/database are volatile, the pg_hba.conf phrase is+ # stable.+ 'connection failed: connection to server at "127.0.0.1", port 36079 failed: FATAL: no '+ 'pg_hba.conf entry for host "172.31.4.66", user "postgres", database "peak_staging_db", '+ 'SSL encryption\nconnection to server at "127.0.0.1", port 36079 failed: FATAL: no '+ 'pg_hba.conf entry for host "172.31.4.66", user "postgres", database "peak_staging_db", '+ "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: no pg_hba.conf entry for host "10.0.0.5", user "postgres", database "app", no encryption',+ ],+ )+ def test_no_pg_hba_conf_entry_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"Missing pg_hba.conf entry error should be non-retryable: {error_msg}"++ def test_no_pg_hba_conf_entry_returns_friendly_message(self, source):+ non_retryable = source.get_non_retryable_errors()+ error_msg = (+ 'connection failed: connection to server at "127.0.0.1", port 36079 failed: FATAL: no '+ 'pg_hba.conf entry for host "172.31.4.66", user "postgres", database "peak_staging_db", '+ "no encryption"+ )+ friendly = [reason for pattern, reason in non_retryable.items() if pattern in error_msg and reason]+ 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",[