Marcio Cunha

Database slow? How to find disk I/O bottlenecks in Linux

Learn how to diagnose storage latency in databases using kernel profiling tools like iostat and blktrace to optimize system performance effectively.

Marcio Cunha•2 min
Also available in:PortuguêsEspañol
Summary
  • The iostat tool is the primary utility for quickly identifying if storage latency is throttling query execution.
  • Detailed analysis with blktrace exposes how the kernel queues and processes every read or write operation at the hardware level.
  • I/O bottlenecks often stem from misconfigured file systems or excessive concurrent thread activity.
  • Precision monitoring requires correlating disk response times with the IOPS demands generated by the database.
  • Performance optimization also includes thermal management, as explained in our guide on why NVMe SSDs run hot and how to lower the temperature .

Why does your database stall on disk operations?

When a database starts showing slowness, the initial reaction is usually to look at SQL queries or CPU usage. However, the silent culprit is often the storage subsystem. Linux manages disk access through several layers, and when request queues exceed hardware capacity, the database enters a wait state. In practice, this means your data is stuck waiting for disk space to read or write, creating a domino effect of latency.

Monitoring I/O health with iostat

The iostat command is the classic starting point for any disk diagnosis. It provides real-time statistics on CPU and input/output (I/O) usage. By running iostat -xz 1, you get a clear view of vital metrics like %util (percentage of time the device was busy) and await (the average time a request waits). If the await value is high, your database is literally waiting for the disk to respond, which is a clear sign of a bottleneck.

Identifying deep bottlenecks with blktrace

When iostat isn't enough, we need to open the kernel's black box with blktrace. This tool tracks every block operation entering the storage subsystem. blktrace collects raw data that can be processed by blkparse, allowing you to see exactly where time is lost between the application request and hardware completion. It is like using a high-speed camera to see which file or process is saturating the data bus.

Practical tracing: step by step

  1. Install the necessary tools with sudo apt install sysstat blktrace.
  2. Monitor activity in real time using iostat -xz 1 to identify the saturated device.
  3. Perform kernel tracing during a peak load with sudo blktrace -d /dev/nvme0n1 -o - | blkparse -i -.
  4. Analyze the generated log to find atypical latencies in specific operations.

Hardware and performance considerations

Identifying the bottleneck is only half the battle; the other half is understanding the hardware. Just as it is vital to monitor component health, such as how to find motherboard shorts with a thermal camera, storage performance depends on well-cooled and configured hardware. If your system suffers from recurring bottlenecks on modern drives, it is worth checking how to debug NVMe I/O bottlenecks in Linux for technology-specific adjustments.

Conclusion

Optimizing I/O is a constant exercise in observability. By combining high-level iostat metrics with deep blktrace tracking, you stop guessing and start acting with precision on what actually impacts your database. Remember that the bottleneck is often not in total capacity, but in the access latency to the most frequently used data blocks.