DBTrail
Capacity Planning

Capacity Planning

What DBTrail uses in memory, CPU and disk, measured on a real deployment, and how big a machine to start with.

One daemon captures, indexes and rotates. The index MySQL holds the state: size that.

The machine that runs DBTrail needs at least 4 physical cores and 16 GB of memory for production; 8 cores and 32 GB are recommended. Count cores, not vCPUs: on most Intel and AMD cloud instances a vCPU is half a core, so 4 cores are 8 vCPUs (on AWS Graviton and the AMD c7a, m7a and r7a families, one vCPU is one core). 8 GB is for evaluating DBTrail on a small database. How big a machine has the details.

The figure below is what capture alone uses on a quiet machine, not a size to plan for: SQL on the copy needs the cores and memory above.

Measured on 2 vCPU and 8 GB with two sources. Memory: index MySQL 833 MB, DBTrail daemon 93 MB, time-travel port 9 MB. CPU about 7 percent daily average, load average 0.1 to 0.2, one replication connection per server.

Disk

Live index with one day of retention: WordPress at 4,500 changes a day uses 39 MB, RDS at 255,000 changes a day uses 128 MB. The whole index data directory is about 3 GB, of which 167 MB are changes and the rest is fixed InnoDB overhead.

Per-change cost grows with row width and with binlog_row_image=FULL. Filtering schemas cuts it.

Watch the index disk

Status → Index disk shows free space and time until full; bintrail doctor prints days until full. A full disk stalls capture, and once the source purges its binlogs the gap is permanent. Status

Disk for a full read of MySQL

A full read of a MySQL or MariaDB server (Read database now, or a scheduled full read) first writes the whole database as an uncompressed dump into the working folder, and only then converts it to Parquet. The dump is deleted when the run ends. This is disk on the DBTrail host, not on the database server.

Free space at the working folder should be at least the size of the dumped tables (data plus indexes), and about 1.8× that when the Parquet goes to the same disk and the data is mostly binary or random.

Before mydumper starts, DBTrail adds up DATA_LENGTH and INDEX_LENGTH of every table it is about to dump and compares them with the free space at the working folder:

Free in the working folderWhat happens
Less than half the size of the data, not counting indexesThe read is refused before anything is dumped. No measured dump came to less than that: the smallest, apart from a table with most of its rows deleted, was 0.89× its data
Less than the data plus the indexesThe read runs, with a warning that the dump may not fit
Less than 1.8× the data plus the indexes, with the Parquet on the same disk as the working folderThe read runs, with a warning that the dump plus its Parquet may not fit
The sizes or the free space cannot be readThe read runs, and says the check did not run

A warning is about that read. Once the read has written its snapshot the note says "This read fit. The next one may not."

The numbers come from one synthetic measurement: MySQL 8.4, mydumper 1.0.5 with the flags DBTrail passes, five tables of different shapes, one machine. It is not yet confirmed on real datasets. Ratios are against DATA_LENGTH + INDEX_LENGTH:

Table shapeDump ÷ (data + indexes)Peak (dump + Parquet) ÷ (data + indexes)
Random strings, 1 secondary index0.821.21
Numbers and dates, 3 secondary indexes0.600.75
Repetitive text and JSON0.981.02
Random binary0.951.80
90% of rows deletedstale sizesstale sizes

The dump alone stayed below the data plus the indexes in every case. With the Parquet on the same disk, data that does not compress peaked at up to 1.8×. The table with 90% of its rows deleted reported its sizes from before the delete, so the estimate was too high, not too low.

  • Where the working folder is: with nothing set, baseline-staging beside DBTrail's own data (/var/lib/bintrail/baseline-staging in the Compose stack). Move it with BINTRAIL_CONSOLE_BASELINE_STAGING, or console-baseline-staging in the option file, then restart DBTrail: console-baseline-staging.
  • Another disk: when the server's Local folder is on another disk, the working folder only has to hold the dump, and a small Local folder is a warning, never a refusal. Another disk means another filesystem: btrfs subvolumes, ZFS datasets and thin LVM volumes draw from one pool, so on those the 1.8× margin is yours to keep.
  • Several reads at once: full reads of several servers that run at the same time share one working folder, and each check sees the whole free space, not what is left after the others. Size the folder for the reads you let overlap.
  • Compressed tables: a table with ROW_FORMAT=COMPRESSED, or one in MyRocks, reports its compressed size and is dumped uncompressed, so the sizes above are not a bound for it. The check counts those tables and names the two largest, and when the free space covers the reported sizes its note opens with "Disk check cannot tell whether this read fits" instead of saying there is room.
  • If the folder fills anyway: the read fails and is recorded as a disk failure. The partial dump is deleted, no new snapshot is made and earlier ones are unchanged. A scheduled full read is tried again at its next time, not sooner.
  • Before the first read, from the command line: bintrail doctor --source-dsn … --staging-dir <folder> reads the same table sizes and compares them with the free space of that folder. It measures the folder on the machine doctor runs on, sizes the tables --schemas selects, and never changes doctor's exit code.
  • Not checked: a dump you run yourself with bintrail dump.

Disk for a PostgreSQL snapshot

A snapshot of a PostgreSQL server has no dump. Each table is copied straight into a Parquet file in the server's Local folder, so the working folder is not involved and the Local folder is the one that has to have the room.

Before a snapshot starts (the first copy after server add, Read database now, snapshot run, a scheduled full read), DBTrail adds up pg_table_size of every table the snapshot copies: the heap and its TOAST, without indexes, and a partitioned table by its partitions. It compares the sum with the free space of the Local folder:

Free in the Local folderWhat happens
Less than 1 GiBThe snapshot is refused before anything is read, and before the replication slot is created. The message gives what is free, the 1 GiB, and the size of the tables
Less than 1.3× the tables' sizeThe snapshot runs, with a warning that it may fail with a full disk. Once it has written its snapshot the note says "This read fit. The next one may not."
The sizes or the free space cannot be readThe snapshot runs, and says the check did not run

The 1 GiB is the room DBTrail keeps free when it writes a snapshot update, so below it no update would be written afterwards either.

The size of the tables alone never refuses, because a snapshot is compressed (zstd) and how much depends on the data. Measured on PostgreSQL 16, as the snapshot's size over pg_table_size:

TableSnapshot / table size
The same text in every row0.007×
Order rows (numbers, a status, dates, short text)0.22×
Long text PostgreSQL already compressed in TOAST0.20×
Random hex text, half the rows deleted0.31×
Random UUIDs and numbers0.65×
Random hex text0.69×
Random bytea (written as hex)1.22×

The warning uses the highest ratio measured, rounded up: it comes early for ordinary data and was not late for any of these.

  • Tables the sizes say little about: one kept by a table access method other than PostgreSQL's own heap (a columnar or compressed store), one with child tables by inheritance (INHERITS, or a TimescaleDB hypertable), and a foreign table among a partitioned table's partitions. The check counts those tables and names the two largest, and when the free space covers the reported sizes its note opens with "Disk check cannot tell whether this snapshot fits" instead of saying there is room. The same goes for a table the server gave no size for.
  • Where you see it: the snapshot's status, its run history and detail, the schedule card, and the message after a snapshot you started yourself. A refusal is recorded as a disk failure, so the schedule does not answer it with another full read into the same disk.
  • More room: free space in the snapshot folder, or give the server a Local folder on a bigger disk (Snapshots, under Where and how often: Backup settings).
  • From the command line, bintrail-pg baseline writes where --output says and does not run this check, and bintrail-pg doctor does not report it.

How retention works

Every hour by default: export old hours to Parquet, upload to S3, delete the local copy only after the upload worked, drop the hours from the index. A failed upload keeps the hours in the index. WordPress binlog 30 MB a day becomes 1.5 MB of Parquet, about 20 to 1. Eight weeks of both sources is 474 MB in S3 for 13.7 million changes, under 1 dollar a month for a year.

Archive compression

zstd by default, snappy and gzip supported. S3 keeps archives per your bucket lifecycle rules. Settings: Retention.

Lag

Change on the source to row in the index: sub-second for typical OLTP, hundreds to low thousands of writes per second. A checkpoint is saved every 10 seconds (--checkpoint); restart resumes from it.

What affects lag

  • Bulk writes: large INSERTs, batch UPDATEs
  • Wide rows: big TEXT or BLOB columns
  • Network distance or an SSH tunnel to the source
  • Index disk speed: SSD; very write-heavy sources may need provisioned IOPS

Restart policy: systemd or Docker (restart: unless-stopped in the bundled stack). Binlogs purged past the checkpoint: take a fresh snapshot.

A busy server, measured

One source at 5,200 row changes a second, on 16 vCPU and 128 GB.

Small installBusy server
Row changes255,000 a day450 million a day
Source binlogunder 1 GB a day150 GB a day
Index disk128 MB a day21 GB an hour
Index MySQL buffer pooldefault48 GB
Daemon memory93 MB0.5 GB idle, 3 to 12 GB during an update
Capture lagunder a secondnone, up to 15,500 changes a second

Rules of thumb

  • Index disk: 1.1 KB per row change, about three times the binlog.
  • Index MySQL: give it memory first. With the default 128 MB buffer pool it captured 1,400 changes a second. With 48 GB, 16,000. How to set it: below.
  • First copy: 100 million rows in 5 to 7 minutes.
  • Parquet copy: 7 to 18 times smaller than the tables in MySQL.
  • Each update: 15 to 30 seconds while the busiest table changes under a million rows per update.

Measured with DBTrail 0.98.0 under a sysbench-tpcc load, on a 16,000 IOPS SSD.

Give the index MySQL memory

MySQL's default is a 128 MB buffer pool on any machine. On a busy source that caps capture at about 1,400 row changes a second, and the lag grows without end while the machine sits mostly idle. Nothing stops; the copy just falls further behind.

The bundled stack sizes it through INDEX_BUFFER_POOL in the .env next to docker-compose.yml. A fresh install.sh writes it for you: a quarter of the memory Docker has, whole gigabytes from 1G up, at most 32G. A quarter, not more, because the SQL engine in the web interface takes up to 4 GB and your source MySQL may run on the same machine. Raise it when the machine runs nothing else.

To set or change it on a stack you already have (the installer never rewrites a value you set, and a re-run only prints the line to add):

echo 'INDEX_BUFFER_POOL=8G' >> .env   # whole GB, or e.g. 512M
docker compose up -d                  # restarts the index MySQL; capture resumes from its checkpoint

A docker-compose.yml from before v0.100.0 does not pass the value on. Take the current file first: Upgrading the stack.

bintrail doctor, the startup checklist and the server checks in the web interface warn Index buffer pool when an index on this machine still runs with 128 MB and the machine has about 4 GB or more. DBTrail only reads the setting; it never changes your index. With your own MySQL as the index (INDEX_DSN), set innodb_buffer_pool_size yourself, 50 to 70% of the RAM it has to itself.

How big a machine

Physical coresMemoryIndex buffer poolDisk
Evaluation, one small database28 GB2 GB20 GB SSD
Production, minimum416 GB4 GBfrom Disk
Production, recommended832 GB8 GBfrom Disk
One busy server, 150 GB of binlog a day8 or more64 GB or more32 to 48 GB1 TB SSD without S3
  • Cores, not vCPUs. SQL on the copy runs on cores, and two threads of one core do not add up to two cores: an analytical query is noticeably faster on 4 physical cores than on 4 vCPUs that are 2 cores. Capture and the snapshot refresh use the cores too; 8 leave them room without slowing the statements down.
  • Memory is shared by the index MySQL's buffer pool, capture and the SQL statements. On 8 GB, a database of tens of GB under constant writes runs the machine out of memory, and capture is the first process to stop: a stopped capture is a gap in what you can recover.
  • The index buffer pool column is the quarter of the memory install.sh writes for you (see above).
  • Below the minimum, a problem caused by memory or CPU is not something we tune for.

Many clients on the MySQL port

Heavy queries on the copy use the cores. Once every worker is busy, more clients make the line longer, not the answers more frequent.

24heavy a secondWhat the copy answered on 16 cores, full scans of a 10-million-row table, from 50 clients to 2,000. CPU was the limit; memory peaked at 2.2 GiB.
line ÷ 24the waitA heavy query waits for the line ahead of it to clear: 1,953 waiting at 2,000 clients is about 81 s.
1.1 to 1.8 msa lookup by keyWith Engine Routing on, lookups go to MySQL and skip the line: that median at every step, straight to the port.
0client errorsUp to 2,000 clients. Past the ceiling nothing was refused for load: heavy queries waited in line.

Numbers of one test setup on DBTrail 0.133.1, with the source taking 400 writes a second. The setup, the curves and how to work out your own ceiling: Many clients at once. From 0.139.1 the router takes 256 connected clients unless you raise it, and 1024 at most.

Next

On this page