: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
feat(data-warehouse): list publication tables in CDC status (#64594)
Daniel RC211f33236c0f
diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.tsindex 4cb8baa1e6d9..ab8a13e2c713 100644--- a/frontend/src/lib/api.ts+++ b/frontend/src/lib/api.ts@@ -5872,6 +5872,7 @@ const api = {slot_exists?: booleanpublication_exists?: booleanlag_bytes?: number | null+ published_tables?: string[]}> {return await new ApiRequest().externalDataSource(sourceId).withAction('cdc_status').get()},diff --git a/posthog/temporal/data_imports/sources/postgres/cdc/adapter.py b/posthog/temporal/data_imports/sources/postgres/cdc/adapter.pyindex e6cc6000de3a..7d81b2ac7682 100644--- a/posthog/temporal/data_imports/sources/postgres/cdc/adapter.py+++ b/posthog/temporal/data_imports/sources/postgres/cdc/adapter.py@@ -16,6 +16,7 @@ from posthog.temporal.data_imports.sources.postgres.cdc.slot_manager import (drop_slot,drop_slot_and_publication,get_max_slot_wal_keep_size_mb,+ get_publication_tables,get_slot_lag_bytes,is_slot_invalidation_error,publication_exists,@@ -221,10 +222,16 @@ class PostgresCDCAdapter:publication_exists(conn, cdc_config.publication_name) if cdc_config.publication_name else False)lag_bytes = get_slot_lag_bytes(conn, cdc_config.slot_name) if cdc_config.slot_name else None+ published_tables = (+ get_publication_tables(conn, cdc_config.publication_name)+ if cdc_config.publication_name and pub_present+ else []+ )return {"slot_exists": slot_present,"publication_exists": pub_present,"lag_bytes": lag_bytes,+ "published_tables": published_tables,}def add_table(self, source: ExternalDataSource, schema: str, table: str) -> None:diff --git a/posthog/temporal/data_imports/sources/postgres/cdc/slot_manager.py b/posthog/temporal/data_imports/sources/postgres/cdc/slot_manager.pyindex 413aa97f4956..33434d45de6e 100644--- a/posthog/temporal/data_imports/sources/postgres/cdc/slot_manager.py+++ b/posthog/temporal/data_imports/sources/postgres/cdc/slot_manager.py@@ -272,3 +272,19 @@ def publication_exists(conn: psycopg.Connection, pub_name: str) -> bool:with conn.cursor() as cur:cur.execute(sql.SQL("SELECT 1 FROM pg_publication WHERE pubname = {}").format(sql.Literal(pub_name)))return cur.fetchone() is not None+++def get_publication_tables(conn: psycopg.Connection, pub_name: str) -> list[str]:+ """List the schema-qualified tables (``schema.table``) in a publication, sorted.++ Returns an empty list when the publication doesn't exist or has no tables.+ These are exactly the tables whose changes the replication slot streams.+ """+ with conn.cursor() as cur:+ cur.execute(+ sql.SQL(+ "SELECT schemaname, tablename FROM pg_publication_tables "+ "WHERE pubname = {} ORDER BY schemaname, tablename"+ ).format(sql.Literal(pub_name))+ )+ return [f"{schemaname}.{tablename}" for schemaname, tablename in cur.fetchall()]diff --git a/posthog/temporal/data_imports/sources/postgres/cdc/tests/test_adapter.py b/posthog/temporal/data_imports/sources/postgres/cdc/tests/test_adapter.pyindex ddf3395760ce..3382cf9e4642 100644--- a/posthog/temporal/data_imports/sources/postgres/cdc/tests/test_adapter.py+++ b/posthog/temporal/data_imports/sources/postgres/cdc/tests/test_adapter.py@@ -202,3 +202,33 @@ class TestAlterPublicationMembership:source = _source(cdc_enabled=True, cdc_management_mode="posthog")PostgresCDCAdapter().add_table(source, "public", "orders")mock_add.assert_not_called()+++class TestGetStatus:+ @patch(f"{_ADAPTER}.get_publication_tables", return_value=["public.orders", "public.users"])+ @patch(f"{_ADAPTER}.get_slot_lag_bytes", return_value=42)+ @patch(f"{_ADAPTER}.publication_exists", return_value=True)+ @patch(f"{_ADAPTER}.slot_exists", return_value=True)+ @patch(f"{_ADAPTER}.cdc_pg_connection", new_callable=_fake_conn)+ def test_includes_published_tables(self, _conn, _slot, _pub, _lag, mock_tables) -> None:+ source = _source(cdc_enabled=True, cdc_slot_name="slot", cdc_publication_name="pub")+ status = PostgresCDCAdapter().get_status(source)+ assert status == {+ "slot_exists": True,+ "publication_exists": True,+ "lag_bytes": 42,+ "published_tables": ["public.orders", "public.users"],+ }+ mock_tables.assert_called_once()+ assert mock_tables.call_args.args[1] == "pub"++ @patch(f"{_ADAPTER}.get_publication_tables")+ @patch(f"{_ADAPTER}.get_slot_lag_bytes", return_value=None)+ @patch(f"{_ADAPTER}.publication_exists", return_value=False)+ @patch(f"{_ADAPTER}.slot_exists", return_value=False)+ @patch(f"{_ADAPTER}.cdc_pg_connection", new_callable=_fake_conn)+ def test_skips_table_lookup_when_publication_missing(self, _conn, _slot, _pub, _lag, mock_tables) -> None:+ source = _source(cdc_enabled=True, cdc_slot_name="slot", cdc_publication_name="pub")+ status = PostgresCDCAdapter().get_status(source)+ assert status["published_tables"] == []+ mock_tables.assert_not_called()diff --git a/posthog/temporal/data_imports/sources/postgres/cdc/tests/test_slot_manager.py b/posthog/temporal/data_imports/sources/postgres/cdc/tests/test_slot_manager.pyindex 8047d9831f43..1677351bb31a 100644--- a/posthog/temporal/data_imports/sources/postgres/cdc/tests/test_slot_manager.py+++ b/posthog/temporal/data_imports/sources/postgres/cdc/tests/test_slot_manager.py@@ -14,6 +14,7 @@ from posthog.temporal.data_imports.sources.postgres.cdc.slot_manager import (add_table_to_publication,cdc_pg_connection,get_max_slot_wal_keep_size_mb,+ get_publication_tables,is_slot_invalidation_error,remove_table_from_publication,)@@ -129,6 +130,21 @@ class TestGetMaxSlotWalKeepSizeMb:assert get_max_slot_wal_keep_size_mb(conn) == expected+class TestGetPublicationTables:+ @parameterized.expand(+ [+ ("with_tables", [("public", "orders"), ("analytics", "events")], ["public.orders", "analytics.events"]),+ ("empty_publication", [], []),+ ]+ )+ def test_returns_schema_qualified_tables(self, _name, fetchall, expected):+ conn, cursor = _mock_conn()+ cursor.fetchall.return_value = fetchall++ assert get_publication_tables(conn, pub_name="my_pub") == expected+ assert "pg_publication_tables" in str(cursor.execute.call_args[0][0])++class TestRemoveTableFromPublication:def test_remove_table_success(self):conn, cursor = _mock_conn()diff --git a/products/data_warehouse/frontend/scenes/SourceScene/tabs/CDCSection.tsx b/products/data_warehouse/frontend/scenes/SourceScene/tabs/CDCSection.tsxindex 561745dcca08..0793f81d30ef 100644--- a/products/data_warehouse/frontend/scenes/SourceScene/tabs/CDCSection.tsx+++ b/products/data_warehouse/frontend/scenes/SourceScene/tabs/CDCSection.tsx@@ -333,6 +333,27 @@ function EnabledControls({ source }: { source: ExternalDataSource }): JSX.Elemen: 'The publication is missing on your database — recreate it (self-managed) or disable and re-enable CDC (PostHog-managed).'}</LemonBanner>)}+ {status?.publication_exists && (+ <div className="mt-3">+ <div className="text-secondary text-xs mb-1">+ Replicated tables {status.published_tables ? `(${status.published_tables.length})` : ''}+ </div>+ {status.published_tables && status.published_tables.length > 0 ? (+ <div className="flex flex-wrap gap-1">+ {status.published_tables.map((table: string) => (+ <LemonTag key={table} type="muted">+ <code className="text-xs">{table}</code>+ </LemonTag>+ ))}+ </div>+ ) : (+ <p className="text-xs text-secondary m-0">+ No tables are in the publication yet — pick CDC as the sync type on the Schemas tab to+ add one.+ </p>+ )}+ </div>+ )}</div><LemonDivider />diff --git a/products/data_warehouse/frontend/scenes/SourceScene/tabs/sourceSettingsLogic.ts b/products/data_warehouse/frontend/scenes/SourceScene/tabs/sourceSettingsLogic.tsindex 501bf34ec02a..821493e3c023 100644--- a/products/data_warehouse/frontend/scenes/SourceScene/tabs/sourceSettingsLogic.ts+++ b/products/data_warehouse/frontend/scenes/SourceScene/tabs/sourceSettingsLogic.ts@@ -45,6 +45,7 @@ export interface CdcStatus {slot_exists?: booleanpublication_exists?: booleanlag_bytes?: number | null+ published_tables?: string[]}const REFRESH_INTERVAL = 5000