---
title: "VACUUM"
description: "VACUUM is a SQL statement, used by databases like PostgreSQL and DuckDB, that performs maintenance such as reclaiming space from deleted rows or refreshing planner statistics."
canonical: "https://motherduck.com/glossary/vacuum/"
related:
  - title: "VACUUM | MotherDuck Docs"
    url: "https://motherduck.com/docs/sql-reference/duckdb-sql-reference/duckdb-statements/vacuum/"
  - title: "DuckLake Architecture Deep Dive"
    url: "https://motherduck.com/blog/ducklake-architecture-deep-dive/"
  - title: "DuckDB statements | MotherDuck Docs"
    url: "https://motherduck.com/docs/sql-reference/duckdb-sql-reference/duckdb-statements/"
gated_asset:
  title: "DuckLake on MotherDuck"
  url: "https://motherduck.com/product/ducklake/"
---

# VACUUM

> VACUUM is a SQL statement, used by databases like PostgreSQL and DuckDB, that performs maintenance such as reclaiming space from deleted rows or refreshing planner statistics.

## Overview

`VACUUM` originated in PostgreSQL, where MVCC leaves behind "dead" row versions after updates and deletes; running `VACUUM` reclaims that space and prevents unbounded table bloat. The exact behavior of `VACUUM` differs significantly between database systems, so it's worth checking what it actually does in the one you're using rather than assuming Postgres semantics apply everywhere.

## DuckDB's VACUUM

DuckDB only has basic support for `VACUUM`, provided mainly for SQL compatibility with Postgres-style tooling. Plain `VACUUM` is essentially a no-op in DuckDB — it does **not** reclaim disk space freed by deleted or updated rows. To actually reclaim space after large deletes, you need to run `CHECKPOINT` (or, in some cases, export and re-import the database).

What `VACUUM` *does* do in DuckDB is refresh statistics used by the query optimizer. `VACUUM ANALYZE` recomputes table- and column-level statistics — such as distinct-value counts — that may have gone stale after inserts, updates, or deletes, which helps the cost-based optimizer make better join-order and cardinality decisions:

```sql
-- Recompute statistics for every table
VACUUM ANALYZE;

-- Recompute statistics for one table/column
VACUUM ANALYZE my_table(my_column);
```

Because DuckDB automatically maintains statistics as data is loaded, `VACUUM ANALYZE` is mainly useful after bulk updates or deletes that could leave existing statistics stale.
