








A query passes every test. Then production slows down after a release, and everyone has a theory. This note looks at why that happens, what evidence a database RCA (root cause analysis) needs, and what a DBOps Engineer, an AI Coworker, should check before it names a cause. It also covers where the Coworker should stop and hand the decision to a person.
Most database incidents sound the same. The application team says the query passed its tests. The database team says the query is inefficient. The platform team points at CPU, storage or connections. QA says it worked in pre-production. The incident channel fills with screenshots, copied SQL and confident guesses. Meanwhile, customers wait for a page that used to load in a second.
Most of these incidents don’t come from an exotic database bug. They come from an ordinary change meeting real data and real traffic. A developer on Software Engineering Stack Exchange asked how to catch slow queries before production, because everything looked fine in development and staging. Teams can’t copy every production database into a test environment, so that gap stays open.
A small table can make reading every row look harmless. A bigger one turns the same plan into an outage. Statistics go stale, a migration changes the shape of the data, and one deployment can add dozens of hidden queries to a single request. A query can be correct and still wrong for production.
A database RCA is the work of tracing a production slowdown back to its cause, such as a query, a plan, a deployment or a resource limit, using evidence and not theories.
A recent Reddit thread described the frustration well. A query looked right, returned the correct data and passed its tests, yet used far more CPU in production because the optimizer chose a different path. The usual suspects were how the data is spread, old statistics, inefficient joins and plans that depend on the parameter.
Developers usually couldn’t have predicted that. The lesson is that “the SQL didn’t change” is not proof that the behaviour didn’t. An investigation has to put the environments side by side and compare evidence. That means looking at:
No single dashboard holds all of that.
An application loads a list of records, then runs one more query for each record to load related data. For 100 records, the request runs 101 queries instead of one or two. Each query is fast, so no slow-query threshold fires. The request is still slow. The Stack Overflow explanation of the N+1 problem makes the same point: the extra queries are rarely slow enough, one by one, to get flagged.
This is where application traces help. A database dashboard shows many small queries. A request trace shows that they all belong to one endpoint and one code path. So the useful question isn’t “which query took more than a second?” It’s “why did this request make 101 database calls to return one page?” Answering that takes application developers, DBAs and platform engineers together.
When a query is slow, “add an index” is often the first suggestion. Sometimes it’s exactly right. Sometimes it’s incomplete, and sometimes it makes the wider workload worse. A DBA Stack Exchange discussion describes an index suggested by SQL Server that didn’t speed up the query and, in some cases, slowed it down.
An index costs storage and maintenance, and it adds work to every write. It can overlap with one you already have. The database may skip it if the filter isn’t selective, or if the query wraps the column in a function. It can help one query and change the plan for another.
So the question isn’t “can we add this index?” It’s “what happens to the workload if we add it, and how will we prove it?” That needs a before-and-after plan, realistic parameters, the write impact, the affected query history and a rollback plan.
Some of the hardest incidents are the ones where the same query is fast once and slow the next time. In an Oracle discussion, a large query ran in about seven minutes, then picked a different plan on a later run. It ran for more than 20 minutes and used up a large amount of temporary space. The author was trying to understand why re-optimisation and cardinality feedback had made things worse.
Similar reports follow database upgrades. In one Microsoft Q&A thread, a query that used to finish in minutes took hours after a SQL Server version and compatibility-level change.
In cases like these, code review shows no obvious regression. The investigation has to compare plans, statistics, parameters, engine versions, waits and resource use over time.
The useful version isn’t a chatbot that rewrites SQL from a pasted example. It’s a database RCA Coworker, the DBOps Engineer, that brings the evidence together. Take an incident like “the checkout API got slow after yesterday’s release”. The Coworker should be able to:
The important word is evidence. If traces are missing, the Coworker should say it can’t confirm an N+1 pattern. If there is no plan history, it shouldn’t claim a plan regression. If CloudWatch shows high CPU but the query spans don’t account for the latency, it shouldn’t force the database to be the culprit. We saw the same trap when a Databricks job reported success while the data was still wrong.
A credible setup needs a clear technical boundary. One practical starting point is PostgreSQL on Amazon RDS or Aurora PostgreSQL, with applications running on EKS, ECS or Lambda. The Coworker draws on these sources:
| Source | What the Coworker uses it for |
|---|---|
| OpenTelemetry | Request and database traces |
| CloudWatch | AWS metrics and logs |
| PostgreSQL query statistics and metadata | Database context |
| GitHub | Code and deployment changes |
| Slack or Teams | The incident conversation |
The first version can stay read-only. It can inspect query statistics, plans the team supplies, schema metadata, RDS metrics, locks, connections, container pressure, deployment history and traces. It can recommend an index or a query change. It shouldn’t create the index, change a production schema, alter an AWS resource or run an unsafe analysis query without explicit approval.
A diagnosis isn’t a production change. Keeping the two apart is how the team stays in control.
Here is the kind of answer that works for everyone. The example is illustrative, not from a live run:
The checkout endpoint got slower after deployment abc123. Database spans account for most of the extra request time. The request now runs repeated order-item lookups from the serializer introduced in pull request #418. No matching lock or CPU saturation was seen. This is consistent with an N+1 query regression. Next step: restore eager loading or batch the lookup, then validate with the same request trace.
That gives the application team a code location, the DBA a database pattern, the platform team a sign that resource saturation wasn’t seen, and the incident lead a safe next step. It also leaves room for doubt. “Consistent with” is more honest than “definitely caused by” when the evidence is incomplete. We saw the same care in an Airflow demo, where the Coworker held off touching production until two people agreed which signal to believe.
Most teams don’t lack database expertise. The expertise is trapped in individuals and incident channels, so the same questions keep coming back. Why was it fast in staging? Which code path made these calls? Was the index used? Did the deployment change the plan? Did the database run out of capacity, or did the application misuse the connection pool? How do we know the fix worked? A DBOps Engineer should keep the answers as investigation notes and runbooks, so the next engineer doesn’t rebuild the reasoning from a week-old chat thread and a few screenshots.
The promise isn’t that AI will tune every query. It’s that your team reaches a grounded answer faster, can see why it’s credible, and carries the knowledge forward. The database didn’t become mysterious. The system grew too distributed for one person to hold in their head. An AI SRE did something similar for incident response, with triage and the postmortem written for the team.
If your incident channel still fills with theories, that’s where I’d point a DBOps Engineer first. You’ll get one evidence-backed cause, a recommended next step and a way to check that it worked.
Faq answer paragraph
Faq answer paragraph