IP

isdaniel/pgtuner_mcp

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

30 stars 5 forks 质量 78 趋势 15Apache-2.0

提供由 AI 驱动的 PostgreSQL 性能调优功能。

概览

一个模型上下文协议(MCP)服务器,提供基于 AI 驱动的 PostgreSQL 性能调优功能。该服务器帮助识别慢查询,推荐最优索引,分析执行计划,并利用 HypoPG 进行假设性的索引测试。 - 从pg_stat_statements中检索慢查询并附有详细统计数据 - 用EXPLAIN和EXPLAIN ANALYZE分析查询执行计划 - 通过自动计划分析识别性能瓶颈 - 监控活跃查询并检测长期交易 - 基于查询工作负载分析的AI驱动索引推荐 - 假设性索引测试带扩展(无磁盘使用) - 查找未使用的和重复索引进行清理 - 创建前估计索引大小 - 在实施前用拟议索引测试查询计划 - 全面的健康评分,包含多重检查 - 连接利用率监控 - 缓存命中率分析(缓冲区和索引) - 锁争用检测 - 真空健康状况和事务ID......

概述(AI 翻译)

一个模型上下文协议(MCP)服务器,提供基于 AI 驱动的 PostgreSQL 性能调优功能。该服务器帮助识别慢查询,推荐最优索引,分析执行计划,并利用 HypoPG 进行假设性的索引测试。

特色

查询分析

  • 从pg_stat_statements获取带有详细统计的慢查询
  • 分析带有EXPLAIN和EXPLAIN ANALYZE的查询执行计划。
  • 通过自动化计划分析识别性能瓶颈
  • 监控活跃查询并检测长期运行的事务

指标调音

  • 基于查询工作负载分析的AI驱动索引推荐
  • 假设性索引测试,使用 HypoPG 扩展(无磁盘使用)
  • 查找未使用的和重复索引进行清理
  • 在创建前估算指数大小
  • 在实施前用拟议索引测试查询计划

数据库健康

  • 多重检查的综合健康评分
  • 连接利用率监控
  • 缓存命中率分析(缓冲区和索引)
  • 锁争用检测
  • 真空健康状态和事务ID环绕监控
  • 复制滞后监测
  • 背景写作与检查点分析

真空监测

本页由 AI 翻译,技术细节请以原文为准。

README

以下为原文 README 节选,完整内容请查看原文。

PostgreSQL Performance Tuning 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)

在 GitHub 查看完整 README

安装

docker run -p 8080:8080 \
新手?先看 mcpskill.org 教程 →

配置

{ "mcpServers": { "pgtuner_mcp": { "command": "python", "args": ["-m", "pgtuner_mcp"], "env": { "DATABASE_URI": "postgresql://user:password@localhost:5432/mydb" }, "disabled": false, "autoApprove": [] } } }