dbtrail blog
GitHub dbtrail.com
Back to the blog
dbtrail

Run your heaviest PostgreSQL reports without touching production

On a machine the same size as a streaming replica, 22 CH-benCHmark reports ran about 10 times faster, with the copy 5 seconds behind the source.

DG Daniel Guzman-Burgos December 1, 2026 8 min read

The report that sums a year of orders runs on the same PostgreSQL that takes the orders. While it scans, the sales wait for CPU and disk, and the person who asked for the report waits too. A read replica takes the report away from the sales, but the report is just as slow there.

DBTrail is open source and now works with PostgreSQL. You point your BI tool, psql or the reporting part of your application at DBTrail’s PostgreSQL port. Heavy reports are answered from a copy of your tables that DBTrail keeps a few seconds behind your database, so they no longer run on it. Your application keeps writing to your database as it does today. And when someone runs an UPDATE without a WHERE, DBTrail gives you the SQL that puts the rows back.

Live board: 22 reports on DBTrail and on a PostgreSQL replica of the same size, DBTrail about 10 times faster, its copy 3 seconds behind
The board we keep running on AWS, 15 minutes on 1 December: HammerDB writes into PostgreSQL the whole time, and each report runs on a replica and on DBTrail at the same moment, on machines of the same size. At that moment the copy was 3 seconds behind.

What changes for you

  • Reports come back in seconds. On the board above, 22 reports that took from 4 seconds to over 5 minutes on a replica of the same size took between 0.5 and 7 seconds on DBTrail.
  • The data is seconds old. The copy follows your database’s changes as they happen: over 6 hours of steady writes it was typically 5 seconds behind, and 10 seconds at most. You can set a maximum age; a report that would read older data then runs on your database instead.
  • Your writes do not go through DBTrail. DBTrail’s port only reads, so your application keeps writing to your database directly, and if DBTrail stops, your orders keep coming in. The reads that DBTrail passes to your database take about 2 ms more than going there directly (3.0 ms against 0.8 ms at the median).
  • No extension, no schema changes. DBTrail uses PostgreSQL’s logical replication. You set wal_level = logical, which needs a restart, and create a publication and a role; DBTrail creates its replication slot and checks the rest when you connect it. Like any logical replication client, the slot keeps WAL until DBTrail has read it, so set max_slot_wal_keep_size to cap the disk it can use. If that cap is reached and the slot is dropped, DBTrail records which changes it missed, and catching up again takes a new first copy.
  • An undo for bad writes. The same capture keeps the previous value of every row. If someone runs an UPDATE or DELETE without a WHERE, DBTrail shows what the rows looked like before and writes the SQL that puts them back, without restoring a backup.
Someone forgets the WHEREUPDATE orders SET status = ‘cancelled’;orders, before and after1001shipped→cancelled1002pending→cancelled1003shipped→cancelledDBTrail writes the SQL to undo itUPDATE orders SET status = ‘shipped’  WHERE id = 1001;UPDATE orders SET status = ‘pending’  WHERE id = 1002;UPDATE orders SET status = ‘shipped’  WHERE id = 1003;From the history DBTrail keeps of every row change. No backup to restore.

The undo comes from the history DBTrail keeps of every row change.

Getting started

On a Linux server (Ubuntu 22.04 or 24.04, Debian 12, Amazon Linux 2023, RHEL, Rocky or AlmaLinux 9), one command installs DBTrail as services of the machine, without Docker:

curl -fsSL https://raw.githubusercontent.com/dbtrail/dbtrail/main/install-server.sh | sudo DBTRAIL_FOR=postgres sh

On any machine with Docker and Compose:

curl -fsSL https://raw.githubusercontent.com/dbtrail/dbtrail/main/install-postgres.sh | sh

Both installers are scripts you can download and read before running them. The packages they install (.deb and .rpm) are also available on their own.

Then connect your database and take the first copy:

sudo dbtrail server add --flavor postgres -h <host> -u dbtrail -p -d <dbname> --publication <publication>
sudo dbtrail snapshot run <name>

The installer prints the psql command for DBTrail’s port, 5433. Point your report tool at the same address. The PostgreSQL quick start has every step, including the commands that prepare your database. It works with PostgreSQL 15 to 18, on your own servers and on RDS and Aurora.

How it works

Your applicationwrites, as todayYour PostgreSQLtakes the writesBI tool, psqlyour reportsDBTrailport 5433, read-onlyThe copyParquet, read by DuckDBwrites and its own readsheavy reportsshort readschanges, seconds later

Your application keeps writing to PostgreSQL. Report tools connect to DBTrail.

DBTrail reads your database’s changes as a logical replication client, with the pgoutput plugin included in PostgreSQL. It keeps every change in its history store and builds a copy of your tables as Parquet files, which DuckDB reads. On port 5433 it speaks the PostgreSQL protocol and decides, for each statement, where to run it: heavy reads such as aggregations and joins over large tables run on the copy, and the rest goes to your database, read-only. A transaction block opened on the port (BEGIN to COMMIT) runs entirely on your database. Statements that write are refused: they belong on your database’s own connection.

The numbers, and how we got them

The numbers come from the board in the screenshot above, which compares DBTrail with a PostgreSQL streaming replica on a machine of the same size. We compare with a replica because it is what teams usually run for reports today. Columnar extensions that run inside PostgreSQL are another option; DBTrail runs beside your database instead. We took 6 hours of the board.

One pass over the 22 reports, same machine sizePostgreSQL replica18 minDBTrail1 minSum of the 22 median times over 6 hours, HammerDB writing the whole time.

Both sides ran the same reports at the same moment.
  • Source: PostgreSQL 18 (4 vCPU, 8 GB) with HammerDB TPROC-C at 200 warehouses, writing for the whole run: about 130 transactions and 260 changed rows a second.
  • Replica: PostgreSQL 18, streaming from the source, on an AWS c7g.2xlarge (8 vCPU, 16 GB, the same disk as DBTrail’s machine), with memory and parallel settings tuned for that machine.
  • DBTrail: version 0.156.0, installed with the command above on another c7g.2xlarge, with 3 GB for its history store and two reports at a time on the copy.
  • Reports: the 22 analytic queries of CH-benCHmark, TPC-H style reports over the TPC-C tables. Each report started on the replica and on DBTrail at the same time, and the next one started when both had finished. A report that did not finish in 5 minutes counted as 5 minutes.
  • Duration: 6 hours, 36 or 37 runs of each report on each side.
Report Replica DBTrail
Q1 Pricing summary 6.0 s 1.2 s
Q2 Cheapest supplier 119 s 1.1 s
Q3 Unshipped orders by value 42 s 1.5 s
Q4 Orders with a late line 42 s 3.0 s
Q5 Revenue by nation 84 s 4.2 s
Q6 Revenue in a range 6.0 s 1.1 s
Q7 Trade between two nations 106 s 6.7 s
Q8 Market share 6.0 s 2.1 s
Q9 Profit by nation and year 7.5 s 1.9 s
Q10 Top customers by revenue 168 s 4.7 s
Q11 Most important stock 19 s 1.1 s
Q12 Carriers and late lines 60 s 2.4 s
Q13 Customers by number of orders 6.0 s 0.5 s
Q14 Promotion share 6.7 s 1.9 s
Q15 Top supplier 21 s 3.8 s
Q16 Suppliers per part 34 s 6.0 s
Q17 Small-quantity revenue 12 s 3.0 s
Q18 Large orders over 5 min 4.2 s
Q19 Discounted revenue 3.8 s 0.8 s
Q20 Suppliers to promote 6.7 s 1.3 s
Q21 Suppliers who kept orders waiting 21 s 5.3 s
Q22 Customers worth calling 13 s 1.1 s

The table shows the median time of each report. The board records times in steps about 12% apart, which is why some reports show the same value, such as 6.0 s. The geometric mean of the 22 ratios is 10.5. The copy answered all 22 reports in every run. One pass over the 22 reports took about 1 minute on DBTrail and about 18 minutes on the replica.

The copy was typically 5 seconds behind the source, and 10 seconds at most during the 6 hours. The replica was typically 0.05 seconds behind, and 23 seconds at most while it ran the reports.

Short reads sent through DBTrail to the source took 3.0 ms at the median, against 0.8 ms when sent to the source directly. The difference is the extra network hop. None of the 424,793 short reads took longer than 300 ms.

Limits

  • Write rate. These numbers are at about 260 changed rows a second. In a separate run with HammerDB at full speed, about 6,500 rows a second, the 16 GB DBTrail machine ran out of memory while the reports ran, and the copy fell up to 28 minutes behind. We are working on it and will publish that benchmark when the copy keeps up.
  • Seconds-old data. A report on the copy sees data a few seconds old, so it is not for reads that must see a write made a moment earlier. If you set a maximum age and the copy is older, the report runs on your database.
  • Statements the copy cannot run. They go to your database, and you get its answer.
  • One workload, one run. CH-benCHmark on tables that keep growing, measured once. It is not a TPC result, and your reports will behave differently. The quick start gets you to your own numbers.
  • Platforms. The server install is for Linux. RHEL 8 and its derivatives are not supported.

Try it

DBTrail is open source under the Apache 2.0 license, at github.com/dbtrail/dbtrail. To start, follow the PostgreSQL quick start. If one of your reports runs on your database instead of the copy, open an issue with the statement.

CH-benCHmark is derived from the TPC-C and TPC-H specifications. These results are not TPC results and are not comparable to them. TPC-C and TPC-H are trademarks of the Transaction Processing Performance Council.

Get new posts by email

One email when a new post is out. Nothing else, and you can unsubscribe from any email.

Leave a comment