# pg-bloat-detective: Postgres Bloat and VACUUM Diagnosis

> Diagnose Postgres table and index bloat, find what is blocking VACUUM, and get the cheapest fix with PID and query evidence. Read-only, works with the pg-bloat-detective MCP server.

pg-bloat-detective: Postgres Bloat and VACUUM Diagnosis is a free AI agent skill on Agensi by rishabh, in Data & Databases. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: Free
- Creator: [rishabh](https://www.agensi.io/creators/rishabh)
- Category: [Data & Databases](https://www.agensi.io/skills/data-databases)
- Uses: 2
- Version: 1.0
- Last updated: 2026-10-17
- Security: scan passed (2026-10-17); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/pg-bloat-detective-postgres-bloat-and-vacuum-diagnosis
- Tags: database, postgresql, llm-ops, mcp-server, performance-tuning

## About this skill

Teaches your agent to use the open-source pg-bloat-detective tool (MIT, on PyPI and the official MCP registry) to diagnose PostgreSQL bloat without writing to your database.

### What it does
- Collects read-only snapshots (read-only transactions, 5s statement timeout) and returns one verdict per table or index.
- Table verdicts: normal, vacuum-starved, blocked by an idle transaction, replication slot, prepared transaction or active transaction, and needs-rewrite.
- Index verdicts: index-bloated (needs REINDEX) and index-unused (DROP candidate, confirm with pg_stat_statements first).
- Names the PID, query and xmin age holding VACUUM back, and gives the matching fix.

### How it works
The skill walks your agent through installing the tool (`pip install pg-bloat-detective`), running the `bloat-mcp` server, and using its five tools: `bloat_check`, `bloat_collect`, `bloat_timeline`, `bloat_blockers` and `bloat_live_diagnose`. It never runs fixes for you. It shows the statement and the evidence and you decide.

Works with Postgres 12-17 on RDS, Neon, Supabase or self-hosted, per the project README. Source: https://github.com/r69shabh/pg-bloat-detective

## Requires

- Bloat MCP
- Python

## Known limitations

Requires Python environment and pg-bloat-detective package. Default 1GB guard on large index scans. Needs pgstattuple extension for exact bloat metrics. Read-only access only.

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the pg-bloat-detective: Postgres Bloat and VACUUM Diagnosis skill from Agensi" and describe your task.
3. Your agent loads the skill from Agensi when it needs it. Nothing is downloaded.

## Frequently asked questions

### How does this skill differ from simply running a standard VACUUM command?

This skill automates the identification of disk-space-wasting 'bloat' by analyzing system catalogs and leaf density, saving you from writing manual, complex SQL queries to find hidden performance bottlenecks.

### Do I need superuser or administrative permissions on my PostgreSQL instance to use this?

Yes, the 'pg bloat detective' is designed to work without superuser privileges or write access, making it safe for use in production environments where security is a priority.

### What are the specific database version requirements and dependencies?

The skill is compatible with PostgreSQL version 12 and newer; for the most precise leaf density metrics, having the `pgstattuple` extension pre-installed on your database is recommended.

### Can this tool help me identify trends, or does it only show a snapshot of current bloat?

Unlike static prompts, this skill uses a SQLite-backed history to track bloat trends over time, helping you distinguish between a temporary spike in dead tuples and chronic, structural growth.

### What kind of 'blockers' can the skill detect when my database cleanup stalls?

It identifies specific PIDs, active queries, and stale replication slots that are pinning the `backend_xmin` and preventing Autovacuum from cleaning up dead tuples.

### Are there any safety limits in place for very large production databases?

To prevent performance degradation on your database, the skill automatically skips diagnostic scans for indexes larger than 1GB by default.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
