Skip to content

feat: TUI Active Session History (/ash command) #753

@NikolayS

Description

@NikolayS

Summary

Add a \ash command that shows a live TUI-style Active Session History view, inspired by Oracle ASH and pg_ash. Works in two modes depending on whether pg_ash is installed.

Motivation

pg_stat_activity polling is already available to any connected user. pg_ash stores historical samples. rpg can surface both in a unified TUI — giving DBAs an ASH-quality view without leaving the terminal.

Design

Command

\\ash

Layer 1 — always available (no extension needed)

  • Poll pg_stat_activity every 1s (configurable)
  • Live updating stacked bar / sparkline by wait_event_type
  • Drill-down hierarchy: wait_event_typewait_eventquery_idpid

Layer 2 — pg_ash installed

  • Detect via SELECT 1 FROM pg_extension WHERE extname = 'pg_ash' or presence of ash.samples
  • Time-range slider: zoom in/out on historical data
  • Aggregation: 1s buckets recent, 10s/1m/5m for older
  • Same drill-down hierarchy works on historical data

Color scheme (matches pg_ash / PostgresAI monitoring — 24-bit RGB)

Wait type Color RGB
CPU* green 80, 250, 123
IdleTx light yellow 241, 250, 140
IO vivid blue 30, 100, 255
Lock red 255, 85, 85
LWLock pink 255, 121, 198
IPC cyan 0, 200, 255
Client yellow 255, 220, 100
Timeout orange 255, 165, 0
BufferPin teal 0, 210, 180
Activity purple 150, 100, 255
Extension light purple 190, 150, 255
Unknown/Other gray 180, 180, 180

CPU* = on CPU or uninstrumented wait event (wait_event_type IS NULL in pg_stat_activity).
IdleTx = state = 'idle in transaction'.

Display modes

  • Horizontal: time on X axis, AAS on Y, stacked bars by wait_event_type
  • Vertical: current snapshot, top N wait events ranked

Key bindings

Key Action
q / Esc exit
/ zoom out / in (pg_ash mode)
/ select row
Enter drill into selected level
b back up one level
r cycle refresh interval (1s / 5s / 10s)

Drill-down levels

  1. wait_event_type (top level — 12 categories)
  2. wait_event (within selected type)
  3. query_id (top queries within selected wait event)
  4. pid (individual session detail)

Acceptance criteria

  • \ash launches TUI, exits cleanly on q, Esc, and Ctrl-C
  • Live mode works with no pg_ash extension (pg_stat_activity only)
  • pg_ash detected automatically; history mode activates when available
  • Zoom in/out works in history mode
  • Drill-down through all 4 levels works
  • Colors match 24-bit RGB scheme above (respects --no-color / NO_COLOR env)
  • Works inside alias psql=rpg (is_terminal() guarded)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions