Comparison

DuckDB vs Postgres for analytics

What an embedded columnar engine does that your Supabase Postgres database doesn't, where each one belongs, and the ways to point DuckDB at the data you already have.

By Postgres Analytics Layer Editors · Updated

The short answer

DuckDB does not replace Postgres. Postgres is the database your application writes to and the one place your rows, permissions and history are authoritative. DuckDB is an analytical engine you run next to it, inside a script, a notebook, a job or Postgres itself, to answer questions that need a scan of many rows. Most Supabase teams who use DuckDB keep Postgres exactly as it is and give DuckDB a read-only view of it.

  • Stay in Postgres for anything your app or your users write, anything that must respect Row Level Security, and metrics you can pre-calculate into small tables or materialized views.
  • Reach for DuckDB when an analyst, a scheduled job or an agent needs ad hoc aggregations over large tables or exported files, and running them on your primary would slow the app down.
  • Keep Postgres as the source of truth either way. DuckDB reads from it, or from snapshots of it, not the other way round.

Side by side

Postgres (Supabase)DuckDB
Built forTransactions (OLTP): many users making small reads and writes to individual rows.Analytics (OLAP): scanning and aggregating many rows over a few columns.
How it runsA database server your app, API and tools connect to over the network.A library inside another process (Python, Node.js, the CLI, or Postgres itself through pg_duckdb). No server to run.
Storage layoutRow-oriented heap: each row's columns are stored together.Column-oriented and compressed, processed in vectorized batches across all CPU cores.
Where the data livesIn its own tables.Its own database file, memory, or other people's data read in place: Parquet, CSV and JSON files, object storage, and attached Postgres databases.
ConcurrencyMany concurrent readers and writers, each on its own connection.One process may write to a database file; several may open it read-only. DuckDB 2.0 adds a client-server protocol (Quack) for writes from more processes.
Access controlRoles and Row Level Security policies (what Supabase's auth relies on).Whatever the host process and its files allow. Postgres RLS does not travel with data copied into DuckDB or Parquet.
For a Supabase teamAlready running: it is your project's database.Something you add beside it: a notebook or job that attaches your database, Parquet exports in Supabase Storage, or Supabase's DuckDB wrapper.
PricePart of your Supabase plan and compute size; see supabase.com/pricing.Open source (MIT); you pay for wherever it runs. MotherDuck, a hosted DuckDB service, bills separately; see motherduck.com/pricing.

Costs depend on usage, region and plan, so this page quotes none. Check Supabase's pricing (including read replicas, if you plan to point DuckDB at one) and, if you would rather not run DuckDB yourself, MotherDuck's pricing.

Why the same query behaves so differently

“Revenue by plan by week for the last year” reads two or three columns across a very large number of rows. Postgres stores each row's columns together, so it reads whole rows to reach the columns it needs, checks each row's visibility under MVCC, and does it on the same CPU, memory and connections your application uses. Our piece on analytical query performance on Supabase Postgres goes through where that cost shows up.

DuckDB stores each column separately and compressed, reads only the columns a query names, and processes them in vectorized batches spread across every core of the machine it runs on. Because it runs in-process, there is no server to provision and no network hop between the engine and your code. The trade-offs run the other way: it is not built for many users writing at once (only one process may write to a database file, per DuckDB's concurrency docs), it knows nothing of Supabase Auth or RLS, and it is a poor home for the rows your app reads and updates one at a time.

When Postgres is enough

A second engine is worth adding only when Postgres has run out of cheap fixes. It usually hasn't when:

  • Your questions are known in advance. A handful of numbers (revenue, signups, activation, retention) asked repeatedly can come from materialized views refreshed on a schedule, so dashboards read a few hundred rows instead of millions.
  • Reads can move off the primary. A read replica isolates analytical load from your app. It is still row-oriented, so very large scans stay slow, but moderate ones stop hurting production.
  • Permissions must hold. Analytics served to customers or teammates that must respect RLS, per tenant or per user, is simplest when it never leaves Postgres; see how RLS affects analytical queries.
  • The data is live and small. If the answer must reflect the last second and the tables are modest, a well-indexed query in Postgres is the shortest path.

When DuckDB earns its place

  • Analysts or agents ask questions nobody pre-aggregated, by arbitrary dimensions, over event, log or order tables that have grown large.
  • The heavy work is periodic (a nightly report, a weekly board deck, a backfill) and can run in a job or notebook rather than on the database your users hit.
  • You want to join Postgres data with files that never belonged in Postgres: Parquet or CSV exports, data in object storage, another team's dumps.
  • You want columnar speed without running a second database server. That is the difference from ClickHouse, which is a separate system you operate or rent; our ClickHouse vs Postgres comparison covers when that heavier step is worth it, and Redshift vs Postgres covers a full warehouse on AWS.

Running DuckDB on Supabase data: four ways

Our guide to DuckDB queries over Supabase Postgres data goes deeper into each pattern and where it breaks. In short:

DuckDB reads Postgres: the postgres extension

DuckDB's postgres extension attaches a running Postgres database so its tables can be queried as if they were DuckDB's own, with filters pushed down to Postgres. Attach it READ_ONLYso a stray statement can't change production, keep the password in a DuckDB secret rather than the connection string, and point it at a read replica if the scans are large. For repeated analysis, copy the tables you need into a local DuckDB table or a Parquet file once, then query the copy.

DuckDB inside Postgres: pg_duckdb

pg_duckdb, built by DuckDB with Hydra and MotherDuck, embeds DuckDB's engine in the Postgres server, so ordinary SQL against Postgres tables can be executed by DuckDB and joined with Parquet, Iceberg or Delta files in object storage. It shares the server's CPU and memory with your transactional work, so it belongs on a replica or a separate instance rather than a busy primary. Whether you can install it depends on your host and Postgres version; check Supabase's extensions list for your project before planning around it.

Snapshots: Parquet in object storage

Export the tables you analyse to Parquet on a schedule (Supabase Storage is S3-compatible) and query the files with DuckDB anywhere. Production never sees the query load and an agent never touches the live database; the price is that the answers are only as fresh as the last export, which suits daily or hourly reporting. Our piece on governed datasets vs raw database access for AI agents explains why that boundary matters once agents are in the loop.

Postgres reads DuckDB: Supabase's DuckDB wrapper

Supabase's DuckDB wrapper runs the other way: a foreign data wrapper that lets Postgres read data DuckDB can reach, such as Parquet files in S3, R2 or Supabase Storage, Iceberg catalogs, or a MotherDuck database, as foreign tables. It is read-only, pushes down where, order by and limit, and Supabase recommends keeping its credentials in Vault. It is a way to bring files into your Postgres workflow, not a way to speed up queries on your Postgres tables.

Permissions do not come along

When DuckDB attaches Postgres, it sees exactly what the role it connects as may see. Once rows are copied into a DuckDB file or a Parquet export, your RLS policies no longer apply to them: anyone who can open the file can read every row in it. Connect with a dedicated read-only role, export only the columns and tenants a consumer should see, and decide where per-tenant isolation lives before anyone shares a file. Our piece on AI agent access to production Postgres databases covers the same question for agents.

A quick way to decide

  1. List the questions your dashboards, reports and agents ask most. If each can be answered from a table you refresh on a schedule, stay in Postgres.
  2. For the ones that can't, check who asks and how often. A person or a job asking occasionally is a good fit for DuckDB attached read-only to a replica, or reading a Parquet export.
  3. If many users need those answers at once, interactively, DuckDB in a single process will become the bottleneck; look at a governed layer of pre-calculated results or a server-based engine instead.
  4. Before anything leaves Postgres, decide which role reads it and which rows and columns it may take with it.