ENGINEERING

Nightly pg_stat_statements baseline drift sentry

Each night, snapshots pg_stat_statements mean and tail latency, compares against the rolling 7-day baseline, and posts the top regressed queries to Slack with the normalized SQL.

CategoryEngineering
Enginesim
Difficultyintermediate
Triggerschedule
Steps5
Setup~15 min

How it runs

The automated pipeline, trigger to output.

  • TriggerNightly schedule
  • ActionRead pg_stat_statements mean/calls/tail per queryPostgreSQLPostgres
  • LogicCompare to 7-day baseline, filter regressions past threshold
  • ActionPersist new snapshot as next baselinePostgreSQLPostgres
  • OutputPost ranked regressions to Slack with normalized SQLSlack

What it does

On a nightly schedule, this workflow reads pg_stat_statements directly from Postgres to capture per-statement mean execution time, total calls, and tail latency. It compares the current snapshot to a rolling 7-day baseline stored alongside it, ranks statements by how far their mean and 95th-percentile timing drifted upward, and posts the worst offenders to Slack with the normalized query text and call volume so the team can triage at standup.

When to use it

Use this when you do not have a deploy webhook to hang regression checks on, or when slow creep matters as much as deploy-time spikes — index bloat, plan flips, and growing tables that degrade gradually. It gives a daily heartbeat of which statements are getting slower regardless of release cadence.

How it works

  1. 1Nightly schedule trigger fires.
  2. 2Query pg_stat_statements for mean time, calls, and tail timing per normalized statement.
  3. 3Compare to the stored 7-day rolling baseline and compute drift.
  4. 4Filter to statements whose drift exceeds the regression threshold.
  5. 5Write the new snapshot back as the next baseline.
  6. 6Post the ranked regressions to Slack with normalized SQL.

Set it up

What you configure once, before turning it on.

  1. 1
    Connect PostgresAny Postgres URL — query, write, migrate.
  2. 2
    Connect SlackChannels, DMs, threads, mentions.
  3. 3
    Set each agent's modelWe leave models unset so you pick the tier — fast + cheap, or top-quality.
  4. 4
    Tune it to your dataEdit the prompts, filters, and field mappings so it matches how your team works.
  5. 5
    Test, then turn it onRun once against a sample, confirm the output, then enable the trigger.

Run this workflow in your colony.

14-day trial. No DevOps. No Sales call. Provisioned in under a minute.