Skip to main content

MCP server for PostgreSQL performance auditing

Project description

pgtriage

MCP server for PostgreSQL performance auditing. Connect it to Claude Code (or any MCP client) and say "audit my database" to get actionable performance findings with exact fixes.

Not related to the pgAudit logging extension. pgtriage does performance triage, not compliance logging.

How it works

Claude Code (AI interpretation)
       |  MCP (stdio)
       v
pgtriage (data collection + pattern detection)
       |  psycopg3 (read-only)
       v
PostgreSQL database

pgtriage connects to your PostgreSQL database and exposes performance auditing tools via the Model Context Protocol. It collects metrics from PostgreSQL system views, runs deterministic pattern detection, and returns structured findings. The MCP client provides the AI layer, interpreting results and explaining fixes in plain English.

No API keys required. No AI costs. The intelligence comes from your MCP client.

What it finds

  • Sequential scans on large tables with missing index suggestions
  • Dead tuple buildup and autovacuum health issues
  • Unused and duplicate indexes wasting disk and slowing writes
  • N+1 query patterns from pg_stat_statements analysis
  • Stale table statistics causing bad query plans
  • TOAST table bloat from large JSONB/TEXT columns
  • Configuration issues (shared_buffers, work_mem, autovacuum tuning)
  • Connection pressure approaching max_connections
  • Long-running queries holding locks

Quick start

Install

pip install pgtriage

Configure Claude Code

Add to your MCP settings (.claude/settings.json or project settings):

{
  "mcpServers": {
    "pgtriage": {
      "command": "python",
      "args": ["-m", "pgtriage"],
      "env": {
        "PGAUDIT_CONNECTION_STRING": "postgres://user:pass@localhost:5432/dbname"
      }
    }
  }
}

Use

> audit my database

> check table health for the users table

> are there any unused indexes?

> review my PostgreSQL configuration

> find slow queries

Tools

full_audit

Run a comprehensive performance audit covering table health, slow queries, index health, and configuration. Returns all findings sorted by severity.

check_table_health

Analyze dead tuples, autovacuum stats, sequential scan ratios, and TOAST bloat. Optionally filter to a specific table.

analyze_slow_queries

Pull the slowest queries from pg_stat_statements, run EXPLAIN ANALYZE on each, and detect patterns like sequential scans, stale statistics, and N+1 queries.

check_index_health

Find unused indexes (zero scans), duplicate indexes (same column definition), and tables that likely need indexes based on scan patterns.

check_config

Review PostgreSQL settings (shared_buffers, work_mem, autovacuum_vacuum_scale_factor, random_page_cost, etc.) and flag suboptimal values. Checks connection utilization and long-running queries.

Resources

Resource Description
pgtriage://status Connection status, PostgreSQL version, loaded extensions
pgtriage://tables All tables with sizes and approximate row counts

Requirements

  • Python 3.11+
  • PostgreSQL 12+
  • pg_stat_statements extension (recommended for slow query analysis, not required for other tools)
  • Database user with read access to pg_stat_* views

Safety

  • All connections enforce SET default_transaction_read_only = true
  • EXPLAIN ANALYZE only runs on SELECT queries (validated before execution)
  • Connection strings are never exposed in tool outputs
  • Single read-only connection, no write operations

Development

git clone https://github.com/pgtriage/pgtriage.git
cd pgtriage
python3 -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
pytest

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pgtriage-0.1.1.tar.gz (17.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pgtriage-0.1.1-py3-none-any.whl (20.1 kB view details)

Uploaded Python 3

File details

Details for the file pgtriage-0.1.1.tar.gz.

File metadata

  • Download URL: pgtriage-0.1.1.tar.gz
  • Upload date:
  • Size: 17.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for pgtriage-0.1.1.tar.gz
Algorithm Hash digest
SHA256 eed9c7066501930bb96c6c6981b8949a36df6a7891bae1910f081104dea11bd3
MD5 e01f16d37a7398c4fade99a572d056ff
BLAKE2b-256 b11464a29210aa1bdb264e499ef2edac1f667f3e1700c505c97cc8d48d1f4030

See more details on using hashes here.

File details

Details for the file pgtriage-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pgtriage-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 20.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for pgtriage-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0dcac218fca42f1fa843e467d68c3089a89184350adb19661fa56bfb52b373bf
MD5 daa40bf353e0c58e5ffe0c81ce5850c8
BLAKE2b-256 20aa7f6d196ba48aec4824b2c142300c05575a14962ba1d76eb9c514485c6eee

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page