Skip to content

Conversation

@jssmith
Copy link
Contributor

@jssmith jssmith commented Jan 20, 2026

Summary

Fixes #111 - get_top_queries now 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 (was stddev_time in 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_time
  • wal_bytes0 AS wal_bytes (column doesn't exist)

PostgreSQL 13+:

  • total_exec_time, mean_exec_time, stddev_exec_time
  • wal_bytes (actual column)

Also added NULLIF() to prevent division by zero errors.

Testing

  • ✅ Added 2 unit tests for PG12 and PG13 resource queries
  • ✅ Added postgres:12 to test matrix in conftest.py
  • ✅ Integration tests verified with real PostgreSQL 12, 15, and 16 databases
  • ✅ All 164 tests pass (161 passed, 48 skipped, 1 xfailed)

Files Changed

  • src/postgres_mcp/top_queries/top_queries_calc.py - Version-aware column selection
  • tests/conftest.py - Added postgres:12 to test matrix
  • tests/unit/top_queries/test_top_queries_calc.py - Added 2 new tests

🤖 Generated with Claude Code

jssmith and others added 2 commits January 20, 2026 00:30
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>
@jssmith jssmith force-pushed the fix/pg12-top-queries branch from b662e04 to c07a18b Compare January 20, 2026 00:30
@jssmith jssmith merged commit 3ad5cff into main Jan 20, 2026
1 check passed
@jssmith jssmith deleted the fix/pg12-top-queries branch January 20, 2026 00:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

get_top_queries fails on PostgreSQL ≤ 12: references non-existent column "stddev_exec_time" in pg_stat_statements

2 participants