Skip to content

session: active sessions, PID detail and wait summary

List active and blocking sessions, inspect one PID’s SQL and locks, or group current wait events.

Inspect live instance sessions from three angles: session (overview and active/blocking list), session <pid> (one session’s full SQL, waits, and locks), and session waits (wait-event distribution). Read-only: never terminates or cancels backends.

Usage

kbdiag session                   # overview + active/in-txn/blocking list
kbdiag session --app order-svc   # filter table rows (excludes idle by default)
kbdiag session --all --wide      # include idle/background + client/queryid
kbdiag session 91166             # one PID's SQL, waits, and held/waiting locks
kbdiag session waits             # group active/waiting sessions by wait event

Key Options

OptionEffect
--app, --session-user, --session-dbNarrow displayed rows ([OVERVIEW] and JSON remain instance-wide)
--state, --wait-type, --min-xact-ageFilter by session state (active/idle/idle-in-txn/waiting), wait type, or txn age
--sort xact|query, --limit N, --wideControl row sorting, display cap, and client/queryid columns

Verdict & Reading Output

  • WARN (exit=1): Open idle in transaction session >= 300s (--idle-in-txn-warn), or wait >= 10s (--lock-wait-warn) on session <pid>.
  • OK (exit=0): All visible sessions within configured thresholds.
  • UNKNOWN (exit=3): Non-monitoring roles unable to read other sessions’ SQL/waits see [REDACTED] and visible counts rather than fake 0 activity.
  • session <pid> / session waits: session <pid> labels idle in transaction queries [LAST SQL] and prints blocker jump commands; session waits separates idle background/walsender loops from active waits.

Example (KES V9 Primary, excerpt, COLUMNS=80)

sessions  OK  (primary, system@local, endpoint=/tmp/.s.KINGBASE.54321,
    2026-12-02T14:29:41Z)

[OVERVIEW]
  connected   : 3 client sessions (not counting kbdiag), 7 background
  states      : active=2, idle-in-txn=1
  wait events : Client=1, Lock=1, Timeout=1 (excl. idle Client/Activity)
  blocking    : 1 direct blocker -> 1 waiting session
                (sessions verdict judges idle-in-txn only)

[BLOCKING FOCUS]
  PID 91166  kbdiag_day2_holder idle in txn    (2s) -> blocking 1 (91169)

[ACTIVE & IN-TXN SESSIONS (3)]
  PID    STATE        XACT  QUERY  WAIT                BLOCK
  91166  idle in txn  2s    2s     Client:ClientRead   blocking 1
    > system/test (kbdiag_day2_holder) | UPDATE public.kb_sess_day2 SET val=...
  91169  active       2s    2s     Lock:transactionid  by 91166
    > system/test (kbdiag_day2_waiter) | UPDATE public.kb_sess_day2 SET val=...
  • kbdiag lock — expand the full blocking hierarchy and DDL queue predecessors
  • kbdiag txn — inspect long open transactions and prepared 2PC horizons
  • kbdiag sql — trace a queryid from session --wide into cumulative statistics