Skip to content

sql: cumulative workload and queryid profile

Rank cumulative SQL workload and inspect a signed queryid profile.

Find top cumulative statements from sys_stat_statements (sql / sql top), then inspect one signed 64-bit queryid profile and its matching active sessions (sql show). Read-only: never runs online EXPLAIN.

Usage

kbdiag sql                                 # default: top by total time
kbdiag sql top --by=calls --limit=20       # time | mean | calls | io | temp
kbdiag sql top --sql-db=app --sql-user=app # filter stats + pass to NEXT
kbdiag sql show --id=-8006383000735440858  # signed int64 profile + active
kbdiag sql show -- -8006383000735440858    # negative positional ID after --

Subcommands & Options

OptionEffect
sql / sql topRank cumulative statements (--by=time|mean|calls|io|temp, --limit N)
sql show --id=<int64>Show one statement’s cumulative metrics plus live sessions sharing queryid
--sql-db, --sql-userFilter statement rows without changing the connection’s -d / -U
--jsonEmit structured JSON (sql.top, sql.show, sql.show.active)

Verdict & Reading Output

  • OK (exit=0): Collected requested cumulative metrics and active match status cleanly; equal queryid entries across different (dbid, userid) pairs stay separate, never summed.
  • UNKNOWN (exit=3): sys_stat_statements missing/track=none with no rows, hidden queryid for non-monitoring accounts, or missing sys_stat_activity.queryid capability (e.g. KES V8R6, where sql show explicitly marks active matching unavailable).
  • Cumulative window caveat: Counters accumulate since the last statistics reset (or retain older rows when sys_stat_statements.track=none).

Example (KES V9 Primary, COLUMNS=80)

sql.show  OK  (primary, system@local, endpoint=/tmp/.s.KINGBASE.54321, db=test,
    2026-12-02T15:23:05Z)

[PROFILE]
  +- queryid=555503969233108775; cumulative since statistics reset (reset time
     unknown)
  +- scope filter: sql_db=test sql_user=system
  +- dbid=14753 userid=10 queryid=555503969233108775
  |  database=test user=system
  |  calls=1 total=1.25 s mean=1.25 s max=1.25 s rows=1
  |  shared hit=866 read=0 temp written=0 blocks
  |  SQL: SELECT pg_sleep($1) FROM public.kb_sql_day3 WHERE id = $2

[ACTIVE]
  +- current active sessions; separate from cumulative counters
  +- dbid=14753 userid=10 queryid=555503969233108775 pid=92579 age=2s
     wait=Timeout/SysSleep

[NEXT]
  +- kbdiag session 92579
  • kbdiag session — inspect live PID details (sql activity, waits, locks)
  • kbdiag lock — check whether top execution time comes from lock contention
  • kbdiag space — inspect temp file / disk headroom when temp or io leads