DLH.io Documentation logoDLH.io Documentation
AgentsSQL Server Agent

How to Stream SQL Server CDC to Iceberg or Delta Lake

Move SQL Server Change Data Capture (CDC) or Change Tracking changes into Apache Iceberg, Delta Lake or Parquet on Amazon S3 or Azure, then query them from Snowflake, Databricks, Athena or DuckDB.

To move SQL Server changes into a data lake, enable Change Data Capture (CDC) or Change Tracking on the database, install the DLH.io SQL Server Agent on a Windows host that can reach SQL Server, and point it at Amazon S3 or Azure Blob / ADLS Gen2 with output_format: iceberg or delta. The first run loads every table in full. Each run after that reads only the rows that changed since the last recorded position and merges them into the Iceberg or Delta tables, including deletes. Snowflake, Databricks, Athena, Trino and DuckDB can then read the tables directly from your storage.

The agent runs inside your network and needs no inbound ports. Your data stays in your own storage account.

CDC or Change Tracking?

Change Tracking (ct)Change Data Capture (cdc)
What it recordsWhich rows changedBefore and after images of each change, with operation metadata
SQL Server Agent serviceNot requiredRequired (capture and cleanup run as SQL Agent jobs)
Agent login needsSELECT and VIEW CHANGE TRACKINGSELECT and read access to the cdc schema
Primary keyRequiredRequired
RecommendationSimpler to operate; use it if you have a free choiceUse it if your DBAs already run CDC or you need the change history it records

Set sync_mode: auto and the agent picks Change Tracking or CDC per table based on what is enabled. Tables without a primary key fall back to the no_pk_strategy setting (a full extract by default). See Data retrieval.

Steps

Enable CDC on the database and tables

USE OrdersDb;
EXEC sys.sp_cdc_enable_db;

EXEC sys.sp_cdc_enable_table
  @source_schema = N'dbo', @source_name = N'Orders',
  @role_name = NULL, @supports_net_changes = 1;

GRANT SELECT ON SCHEMA::cdc TO dlh_agent;
GRANT SELECT ON SCHEMA::dbo TO dlh_agent;

@supports_net_changes = 1 needs a primary key or unique index and lets the agent read one net row per key per interval. Make sure the SQL Server Agent service is running on the instance. For Change Tracking instead, see the SQL in Getting started.

Install the agent

Run the Windows installer on a server with TCP access to SQL Server (port 1433 by default) and HTTPS egress to api.datalakehouse.io and your storage endpoint. Then install the ODBC driver:

.\dlh_agent_sql_server.exe --install-driver --auto

Full requirements and installer details are in Getting started.

Configure the output format

A minimal configuration for CDC into Iceberg on S3:

data_retrieval:
  output_format: iceberg        # or delta, parquet, csv
  direct_cloud_write: true
  storage_base_path: /data/delta_iceberg_tables
  iceberg_apply_deletes: true   # deletes at the source remove the row in Iceberg
  databases:
    - name: OrdersDb
      sync_mode: cdc            # or ct, or auto
      tables:
        - name: dbo.*
          all_columns: true

With a DLH.io API key in the dlh_ref section, the platform issues storage credentials at run time, so no storage keys need to sit on the host. The complete, annotated version of this configuration is in the CDC to Apache Iceberg on Amazon S3 scenario. For Change Tracking into Delta Lake on Azure, see Change Tracking to Delta Lake on Azure and Snowflake.

Check, run once, then schedule

.\dlh_agent_sql_server.exe --config-check
.\dlh_agent_sql_server.exe --diagnose
.\dlh_agent_sql_server.exe

--diagnose is read-only and checks the driver, SQL Server connectivity, CDC / Change Tracking status and storage access. The first run is a full historical load. Later runs print Upserting N cdc changes into Iceberg table ... and skip tables with no changes. Most teams then set the installed Task Scheduler task to repeat every 5 to 15 minutes.

Query the tables

Point your engine at the table folders in your bucket. Snowflake reads them through an external volume and an Iceberg catalog integration; Athena through the Glue catalog; DuckDB attaches the warehouse directly. Examples are in the scenario guide and in Output formats.

Keep retention longer than any outage

SQL Server removes old change rows (CDC cleanup defaults to 3 days; Change Tracking to 2 days). If the agent cannot sync a table for longer than the retention, that table is reloaded in full on the next run.

Common questions

Does CDC to Iceberg handle deletes? Yes. With iceberg_apply_deletes: true, a delete at the source removes the row from the Iceberg table. Set ct_cdc_delete_mode: logical on a table to keep deleted rows flagged with _cdc_deleted = true instead.

What if one table fails? Each table is extracted and written independently. A failing table keeps its CDC position, so its changes are retried on the next run, and every other table still lands.

Can I keep row history? Yes. Give a table write_strategy: scd2 for SCD Type 2 history in Iceberg or Delta. See SCD Type 2 history tables.

Can I try it without an account? Without an API key the agent runs in Community mode: output stays on the local disk and each table is capped at 10,000 rows. Contact us for a trial with cloud uploads.