iberezh
← All writing
· Databases

DuckDB vs Postgres on the same query

Same query, same 2M rows. Postgres took 55 ms. DuckDB took 5.7 ms on 1 core.

DuckDB 2.0 came out on October 21. It's a database that runs inside your app, like SQLite, but made for analytics. No server. You can point it at a CSV or Parquet file and query it with SQL.

The difference is how they store data. Postgres keeps each row together, so to sum one column it reads every column of every row. DuckDB keeps each column together, so it reads only the 2 columns the query needs. The same table took 100 MB in Postgres and 38 MB in DuckDB.

Where it fits: - reports and dashboards over millions of rows - CSV, Parquet or JSON files you want to query without loading them anywhere - analytics in a script or a notebook

Where it doesn't: your main app database with lots of small writes. Keep Postgres there.

Discussion on LinkedIn

Next: Two users sign up as "José" →