How can you tell whether a SQL query is CPU-bound or I/O-bound?

The same PostgreSQL query sometimes finishes in 200 ms and sometimes takes 8 seconds. You need to find out where the time goes: computation, reading data, waiting, or transferring results to the application. Which tools and metrics would you check? What do the BUFFERS values tell you, and why isn't a single execution plan enough to identify the cause of the slowdown?

ExplainEXPLAIN and optimizationSeniorBackendData Engineer