: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(warehouse): add per-table xmin sync radio (flag-gated) (#64718)
Daniel RCa625773028a4
diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsxindex b57be4888e15..2457ecc1d1ae 100644--- a/frontend/src/lib/constants.tsx+++ b/frontend/src/lib/constants.tsx@@ -197,7 +197,6 @@ export const FEATURE_FLAGS = {BATCH_EXPORTS_POSTHOG_HTTP: 'posthog-http-batch-exports', // owner: #team-batch-exportsBILLING_SKIP_FORECASTING: 'billing-skip-forecasting', // owner: @zachBOX_PLOT_INSIGHT: 'box-plot-insight', // owner: @pauldambra #team-product-analytics- METRIC_INSIGHT: 'metric-insight', // owner: @sampennington #team-product-analyticsCALENDAR_HEATMAP_INSIGHT: 'calendar-heatmap-insight', // owner: @jabahamondes #team-web-analyticsCOOKIELESS_SERVER_HASH_MODE_SETTING: 'cookieless-server-hash-mode-setting', // owner: #team-web-analyticsEXPERIMENT_INTERVAL_TIMESERIES: 'experiments-interval-timeseries', // owner: @jurajmajerik #team-experiments@@ -209,6 +208,7 @@ export const FEATURE_FLAGS = {IMPROVED_COOKIELESS_MODE: 'improved-cookieless-mode', // owner: #team-web-analyticsLINEAGE_DEPENDENCY_VIEW: 'lineage-dependency-view', // owner: #team-data-modelingMEMBERS_CAN_USE_PERSONAL_API_KEYS: 'members-can-use-personal-api-keys', // owner: @yasen-posthog #team-platform-features+ METRIC_INSIGHT: 'metric-insight', // owner: @sampennington #team-product-analyticsPERSONLESS_EVENTS_NOT_SUPPORTED: 'personless-events-not-supported', // owner: #team-analytics-platformQUERY_RUNNING_TIME: 'query_running_time', // owner: #team-analytics-platformREPLAY_HOGQL_FILTERS: 'replay-hogql-filters', // owner: @pauldambra #team-replay@@ -284,6 +284,7 @@ export const FEATURE_FLAGS = {DWH_FREE_SYNCS: 'dwh-free-syncs', // owner: @Gilbert09 #team-warehouse-sourcesDWH_JOIN_TABLE_PREVIEW: 'dwh-join-table-preview', // owner: @arthurdedeus #team-customer-analyticsDWH_POSTGRES_CDC: 'dwh-postgres-cdc', // owner: #team-warehouse-sources+ DWH_POSTGRES_XMIN: 'dwh-postgres-xmin', // owner: #team-warehouse-sourcesDWH_SOURCE_METRICS: 'dwh-source-metrics', // owner: #team-warehouse-sourcesEDITOR_DRAFTS: 'editor-drafts', // owner: @EDsCODE #team-data-toolsENDPOINTS: 'embedded-analytics', // owner: @sakce #team-clickhousediff --git a/frontend/src/types.ts b/frontend/src/types.tsindex 4e1fd7bcfc02..d7785e612e49 100644--- a/frontend/src/types.ts+++ b/frontend/src/types.ts@@ -6082,7 +6082,7 @@ export interface SimpleExternalDataSourceSchema {label: string | nullshould_sync: booleanlast_synced_at?: Dayjs- sync_type?: 'full_refresh' | 'incremental' | 'append' | 'webhook' | 'cdc' | null+ sync_type?: 'full_refresh' | 'incremental' | 'append' | 'webhook' | 'cdc' | 'xmin' | null}export interface AvailableColumn {@@ -6111,6 +6111,7 @@ export type SchemaIncrementalFieldsResponse = {available_columns: AvailableColumn[]detected_primary_keys: string[] | nullcdc_available?: boolean+ xmin_available?: boolean}// numeric is snowflake specific and objectid is mongodb specific@@ -6136,11 +6137,12 @@ export interface ExternalDataSourceSyncSchema {/** Seconds subtracted from the incremental watermark at sync time to re-read a rolling overlap* window (catches late/backdated rows). Timestamp/date incremental fields only. */incremental_field_lookback_seconds?: number | null- sync_type: 'full_refresh' | 'incremental' | 'append' | 'webhook' | 'cdc' | null+ sync_type: 'full_refresh' | 'incremental' | 'append' | 'webhook' | 'cdc' | 'xmin' | nullincremental_fields: IncrementalField[]incremental_available: booleanappend_available: booleancdc_available?: boolean+ xmin_available?: booleancdc_table_mode?: 'consolidated' | 'cdc_only' | 'both'supports_webhooks: boolean/** True when the resource has no API list endpoint and can only be populated via webhooks@@ -6178,7 +6180,7 @@ export interface ExternalDataSourceSyncSchema {export interface ExternalDataSourceSchema extends SimpleExternalDataSourceSchema {table?: SimpleDataWarehouseTableincremental: boolean- sync_type: 'incremental' | 'full_refresh' | 'append' | 'webhook' | 'cdc' | null+ sync_type: 'incremental' | 'full_refresh' | 'append' | 'webhook' | 'cdc' | 'xmin' | nullsync_time_of_day: string | nullstatus?: ExternalDataSchemaStatuslatest_error: string | nulldiff --git a/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardLogic.tsx b/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardLogic.tsxindex 1bab917a0d86..cd65e936a976 100644--- a/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardLogic.tsx+++ b/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardLogic.tsx@@ -1138,6 +1138,9 @@ export const sourceWizardLogic = kea<sourceWizardLogicType>([const incrementalTables = values.databaseSchema.filter((schema) => schema.should_sync && schema.sync_type === 'incremental')+ const xminTables = values.databaseSchema.filter(+ (schema) => schema.should_sync && schema.sync_type === 'xmin'+ )const fullRefreshTables = values.databaseSchema.filter((schema) => schema.should_sync && schema.sync_type === 'full_refresh')@@ -1178,6 +1181,18 @@ export const sourceWizardLogic = kea<sourceWizardLogicType>([<span className="font-mono text-xs">updated_at</span>.</div>+ {/* xmin - Good */}+ {xminTables.length > 0 && (+ <>+ <div className="font-bold text-success">xmin</div>+ <div>+ <span className="text-muted">{tableCountFormatter(xminTables.length)}</span> — Syncs+ only changed rows using Postgres' internal{' '}+ <span className="font-mono text-xs">xmin</span> column. No cursor field required.+ </div>+ </>+ )}+{/* Append-only - Caution */}<div className="font-bold text-warning">Append-only</div><div>diff --git a/products/data_warehouse/frontend/scenes/SchemaScene/ConfigurationTab.tsx b/products/data_warehouse/frontend/scenes/SchemaScene/ConfigurationTab.tsxindex d0880c2cd4d2..d47c06f4dd04 100644--- a/products/data_warehouse/frontend/scenes/SchemaScene/ConfigurationTab.tsx+++ b/products/data_warehouse/frontend/scenes/SchemaScene/ConfigurationTab.tsx@@ -358,7 +358,7 @@ function SyncMethodSection({cdcTableMode?: 'consolidated' | 'cdc_only' | 'both',incrementalFieldLookbackSeconds?: number | null): Promise<void> => {- const noIncrementalField = syncType === 'full_refresh' || syncType === 'cdc'+ const noIncrementalField = syncType === 'full_refresh' || syncType === 'cdc' || syncType === 'xmin'setSaving(true)try {await api.externalDataSchemas.update(schema.id, {@@ -413,6 +413,7 @@ function SyncMethodSection({incremental_available: schemaIncrementalFields.incremental_available,append_available: schemaIncrementalFields.append_available,cdc_available: schemaIncrementalFields.cdc_available,+ xmin_available: schemaIncrementalFields.xmin_available,cdc_table_mode: schema.cdc_table_mode,incremental_fields: schemaIncrementalFields.incremental_fields,supports_webhooks: schemaIncrementalFields.supports_webhooks ?? false,@@ -860,7 +861,7 @@ function DangerZoneSection({deleteTable: (schema: ExternalDataSourceSchema) => void}): JSX.Element {const hasFullCdcResync = schema.sync_type === 'cdc'- const hasDeleteAndResync = schema.incremental || schema.sync_type === 'webhook'+ const hasDeleteAndResync = schema.incremental || schema.sync_type === 'webhook' || schema.sync_type === 'xmin'const canDeleteTable = !!schema.tableif (!hasFullCdcResync && !hasDeleteAndResync && !canDeleteTable) {diff --git a/products/data_warehouse/frontend/shared/components/forms/SyncMethodForm.test.tsx b/products/data_warehouse/frontend/shared/components/forms/SyncMethodForm.test.tsxnew file mode 100644index 000000000000..44247c397d8d--- /dev/null+++ b/products/data_warehouse/frontend/shared/components/forms/SyncMethodForm.test.tsx@@ -0,0 +1,37 @@+import { ExternalDataSourceSyncSchema } from '~/types'++import { SyncTypeLabelMap } from '../../../utils'+import { shouldOfferXmin } from './SyncMethodForm'++const baseSchema: ExternalDataSourceSyncSchema = {+ table: 'orders',+ should_sync: false,+ sync_time_of_day: null,+ incremental_field: null,+ incremental_field_type: null,+ sync_type: null,+ incremental_fields: [],+ incremental_available: false,+ append_available: false,+ supports_webhooks: false,+ should_sync_default: false,+ primary_key_columns: null,+ available_columns: [],+ detected_primary_keys: ['id'],+ xmin_available: true,+}++describe('SyncMethodForm', () => {+ it.each([+ ['flag on + available', { xmin_available: true }, true, true],+ ['flag off', { xmin_available: true }, false, false],+ ['not available', { xmin_available: false }, true, false],+ ['webhook-only table', { xmin_available: true, webhook_only: true }, true, false],+ ])('offers xmin: %s', (_, overrides, flagEnabled, expected) => {+ expect(shouldOfferXmin({ ...baseSchema, ...overrides }, flagEnabled)).toBe(expected)+ })++ it('exposes a label for the xmin sync type', () => {+ expect(SyncTypeLabelMap.xmin).toBe('xmin')+ })+})diff --git a/products/data_warehouse/frontend/shared/components/forms/SyncMethodForm.tsx b/products/data_warehouse/frontend/shared/components/forms/SyncMethodForm.tsxindex 6ff5b15d215f..5f1947c055b4 100644--- a/products/data_warehouse/frontend/shared/components/forms/SyncMethodForm.tsx+++ b/products/data_warehouse/frontend/shared/components/forms/SyncMethodForm.tsx@@ -2,6 +2,7 @@ import { forwardRef, useEffect, useImperativeHandle, useState } from 'react'import { LemonButton, LemonInput, LemonSelect, LemonTag, lemonToast } from '@posthog/lemon-ui'+import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'import { LemonBanner } from 'lib/lemon-ui/LemonBanner'import { LemonInputSelect } from 'lib/lemon-ui/LemonInputSelect'import { LemonRadio } from 'lib/lemon-ui/LemonRadio'@@ -123,8 +124,12 @@ const getCdcSyncSupported = (}}+// xmin is offered only when the source advertises it for the table and the gating flag is on.+export const shouldOfferXmin = (schema: ExternalDataSourceSyncSchema, xminFlagEnabled: boolean): boolean =>+ !schema.webhook_only && xminFlagEnabled && !!schema.xmin_available+const getSaveDisabledReason = (- syncType: 'full_refresh' | 'incremental' | 'append' | 'webhook' | 'cdc' | undefined,+ syncType: 'full_refresh' | 'incremental' | 'append' | 'webhook' | 'cdc' | 'xmin' | undefined,incrementalField: string | null,appendField: string | null): string | undefined => {@@ -145,7 +150,7 @@ const getInitialRadioState = (schema: ExternalDataSourceSyncSchema,incrementalSyncSupported: boolean,appendSyncSupported: boolean-): 'full_refresh' | 'incremental' | 'append' | 'webhook' | 'cdc' => {+): 'full_refresh' | 'incremental' | 'append' | 'webhook' | 'cdc' | 'xmin' => {if (schema.sync_type) {return schema.sync_type}@@ -183,6 +188,7 @@ export const SyncMethodForm = forwardRef<SyncMethodFormHandle, SyncMethodFormPro},ref): JSX.Element {+ const xminFlagEnabled = useFeatureFlag('DWH_POSTGRES_XMIN')const incrementalSyncSupported = getIncrementalSyncSupported(schema)const appendSyncSupported = getAppendOnlySyncSupported(schema)const cdcSyncSupported = getCdcSyncSupported(schema)@@ -224,7 +230,7 @@ export const SyncMethodForm = forwardRef<SyncMethodFormHandle, SyncMethodFormProlookbackAmount != null && lookbackAmount > 0 ? lookbackAmount * LOOKBACK_UNIT_SECONDS[lookbackUnit] : nullconst radioOptions: {- value: 'webhook' | 'incremental' | 'append' | 'full_refresh' | 'cdc'+ value: 'webhook' | 'incremental' | 'append' | 'full_refresh' | 'cdc' | 'xmin'disabledReason?: stringlabel: JSX.Element}[] = []@@ -325,6 +331,28 @@ export const SyncMethodForm = forwardRef<SyncMethodFormHandle, SyncMethodFormPro})}+ if (shouldOfferXmin(schema, xminFlagEnabled)) {+ radioOptions.push({+ value: 'xmin',+ label: (+ <div className="mb-4 font-normal">+ <div className="items-center flex leading-[normal] overflow-hidden mb-1">+ <h4 className="mb-0 mr-2 text-base font-semibold">xmin replication</h4>+ </div>+ <p className="mb-2">+ Incremental replication using Postgres' internal <code>xmin</code> system column to track+ changed rows — no <code>updated_at</code> column required. Each sync reads only rows inserted or+ updated since the last run. Requires a primary key on the source table.+ </p>+ <p className="mb-2">+ Does not capture row deletes, and reads the full table on every sync (the <code>xmin</code>{' '}+ column is unindexed). Choose CDC if you need deletes or have a very large, high-churn table.+ </p>+ </div>+ ),+ })+ }+if (!hideNonWebhookOptions) {radioOptions.push({@@ -607,6 +635,9 @@ export const SyncMethodForm = forwardRef<SyncMethodFormHandle, SyncMethodFormProonSave('webhook', null, null, null)} else if (radioValue === 'cdc') {onSave('cdc', null, null, null, cdcTableMode)+ } else if (radioValue === 'xmin') {+ // xmin carries no user-picked incremental field; the source projects the system column.+ onSave('xmin', null, null, null)} else if (radioValue === 'incremental') {const fieldSelected = schema.incremental_fields.find((n) => n.field === incrementalFieldValue)if (!fieldSelected) {diff --git a/products/data_warehouse/frontend/utils.ts b/products/data_warehouse/frontend/utils.tsindex bc6dd8f70f9b..600795f09159 100644--- a/products/data_warehouse/frontend/utils.ts+++ b/products/data_warehouse/frontend/utils.ts@@ -165,6 +165,7 @@ export const SyncTypeLabelMap: Record<NonNullable<ExternalDataSourceSyncSchema['append: 'Append only',webhook: 'Webhook',cdc: 'CDC',+ xmin: 'xmin',}export const SyncFrequencyLabelMap: Record<DataWarehouseSyncInterval, string> = {