-
Notifications
You must be signed in to change notification settings - Fork 8
feat(ash): pg_ash history integration — /ash reads ash.samples when pg_ash is installed #761
Description
Goal
When pg_ash is installed on the server, /ash should immediately show the full history available in ash.samples, then continue streaming live data. Today it always uses the live ring buffer (600 samples max, ~10 min).
Current behavior
AshState.pg_ash_installed is detected but ViewMode::History never activates — the code falls back to live ring buffer unconditionally (documented TODO in state.rs:102).
Desired behavior
- On connect — detect
pg_ashviaSELECT 1 FROM pg_extension WHERE extname = 'pg_ash' - If installed — query
ash.samplesfor the configured window (default 10 min, up to 24h via zoom) - Merge — history snapshots pre-populate the ring buffer; live
pg_stat_activitypolls append new samples - Seamless — left side of timeline = history, right side = live. No gap, no jump.
- Zoom — when user zooms out beyond ring buffer capacity, re-query
ash.samplesfor larger window
Implementation plan
Sampler changes (src/ash/sampler.rs)
Add query_ash_history():
select
wait_event_type,
wait_event,
query_id,
left(query, 80) as q,
count(*) as count,
bucket_ts -- truncated to bucket_secs
from ash.samples
where sample_ts >= now() - interval '10 minutes'
group by 1, 2, 3, 4, bucket_ts
order by bucket_tsNote: ash.samples schema — verify column names against pg_ash v1.2 (sample_ts, wait_event_type, wait_event, query_id, query).
State changes (src/ash/state.rs)
Activate ViewMode::History when pg_ash_installed = true. On zoom out past ring buffer, trigger re-query.
mod.rs event loop
// On startup, if pg_ash installed:
let history = query_ash_history(&client, window_secs).await?;
for snap in history {
snapshots.push_back(snap);
}
// Then continue live polling as normalCI tests required
- Unit test:
query_ash_history()SQL correctness (mock rows) - Integration test (ignored by default, needs pg_ash): populate
ash.samples, verify ring buffer pre-populated - State test:
pg_ash_installed = trueactivates history mode
AI test required
New file: tests/ai/slash-ash-pgash.md
- Setup: install pg_ash, run pgbench for 5 min to populate history
- Steps: connect, run
/ash, verify left side of timeline shows pre-existing history (not empty) - GIF: record 10s showing bars from minute 0, new bars scrolling in live
- Post GIF to PR as evidence
References
- pg_ash repo: https://github.com/NikolayS/pg_ash
- ash.samples schema: see pg_ash v1.2
sql/directory - Current stub:
src/ash/state.rs:102(TODO: history mode (pg_ash Layer 2)) - PR feat(ash): Active Session History TUI — /ash command #756 (base implementation): feat(ash): Active Session History TUI — /ash command #756
Scope
New PR on top of main (after #756 merges). Do not modify existing /ash live behavior — history is additive.