Price Per TokenPrice Per Token
pgtuner_mcp

pgtuner_mcp

by isdaniel

GitHub 17 44 uses Remote
0

About

pgtuner_mcp is an AI-powered PostgreSQL performance tuning assistant that analyzes database workloads and provides actionable optimization recommendations. It integrates with PostgreSQL's system statistics and extensions to identify bottlenecks, suggest improvements, and test optimizations without impacting production systems. Key features: - Query performance analysis with slow query identification from pg_stat_statements and execution plan examination using EXPLAIN and EXPLAIN ANALYZE - AI-powered index recommendations with hypothetical index testing via the HypoPG extension to validate improvements before implementation - Database health monitoring including connection utilization, buffer and index cache hit ratios, lock contention detection, and replication lag tracking - Real-time vacuum monitoring with tracking of VACUUM and autovacuum operations, progress monitoring, and transaction ID wraparound alerts - I/O performance analysis with disk read/write pattern identification across tables and indexes, temporary file usage tracking, and PostgreSQL 16+ pg_stat_io metrics support - Configuration analysis with categorized setting reviews and recommendations for memory, checkpoint, WAL, autovacuum, and connection parameters

README

PostgreSQL Performance Tuning MCP

[](https://pypi.org/project/pgtuner-mcp/) [](https://pypi.org/project/pgtuner-mcp/) [](https://www.python.org/downloads/) [](https://pypi.org/project/pgtuner-mcp/) [](https://hub.docker.com/r/dog830228/pgtuner_mcp)

A Model Context Protocol (MCP) server that provides AI-powered PostgreSQL performance tuning capabilities. This server helps identify slow queries, recommend optimal indexes, analyze execution plans, and leverage HypoPG for hypothetical index testing.

Features

Query Analysis

  • Retrieve slow queries from pg_stat_statements with detailed statistics
  • Analyze query execution plans with EXPLAIN and EXPLAIN ANALYZE
  • Identify performance bottlenecks with automated plan analysis
  • Monitor active queries and detect long-running transactions
  • Index Tuning

  • AI-powered index recommendations based on query workload analysis
  • Hypothetical index testing with HypoPG extension (no disk usage)
  • Find unused and duplicate indexes for cleanup
  • Estimate index sizes before creation
  • Test query plans with proposed indexes before implementing
  • Database Health

  • Comprehensive health scoring with multiple checks
  • Connection utilization monitoring
  • Cache hit ratio analysis (buffer and index)
  • Lock contention detection
  • Vacuum health and transaction ID wraparound monitoring
  • Replication lag monitoring
  • Background writer and checkpoint analysis
  • Vacuum Monitoring

  • Track long-running VACUUM and VACUUM FULL operations in real-time
  • Monitor autovacuum progress and performance
  • Identify tables that need vacuuming
  • View recent vacuum activity history
  • Analyze autovacuum configuration effectiveness
  • I/O Performance Analysis

  • Analyze disk read/write patterns across tables and indexes
  • Identify I/O bottlenecks and hot tables
  • Monitor buffer cache hit ratios
  • Track temporary file usage indicating work_mem issues
  • Analyze checkpoint and background writer I/O
  • PostgreSQL 16+ enhanced pg_stat_io metrics support
  • Configuration Analysis

  • Review PostgreSQL settings by category
  • Get recommendations for memory, checkpoint, WAL, autovacuum, and connection settings
  • Identify suboptimal configurations
  • MCP Prompts & Resources

  • Pre-defined prompt templates for common tuning workflows
  • Dynamic resources for table stats, index info, and health checks
  • Comprehensive documentation resources
  • Installation

    Standard Installation (for MCP clients like Claude Desktop)

    pip install pgtuner_mcp
    

    Or using uv:

    uv pip install pgtuner_mcp
    

    Manual Installation

    git clone https://github.com/isdaniel/pgtuner_mcp.git
    cd pgtuner_mcp
    pip install -e .
    

    Configuration

    Environment Variables

    | Variable | Description | Required | |----------|-------------|----------| | DATABASE_URI | PostgreSQL connection string | Yes | | PGTUNER_EXCLUDE_USERIDS | Comma-separated list of user IDs (OIDs) to exclude from monitoring | No |

    Connection String Format: postgresql://user:password@host:port/database

    Minimal User Permissions

    To run this MCP server, the PostgreSQL user requires specific permissions to query system catalogs and extensions. Below are the minimal permissions needed for different feature sets.

    #### Basic Permissions (Required for Core Functionality)

    -- Create a dedicated monitoring user
    CREATE USER pgtuner_monitor WITH PASSWORD 'secure_password';

    -- Grant connection to the target database GRANT CONNECT ON DATABASE your_database TO pgtuner_monitor;

    -- Grant usage on schemas GRANT USAGE ON SCHEMA public TO pgtuner_monitor; GRANT USAGE ON SCHEMA pg_catalog TO pgtuner_monitor;

    -- Grant SELECT on user tables and indexes (for table stats and analysis) GRANT SELECT ON ALL TABLES IN SCHEMA public TO pgtuner_monitor; ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO pgtuner_monitor;

    -- Grant access to system catalog views (read-only) GRANT pg_read_all_stats TO pgtuner_monitor; -- PostgreSQL 10+

    #### Extension-Specific Permissions

    For pgstattuple (Bloat Detection):

    ```sql -- Create the extension (requires superuser or appropriate privileges) CREATE EXTENSION IF NOT EXISTS pgstattuple;

    -- Grant execution on pgstattuple functions GRANT EXECUTE ON FUNCTION pgstattuple(regclass) TO pgtuner_monitor; GRANT EXECUTE ON FUNCTION pgstattuple_approx(regclass) TO pgtuner_monitor; GRANT EXECUTE ON FUNCTION pgstatindex(regclass) TO pgtuner_monitor; GRANT EXECUTE ON FUNCTION pgsta

    Related MCP Servers

    AI Research Assistant

    AI Research Assistant

    hamid-vakilzadeh

    AI Research Assistant provides comprehensive access to millions of academic papers through the Semantic Scholar and arXiv databases. This MCP server enables AI coding assistants to perform intelligent literature searches, citation network analysis, and paper content extraction without requiring an API key. Key features include: - Advanced paper search with multi-filter support by year ranges, citation thresholds, field of study, and publication type - Title matching with confidence scoring for finding specific papers - Batch operations supporting up to 500 papers per request - Citation analysis and network exploration for understanding research relationships - Full-text PDF extraction from arXiv and Wiley open-access content (Wiley TDM token required for institutional access) - Rate limits of 100 requests per 5 minutes with options to request higher limits through Semantic Scholar

    Web & Search
    12 8
    Linkup

    Linkup

    LinkupPlatform

    Linkup is a real-time web search and content extraction service that enables AI assistants to search the web and retrieve information from trusted sources. It provides source-backed answers with citations, making it ideal for fact-checking, news gathering, and research tasks. Key features of Linkup: - Real-time web search using natural language queries to find current information, news, and data - Page fetching to extract and read content from any webpage URL - Search depth modes: Standard for direct-answer queries and Deep for complex research across multiple sources - Source-backed results with citations and context from relevant, trustworthy websites - JavaScript rendering support for accessing dynamic content on JavaScript-heavy pages

    Web & Search
    2 24
    Math-MCP

    Math-MCP

    EthanHenrickson

    Math-MCP is a computation server that enables Large Language Models (LLMs) to perform accurate numerical calculations through the Model Context Protocol. It provides precise mathematical operations via a simple API to overcome LLM limitations in arithmetic and statistical reasoning. Key features of Math-MCP: - Basic arithmetic operations: addition, subtraction, multiplication, division, modulo, and bulk summation - Statistical analysis functions: mean, median, mode, minimum, and maximum calculations - Rounding utilities: floor, ceiling, and nearest integer rounding - Trigonometric functions: sine, cosine, tangent, and their inverses with degrees and radians conversion support

    Developer Tools
    22 81