Profiling PostgreSQL: perf, Flame Graphs, and eBPF Tools in Practice
April 21–22
PostgreSQL is highly optimized, but workloads often reveal performance problems that are hard to diagnose with SQL tooling like EXPLAIN alone.
Many engineers use perf as the go-to profiler for Linux systems. However, several other tools allow you to visualize information more clearly, provide additional insights, or analyze function calls. For example, flame graphs are a common way to visualize stack traces and the time spent in each function. On-CPU and off-CPU flame graphs help to understand where CPU hotspots exist or if functions have to wait for resources like I/O. Differential flame graphs can be used to compare two profiling runs (e.g., an optimized versus a non-optimized implementation) to identify where performance improves or degrades. Other eBPF-based tools (e.g., funccount, funclatency, bpftrace) can be used to go even further. They allow you to count function invocations, measure the latency of individual function calls, or consider function parameters.
In my talk, I will discuss how to use these tools to detect performance bottlenecks in an example PostgreSQL extension. The audience will learn how to use these tools, their limitations, and the differences between production and debug builds of PostgreSQL.