Skip to main content
Glama
MCPg - Production-grade PostgreSQL MCP Server

MCPg - Production-grade PostgreSQL MCP Server

Analyze table bloat

analyze_table_bloat
Read-only

Rank a schema's tables and indexes by estimated bloat, worst first, to identify maintenance targets; use cheap catalog estimates or precise pgstattuple scans when available.

Instructions

Rank a schema's tables and indexes by estimated bloat, worst first. By default uses a cheap catalog-only estimate (relpages vs a reltuples/row-width floor) plus the dead-tuple ratio from pg_stat_user_tables. Set precise=true to use pgstattuple / pgstatindex for an exact (but I/O-heavy) read when the extension is installed — it falls back to the estimate and reports method='estimate' if it isn't. Returns tables and indexes (each capped at limit) with per-object est_bloat_pct, plus available and method.

Example: analyze_table_bloat(schema='public', limit=20, precise=false)

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "schema": "<schema>"
    },
    "name": "analyze_table_bloat"
  }
}

Input Schema

NameRequiredDescriptionDefault
limitNo
schemaYes
preciseNo
databaseNoOptional: a database id from list_databases, to target a configured secondary (read-only) database; omit for the primary. Database names that are not configured ids are rejected.

Output Schema

NameRequiredDescriptionDefault
detailYes
methodYes
schemaYes
tablesYes
indexesYes
availableYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changedv0.8.4
    • changedInput schema / properties / database / description
      Previous value: -"Optional: target a configured secondary (read-only) database by name; omit for the primary. Call list_databases to see the configured ids."New value: +"Optional: a database id from list_databases, to target a configured secondary (read-only) database; omit for the primary. Database names that are not configured ids are rejected."
  2. First observedv0.6.8

TDQS

A4.7/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Beyond the readOnlyHint/openWorldHint annotations, it discloses that the default path reads relpages/reltuples plus pg_stat_user_tables, that the precise path is I/O-heavy, and — critically — that the tool silently falls back to the estimate and reports `method='estimate'` when pgstattuple is absent. That fallback semantics is exactly the kind of non-obvious behavior an agent needs before interpreting results.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Front-loads the purpose in the first sentence, then default behavior, then the opt-in precise mode, then the return shape, then a concrete example. Every clause carries information — the row-width floor, the dead-tuple ratio, and the fallback are all load-bearing.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 4-parameter read-only analysis tool with an output schema, this covers everything needed: cost profile, extension dependency, fallback reporting, and which keys come back. Nothing an agent needs to call it correctly or interpret `method` is missing.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is only 25% (only `database` is documented inline), so the description must compensate, and it largely does: `precise` gains fallback/extension semantics, `limit` is explained as a per-collection cap on `tables` and `indexes`, and `schema` is demonstrated in the example. Only `database` is left to the schema, which already documents it adequately.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Names a specific verb (rank) and resource (a schema's tables and indexes) plus the ordering guarantee (worst bloat first). No sibling tool in the list covers bloat estimation, and the description makes the output shape explicit enough that an agent can distinguish it from neighbors like summarize_table or recommend_index_drops.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Gives clear when-to-use guidance for the key decision: default cheap catalog-only estimate versus `precise=true` when exact pgstattuple/pgstatindex reads are needed and the extension is installed. It flags the I/O cost of the precise path, which is the main tradeoff an agent must weigh. It does not explicitly say when not to use the tool or name an alternative sibling, so it falls short of a 5.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Deploy Server

Other Tools