---
title: "What is direct I/O, and why does ClickHouse Managed Postgres use it for backups?"
description: "A base backup reads every byte of a live database off the same NVMe drives that serve queries. Buffered reads go through the kernel page cache, evicting warm database pages and adding a kernel copy per byte. Direct I/O skips the cache, leaving Postgres’s warm data in place, but also disables kernel readahead. On a RAID0 array, small direct reads hit only one drive, so ClickHouse Managed Postgres sizes each direct read to span the whole stripe and scales the reader count to the hardware. On a 48 vCPU box with four NVMe drives and a 467 GB database, the direct I/O backup evicted nothing, cut query latency impact by about two thirds, used about 14% less CPU, and finished in 71 seconds."
---

# What is direct I/O, and why does ClickHouse Managed Postgres use it for backups?

[Clickhouse](https://yomu.fyi/company/clickhouse) · Oct 2, 2026

**Type:** Explainer

## Summary

A base backup reads every byte of a live database off the same NVMe drives that serve queries. Buffered reads go through the kernel page cache, evicting warm database pages and adding a kernel copy per byte. Direct I/O skips the cache, leaving Postgres’s warm data in place, but also disables kernel readahead. On a RAID0 array, small direct reads hit only one drive, so ClickHouse Managed Postgres sizes each direct read to span the whole stripe and scales the reader count to the hardware. On a 48 vCPU box with four NVMe drives and a 467 GB database, the direct I/O backup evicted nothing, cut query latency impact by about two thirds, used about 14% less CPU, and finished in 71 seconds.

## Context

ClickHouse Managed Postgres runs on local NVMe drives striped with mdadm RAID0. A base backup reads the entire live data directory from the same drives serving queries. Buffered reads go through the kernel page cache, evicting warm database pages and adding a kernel copy per byte. Direct I/O skips the cache but also loses kernel readahead, which on RAID0 causes small reads to hit only one drive.

## Approach / What changed

ClickHouse Managed Postgres configures wal-g with WALG\_DIRECT\_IO=true and sets WALG\_DIRECT\_IO\_BLOCK\_COUNT to 256 blocks per member drive (1 MiB per drive), so each direct read spans the entire RAID0 stripe. The reader count is scaled to the hardware (vCPU/2 for buffered, vCPU for direct I/O).

## Takeaways

- Buffered backup reads fill the page cache with data read once, evicting warm database pages that Postgres relies on, which slows subsequent queries.
- Direct I/O skips the page cache but also disables kernel readahead; on RAID0, small direct reads hit only one drive, so reads must be sized to span the whole stripe.
- ClickHouse Managed Postgres configures wal-g with stripe-sized direct reads (256 blocks per drive) and scales reader count to hardware, achieving a backup that evicts no warm data and finishes as fast as the buffered version.

## FAQ

### What is direct I/O?

Direct I/O (O\_DIRECT) reads data straight from the block device into the process's own buffer without leaving a copy in the kernel page cache. This prevents the backup from evicting warm database pages that Postgres relies on.

### Why does direct I/O lose throughput on RAID0?

Direct I/O disables kernel readahead. On a RAID0 array, a small direct read lands inside one chunk on one drive, leaving the other drives idle. Making each read large enough to span the whole stripe (e.g., 4 MiB on four drives) forces every drive to serve part of the request.

### What performance impact did direct I/O have in testing?

On a 48 vCPU box with four NVMe drives and a 467 GB database under a live workload, the buffered backup evicted all 40 GiB of a warm idle table. The direct I/O backup with stripe-sized reads evicted nothing and finished in 71 seconds, while query latency impact dropped by about two thirds and CPU usage fell by about 14%.

**Tags:** [Backups](https://yomu.fyi/topic/backups), [ClickHouse](https://yomu.fyi/topic/clickhouse), [Direct I/O](https://yomu.fyi/topic/direct-io), [Postgres](https://yomu.fyi/topic/postgres)

- Source: [Clickhouse](https://clickhouse.com/blog/direct-io-managed-postgres-backups)
- Source URL: https://clickhouse.com/blog/direct-io-managed-postgres-backups
- Ingested by Yomu: 2026-10-02T12:00:09.178Z

[Read original post](https://clickhouse.com/blog/direct-io-managed-postgres-backups)
