AI Slop Damian
MotherDuck vs Postgres

Postgres is Full

Postgres ships your product. Nobody plans for it to do analytics, it just happens: a dashboard here, a usage tab there, the weekly number someone in the business needs. For a year it's fine. Then one day the page takes ten seconds, the API gateway gives up at sixty, and a designer files a ticket about the spinner.

This post is a condensed, interactive take on Postgres is Full, an internal MotherDuck guide by Mehdi Ouazza, DevRel at MotherDuck. MotherDuck is a cloud analytics database built on DuckDB, an open-source database designed for analytical queries. The claim fits in one line: you don't need to leave Postgres, you need to stop asking it to do two opposite jobs. Everything below is clickable.

One database, two opposite jobs

Postgres is an OLTP database (online transaction processing): it charges cards, inserts orders and looks up a user by id. Small operations that touch a row or two. Analytics, or OLAP (online analytical processing), is the opposite shape: a few big queries that read one or two columns across millions of rows.

The difference starts with how each engine lays bytes on disk. Postgres stores data row by row. A column store like DuckDB stores it column by column. Try both queries:

Row storage · Postgres
id
user
day
amount
41
ana
mon
30
42
bo
mon
12
43
cy
tue
45
44
di
wed
8
45
ed
wed
27
46
flo
thu
19
Pick a query
Column storage · MotherDuck
id
user
day
amount
41
ana
mon
30
42
bo
mon
12
43
cy
tue
45
44
di
wed
8
45
ed
wed
27
46
flo
thu
19
Pick a query
Six orders, two ways to lay them on disk · pale: read from disk · bright: actually needed · one fetch: one block of the layout

Neither layout is wrong: each is great at one job and bad at the other. Layout is only part of the gap, though. Column stores also compress each column and process values in large batches. On ClickBench, a public benchmark of 43 analytical queries, plain Postgres comes out over 1000× slower than MotherDuck. Postgres with indexes built for those exact queries narrows that to around 25×, after almost three extra hours of loading to build them. The real-world test further down measured 83× to 483×.

That's also why the usual reflex, adding an index, doesn't save you. An index on the order date narrows a 90-day report to those 90 days, but Postgres still reads every one of those orders, whole rows, to add up one column. Worse, every index you add for a report is extra work on every INSERT your app makes.

Postgres under load

Nobody decides to do analytics on Postgres. The data is already there, so you add a table. The table is there, so you add a dashboard. The trouble is that a big analytical query doesn't just make the dashboard slow: while it runs, it takes CPU, memory and disk away from the app's own queries, so the product slows down too.

Then come the patches, and the trap is that they work: each one buys real months, so you reasonably assume the next one will too. Grow your data with the slider and try them as things start to hurt:

Dashboard query
1.6 s
App write latency
4.2 ms
Dashboard data is
live
Postgres bill
1×
Nothing hurts yet. Drag the slider.
Illustrative model, not a benchmark. One point is measured: 39M rows took ~100 s on Postgres (½ vCPU, 4 GB RAM) and ~0.2 s warm on MotherDuck (1.3 s cold). Every other number is shaped to match how these patches behave.

Sharding is the other big patch teams reach for: splitting tables across several Postgres machines, for example with the Citus extension. It's built to scale writes, and a report that groups across every customer still has to visit every machine.

Postgres stays, analytics moves

The fix fits on a sticky note: keep Postgres as the system of record and send the analytical queries somewhere built for them. Nothing moves off Postgres: you give the second workload its own room.

The engine is MotherDuck either way. The real question is how the data gets there:

Analytics moves to MotherDuck. How does the data get there?
Can your data leave Postgres at all (compliance, network rules)?

What the move actually is

The example is a multi-shop e-commerce platform: lots of shops selling through one Next.js app on Vercel, backed by a managed Postgres with 39.4M rows in order_items. MotherDuck publishes the dataset as a share, a read-only database you attach by its link. With a MotherDuck account, run this in the DuckDB CLI or the MotherDuck web UI to query it yourself:

sql
ATTACH 'md:_share/multishop_commerce/ac3d36cc-f295-4c66-bf13-371b998f12e8';

The copy runs as a Flight: a single Python file that MotherDuck runs on its own compute, on a schedule. It uses DuckDB's Postgres scanner, an extension that reads Postgres tables over a normal connection, to copy each table over. Abridged:

flights/sync_postgres.py
import os, duckdb

# A MotherDuck secret named 'pg' arrives as pg_HOST, pg_USER, ... Copy them to the standard
# PG* variables, so the password never appears in SQL.
for key in ["HOST", "PORT", "DATABASE", "USER", "PASSWORD", "SSLMODE"]:
if os.environ.get(f"pg_{key}"):
os.environ[f"PG{key}"] = os.environ[f"pg_{key}"]

con = duckdb.connect("md:")  # the MotherDuck token is injected by the Flight
con.execute("CREATE DATABASE IF NOT EXISTS multishop_commerce; USE multishop_commerce")
con.execute("ATTACH '' AS pg (TYPE postgres, READ_ONLY)")  # reads the PG* variables

tables = con.execute(
"SELECT table_name FROM postgres_query('pg', "
"'SELECT table_name FROM information_schema.tables "
"WHERE table_schema = ''public'' AND table_type = ''BASE TABLE''')"
).fetchall()
for (table,) in tables:
# One statement per table: atomic, and re-running it just replaces the copy
con.execute(f'CREATE OR REPLACE TABLE "{table}" AS SELECT * FROM pg.public."{table}"')

That's a full read of every table each hour. Point it at a read replica if you have one, and switch to an incremental sync or to CDC once a full copy stops fitting in the hour. MotherDuck's Postgres-ingest Flight adds the parts this excerpt leaves out: filters, retries and an audit table.

Then the reads. MotherDuck speaks the Postgres wire protocol, so the dashboard keeps its pg driver and only its connection settings change. Standard analytical SQL, like the query in the race below, runs unchanged. Under the hood you're now writing DuckDB's SQL dialect, so check any Postgres-specific functions your dashboards use.

lib/db.ts
export function poolFor(source: 'postgres' | 'motherduck') {
if (source === 'motherduck') {
return new Pool({
host: process.env.MD_PG_HOST, // e.g. pg.us-east-1-aws.motherduck.com
user: 'postgres',
password: process.env.MOTHERDUCK_TOKEN, // the token is the credential
database: process.env.MD_DATABASE,
ssl: true // and verify the certificate: that token is a password
});
}
return new Pool({ connectionString: process.env.POSTGRES_URL }); // your managed Postgres
}

For the dashboards your customers see, there's one more piece: an Embedded Dive, an interactive MotherDuck dashboard you show inside your app in a sandboxed iframe. Your backend creates an embed session limited to one customer's data, so the browser never decides what it may see. According to MotherDuck, the filters and drill-downs then run in the customer's browser on DuckDB-Wasm, DuckDB compiled to WebAssembly, so a click never waits on your server. Embedding needs MotherDuck's Business plan.

That's the shape of the move. Doing it for real also takes network access from MotherDuck to your Postgres, a read-only database user, and a pass over your dashboard SQL for dialect differences.

The race

The platform's internal admin dashboard asks one question, revenue per month across all shops by plan tier:

sql
SELECT s.plan_tier,
date_trunc('month', o.ordered_at) AS month,
SUM(oi.line_total)                 AS revenue,
COUNT(DISTINCT o.order_id)         AS orders
FROM order_items oi
JOIN orders o ON o.order_id = oi.order_id
JOIN shops s ON s.shop_id = o.shop_id
WHERE o.status = 'paid'
GROUP BY 1, 2 ORDER BY 1, 2;

Here it is on both engines, replayed at the speed it was measured.1 Postgres has the indexes a real app would have and fresh statistics, but it runs on a small instance and has to scan a fact table that doesn't fit in its RAM.

Postgres direct connection 0.00 s
ready
MotherDuck via the Postgres endpoint 0.00 s
ready
Same query · same pg driver · only the host changes. A real-time replay of measured timings.

Same query, same driver, same 111 rows back. Postgres keeps serving the app, and the dashboard stops competing with it.

Appendix: running it on day 2

Shipping it is the easy part. Operating it:

  • Schema drift. A full-copy sync picks up schema changes on its own, new columns included. Renames and type changes flow straight through too, and break the dashboard queries that still use the old name or type. The durable fix is upstream: agree with whoever owns those tables which columns analytics depends on, so a breaking change is a decision and not a 6 AM surprise.
  • Cost. MotherDuck bills compute by the second while it runs, plus storage, on top of a monthly plan fee (Business is $250 per organization as of November 2026). Analytics is peaky (everyone opens the dashboards on Monday morning), so idle hours cost little, unlike an always-on warehouse. An hourly sync still runs through the quiet hours.
  • Security. Don't sync as the superuser. Create a replicator role with SELECT on the analytics tables only, and treat the MotherDuck token like a database password.
  • Observability. Flights log every run and MotherDuck keeps a queryable query history. The sneaky failure is a sync that runs fine and copies nothing new, so compare the latest timestamp on both sides after each run and show a last_synced_at on the dashboard.

Choosing Postgres was the right call. The mistake is asking it to be two databases at once. Don't break up with it: re-route.

  1. These are the first, cold runs: Postgres 107.56 s, MotherDuck 1.30 s. The best of three runs was Postgres 101.40 s against MotherDuck 210 ms: 483× faster. Setup: PlanetScale Postgres 18.4, single node, ½ vCPU and 4 GB of RAM, 39.4M order_items (about 6–8 GB), primary keys plus join and filter indexes, then ANALYZE. A bigger Postgres instance would be faster, and the benchmark doesn't state the size of the MotherDuck compute it used. ↩︎