audit-slow-db-queries

Audits slow PostgreSQL queries using Datadog DBM metrics, samples, and explain plans.

7|12|Updated Mar 26, 2026
One-click install
npx skills add https://github.com/OpenRouterTeam/docs --skill audit-slow-db-queries-openrouterteam
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: audit-slow-db-queries
Source: https://github.com/OpenRouterTeam/docs/tree/main/.agents/skills/audit-slow-db-queries
Command: npx skills add https://github.com/OpenRouterTeam/docs --skill audit-slow-db-queries-openrouterteam

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Slow database queries degrade application latency and waste infrastructure resources, but identifying which queries to fix requires evidence rather than guesswork. This Skill runs a structured weekly audit that ranks PostgreSQL queries by total database time and produces evidence-backed optimization recommendations. ## Core Features & Use Cases - Metric-Based Ranking: Queries Datadog scalar metrics (total time, call count, rows, errors) across current and prior weekly windows to rank query signatures by impact and growth. - Evidence Collection: Retrieves normalized SQL from DBM query samples and explain plans via Datadog logs analytics, with fallback to richer metric grouping or safe reproduction plans when DBM access is unavailable. - Actionable Recommendations: Classifies findings as actionable, needs-more-evidence, or no-action, and produces a report with proposed fixes, index specifications, validation plans, and rollback plans. - Use Case: A backend engineer notices rising p95 latency on openrouter-web. They run this audit to identify the top three query signatures consuming database time, confirm a missing index via an explain plan, and ship an idempotent CREATE INDEX CONCURRENTLY migration. ## Quick Start Ask the AI to run the weekly slow query audit for the primary database instance using the configured Datadog credentials and deliver the report as an attached markdown file.

Frequently Asked Questions about audit-slow-db-queries

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I find slow PostgreSQL queries in Datadog?▼

Query the Datadog scalar metrics API for postgresql.queries.time grouped by query_signature and database_instance, then rank signatures by total time over a weekly window. Enrich top signatures with DBM query samples and explain plans for evidence.

How to get explain plans from Datadog Database Monitoring?▼

Use the DBM logs analytics endpoint with a search query containing dbm_type:plan, the target query signature, and the database instance filter. The response includes the plan definition, plan signature, cost, and scan or join behavior.

Why does the Datadog DBM logs analytics endpoint return Forbidden?▼

Forbidden errors occur when the application key is scoped rather than unscoped, since scoped keys lack the built_in_features scope required by the DBM logs analytics endpoint. Continue with scalar DBM metrics and record the permission gap.

When is a slow query not worth fixing?▼

A query is not actionable when evidence only shows a signature hash and aggregate timing without samples, plans, or reproduction cases. One-off expensive queries are also deprioritized unless they are recurring, user-visible, or operationally risky.

How do I safely add an index to a production PostgreSQL database?▼

Use CREATE INDEX CONCURRENTLY IF NOT EXISTS for non-trivial index builds to keep migrations idempotent and avoid blocking writes. If a concurrent build fails, drop the resulting INVALID index with DROP INDEX CONCURRENTLY before rerunning.