Fast queries in DuckDB
Open the copy of your tables in DuckDB on your laptop, a server or the DBTrail machine, and run any report or heavy query without slowing down your MySQL.
Run any report or heavy query on your laptop or a server, on a copy of your tables, without slowing down your MySQL. Pick where DuckDB runs below; the closer it sits to the files, the faster the answers.
You need:
- DuckDB installed on the machine that runs the queries.
- The
views.sqlfile. It tells DuckDB where each Parquet file is, so every table becomes a view with the table's own name:shop.orders. Each of the four ways below says where to get it.
Four ways to do it
All four open the same copy. They differ in speed and convenience: the closer DuckDB sits to the files, the faster the queries; the more current you want the data, the more access you need.

| Where | Speed | Current data? | What it takes |
|---|---|---|---|
| 1. Your computer, reading S3 | Slowest: every query goes over the internet | Yes | An S3 location and AWS access |
| 2. Your computer, files downloaded | Fast: local disk | No, the moment you downloaded | Nothing. Start here |
| 3. The DBTrail machine | Fastest: the files are right there | Yes | A shell on that machine, and a non-Docker install |
| 4. Inside the Docker box | Fast | Yes | One docker run on that machine |
1. Your computer, reading S3
Snapshots → Download → Use it where it lives → Download a DuckDB schema → tick Works on
another machine (it shows when the server keeps snapshots in S3) → download
views.sql. It uses the AWS access your machine already has.
duckdb -init views.sql lake.dbUse DuckDB 1.5 or newer: the file then opens in about 9 seconds over the
internet for 17 tables. Older versions take closer to a minute. To move to a
newer snapshot in a session that is already open, read the file again
(.read views.sql).
Someone else should read the bucket too? Give them the read-only policy.
2. Your computer, files downloaded
Snapshots → Download → Download the data. Unpack it and open DuckDB inside the folder it creates:
tar xzf dbtrail-backup-*.tar.gz
cd <the folder it created>
duckdb -init views.sql lake.dbWhat you downloaded is the copy at that moment. For newer data, download again.
3. The DBTrail machine
Snapshots → Download → Use it where it lives → Download a DuckDB schema, with Works on another
machine unticked. Then, on that machine, duckdb -init views.sql lake.db.
On the Docker install the files live inside a Docker volume, so this file's paths do not exist on the machine itself: use option 4.
4. Inside the Docker box
Get views.sql as in option 3 and put it in the folder with
docker-compose.yml on the server. Then, in that folder:
docker run --rm -it \
-v "$(basename "$PWD")_bintrail-state:/var/lib/bintrail:ro" \
-v "$PWD:/work" \
duckdb/duckdb -init /work/views.sql /work/lake.dbKeep it current
Options 1, 3 and 4 follow the copy as DBTrail updates it, once the schedule is
on: Snapshots, tab Settings, card Update the copy, pick how often,
Turn on. It is off until you do. An S3 location alone works too (since
0.101.0); before that version, add a Local folder, or every update reads
your whole database again.
Download views.sql again when a table is added, dropped or changes shape.
How the updates work: How the Parquet copy works.
An error opening the copy: Troubleshooting. Charts on top of it: Dashboards.
One connection, with ProxySQL
Your application keeps one connection and its own PostgreSQL login. ProxySQL sends writes and transactions to your PostgreSQL, and reads to DBTrail, which answers the heavy ones from the copy.
Dashboards
Dashboards in Metabase, or any tool that runs DuckDB, that never slow down your MySQL and update on their own with every snapshot.