PostgreSQL Performance Tuner MCP Server

provides AI-powered PostgreSQL performance tuning capabilities.

Local serverstdioPython

What is the PostgreSQL Performance Tuner MCP server?

PostgreSQL Performance Tuner MCP server exists for a simple reason — assistants are far more useful when they can act on PostgreSQL Performance Tuner directly instead of describing what you should do. provides AI-powered PostgreSQL performance tuning capabilities.

What you get

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.

Setting it up

Installation goes through your MCP client rather than a global install: point it at pgtuner_mcp on PyPI and it is fetched when the client starts. The copy-paste blocks for Claude Desktop, Claude Code and Cursor are further down this page.

What the assistant can call

Once PostgreSQL Performance Tuner is connected, these are the calls the assistant has available:

  • get_slow_queries — Retrieve slow queries from pg_stat_statements with detailed stats (total time, mean time, calls, cache hit ratio). Excludes system catalog queries
  • analyze_query — Analyze a query's execution plan with EXPLAIN ANALYZE, including automated issue detection
  • get_table_stats — Get detailed table statistics including size, row counts, dead tuples, and access patterns
  • analyze_disk_io_patterns — Analyze disk I/O read/write patterns, identify hot tables, buffer cache efficiency, and I/O bottlenecks. Supports filtering by analysis type (all
  • get_index_recommendations — AI-powered index recommendations based on query workload analysis
  • explain_with_indexes — Run EXPLAIN with hypothetical indexes to test improvements without creating real indexes
  • manage_hypothetical_indexes — Create, list, drop, or reset HypoPG hypothetical indexes. Supports hide/unhide existing indexes
  • find_unused_indexes — Find unused and duplicate indexes that can be safely dropped
  • check_database_health — Comprehensive health check with scoring (connections, cache, locks, replication, wraparound, disk, checkpoints)
  • get_active_queries — Monitor active queries, find long-running transactions and blocked queries. By default excludes system processes
  • analyze_wait_events — Analyze wait events to identify I/O, lock, or CPU bottlenecks. Focuses on client backend processes
  • review_settings — Review PostgreSQL settings by category with optimization recommendations

Configuration and credentials

You will need 2 environment variables: DATABASE_URI, PGTUNER_EXCLUDE_USERIDS. Keep credentials in your client's env block or a secrets manager rather than in a file you might commit.

Before you rely on it

  • It runs with your machine's permissions. That is convenient and also the reason to think about what you point it at before you approve a tool call.
  • With 14 tools registered it takes up a noticeable share of the context window; turn it off in projects that never touch PostgreSQL Performance Tuner.
  • MCP clients confirm each tool call by default. Leave that on until you have watched what the postgresql performance tuner mcp server does with a few real requests.

Choosing this one

Among the database access options, the useful question is rarely "what can it do" but "what does it cost you to run" — permissions, credentials, and how much of your context its toolset consumes. PostgreSQL Performance Tuner's toolset — get_slow_queries, analyze_query, get_table_stats and 11 more — is a fair guide to whether it matches your workflow. It is maintained by isdaniel; worth a glance at recent repository activity before you build anything load-bearing on it.

SyncDev reviews every entry in this directory against the project's own documentation before publishing, and revisits them as servers change.

Available tools

ToolWhat it does
get_slow_queriesRetrieve slow queries from pg_stat_statements with detailed stats (total time, mean time, calls, cache hit ratio). Excludes system catalog queries.
analyze_queryAnalyze a query's execution plan with EXPLAIN ANALYZE, including automated issue detection
get_table_statsGet detailed table statistics including size, row counts, dead tuples, and access patterns
analyze_disk_io_patternsAnalyze disk I/O read/write patterns, identify hot tables, buffer cache efficiency, and I/O bottlenecks. Supports filtering by analysis type (all, buffer_pool, tables, indexes, temp_files, checkpoints).
get_index_recommendationsAI-powered index recommendations based on query workload analysis
explain_with_indexesRun EXPLAIN with hypothetical indexes to test improvements without creating real indexes
manage_hypothetical_indexesCreate, list, drop, or reset HypoPG hypothetical indexes. Supports hide/unhide existing indexes.
find_unused_indexesFind unused and duplicate indexes that can be safely dropped
check_database_healthComprehensive health check with scoring (connections, cache, locks, replication, wraparound, disk, checkpoints)
get_active_queriesMonitor active queries, find long-running transactions and blocked queries. By default excludes system processes.
analyze_wait_eventsAnalyze wait events to identify I/O, lock, or CPU bottlenecks. Focuses on client backend processes.
review_settingsReview PostgreSQL settings by category with optimization recommendations
analyze_table_bloatAnalyze table bloat using pgstattuple extension. Shows dead tuple counts, free space, and wasted space percentage.
analyze_index_bloatAnalyze B-tree index bloat using pgstatindex. Shows leaf density, fragmentation, and empty/deleted pages. Also supports GIN and Hash indexes.

How to install the PostgreSQL Performance Tuner MCP server

Or Streamable HTTP Mode

```json
{
  "mcpServers": {
    "pgtuner_mcp": {
      "type": "http",
      "url": "http://localhost:8080/mcp"
    }
  }
}

Configuration as documented by the project. Restart the client after saving.

Configuration

VariableDescriptionRequired
DATABASE_URIConfiguration value read at startup.Optional
PGTUNER_EXCLUDE_USERIDSConfiguration value read at startup.Optional

Example prompts to try

  • Use PostgreSQL Performance Tuner to get slow queries.
  • Use PostgreSQL Performance Tuner to analyze query.
  • Use PostgreSQL Performance Tuner to get table stats.

Frequently asked questions

It connects PostgreSQL Performance Tuner to MCP-compatible AI assistants such as Claude and Cursor, exposing 14 tools (get_slow_queries, analyze_query, get_table_stats, and more) that the assistant can call on your behalf. Instead of copying data back and forth by hand, the assistant works with PostgreSQL Performance Tuner directly.