Direct I/O: ClickHouse's Backup Secret
Alps Wang
Oct 2, 2026 · 30 views
Optimizing Database Backups with Direct I/O
The article provides a compelling case for Direct I/O in ClickHouse Managed Postgres backups, effectively demonstrating its benefits in reducing query latency and CPU usage during backup operations. The detailed explanation of how default buffered I/O negatively impacts performance by evicting crucial data from the page cache, and how Direct I/O circumvents this, is technically sound. The authors do an excellent job of illustrating the problem and solution through empirical data and clear explanations of the underlying mechanisms. The tuning of read size and reader count to match the RAID0 stripe configuration is a particularly noteworthy technical detail that showcases a deep understanding of hardware-software interaction.
However, a potential limitation lies in the assumption that Direct I/O is a universally applicable silver bullet. While highly effective for backup scenarios where data is read sequentially and once, its application in other I/O patterns or for different database operations might be less beneficial or even detrimental. The article correctly points out that Direct I/O bypasses kernel readahead, which can be a performance bottleneck if not managed properly, as demonstrated by the need to carefully size read operations. Furthermore, the article focuses heavily on NVMe drives and RAID0 configurations. While these are common in high-performance database environments, users with different storage setups (e.g., traditional HDDs, different RAID levels, or cloud-managed block storage with varying I/O characteristics) might need to conduct their own extensive testing to validate these findings. The article also doesn't deeply explore the overhead of managing Direct I/O tuning, especially in highly dynamic environments where storage configurations might change frequently. Despite these minor points, the article's contribution to understanding and optimizing database backups is significant.
Key Points
- Direct I/O bypasses the Linux page cache, preventing backup reads from evicting critical database data (like indexes, WAL, and hot tables) that is actively used by running queries.
- By skipping the page cache, Direct I/O reduces query latency during backups by approximately two-thirds and consumes about 14% less CPU.
- Direct I/O disables kernel readahead, which can lead to inefficient I/O on striped NVMe drives. To mitigate this, ClickHouse Managed Postgres sizes Direct I/O reads to span the entire RAID0 stripe and scales the reader count to match the hardware (e.g., 4 MiB reads on a 4-drive RAID0).
- The article demonstrates empirical evidence of Direct I/O's benefits using a live PostgreSQL instance, showing significantly less data eviction and faster recovery to baseline query performance compared to buffered reads.
- Workload protection is further enhanced by using cgroups to limit backup CPU usage and by carefully managing wal-g's upload buffer sizes.

📖 Source: What is direct I/O, and why does ClickHouse Managed Postgres use it for backups?
Related Articles
Comments (0)
No comments yet. Be the first to comment!
