--- pretty_name: Postgres Incident Diagnosis Benchmark license: mit task_categories: - question-answering - text-classification language: - en tags: - postgres - databases - observability - sre - agents - benchmark size_categories: - n<1K --- # Postgres Incident Diagnosis Benchmark Real telemetry from a Postgres 16 database in six states — one healthy, five broken — paired with the ground-truth root cause of each. The task: given the stats views, say what is wrong. Or say that nothing is. ## Why this exists There is no standard benchmark for database incident diagnosis, so everyone building an AI SRE tool invents their own eval. This is a small, reproducible one with a specific property: **on four of the five faults, the obvious answer is wrong.** | id | what a naive answer says | actually correct | |---|---|---| | `missing_index` | add an index | ✅ yes | | `plan_regression` | add an index | ❌ run `ANALYZE` — the schema is fine | | `bloat` | the table is just large | ❌ dead tuples, autovacuum is off | | `lock_contention` | kill the slow queries | ❌ they're victims; one holder is at fault | | `n_plus_1` | nothing is slow, it's healthy | ❌ 1000 calls at 0.04ms each | | `healthy_baseline` | find something anyway | ❌ the answer is "no finding" | The healthy baseline is included deliberately: a diagnostic tool that invents problems on a working database is worse than one that misses them. ## Baselines Measured, not asserted. `python -m evals.baselines` reproduces this table. | approach | score | |---|---| | `always_index` — always name something; for a database that's usually an index | 1/6 | | `slow_and_big` — slowest statement over 10ms **and** a large table → missing index | 2/6 | | deterministic detectors (reference implementation) | 6/6 | `slow_and_big` is right twice: it names the one genuine index problem, and it stays quiet on the healthy database. On the other four it returns **nothing at all** — once the rig's own statements are excluded (see below), none of those faults presents as a slow query. Stale statistics, bloat, a lock holder and an N+1 loop are all invisible to any heuristic that ranks by duration. ## Telemetry contains application traffic only Each scenario clears `pg_stat_statements` *after* the fault is created and *before* the workload runs, so the injector's own work never reaches the snapshot. Without that, `plan_regression` ships with a 9.6-second `INSERT INTO orders … generate_series(1, 300000)` and an `ALTER TABLE orders SET (autovacuum_enabled = false)` sitting in the statements, which name the root cause outright and make the scenario trivial. For the same reason the healthy record is captured *after* running the same background traffic as every fault case — an empty `statements` list would make `len(statements) == 0` a free correct answer. ## Labels `expected_detector` is one of `missing_index`, `stale_stats`, `bloat`, `lock_contention`, `n_plus_1`, or `null` for the healthy case. Six records, one per class, so treat this as a probe rather than a training set. ## Fields | field | description | |---|---| | `id` | scenario identifier | | `title` | human-readable name | | `expected_root_cause` | ground truth, free text | | `expected_detector` | ground-truth label, `null` when healthy | | `category` | `indexing`, `statistics`, `vacuum`, `locking`, `application`, `none` | | `fix_target` | whether the fix is in the `database`, a `session`, or the `application` | | `naive_answer` | what a pattern-matching tool would say | | `naive_answer_correct` | whether that happens to be right | | `telemetry.statements` | `pg_stat_statements` rows | | `telemetry.tables` | `pg_stat_user_tables` + size + `autovacuum_enabled` | | `telemetry.activity` | `pg_stat_activity` rows | | `telemetry.blocking` | waiter → blocker edges from `pg_blocking_pids()` | | `telemetry.settings` | relevant `pg_settings` values | ## Usage ```python from datasets import load_dataset ds = load_dataset("yashMaini/postgres-incident-diagnosis", split="train") correct = 0 for r in ds: prediction = your_model(r["telemetry"]) # -> a detector name, or None correct += prediction == r["expected_detector"] print(f"{correct}/{len(ds)}") ``` `telemetry` holds the raw stats rows. A useful prompt is usually `telemetry["statements"]` plus `telemetry["tables"]`; `lock_contention` is only solvable from `telemetry["blocking"]`, which is the point of including it. ## Reproducing The telemetry is generated, not hand-written — each row is captured from a live Postgres after a scripted fault injection, against a deterministic 5.2M row dataset (`setseed(0.42)`). ```bash git clone https://github.com/Yashmaini30/pg-reliability-agent docker compose up -d --build python -m evals.export_benchmark --out data/ ``` The reference implementation in that repo scores **5/5 detected, 5/5 ranked first, 0 findings on the healthy baseline** using deterministic rules and `EXPLAIN (GENERIC_PLAN)` — no model in the detection path. Project overview, with the findings the detectors produce for each scenario: (a static page — the clickable sandbox runs locally from the repo above). ## Caveats - Six records. This is a sharp probe, not a broad benchmark. - Synthetic e-commerce schema, single Postgres 16 instance. - Absolute timings reflect the machine that generated it; the *ratios* are the signal, not the milliseconds.