: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 a session parameter the database doesn't define (#83686)
Tom Owersb0d9164ab62f
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 abb1382b3497..600a2c1727c6 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@@ -515,6 +515,21 @@ class PostgresSource(SQLSource[PostgresSourceConfig], SSHTunnelMixin, ValidateDa'(PostgreSQL reported "permission denied"). Grant the connecting role SELECT on those tables '"(for example: GRANT SELECT ON <table> TO <role>), then re-enable the sync."),+ # A custom "app.*" session GUC the connecting role doesn't set — raised (SQLSTATE 42704)+ # by a row-level security policy, view, or connection pooler that reads a per-session+ # setting the application is expected to set (e.g. `current_setting('app.client_id')`).+ # PostHog only ever sets standard parameters (client_encoding, statement_timeout,+ # DateStyle, idle_in_transaction_session_timeout), so an unrecognized `app.*` parameter is+ # always the customer's own setup and is permanent until they change it — retrying just+ # re-hits it. Match the stable "app." namespace prefix; the parameter name after it varies.+ 'unrecognized configuration parameter "app.': (+ "Your database expects a session setting that PostHog doesn't provide (PostgreSQL "+ 'reported "unrecognized configuration parameter"). This usually comes from a row-level '+ "security policy, view, or connection pooler that reads a custom setting (for example "+ "app.current_tenant). Make that setting optional in your database (for example with "+ "current_setting('setting_name', true)), or remove the affected tables from this sync, "+ "then re-enable the sync."+ ),# A row-level security policy on this table (or another table its policy queries) is# self-referential, so Postgres can't evaluate it and raises SQLSTATE 42P17 on every# read attempt. The raw psycopg message ("infinite recursion detected in policy fordiff --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 9620e63cc152..aa78c615cdd1 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@@ -418,6 +418,10 @@ class TestPostgresSourceNonRetryableErrors:# Newlines are normalized to spaces upstream, so the FATAL/DETAIL pair arrives on one line.# Permanent until the replica's config changes or it's promoted — must not keep retrying.'connection failed: connection to server at "10.0.0.1", port 5432 failed: FATAL: the database system is not accepting connections DETAIL: Hot standby mode is disabled.',+ # A custom app.* session GUC the connecting role doesn't set (SQLSTATE 42704), read by a+ # customer RLS policy, view, or pooler. Permanent until the customer changes it — must not+ # keep retrying. Parameter name is invented, not a real customer value.+ 'unrecognized configuration parameter "app.current_tenant"',],)def test_permanent_connection_errors_are_non_retryable(self, source, error_msg):@@ -425,6 +429,20 @@ class TestPostgresSourceNonRetryableErrors:is_non_retryable = any(pattern in error_msg for pattern in non_retryable.keys())assert is_non_retryable, f"Permanent error should be non-retryable: {error_msg}"+ def test_unrecognized_session_parameter_surfaces_actionable_message(self, source):+ # A missing custom app.* session setting must stop retrying and explain the pooler/RLS/view+ # source, rather than storing the raw driver text. Mirror the finalizer's first-match+ # selection so a future reorder that shadows it with an earlier None-valued key is caught.+ error_msg = 'unrecognized configuration parameter "app.current_tenant"'+ matches = [+ friendly+ for pattern, friendly in source.get_non_retryable_errors().items()+ if error_message_matches(error_msg, [pattern])+ ]+ assert matches, "unrecognized session parameter must be classified non-retryable"+ assert matches[0] is not None, "unrecognized session parameter must surface an actionable message"+ assert "session setting" in matches[0].lower()+def test_connect_timeout_surfaces_actionable_message(self, source):# A persistently timing-out connect stays non-retryable, but must surface firewall/reachability# guidance rather than the bare "connection timeout expired" driver text. Mirror the finalizer's