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
When you open or update a pull request, Datadog reads the diff and looks for database changes:
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.
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.
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.
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:
Field
Description
Executions/day
Average daily executions of the query.
Avg execution time
Average execution time of the query.
Share of query traffic
The query’s percentage of all query executions on the database.
Share of DB workload
The query’s percentage of total database time.
View in Database Monitoring
A link to the query in Database Monitoring.
Severity depends on the query’s share of database workload:
Share of DB workload
Severity
5% or more
High
0.5% to 5%
Medium
Less than 0.5%, or unknown
Low
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:
ALTERTABLEordersDROPCOLUMNlegacy_status;
Another service still runs this query in production:
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.
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:
Suggestion
What Datadog flags
Missing index
The 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:
Change
What Datadog does
What the comment shows
Migration that drops or renames an object, in raw SQL
Applies 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 fails
Applies the changed statements to a Workbench instance.
The error that Postgres returned.
Migration that causes a production query to fail
Applies 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 statement
Runs 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
Limitation
Details
Only GitHub is supported
Pull requests on GitLab, Azure DevOps, and Bitbucket are not reviewed.
Queries must run on a monitored database to carry evidence
Evidence 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 only
Other database engines are not supported for these features.
Test and generated files are not reviewed
Queries in test files don’t reflect what your application runs, and generated code duplicates its source, so Datadog skips both.
Only some languages are supported
Datadog 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 SQL
Breaking 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 approximate
SQL reconstructed from ORM code may not match the exact statement your application sends, so some changed queries are not matched to production.
Further reading
Additional helpful documentation, links, and articles: