Skip to content →
  1. Docs
  2. Loops use case: Database Query
Sign upOpen app
Seek to:00:00 / 

Linear runs millions of PostgreSQL queries every day, and even a single inefficient one can degrade performance, or worse, cause an outage. Until recently, this meant that infrastructure engineer Sean Callahan began each day combing through hundreds of healthy queries in Datadog to find the two or three that weren’t.

The loop

Sean has since reclaimed his mornings by setting up a loop. Every weekday, it reviews the last 24 hours of query performance through the Datadog MCP and chooses the three highest-impact candidates for investigation.

The loop first checks for known issues and tests potential changes through an internal database MCP to confirm whether a practical fix exists. When it finds something actionable, it creates an issue, and from there, the infrastructure team can decide what happens next. Sean or another engineer can pick it up, or, with code intelligence and coding sessions enabled, the loop can open a PR for review. If there are no new offending queries, the loop notifies him of the fact.

A seasoned workflow

Sean wrote the first version of the prompt himself, subsequently revising it with Linear agent to focus each run on the most relevant queries. He taught the loop to ignore ones that were unlikely to have an actionable solution, as well as queries that were slow but already as optimized as possible. It now saves him 30 to 45 minutes of reviewing a sea of data each morning, helping keep Linear performant (and lightning-fast).

Build your own

If you want to build something similar, start with the part of your workflow where dense data makes your eyes glaze over, connect the loop to the tools it needs to access the data and investigate what it finds, and refine the instructions after a few real runs.

Build a Loop to investigate performance issues

Want to apply this workflow to your own telemetry? Open this prompt in Linear Agent to adapt it to your team, tools, and performance signals.