Database Monitoring PR Reviews

Join the Preview!

Database Monitoring PR Reviews is in preview. To request access, contact your Datadog account team.

Overview

Database Monitoring PR Reviews brings production context into code review, so you can catch unexpected problems before you merge instead of after you deploy.

When a GitHub pull request changes a database query or schema, Datadog checks the change against what Database Monitoring observes in production. Authors and reviewers see the impact where they already work, without switching tools or relying on guesswork.

With PR Reviews:

  • See how much production traffic a changed query carries before you merge it
  • Catch migrations that drop or rename a table or column that live queries still reference
  • Get index and query optimizations for new and changed Postgres queries
  • Test migrations and new queries on a Workbench instance to catch failures, broken queries, and plan changes before you merge

Requirements

How it works

When you open or update a pull request, Datadog reads the diff and looks for database changes:

  1. Find queries. Datadog finds SQL in .sql files, in string literals and heredocs, and in ORM and query-builder code. For ORM code, it uses AI to reconstruct the SQL that the code generates.
  2. Match queries to production. Datadog normalizes each query and matches it against the queries Database Monitoring observed in the last 24 hours. Matched queries carry production evidence, such as execution count and share of database load.
  3. Find risky schema changes. In SQL files and SQL strings, Datadog looks for statements that drop or rename a table or column, and finds any production queries that still reference that object.
  4. Report findings. Datadog posts an inline comment for each finding that has production evidence or a medium or high severity. Low-severity findings without production evidence are not posted.
Datadog only analyzes the forward half of a migration. Rollback code, such as a down method or a -- migrate:down section, and files named like *.down.sql are skipped.

What it checks

Production query changes

Datadog flags pull requests that change or remove a query that runs in production. The inline comment shows the query before and after the change, and the query’s production footprint:

FieldDescription
Executions/dayAverage daily executions of the query.
Avg execution timeAverage execution time of the query.
Share of query trafficThe query’s percentage of all query executions on the database.
Share of DB workloadThe query’s percentage of total database time.
View in Database MonitoringA link to the query in Database Monitoring.

Severity depends on the query’s share of database workload:

Share of DB workloadSeverity
5% or moreHigh
0.5% to 5%Medium
Less than 0.5%, or unknownLow

Schema changes that break live queries

Datadog flags migrations that drop or rename a table or column that a production query referenced in the last 24 hours. For example, if a pull request adds this migration:

ALTER TABLE orders DROP COLUMN legacy_status;

Another service still runs this query in production:

SELECT id, total, legacy_status
FROM orders
WHERE customer_id = $1;

The query fails after the migration runs, because orders.legacy_status no longer exists. Datadog comments on the DROP COLUMN line and lists the queries that still read orders.legacy_status, with execution counts, when each query was last seen, and links to Database Monitoring. If more than four queries are affected, the comment lists the three with the most impact and summarizes the rest.

A Datadog comment on a migration that drops the order_item.quantity column, listing the affected queries with execution counts, when each was last seen, and Workbench results

Datadog detects the following statements in SQL files and SQL strings in your code:

  • DROP TABLE
  • ALTER TABLE ... DROP COLUMN
  • ALTER TABLE ... RENAME TO
  • ALTER TABLE ... RENAME COLUMN
Datadog does not review ORM migration methods, such as remove_column or rename_table.

Query optimizations

Datadog runs new and changed Postgres queries through Database Monitoring query optimizers, and comments with a suggested fix for identified issues:

SuggestionWhat Datadog flags
Missing indexThe query has no index that supports its filter or sort. The comment includes the CREATE INDEX statement to add and how many other queries the index would help.
SELECT *The query selects every column. When possible, the comment includes a rewrite that names the columns.

Impact analysis

When you enable the Database Monitoring Workbench, Datadog can run your change against an ephemeral Postgres instance built from the schema and statistics Database Monitoring collects to assess the following:

ChangeWhat Datadog doesWhat the comment shows
Migration that drops or renames an object, in raw SQLApplies the changed statements to a Workbench instance and replays the production queries that use the affected tables.The queries whose plan, index usage, execution time, or logical reads changed.
Migration that failsApplies the changed statements to a Workbench instance.The error that Postgres returned.
Migration that causes a production query to failApplies the changed statements and replays the production queries that use the affected tables.The query that failed and why.
New query: a Postgres SELECT, INSERT, UPDATE, or DELETE statementRuns the query on a Workbench instance alongside the production workload for the same tables.Median and p95 execution time, median logical reads, indexes used, and an outline of the query plan.

Failures caused by objects or data that Workbench does not reproduce, such as a missing function or a constraint violation on synthetic rows, are not reported.

Workbench only replays CREATE, ALTER, DROP, and RENAME statements, and SET search_path. It never replays data-changing or procedural statements from a migration.

Limitations

LimitationDetails
Only GitHub is supportedPull requests on GitLab, Azure DevOps, and Bitbucket are not reviewed.
Queries must run on a monitored database to carry evidenceEvidence comes from the last 24 hours of Database Monitoring data. Queries that ran less recently, or on databases that Database Monitoring does not monitor, are not matched.
Optimizations and impact analysis support Postgres onlyOther database engines are not supported for these features.
Test and generated files are not reviewedQueries in test files don’t reflect what your application runs, and generated code duplicates its source, so Datadog skips both.
Only some languages are supportedDatadog reviews Python, Go, JavaScript and TypeScript, Ruby, Java and Kotlin, Rust, PHP, C#, Elixir, and SQL. Files in other languages are skipped.
Migration review requires SQLBreaking schema changes are detected in SQL files and SQL strings, not in ORM migration methods. Workbench only runs migrations from SQL files in a migrations directory.
Reconstructed SQL is approximateSQL reconstructed from ORM code may not match the exact statement your application sends, so some changed queries are not matched to production.

Further reading