Skip to main content
Glama
YawLabs

@yawlabs/postgres-mcp

by YawLabs

Find tables with heavy sequential scans

pg_seq_scan_tables
Read-onlyIdempotent

Find PostgreSQL tables with high sequential scans versus index scans to spot missing-index candidates. Pair with query analysis to identify the offending queries.

Instructions

Tables with high sequential-scan counts relative to index scans - the first place to look for missing-index candidates. Returns {rows, stats_reset, stats_reset_age_seconds}: each row has seq_scans, idx_scans, live tuples, and the ratio. A high ratio on a large table usually means a query is reading the whole table where an index would suffice. Pair with pg_top_queries to find which query is doing it. These counters are cumulative since the last statistics reset, so every ratio here is only meaningful relative to the top-level stats_reset (and stats_reset_age_seconds). A ratio measured over a window that was reset minutes ago describes that window, not the workload; stats_reset: null means the start of the window is unknown. On PostgreSQL 16+ each row also carries last_seq_scan and last_idx_scan timestamps (null = no such scan since the reset), which separate 'scanned hard months ago' from 'being scanned right now' in a way the raw counts cannot.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNoMax rows to return (default 20).
schemaNoLimit to one schema. If omitted, all user schemas are included.
minSizeNoMinimum live tuple count to include (default 1000, filters out tiny/empty tables).

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
rowsYes
_warningsNo
stats_resetYesEvery counter in `rows` is cumulative SINCE this point. Null = start of the window unknown.
stats_reset_age_secondsYesSeconds since `stats_reset`; null whenever that is null.

Schema Changelog

Changes observed during successful MCP inspections. Dates show when Glama detected each change.

  1. Changed10 schema fields changedv0.12.1
    • removedOutput schema / properties / rows / items / properties / last_idx_scan / anyOf
      Removed value: -[
      -  {
      -    "type": "string"
      -  },
      -  {
      -    "type": "null"
      -  }
      -]
    • addedOutput schema / properties / rows / items / properties / last_idx_scan / type
      Added value: +[
      +  "string",
      +  "null"
      +]
    • removedOutput schema / properties / rows / items / properties / last_seq_scan / anyOf
      Removed value: -[
      -  {
      -    "type": "string"
      -  },
      -  {
      -    "type": "null"
      -  }
      -]
    • addedOutput schema / properties / rows / items / properties / last_seq_scan / type
      Added value: +[
      +  "string",
      +  "null"
      +]
    • removedOutput schema / properties / rows / items / properties / ratio / anyOf
      Removed value: -[
      -  {
      -    "type": "number"
      -  },
      -  {
      -    "type": "null"
      -  }
      -]
    • addedOutput schema / properties / rows / items / properties / ratio / type
      Added value: +[
      +  "number",
      +  "null"
      +]
    • removedOutput schema / properties / stats_reset / anyOf
      Removed value: -[
      -  {
      -    "type": "string"
      -  },
      -  {
      -    "type": "null"
      -  }
      -]
    • addedOutput schema / properties / stats_reset / type
      Added value: +[
      +  "string",
      +  "null"
      +]
    • removedOutput schema / properties / stats_reset_age_seconds / anyOf
      Removed value: -[
      -  {
      -    "type": "number"
      -  },
      -  {
      -    "type": "null"
      -  }
      -]
    • addedOutput schema / properties / stats_reset_age_seconds / type
      Added value: +[
      +  "number",
      +  "null"
      +]
  2. Changed2 schema fields changedv0.12.0
    • changedInput schema / $schema
      Previous value: -"http://json-schema.org/draft-07/schema#"New value: +"https://json-schema.org/draft/2020-12/schema"
    • changedOutput schema / (root)
      Previous value: -nullNew value: +{
      +  "$schema": "https://json-schema.org/draft/2020-12/schema",
      +  "additionalProperties": false,
      +  "properties": {
      +    "_warnings": {
      +      "items": {
      +        "type": "string"
      +      },
      +      "type": "array"
      +    },
      +    "rows": {
      +      "items": {
      +        "additionalProperties": false,
      +        "properties": {
      +          "idx_scans": {
      +            "description": "COALESCEd to '0', so a never-index-scanned table reads as 0, not null.",
      +            "type": "string"
      +          },
      +          "last_idx_scan": {
      +            "anyOf": [
      +              {
      +                "type": "string"
      +              },
      +              {
      +                "type": "null"
      +              }
      +            ],
      +            "description": "PostgreSQL 16+ only, absent below that. Null = no index scan since the reset."
      +          },
      +          "last_seq_scan": {
      +            "anyOf": [
      +              {
      +                "type": "string"
      +              },
      +              {
      +                "type": "null"
      +              }
      +            ],
      +            "description": "PostgreSQL 16+ only, absent below that. Null = no sequential scan since the reset."
      +          },
      +          "live_tuples": {
      +            "type": "string"
      +          },
      +          "ratio": {
      +            "anyOf": [
      +              {
      +                "type": "number"
      +              },
      +              {
      +                "type": "null"
      +              }
      +            ],
      +            "description": "seq_scans / idx_scans; null when idx_scans is 0 (division guard)."
      +          },
      +          "schema": {
      +            "type": "string"
      +          },
      +          "seq_scans": {
      +            "description": "Bigint as a decimal string.",
      +            "type": "string"
      +          },
      +          "seq_tup_read": {
      +            "type": "string"
      +          },
      +          "table": {
      +            "type": "string"
      +          }
      +        },
      +        "required": [
      +          "schema",
      +          "table",
      +          "seq_scans",
      +          "idx_scans",
      +          "live_tuples",
      +          "seq_tup_read",
      +          "ratio"
      +        ],
      +        "type": "object"
      +      },
      +      "type": "array"
      +    },
      +    "stats_reset": {
      +      "anyOf": [
      +        {
      +          "type": "string"
      +        },
      +        {
      +          "type": "null"
      +        }
      +      ],
      +      "description": "Every counter in `rows` is cumulative SINCE this point. Null = start of the window unknown."
      +    },
      +    "stats_reset_age_seconds": {
      +      "anyOf": [
      +        {
      +          "type": "number"
      +        },
      +        {
      +          "type": "null"
      +        }
      +      ],
      +      "description": "Seconds since `stats_reset`; null whenever that is null."
      +    }
      +  },
      +  "required": [
      +    "rows",
      +    "stats_reset",
      +    "stats_reset_age_seconds"
      +  ],
      +  "type": "object"
      +}
  3. First observedv0.7.0

TDQS

A4.5/5.0
Behavior5/5

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

Annotations already mark the tool read-only, idempotent, and non-destructive, but the description goes far beyond that by documenting that counters are cumulative since stats reset, ratios are only meaningful relative to stats_reset, and how null timestamps behave on PostgreSQL 16+. This is exactly the kind of non-obvious behavior an agent needs.

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?

The description is front-loaded with purpose and return shape, then layers necessary caveats about reset semantics and PG16-specific fields. Every sentence earns its place; the length is justified by the non-obvious cumulative-counter behavior that would otherwise trip up an agent.

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 read-only diagnostic tool with a full output schema and fully documented parameters, the description supplies the interpretive context that structured data cannot: what a high ratio means, how to use stats_reset, and how to connect results to pg_top_queries. Nothing essential is missing for correct invocation and result reasoning.

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

Parameters3/5

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

Schema coverage is 100%, with limit, schema, and minSize each documented. The description adds no parameter-specific semantics, focusing instead on output interpretation, so the schema carries the load and the baseline 3 applies.

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?

The description opens with a specific resource and scope: 'Tables with high sequential-scan counts relative to index scans' and frames it as 'the first place to look for missing-index candidates.' It states the return shape and makes the tool's diagnostic role unmistakable, distinguishing it from sibling tools like pg_unused_indexes and pg_top_queries.

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?

The description gives clear usage context: use this as the first stop for missing-index candidates and pair with pg_top_queries to find the responsible query. It does not explicitly state when-not-to-use or name alternatives, so it stops short of a full routing guide.

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

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/YawLabs/postgres-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server