Skip to content

: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.

fix(postgres): handle unrecognized max_replication_slots parameter in CDC check (#130299)

Tom Owers702f893b72d3
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/cdc/prerequisite_validator.py b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/cdc/prerequisite_validator.py
index ce385f4dda24..8e89f4f7bba7 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/cdc/prerequisite_validator.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/cdc/prerequisite_validator.py
@@ -265,7 +265,19 @@ def _check_replication_role(conn: psycopg.Connection) -> list[str]:
def _check_replication_slot_capacity(conn: psycopg.Connection) -> list[str]:
"""Check if there's capacity for a new replication slot."""
with conn.cursor() as cur:
- cur.execute("SHOW max_replication_slots")
+ try:
+ cur.execute("SHOW max_replication_slots")
+ except psycopg.errors.UndefinedObject:
+ # Twin of the `_check_wal_level` guard above: a pooler or wire-compatible database
+ # that doesn't expose this parameter can't support logical replication CDC either.
+ conn.rollback()
+ return [
+ "This database doesn't expose the max_replication_slots setting, so it can't "
+ "support logical replication CDC. This usually means the connection goes through "
+ "a pooler (such as PgBouncer in transaction mode) or to a database that isn't a "
+ "logical-replication-capable PostgreSQL. Connect directly to the primary "
+ "PostgreSQL server, or switch these tables to Incremental sync."
+ ]
max_row = cur.fetchone()
if max_row is None:
return ["Could not determine max_replication_slots."]
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/cdc/tests/test_prerequisite_validator.py b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/cdc/tests/test_prerequisite_validator.py
index 9b32a25d3e27..e6a3cacec4c0 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/cdc/tests/test_prerequisite_validator.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/cdc/tests/test_prerequisite_validator.py
@@ -181,6 +181,22 @@ class TestValidateCDCPrerequisites:
errors = validate_cdc_prerequisites(conn=conn, management_mode="posthog", tables=["users"])
assert any("capacity" in e for e in errors)
+ def test_max_replication_slots_unrecognized_parameter(self):
+ # Same class of failure as test_wal_level_unrecognized_parameter: a pooler or
+ # wire-compatible database that doesn't expose max_replication_slots must surface a
+ # graceful prerequisite error, not crash the whole validation.
+ conn = _mock_conn(
+ [_PG_15, _WAL_LOGICAL, _HAS_PK, _HAS_REPL_ROLE],
+ raise_on={
+ "max_replication_slots": psycopg.errors.UndefinedObject(
+ 'unrecognized configuration parameter "max_replication_slots"'
+ )
+ },
+ )
+ errors = validate_cdc_prerequisites(conn=conn, management_mode="posthog", tables=["users"])
+ assert any("logical replication CDC" in e for e in errors)
+ conn.rollback.assert_called()
+
def test_self_managed_no_slot_name_is_ok(self):
# PostHog creates the slot — slot_name omission is fine in self-managed.
conn = _mock_conn([_PG_15, _WAL_LOGICAL, _HAS_PK, _HAS_REPL_ROLE, _MAX_SLOTS_10, _SLOT_COUNT_2, _PUB_EXISTS])