Skip to main content
Glama

Index statistics

pg_index_stats
Read-onlyIdempotent

Inspect PostgreSQL index size, scans and definitions, then flag unused, duplicate, redundant or invalid indexes to safely identify which ones to drop.

Instructions

List indexes with size, scans, tuples read and fetched, unique/primary/valid flags, access method and definition, and find the ones to drop: show="unused" (never scanned and not backing a constraint), "duplicate" (same columns, operator classes and predicate as another index), "redundant" (columns are the leading columns of a longer index) or "invalid" (a failed CREATE INDEX CONCURRENTLY).

Filter with schema and table (name, schema.name or a pattern with *). "Unused" counts scans since the statistics reset (counters_since) on this server only: an index used just on a replica or by a rare job looks unused here, so check before dropping.

Tool call template

This tool declares no required parameters. Add optional parameters from the input schema as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {},
    "name": "pg_index_stats"
  }
}

Input Schema

NameRequiredDescriptionDefault
showNoall
limitNo
tableNo
schemaNo
connectionNo

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A4/5.0
Behavior4/5

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

Annotations already declare readOnlyHint, idempotentHint, destructiveHint=false and openWorldHint=false, so the safety profile is covered. The description adds genuinely non-obvious behavior: scan counts are scoped to this server and reset at `counters_since`, and 'invalid' implies a failed concurrent build. It does not explain the effect of `limit` or what `connection` selects, which are the remaining behavioral gaps.

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

Conciseness4/5

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

Front-loaded with the resource and returned fields, then modes, then filters, then the caveat — a sensible information order with no filler. The mode list and the returned-column list are dense run-ons, but every clause carries meaning, so nothing is genuinely wasteful.

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

Completeness4/5

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

With no output schema, the description compensates by naming the returned columns and explaining what each mode filters to. The caveat about counter scope is exactly the kind of context needed before destructive follow-up action. The unmentioned `connection` parameter and `limit` semantics are the only material omissions for a five-parameter tool.

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 coverage is 0%, so the description must carry the burden, and it does for three of five parameters: it defines every `show` enum value by behavior rather than label, and specifies that `schema`/`table` accept a bare name, `schema.name`, or a `*` pattern — detail absent from the schema. `limit` and `connection` receive no explanation at all, which keeps this below a 5.

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

Purpose4/5

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

The description opens with a specific verb and resource ('List indexes') and enumerates exactly what is returned: size, scans, tuples read/fetched, unique/primary/valid flags, access method and definition. The 'show' mode enumeration makes the tool's four analysis angles explicit. It never contrasts itself with the sibling pg_index_advisor, so an agent must infer whether advisory recommendations come from here or there.

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?

Each mode is defined with a precise selection condition: 'unused' = never scanned and not backing a constraint, 'duplicate' = same columns/opclasses/predicate, 'redundant' = leading columns of a longer index, 'invalid' = failed CREATE INDEX CONCURRENTLY. The warning that an index used only on a replica or by a rare job looks unused 'on this server only' is a strong, actionable caveat. No alternative tool is named for the recommendation workflow that logically follows discovery.

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