Skip to content

Investigate slow SQL

Separate instantaneous waits, cumulative counters and active query identity.

Separate now from history

session waits shows what is waiting right now; session identifies active PIDs. sql top ranks cumulative sys_stat_statements workload since the last reset—it does not prove a query is slow at this exact second. Review calls, mean, max, and total together.

kbdiag session waits
kbdiag session
kbdiag sql top --by=time
kbdiag sql top --by=calls --sql-db=test --sql-user=system
kbdiag sql show --id=<signed-int64> --sql-db=test --sql-user=system
kbdiag session <pid>

Statement queryid values are signed 64-bit integers and can be negative; always pass negative values via --id=<negative> or after --. --sql-db and --sql-user filter statement metrics, while -d and -U choose the database connection.

Match identity and capability

Keep (dbid, userid, queryid) distinct—the same queryid under two users or databases represents separate entries. On KES V9, sql show matches active sessions sharing sys_stat_activity.queryid; on kernels without sys_stat_activity.queryid (such as KES V8R6), sql show reports active matching as unavailable (UNKNOWN) rather than falsely claiming zero matches. SQL text similarity alone is never treated as an identity match.

Follow the bottleneck

Continue with lock --tree for Lock waits, progress for long maintenance operations, or space/wal for heavy temp-block or I/O activity. When statement statistics are missing, or track=none returns zero retained rows, kbdiag reports UNKNOWN/skipped (retained historical rows remain readable as OK with a track=none note) without modifying parameters or enabling extensions. kbdiag never runs automatic EXPLAIN.

SQL workload reference · Session reference