: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): tell users when their database user can't sign in (#115031)
Tom Owersa4da88e98046
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 bde0124a2d90..f322fe0b8a7f 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@@ -130,6 +130,13 @@ _INVALID_CREDENTIALS_ERROR = ("this source, then re-enable the sync.")+# The role exists but has NOLOGIN, the default for a role made with CREATE ROLE. libpq prefixes+# the refusal with the customer's host and port, so the raw text names nothing they can act on.+_ROLE_CANNOT_LOG_IN_ERROR = (+ "Your database user isn't allowed to sign in. Grant it the LOGIN privilege or use a different "+ "user, then re-enable the sync."+)+# A DNS-resolution failure for the database host, surfaced by libpq ("could not translate host# name") or the raw socket wording ("Name or service not known" / "No address associated with# hostname"). Already non-retryable, but the bare driver text gives the customer nothing to act on,@@ -591,7 +598,7 @@ class PostgresSource("XminUnsupportedError": None,"xmin replication": None,"NoSuchTableError": None,- "is not permitted to log in": None,+ "is not permitted to log in": _ROLE_CANNOT_LOG_IN_ERROR,"Tenant or user not found connection to server": None,"FATAL: Tenant or user not found": None,# Newer Supabase/Supavisor poolers report a missing tenant/user with a differentdiff --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 0edd6a0d2aac..9586a05d5409 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@@ -566,19 +566,27 @@ class TestPostgresSourceNonRetryableErrors:assert matches[0] is not None, "connect timeout must surface an actionable message, not raw driver text"assert "firewall" in matches[0].lower()- def test_database_not_accepting_connections_surfaces_actionable_message(self, source):- # A paused/disallowed database must stop retrying and tell the customer to restore it,- # rather than storing the raw driver text (which echoes the host, IP, and database name).- # Mirror the finalizer's first-match selection so a future reorder that shadows it with an- # earlier None-valued key is caught. Host/db are invented, not a real value.- error_msg = 'connection failed: connection to server at "db.example.com", port 5432 failed: FATAL: database "postgres" is not currently accepting connections'+ @pytest.mark.parametrize(+ "error_msg",+ [+ 'connection failed: connection to server at "db.example.com", port 5432 failed: FATAL: database "postgres" is not currently accepting connections',+ # A role without the LOGIN privilege.+ 'connection failed: connection to server at "db.example.com", port 5432 failed: FATAL: role "example_user" is not permitted to log in',+ ],+ )+ def test_connection_refusal_surfaces_actionable_message(self, source, error_msg):+ # A paused/disallowed database or a role that can't log in must stop retrying and tell the+ # customer what to fix, rather than storing the raw driver text (which echoes the host, IP,+ # and database or role name). Mirror the finalizer's first-match selection so a future+ # reorder that shadows it with an earlier None-valued key is caught. Hosts, databases and+ # roles are invented, not real values.matches = [friendlyfor pattern, friendly in source.get_non_retryable_errors().items()if error_message_matches(error_msg, [pattern])]- assert matches, "a database not accepting connections must be classified non-retryable"- assert matches[0] is not None, "a database not accepting connections must surface an actionable message"+ assert matches, "a connection refusal must be classified non-retryable"+ assert matches[0] is not None, "a connection refusal must surface an actionable message"assert "re-enable the sync" in matches[0].lower()assert "db.example.com" not in matches[0]