You’re standing up a new database server and you want snapshots, integrity checking, and the option to roll back a bad migration without restoring from backup. ext4 and xfs don’t give you any of that natively; both ZFS and Btrfs do. You read three benchmark posts that contradict each other and you’re now wondering whether to pick the one with the eight-year track record on FreeBSD or the one that ships in mainline Linux. The honest answer is that for a database server, ZFS wins by a noticeable margin — but only if you understand what you’re trading away.
What’s happening
Both ZFS and Btrfs are copy-on-write filesystems. Both checksum every block, both take cheap snapshots, both can give you transparent compression. The differences matter most for a database workload because a database does three things constantly that interact awkwardly with CoW:
- Random small writes, often 8 KB or 16 KB at a time, scattered across a large data file.
- fsync at commit time, which must reach durable storage before the transaction returns.
- Recurrent rewrites of the same blocks (heap pages, index pages, WAL).
Random rewrites are the worst case for any CoW filesystem because every write writes to a new block — the on-disk layout fragments as the file ages, until a single 8 KB read may scatter across many physical locations. The two filesystems handle this differently:
- ZFS runs a tunable record size per dataset. Set
recordsize=8Kon a Postgres data directory andrecordsize=16Kon a MySQL InnoDB directory; the filesystem stops trying to coalesce small writes into large records and the fragmentation cost drops. ZFS also has its own write cache (ZIL) and a separate intent log device (SLOG) you can put on a low-latency NVMe to absorb fsync latency without touching the pool’s main vdevs. - Btrfs has no equivalent of
recordsize. The mitigation for database workloads is to disable CoW on the directory entirely withchattr +C. That gives you per-file overwrite-in-place semantics — and silently disables checksumming and snapshots for those files. A snapshot of a+Cdirectory captures the metadata but the file data is no longer protected by Btrfs’s integrity guarantees. This is a real tradeoff, not a tuning knob.
On fsync, ZFS’s behavior is well-understood: writes go to the ZIL, fsync returns when the ZIL records are durable, and the data is migrated to the pool on the next txg commit. With a SLOG on an enterprise NVMe with PLP (power-loss protection), fsync latency on ZFS can be sub-millisecond even under heavy load. Without a SLOG, the ZIL lives on the data vdevs and fsync becomes sensitive to background pool activity. Btrfs, by contrast, journals metadata but not data; fsync forces the data blocks to platter through the normal write path. With nodatacow files, this is effectively the same as ext4’s fsync behavior. Without nodatacow, fsync on Btrfs is competitive on small loads but degrades faster under fragmentation than ZFS does.
The third axis is memory. ZFS does not use the Linux page cache for data blocks — it uses its own ARC (Adaptive Replacement Cache), which is more sophisticated than the kernel’s LRU but is sized in module zfs zfs_arc_max and is not freed under memory pressure as aggressively as the page cache. On a database server with 64 GB of RAM, a default ZFS install will let the ARC consume up to half of system memory and free -h will report most of it as “used,” not “available.” If you also size shared_buffers or innodb_buffer_pool_size to a quarter of RAM, you can starve the database. The remedy is to set zfs_arc_max to a tight number — for Postgres, we usually set zfs_arc_max to 25% of RAM and shared_buffers to 25%, leaving the rest for the kernel and the application. Btrfs uses the standard page cache, so this whole class of misconfiguration doesn’t exist.
The fourth axis is operational maturity. ZFS-on-Linux has been production-stable since 2.0 (2020) on AlmaLinux, RHEL, and Ubuntu. Btrfs raid5/raid6 is still flagged as “use at your own risk” in the upstream documentation — for a database, that means raid1 or raid10 only. ZFS raidz2 is a first-class production configuration.
How to verify
Before you commit to either, run two short benchmarks against the actual disk you’ll deploy on. They take half an hour and they decide the choice.
Sustained random write IOPS at 8 KB:
# Postgres-shaped: 8 KB random write, 16 threads, fsync on every commit
fio --name=pg-like --rw=randwrite --bs=8k --ioengine=libaio --iodepth=16 \
--direct=1 --fsync=1 --size=10G --numjobs=4 --group_reporting \
--filename=/var/lib/pgsql/fiotest
Compare ZFS with recordsize=8K, compression=lz4, atime=off, logbias=throughput against Btrfs with nodatacow and against Btrfs without it. The third number is usually the worst; the first two are within a small percentage of each other on a single SSD and ZFS pulls ahead on more disks.
fsync latency under load:
fio --name=fsync-only --rw=randwrite --bs=8k --fsync=1 --iodepth=1 \
--numjobs=1 --runtime=60 --time_based --size=1G \
--filename=/var/lib/pgsql/fiotest --output-format=json | \
jq '.jobs[0].sync.lat_ns.percentile."99.000000"'
p99 fsync latency below 1 ms (1,000,000 ns) is healthy. Above 5 ms on a database server suggests the ZIL or the journal can’t keep up.
Memory accounting on a candidate ZFS host:
arcstat 1 5
# time read miss miss% dmis dm% pmis pm% mmis mm% size c avail
# 13:12 2.1K 120 5 80 4 40 1 100 4 14G 24G 6G
cat /sys/module/zfs/parameters/zfs_arc_max # 0 = auto, half of RAM
If zfs_arc_max is 0 on a system that will also run a database, set it explicitly before the application starts — not after.
The fix
A decision matrix that captures the practical defaults we install on customer hosts:
| Scenario | Recommendation | Why |
|---|---|---|
| Single-node Postgres / MySQL with high write rate | ZFS | recordsize matches DB page size; ARC tuning gives predictable memory; SLOG absorbs fsync. |
| Replicated DB (Patroni / Galera) where the DB tolerates a node restore from snapshot | ZFS | Faster snapshots, faster zfs send for cross-region sync. |
| OS root + occasional service rollback after bad updates | Btrfs | Built into the distro, snapper integration, GRUB rollback entries out of the box. |
| Mixed-role host (DB + web + cache) with limited RAM | Btrfs | No ARC accounting surprises; the kernel page cache shrinks under pressure. |
| Multi-PB array with raid5/raid6 equivalent | ZFS raidz2 | Btrfs raid5/6 is not production-grade as of 2026. |
| File server / WORM archive | Either | Both checksum and compress well; pick by team familiarity. |
| Read-heavy DB (analytics, dashboards) with large dataset | ZFS | ARC’s adaptive replacement outperforms LRU on the typical “hot table + occasional scan” pattern. |
Concrete ZFS dataset for Postgres 16:
zfs create \
-o recordsize=8K \
-o compression=lz4 \
-o atime=off \
-o xattr=sa \
-o logbias=throughput \
-o redundant_metadata=most \
tank/pgsql
# Set ARC max to ~25% of RAM (e.g. 16 GB on a 64 GB host)
echo "options zfs zfs_arc_max=17179869184" > /etc/modprobe.d/zfs.conf
Concrete ZFS dataset for MySQL 8 InnoDB:
zfs create \
-o recordsize=16K \
-o compression=lz4 \
-o atime=off \
-o xattr=sa \
-o logbias=throughput \
tank/mysql
Concrete Btrfs setup for a small Postgres on a Btrfs-root host where you really want CoW snapshots on the OS but not on the DB:
btrfs subvolume create /var/lib/pgsql
chattr +C /var/lib/pgsql
# Mount with: noatime,space_cache=v2,compress=no,nodatacow,nodatasum
# Exclude this subvolume from snapper.
The rule of thumb: ZFS for the database server itself, Btrfs for general-purpose Linux hosts where you mostly want OS rollback. A small fleet often ends up with both — ZFS on the database tier, Btrfs on the application tier — because each is the right tool for what it’s actually doing.
If you want this decided once and operated reliably, Stack Harbor scopes filesystem and storage layout as part of Cloud compute and runs the result under Managed Cloud Ops. For a quick second opinion on your current layout, request a storage review.