# pgtuner_mcp [Health: Active]

**Category:** 🗄️ Databases  
**Repository:** https://github.com/isdaniel/pgtuner_mcp  
**GitHub Stars:** 31  
**Views:** 4  
**Installs:** 0  
**Upvotes:** 0  
**Directory Page:** https://allmcps.com/mcp/pgtuner-mcp

## Description
provides AI-powered PostgreSQL performance tuning capabilities.

## Tools
Capabilities this server exposes over MCP:

- **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, buffer_pool, tables, indexes, temp_files, checkpoints).
- **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
- **analyze_table_bloat** — Analyze table bloat using pgstattuple extension. Shows dead tuple counts, free space, and wasted space percentage.
- **analyze_index_bloat** — Analyze B-tree index bloat using pgstatindex. Shows leaf density, fragmentation, and empty/deleted pages. Also supports GIN and Hash indexes.
- **get_bloat_summary** — Get a comprehensive overview of database bloat with top bloated tables/indexes, total reclaimable space, and priority maintenance actions.
- **monitor_vacuum_progress** — Track manual VACUUM, VACUUM FULL, and autovacuum operations. Monitor progress percentage, dead tuples collected, index vacuum rounds, and estimated time remaining. Includes autovacuum configuration review and tables needing maintenance.

## Claude Desktop Quick Installation
Install path detected from listing signals. Uses `uvx` (confidence: high):

```json
"mcpServers": {
  "pgtuner-mcp": {
    "command": "uvx",
    "args": ["pgtuner_mcp"],
    "env": {
      "DATABASE_URI": ""
    }
  }
}
```

**Requires environment variables:** `DATABASE_URI` — the values above are empty placeholders; fill in real credentials before running (see the repository for what each one is for).

## Documentation

## What pgtuner_mcp MCP server does

The pgtuner_mcp MCP server gives an MCP client access to PostgreSQL performance diagnostics and tuning workflows. It reads statistics from PostgreSQL system views and supported extensions, then returns structured analysis for an AI agent to interpret. The tools cover query performance, index usage, table health, database status, configuration, I/O behavior, locking, and maintenance activity.

Query-oriented tools retrieve slow statements from `pg_stat_statements`, inspect active sessions, identify long-running transactions and blocked queries, and analyze execution plans with `EXPLAIN ANALYZE`. The server can also detect plan issues and produce index recommendations based on observed workload data.

## How it works

The server uses a PostgreSQL connection string supplied through `DATABASE_URI`. Monitoring results normally exclude system processes, and slow-query collection excludes system catalog queries. A separate environment variable can exclude selected PostgreSQL user IDs from monitoring results.

HypoPG support lets agents create and inspect hypothetical indexes, compare query plans with those indexes, hide or unhide existing indexes, and reset the session’s hypothetical index state. These operations are session-scoped and do not create physical indexes in the database.

The database health checks examine connections, cache behavior, locks, replication, transaction ID wraparound, disk usage, checkpoints, and related indicators. I/O analysis can focus on buffer pools, tables, indexes, temporary files, or checkpoints. PostgreSQL 16 and later can provide enhanced `pg_stat_io` metrics.

## Setup and configuration

Install the package with `pip install pgtuner_mcp`, use `uv pip install pgtuner_mcp`, or clone the repository and install it in editable mode.

Set `DATABASE_URI` to a PostgreSQL connection string such as `postgresql://user:password@host:port/database`. Optional settings control excluded user IDs, statement, idle-transaction, and lock timeouts, CORS origins, and disabled linter rules.

The monitoring account needs database and schema access, read access to application tables and statistics, and the `pg_read_all_stats` role for core functionality. `pg_stat_statements` is required for statement analysis. Bloat analysis uses `pgstattuple`, while hypothetical index features use `hypopg`; each extension requires its documented installation and grants.

## Tools and capabilities

The pgtuner_mcp MCP server exposes tools for:

- Retrieving slow-query statistics, including total time, mean time, calls, and cache hit ratio.
- Analyzing execution plans and testing proposed indexes without creating real indexes.
- Reviewing table size, row counts, dead tuples, access patterns, and table or index bloat.
- Finding unused or duplicate indexes and generating workload-based index recommendations.
- Checking connections, cache ratios, locks, replication, checkpoints, disk conditions, and wraparound risk.
- Examining wait events, disk I/O, temporary files, checkpoint activity, and buffer efficiency.
- Reviewing PostgreSQL settings and tracking manual or automatic vacuum progress.

## Limitations and notes

Results depend on the PostgreSQL statistics, permissions, extensions, and server version available to the configured account. Bloat features require `pgstattuple` functions, and hypothetical index testing requires HypoPG.

_Full upstream README: https://allmcps.com/mcp/pgtuner-mcp/readme_

