: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 unlogged table read on a read replica (#101400)
Tom Owers97725d781d58
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 719fc6b268e2..46bcee0e137f 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@@ -899,6 +899,20 @@ class PostgresSource(SQLSource[PostgresSourceConfig], SSHTunnelMixin, ValidateDa"Enable hot_standby on the replica and restart it, or point this source at the primary ""database, then re-enable the sync."),+ # Postgres refuses to scan a temporary or unlogged relation on a hot standby:+ # SQLSTATE 0A000 "cannot access temporary or unlogged relations during recovery".+ # Neither relation type is WAL-logged, so a physical replica never receives their+ # data — this is permanent for as long as the relation stays temporary/unlogged and+ # the connection stays pointed at a standby, unlike "the database system is starting+ # up" above (kept retryable there because it comes from a server not yet accepting+ # connections at all, a condition that clears on its own). Match the stable Postgres+ # message verbatim; it names no volatile detail.+ "cannot access temporary or unlogged relations during recovery": (+ "This relation is temporary or unlogged, and PostgreSQL doesn't replicate temporary "+ 'or unlogged relations to read replicas ("cannot access temporary or unlogged '+ 'relations during recovery"). Point this source at the primary database. If this is '+ "an unlogged table, change it to a regular (logged) table, then re-enable the sync."+ ),# SQLSTATE 57P03 with the message "database <name> is not currently accepting connections":# the server is up (it answered with a FATAL) but the target database has datallowconn# turned off, or a managed provider has paused/suspended it (e.g. an inactive Supabasediff --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 bbb6e6b75e06..863f83c19cf0 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@@ -1652,6 +1652,29 @@ class TestPostgresSourceNonRetryableErrors:is_non_retryable = any(pattern in error_msg for pattern in non_retryable.keys())assert is_non_retryable, f"Exhausted recovery-conflict abort should be non-retryable: {error_msg}"+ @pytest.mark.parametrize(+ "error_msg",+ [+ # Raw psycopg message (what the activity-level check sees via str(e)).+ "cannot access temporary or unlogged relations during recovery",+ # Temporal-wrapped message (what the workflow-level check sees) — carries the class name.+ "FeatureNotSupported: cannot access temporary or unlogged relations during recovery",+ ],+ )+ def test_unlogged_table_on_read_replica_is_non_retryable(self, source, error_msg):+ # An unlogged table is never replicated to a standby, so every retry re-hits the same+ # SQLSTATE 0A000 wall — must not keep retrying.+ 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"Unlogged-table-on-standby error should be non-retryable: {error_msg}"++ def test_unlogged_table_on_read_replica_returns_friendly_message(self, source):+ non_retryable = source.get_non_retryable_errors()+ error_msg = "cannot access temporary or unlogged relations during recovery"+ friendly = [reason for pattern, reason in non_retryable.items() if pattern in error_msg and reason]+ assert friendly, "Unlogged-table-on-standby error should surface an actionable message"+ assert "unlogged" in friendly[0]+class TestPostgresSourceRetryableErrors:@pytest.fixture