Skip to main content
Glama
YawLabs

@yawlabs/postgres-mcp

by YawLabs

pg_top_queries

Read-onlyIdempotent

Identify slow PostgreSQL queries by total or mean execution time. Uses pg_stat_statements to return normalized query text, call counts, and timing metrics for optimization.

Instructions

Top N queries by total or mean execution time. Requires the pg_stat_statements extension to be installed and enabled (most managed Postgres providers have it on by default). Returns normalized query text (constants replaced with ?), call count, total/mean/min/max time in ms, rows returned, and cache hit ratio. Use this to find slow queries worth optimizing. On pg_stat_statements >= 1.10 (Postgres 15+), also returns io_read_time_ms and io_write_time_ms to separate IO-bound from CPU-bound queries (null when track_io_timing = off or the query did no measurable IO -- enable track_io_timing in postgresql.conf to get non-null values). Scoped to the database in DATABASE_URL: pg_stat_statements is cluster-wide, so results are filtered by dbid to match every other tool here rather than leaking query text from unrelated databases sharing the cluster.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNoNumber of rows to return (default 20).
orderByNoRanking: total_time (cumulative impact), mean_time (worst per-call), or calls (hottest).total_time
Behavior5/5

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

Beyond the read-only/idempotent annotations, the description discloses extension requirements, database scoping (dbid filter), version-dependent fields (io_read_time_ms/io_write_time_ms on pg_stat_statements >= 1.10), and null behavior when track_io_timing is off. This is rich behavioral context that helps the agent anticipate 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?

The description is well-structured and front-loaded with the core purpose. Each sentence adds necessary detail—requirements, output metrics, version variations, and scope—without extraneous filler. It is appropriately concise given the tool's complexity.

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?

Despite no output schema, the description fully enumerates return values, explains configuration dependencies (track_io_timing), and clarifies behavior in shared clusters. It provides all information an agent needs to decide to invoke and interpret results, making it contextually complete.

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?

The input schema already covers 100% of parameters with descriptions for 'limit' and 'orderBy'. The description indirectly reinforces these by mentioning 'Top N' and 'total or mean execution time', but adds no new parameter-level meaning beyond the schema, so it meets the baseline of 3.

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 clearly states 'Top N queries by total or mean execution time', which is a specific verb-entity and distinguishes the tool from sibling inspection tools. It also explains what it returns (normalized query text, timings, rows, cache hit ratio) and its use case for finding slow 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 explicitly says 'Use this to find slow queries worth optimizing' and notes the pg_stat_statements prerequisite. It provides clear context for when to use the tool, but does not explicitly name alternative tools or say when not to use it, so it falls short of a full 5.

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

Install Server

Other Tools

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