Repository navigation
feat(dbi): Enable PostgreSQL execution plan collection - #2225
Merged
Merged
Conversation
The PostgreSQL receiver can collect query execution plans and attach them to top query events as postgresql.query_plan, but the agent pinned max_explain_each_interval to 0, which disabled collection entirely and left the attribute as an empty string. Set it to the receiver default of 1000. The effective ceiling is top_n_query (200) plan-only operations per collection interval, since only that many queries are considered; cached plans do not consume budget, and the plan cache has a one hour TTL. EXPLAIN is issued without ANALYZE, so no query is executed.
Contributor
Binary Size Reportlinux/amd64
linux/arm64
windows/amd64
Investigating size changesUse go-size-analyzer to compare binaries: GOEXPERIMENT=jsonv2 go install github.com/Zxilly/go-size-analyzer/cmd/gsa@latest
gsa diff --old <baseline-binary> --new <new-binary> |
EduVencovsky
approved these changes
Aug 4, 2026
JayPolanco
reviewed
Aug 4, 2026
JayPolanco
approved these changes
Aug 4, 2026
zhihonl
approved these changes
Aug 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of the issue
PostgreSQL execution plans are never collected for Database Insights. The translator sets the per-interval explain budget to
0, and the receiver gates explain attempts onexplained < maxExplainEachInterval, so that comparison isnever true. Every
db.server.top_queryevent is emitted with an emptypostgresql.query_planattribute.Description of changes
Set the per-interval explain budget to
1000in the PostgreSQL receiver translator so execution plans are collected by default.The value is kept as an explicit assignment rather than removed so it remains easy to adjust.
The expected translator outputs under
translator/tocwconfig/sampleConfigare updated to match, and a test assertion pins the value so it cannot silently regress to disabled.1000is the upstream default for this setting, so this restores upstream behaviour rather than introducing a value we would have to carry as a divergence.The number is not the effective cap on work. The explain loop is bounded by
top_n_query, which is200, so at most 200 explains can be attempted in an interval regardless of this setting.License
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Tests
Unit tests
make fmt,make fmt-shandmake lintare clean.Verified on EC2 instance
Amazon Linux 2, PostgreSQL 14.23 with
pg_stat_statements(track = all), a non-superuser role owning the workload tables, and a monitoring user grantedpg_monitorplusSELECTon those tables.Agent configuration used:
{ "agent": { "region": "us-west-2" }, "opentelemetry": { "collect": { "database_insights": { "postgresql": [ { "endpoint": "localhost:5432", "instance_name": "explain-plans-test", "username": "cw_monitor", "password_file": "/opt/databaseinsights/.pgpass", "logs": { "file_path": "/var/log/postgresql/postgresql-*.log" } } ] } } } }The generated collector configuration now carries the budget:
Sample
db.server.top_queryrecord after the change, from/aws/self-managed-database-insights/postgresql/raw-events:Requirements