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

  1. Migration db/migrate/20260722083209_install_pg_ash_locally.rb — vendors db/pg_ash/ash-install.sql and runs it against the local DB. Guarded to Rails.env.development? and wrapped in the schema-analyzer suppressors, because pg_ash creates its own ash schema (unknown to gitlab_schema).
  2. 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.
  3. Sidekiq cron Ash::SampleWorker (every minute) — drives sampling and the rollups ash.report() reads, since pg_cron is not installed.
  4. Admin UI — the Database Diagnostics page (/admin/database_diagnostics) gains an "Active Session History (pg_ash)" section. A pg_ash_report controller action returns the same JSON as the rake task (shared Gitlab::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_statements for query-text attribution.
  • Higher-fidelity sub-second sampling (pg_cron or a GDK sampler process).

References

Edited by Niko Belokolodov

Merge request reports

Loading
Loading