Draft: Install pg_ash locally for ASH monitoring (dev-only spike)
What / why
Related to https://gitlab.com/gitlab-org/gitlab/-/work_items/606635
Local-development spike, not for merge to master. Explores running
pg_ash (Active Session History for
PostgreSQL — pure SQL/PL-pgSQL, no C extension) inside a local GDK database to
sample pg_stat_activity and surface load/root-cause data as JSON — rendered
in the admin UI and consumable by an LLM.
What's here
- Migration
db/migrate/20260722083209_install_pg_ash_locally.rb— vendorsdb/pg_ash/ash-install.sqland runs it against the local DB. Guarded toRails.env.development?and wrapped in the schema-analyzer suppressors, because pg_ash creates its ownashschema (unknown togitlab_schema). - Rake task
pg_ash:report— prints a self-describing JSON payload (ash.report()+ash.top('wait_event_type')+ a legend) for feeding to an LLM. - Sidekiq cron
Ash::SampleWorker(every minute) — drives sampling and the rollupsash.report()reads, since pg_cron is not installed. - Admin UI — the Database Diagnostics page (
/admin/database_diagnostics) gains an "Active Session History (pg_ash)" section. Apg_ash_reportcontroller action returns the same JSON as the rake task (sharedGitlab::Database::PgAshReport), and a Vue component renders it the way pg_ash prints on the psql console: an AAS-by-wait-class matrix (avg / worst 1m / p99 / p99.9) plus the top wait event types.
Known: why this cannot merge as-is
pg_ash's ash schema is not in Gitlab::Database::EXTRA_SCHEMAS, so a
non-guarded install would fail spec/db/schema_spec.rb and bloat
db/structure.sql (dump_schemas = :all). The dev-only guard keeps CI green by
no-opping outside development; structure.sql is intentionally not updated.
Sampling once a minute is coarse for ASH (built for ~1s sampling). No specs,
and new UI strings are not extracted to locale/gitlab.pot — this is a POC.
Follow-ups (deferred)
pg_stat_statementsfor query-text attribution.- Higher-fidelity sub-second sampling (pg_cron or a GDK sampler process).
References
- Upstream extension: https://github.com/NikolayS/pg_ash