Skip to content

Running OPTIMIZE and VACUUM on Delta tables

Delta tables can accumulate many small files from frequent writes, which slows down query performance; OPTIMIZE compacts these small files into larger ones, and VACUUM removes stale, unreferenced data files to reduce storage costs. Together they are the core maintenance commands for keeping Delta tables performant and cost-efficient on Azure Databricks.

1 · Learn the must-know

  • OPTIMIZE compacts small files into larger ones (up to 1GB by default) using bin-packing, improving read performance without changing table data or history.
  • ZORDER BY can be combined with OPTIMIZE (e.g., OPTIMIZE table ZORDER BY col) to co-locate related data in the same files, improving data-skipping performance for filters on those columns.
  • VACUUM permanently deletes files no longer referenced by the Delta transaction log and older than a retention threshold, defaulting to 7 days (168 hours).
  • Running VACUUM with a retention period shorter than the default requires disabling the safety check (spark.databricks.delta.retentionDurationCheck.enabled=false) and can break time travel or concurrent readers/writers relying on those files.
  • Predictive optimization (where available) can automatically run OPTIMIZE and VACUUM on Unity Catalog managed tables based on usage patterns, reducing the need for manually scheduled maintenance jobs.
  • Auto Optimize (optimizeWrite and autoCompact table properties) can reduce small-file creation at write time, complementing scheduled OPTIMIZE jobs rather than replacing the need for periodic VACUUM.

2 · Check your understanding

Check this objectiveFree · always available

A data engineer runs OPTIMIZE on a large Delta table and then immediately wants to reclaim the storage used by the old, now-unreferenced data files. To do this quickly, the engineer disables the retention duration check and runs VACUUM mytable RETAIN 0 HOURS. What is the primary risk introduced by this action?

Your objective map0 tried · 0 answered correctly · 77 untouched

What you have tried across DP-750's objectives, not a readiness score.

Set up and configure an Azure Databricks environment15-20% of the exam0 of 13 tried
Secure and govern Unity Catalog objects15-20% of the exam0 of 12 tried
Prepare and process data30-35% of the exam0 of 28 tried
Deploy and maintain data pipelines and workloads30-35% of the exam0 of 24 tried

3 · Keep going