/sql-database-pipeline:optimize-sql-performance [pipeline-name] [symptom]from sql-database-pipeline
Diagnoses and resolves slow or memory-heavy SQL extraction in dlt pipelines. Tunes backends, chunk sizes, parallelism, and reflection for Postgres, MySQL, MSSQL, Oracle, Snowflake, etc.
Ships in sql-database-pipeline. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Source-specific tuning for sql_database / sql_table pipelines. Work the loop — diagnose → pick the fix → apply → measure → repeat, one change at a time. Combine these with the source-agnostic stage levers in the performance toolkit's optimize-performance skill.
Essential reading: https://dlthub.com/docs/dlt-ecosystem/verified-sources/sql_database/advanced
Parse $ARGUMENTS:
pipeline-name (optional): the dlt pipeline. If omitted, infer from session context; if ambiguous, ask and stop.symptom (optional): e.g. "extract is slow", "OOM on a wide table", "one table dominates".pipeline.last_trace (or progress="log"); confirm extract is the slow stage (if normalize/load dominates, that's the performance toolkit).adjust-table (it owns cursor/merge/primary_key setup).Match the symptom to a lever. They compose — apply every one that fits; just don't tune what isn't the bottleneck.
| Symptom | Fix (see Apply) |
|---|---|
Row transfer itself is slow (default sqlalchemy) | Faster backend |
| Memory grows with table size; OOM, killed or hung on a small runner | Bounded reads: chunk_size, ConnectorX memory, fewer columns/rows, split backfill |
| Too many round-trips | Tune chunk_size |
| Extract is fast but load is slow | optimize-performance → "Load is slow" (ADBC + parquet, loader formats) |
| One big table, or many tables extracted sequentially | .parallelize() tables |
| Parallelized, but threads stall or the DB refuses connections | Size the connection pool |
| Slow startup before any rows load (many/huge tables) | Reduce reflection_level |
| Pulling tables / columns / rows you don't need | Push filters/projection to SQL |
| Huge first backfill won't finish or OOMs | Partition / split-load the backfill |
Faster backend — the single biggest lever for row-transfer speed:
Size the table first. Get row count and average row width (SELECT count(*), a sampled avg(length(...)) or table stats). Compare it with the RAM of the runner. The dltHub platform default instance has a few GiB and no spill to disk. Out of RAM, a job is killed (exit 137), stalls (exit 247) or hangs until execute.timeout.
| backend | use when | trade-offs |
|---|---|---|
sqlalchemy (default) | small tables, or nested data to unnest into child tables | max type fidelity; only backend that runs normalize; slowest |
pyarrow | medium/large flat tables; chunk_size 5,000–50,000 | needs numpy; keeps decimal/date types; reads in chunk_size batches, so memory stays bounded |
connectorx | fastest reads, table fits easily in RAM | own connection string; holds the whole result in memory and ignores chunk_size; dlt may copy it again for type fixes (see ConnectorX memory) |
pandas | DataFrame workflow only | loses precision on decimal and date columns |
Arrow backends (pyarrow, connectorx) skip normalize and keep nested values as JSON/struct columns. They also let dlt load a bulk format (parquet, or csv on Postgres), so most of their gain is outside extract. Local benchmark (dlt 1.32.0, Postgres → DuckDB, 200k flat rows): pyarrow ~15x and connectorx ~20x faster end to end than sqlalchemy, but only ~2.5x and ~4.5x on extract alone. Ratios change with data shape, network and destination: measure each stage.
from dlt.sources.sql_database import sql_database, sql_table
table = sql_table(table="<table>", backend="pyarrow", chunk_size=50000)
source = sql_database(backend="pyarrow", chunk_size=50000) # all tables
# connectorx: backend_kwargs={"conn": "<conn-str>"}
Install dlt[sql_database] (SQLAlchemy is not in the base workspace), plus numpy for pyarrow or connectorx for connectorx. With connectorx, a sqlite source needs an absolute path (sqlite:////abs/path.db), else "unable to open database file".
ConnectorX memory — peak memory grows with the table. On a small runner this ends in an OOM kill or a hang. Try in this order:
pyarrow when memory matters more than read speed.included_columns, a filtering query_adapter_callback, incremental loading, or date/id-range slices.backend_kwargs={"return_type": "arrow_stream"} (batch_size defaults to chunk_size). Not proven to bound memory — local test (dlt 1.32.0, 313 MB Postgres table, extract only): peak RSS pyarrow 337 MiB, connectorx 492 MiB, arrow_stream 455 MiB. Measure peak RSS (resource.getrusage(...).ru_maxrss, fresh process) on a table larger than the limit first.Tune chunk_size — rows per round-trip; larger = fewer round-trips, more memory. Start at 50000; lower on memory pressure, raise for narrow tables over high-latency links. connectorx uses it only in streaming mode.
Slow load into MSSQL / MySQL / Postgres — not a source problem. Use "Faster loader format (ADBC + parquet)" in optimize-performance (performance toolkit). It also lists loader formats to test for other destinations.
.parallelize() tables — each table extracts in its own thread (no multiprocessing); best when queries are slow or latency is high. Size [extract] workers in optimize-performance.
source = sql_database().parallelize() # all tables
table = sql_table(table="<table>").parallelize() # or per resource
Size the connection pool — .parallelize() runs N threads, each needing its own DB connection; the default SQLAlchemy pool (5) makes extra threads queue, and some DBs reject too many connections. Give the pool room for the parallel threads:
sql_database(engine_kwargs={"pool_size": 8, "max_overflow": 4})
Reduce reflection_level — schema reflection runs before extraction; on many/huge tables it adds startup cost.
sql_database(reflection_level="minimal") # names + nullability only ("full" is default)
For orchestrated / decomposed parallel runs (e.g. Airflow parallel-isolated), defer_table_reflect=True reflects each table at execution time (in its own task/thread) instead of all up front. Requires table_names; and since schema is decided at execution, it can override query_adapter_callback/apply_hints — don't enable it for plain local .parallelize().
Push work to the database — less data crosses the wire:
included_columns pulls only the columns you need (simpler than a table_adapter_callback):
table = sql_table(table="orders", included_columns=["id", "amount", "updated_at"])
query_adapter_callback adds WHERE/LIMIT so the DB filters server-side; table_adapter_callback handles more complex table changes. See create-sql-database-pipeline — "Add transformation callbacks".table_names so dlt reflects only those tables instead of the whole database (.with_resources(...) still reflects everything first, then filters — so it doesn't save the reflection cost):
source = sql_database(table_names=["orders", "customers"])
Partition / split-load a large initial load — for an already-incremental table (set up in adjust-table) whose first backfill is too big for one pass. Two ways:
incremental("updated_at", initial_value=start, end_value=end, range_start="open", range_end="closed").add_limit() loop (caps memory per run) — pull a few chunks per run and repeat until empty:
t = sql_table(table="events", chunk_size=1000,
incremental=dlt.sources.incremental("id", row_order="asc", range_start="open"))
while not pipeline.run(t.add_limit(5)).is_empty: # 5 chunks per run
pass
range_start="open" (>= → >) skips re-fetching boundary rows; row_order="asc" keeps the split gap-free.
pipeline.last_trace against step 1.debug-sql-database-pipeline.chunk_size, fewer columns/rows, sliced backfill, buffers and rotation (optimize-performance). A bigger instance is the last resort and needs the user's explicit approval (optimize-performance, Step 4). It costs more on every run, and a job that holds the whole table in memory fails on the next tier too.optimize-performance (install if not present: uv run dlthub --non-interactive ai toolkit install performance).uv run dlthub --non-interactive ai toolkit install dlthub-platform).What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub dlt-hub/dlthub-ai-harness --plugin sql-database-pipeline8 skills in this plugin
/add-tableAdd a new table or view to an existing dlt SQL database pipeline. Use when the user wants to load additional tables from the same database that already has a working pipeline./adjust-tableAdjust a working dlt SQL database pipeline for production — remove dev limits, add incremental loading, configure merge keys. Use when the user wants to remove .add_limit(), load the full table, or set up incremental loading on a cursor column. For speed/memory tuning (backend, chunk size, parallelism) use optimize-sql-performance instead. For inspecting loaded data or fixing column types/schema after a load, use validate-sql-database-data instead./Other plugins' skills for the same job