fix: Support PostgreSQL 12 in get_top_queries#132
Merged
Conversation
Fixes column name mismatches in get_top_resource_queries() for PG ≤ 12: - Use stddev_time (not stddev_exec_time) for PG12 - Use total_time/mean_time (not *_exec_time) for PG12 - Handle missing wal_bytes column in PG12 (added in PG13) - Add NULLIF to prevent division by zero errors Also: - Add postgres:12 to test matrix - Add 2 unit tests for resource queries on PG12/PG13 - Integration tests verified with real PG 12/15/16 databases Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
b662e04 to
c07a18b
Compare
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.
Summary
Fixes #111 -
get_top_queriesnow works on PostgreSQL 12 and older.Problem
The
get_top_resource_queries()function hardcoded column names that were introduced in PostgreSQL 13:stddev_exec_time(wasstddev_timein PG12)wal_bytes(doesn't exist in PG12)This caused queries to fail on PG ≤ 12 with column not found errors.
Solution
Added version-aware column selection:
PostgreSQL 12 and older:
total_time,mean_time,stddev_timewal_bytes→0 AS wal_bytes(column doesn't exist)PostgreSQL 13+:
total_exec_time,mean_exec_time,stddev_exec_timewal_bytes(actual column)Also added
NULLIF()to prevent division by zero errors.Testing
postgres:12to test matrix inconftest.pyFiles Changed
src/postgres_mcp/top_queries/top_queries_calc.py- Version-aware column selectiontests/conftest.py- Added postgres:12 to test matrixtests/unit/top_queries/test_top_queries_calc.py- Added 2 new tests🤖 Generated with Claude Code