Home / Databricks on Azure

Databricks on AzureChecklistAdvanced

Lakeflow Connect SQL Server ingestion on Azure Databricks: a production checklist for change tracking, CDC, the gateway and full refreshes

Go-live checklist for the managed SQL Server connector covering CT vs CDC, the utility script, log retention against gateway downtime, schema changes that force full refreshes, and the errors you will see.

Deepak Bhardwaj8 min read

Applies toAzure Databricks Lakeflow Connect SQL Server connector (ingestion gateway + managed ingestion pipeline), utility script 1.7, SQL Server 2012+ / Azure SQL Database / Azure SQL Managed Instance

What breaks in production

The managed SQL Server connector has two parts. An ingestion gateway runs on classic compute, continuously reads snapshots and change data from the source, and stages them in a Unity Catalog volume. A managed ingestion pipeline on serverless applies the staged changes to streaming tables. The design is simple. Most incidents come from three gaps:

  • The source purges change data before the gateway reads it.
  • A DDL change on the source needs a full refresh, and nobody planned one.
  • Permissions or capture instances were set up by hand and drifted.

Work through the checklist below before go-live and again after any SQL Server maintenance. Object names and parameters come from utility script version 1.7. Later versions add a new suffix to object names, so check your version first.

1. Source database setup

Pick change tracking or CDC per table

Table shape Use Why
Has a primary key Change tracking (CT) Lighter on the source; recommended by Databricks
No primary key Change data capture (CDC) CT needs a PK
Both enabled Connector uses CT Disable the one you don't need to avoid confusion

Version floor: SQL Server 2012 for CT. For CDC, SQL Server 2012 SP1 CU3, and Enterprise Edition before SQL Server 2016. Only primary replicas are supported. CT and CDC do not work against read replicas or secondaries, so the gateway's load lands on the primary.

Use the utility script, not hand-written grants

  • Run utility_script.sql in the target database as a member of db_owner.
  • Confirm the version and platform:
SELECT dbo.lakeflowUtilityVersion() AS utility_version,
       dbo.lakeflowDetectPlatform() AS platform;
  • Enable CT on PK tables. Set retention to cover your worst-case gateway outage, not the 2-day default:
EXEC dbo.lakeflowSetupChangeTracking
    @Tables = 'Sales.*,Production.Products',
    @User = 'lakeflow_ingest',
    @Retention = '7 DAYS',
    @CreateDdlSupportingObjects = 1;
  • Enable CDC on tables without a PK:
EXEC dbo.lakeflowSetupChangeDataCapture
    @Tables = 'Staging.ImportData,Logs.AuditTrail',
    @User = 'lakeflow_ingest';
  • Grant everything else the ingestion user needs:
EXEC dbo.lakeflowFixPermissions
    @User = 'lakeflow_ingest',
    @Tables = 'Sales.*,Production.Products,Staging.ImportData,Logs.AuditTrail';

lakeflowSetupChangeTracking skips tables without a primary key and lists them in its output. Read that output. A skipped table is a table you think is replicating but isn't.

Warning

SQL Server allows at most two CDC capture instances per table. Lakeflow uses lakeflow_<schema>_<table>_1 and _2 so it can handle schema changes and full refreshes. If both slots already hold capture instances from another tool, Lakeflow can't refresh or evolve that table. @AllowDisablePreExistingCaptureInstances = 1 lets the script remove existing instances. Run it only after confirming no other consumer (SSIS, a third-party CDC tool) depends on them.

2. Retention against gateway downtime

The gateway must read changes before the source cleans them up. If it doesn't, every affected table needs a full refresh. Size retention to your longest realistic outage: a weekend change freeze, a broken network path, or a gateway stuck starting.

  • Check CT retention and auto-cleanup:
SELECT DB_NAME(database_id) AS db, is_auto_cleanup_on,
       retention_period, retention_period_units_desc
FROM sys.change_tracking_databases;
  • For each CT table, confirm the gateway's position is still valid. If min_valid_version passes the version the gateway last synced, the table must be refreshed:
SELECT t.name AS table_name,
       CHANGE_TRACKING_MIN_VALID_VERSION(t.object_id) AS min_valid_version,
       CHANGE_TRACKING_CURRENT_VERSION() AS current_version
FROM sys.change_tracking_tables ct
JOIN sys.tables t ON t.object_id = ct.object_id;
  • For CDC on SQL Server and Managed Instance, check the cleanup job retention (in minutes; the default is 4320, three days):
SELECT job_type, retention FROM msdb.dbo.cdc_jobs;
-- extend to 7 days
EXEC sys.sp_cdc_change_job @job_type = N'cleanup', @retention = 10080;

Azure SQL Database runs CDC through its own scheduler rather than SQL Agent, so check the current docs for how retention is set there.

  • Watch the transaction log. Longer retention means larger side tables, and CDC holds log until changes are harvested:
SELECT name, log_reuse_wait_desc FROM sys.databases WHERE name = DB_NAME();

REPLICATION here on a CDC database means the capture job is behind. The cause is the SQL Server capture job, not Lakeflow, but the log will still grow.

3. Gateway operations

  • The gateway runs in continuous mode. Don't stop it to save money. Every start provisions a new VM, and while it is down the retention window keeps running out.
  • Each ingestion pipeline has exactly one gateway, and gateways can't be shared. Budget one always-on classic VM per pipeline. Right-size it, but don't schedule it off.
  • Whoever creates the gateway needs permission to create clusters. PERMISSION_DENIED: You are not authorized to create clusters means an admin must grant unrestricted cluster creation. A compute policy alone won't fix it.
  • The staging volume and catalog (gateway_storage_catalog, gateway_storage_schema) must sit on storage the classic gateway subnet can reach. A 403 from the gateway is a storage firewall problem. See the ADLS firewall posts.
  • Alert on the gateway, not only the ingestion pipeline. Query its event log:
SELECT timestamp, level, event_type, message
FROM event_log('<gateway_pipeline_id>')
WHERE level IN ('ERROR', 'WARN')
ORDER BY timestamp DESC
LIMIT 50;
  • A gateway stuck in "starting" for more than 15 minutes is usually fixed by moving the pipeline to the current channel. If that doesn't help, open a support ticket. INGESTION_GATEWAY_INTERNAL_ERROR details are in the gateway driver's stdout.

4. Schema changes: which ones cost a full refresh

Source change Effect Action
Add a nullable column Ingested on next run None, unless downstream code uses SELECT *
Add a column with DEFAULT, computed or identity Fails with CDC_INCOMPATIBLE_SCHEMA_CHANGES (e.g. .ADD_COLUMN_WITH_BACKFILL) Full refresh of the table
Column added mid-ingestion NON_INCREMENTAL_SCHEMA_CHANGE Full refresh of the table
Drop a column Marked inactive in destination, not dropped Drop it or refresh before reusing the name
Rename a column, change a type Unsupported incrementally Full refresh of the table
Rename, drop or recreate a table MISSING_TABLE_IN_SOURCE Refresh if recreated; remove from pipeline if retired
Truncate Unsupported incrementally Full refresh
  • Get source DBAs to send DDL through a change process that includes Databricks.
  • If DDL happens often, set auto_full_refresh_policy (enabled, min_interval_hours) at pipeline level under ingestion_definition.table_configuration, or per table. Table-level settings override pipeline-level ones.
  • Set a full_refresh_window (start_hour, days_of_week, time_zone_id) so automatic refreshes snapshot the source off-peak.

5. Running a targeted full refresh

Refresh only the affected tables. A whole-pipeline refresh re-snapshots everything from the primary.

databricks pipelines start-update <ingestion_pipeline_id> --json '{
  "full_refresh_selection": ["orders", "order_lines"]
}'

Check the selection field name against your CLI version's databricks pipelines start-update --help.

Caution

The destination keeps serving the old data until the snapshot finishes, then switches in one update. If you cancel or interrupt retries while the update shows Initializing or Resetting tables, the table can be left partially loaded. If that happens, start a new update with the same table selection. Don't fall back to the old data.

6. Known sharp edges

  • LOB values larger than 10,485,760 bytes arrive empty, with no error. Profile varchar(max)/varbinary(max) columns before go-live.
  • Two source tables with the same name in different schemas can't land in one destination schema (Cannot have multiple queries named ..._snapshot_load). Split them across destination schemas with separate gateway and pipeline pairs.
  • Invalid column name 'SERIAL_NUMBER' comes from an old internal table. Docs fix: DROP TABLE dbo.replicate_io_audit_ddl_trigger_1; on the source database.
  • Upgrading the utility script: pause the pipeline or stop the gateway, rerun the script, then rerun lakeflowSetupChangeTracking and lakeflowSetupChangeDataCapture with the same options as before.

Prevent it next time

  • Set CT/CDC retention at least as long as the longest outage you'd tolerate, and track min_valid_version against it.
  • Alert on gateway ERROR events and on log_reuse_wait_desc at the source.
  • Add "notify the Lakeflow owner" to the source DDL change checklist, with the full-refresh table above attached.
  • Keep the utility script version and setup parameters in source control so you can rerun them exactly.