Slowplan

io.github.GillMacedo由 GitHub 账号 GillMacedo 发布v0.1.0更新于 Nov 3, 2026

Find why a PostgreSQL query is slow from its EXPLAIN output, without a database connection.

已验证STDIO仅桌面数据库开发者工具

概览

AI 生成的概览

读取 PostgreSQL 的 EXPLAIN 输出,告诉助手查询时间花在哪里、应先修哪些问题,且不连接数据库。

可以做什么
  • 审阅单份 PostgreSQL 执行计划,输入可为文本或文件,找出顺序扫描丢弃大量行、行数估算偏差、排序与哈希落盘、嵌套循环重复执行等问题并排序
  • 对比修改前后的两份计划,显示耗时变化以及哪些问题已修复、仍存在或新出现
  • 按计划节点给出时间占比,并按节点占总时间的比例标注严重程度
  • 以规则编号(PG101 至 PG114)标出问题,涵盖索引覆盖、并行 worker 不足与 JIT 开销等
适用场景
适用于 PostgreSQL 查询变慢、手头已有 EXPLAIN (ANALYZE, BUFFERS) 输出可粘贴时,或想确认新建索引是否真的有效时。也适合不希望把数据库凭据交给助手、只想让它分析执行计划的场景。
运行要求
以本地进程通过 stdio 运行,通常用 npx 搭配 Node 18 或更新版本(也提供 Go 安装方式)。未声明需要账号、API 密钥或环境变量。需要用户提供计划文本或 JSON;它本身不连接数据库。
安装前请注意
执行计划可能包含查询中的具体数值,而 MCP 客户端会把工具结果发送给其模型,分享前请检查是否含敏感数据。建议的索引只是候选方案,仅基于一次运行和一组取值,应在真实数据上验证。获取计划时 ANALYZE 会真正执行查询,写入类语句请放在会回滚的事务中。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Slowplan,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

slowplan: why is this PostgreSQL query slow?

[npm] [CI] [MIT license]

An MCP server and CLI that reads PostgreSQL EXPLAIN output and tells you where the time goes and what to try first. It works from the plan text alone, so it never connects to your database.

A long EXPLAIN ANALYZE is hard to read, and a mistake is easy: Postgres reports per-worker averages under parallel plans, and the slowest-looking node often isn't where the time went. slowplan works out the real time for each step, and ranks problems such as sequential scans throwing away rows, wrong row estimates, sorts and hashes spilling to disk, and nested loops run many times.

What you can ask your agent

  • "This Postgres query is slow. Here's the EXPLAIN ANALYZE output."
  • "Why is the planner doing a sequential scan here?"
  • "I added an index. Did it help?"
  • "What's the first thing to fix in this plan?"

Install

As a Claude Code plugin:

claude plugin marketplace add GillMacedo/slowplanclaude plugin install slowplan@slowplan-marketplace

As an MCP server, for any client:

{"mcpServers": {"slowplan": {"command": "npx", "args": ["-y", "[email protected]", "serve"]}}}

As a CLI, with Node 18 or newer:

npx slowplan review plan.txt

Or with Go 1.27 or newer: go install github.com/GillMacedo/slowplan@latest.

Usage

Get a plan with EXPLAIN (ANALYZE, BUFFERS) <your query>, in text or JSON. ANALYZE really runs the query, so wrap anything that writes in a transaction you roll back.

Here's a real plan from PostgreSQL 17, on made-up tables:

$ make demoExecution 48.9 ms, planning 0.3 ms
Where the time goes:   80.8%      39.5 ms  Bitmap Heap Scan on orders    3.9%       1.9 ms  Bitmap Index Scan on orders_status_idx
HIGH   PG102 Bitmap Heap Scan on orders  The index doesn't cover the whole filter. Read and threw away 84857 rows to keep 857, using filter (bucket = 7).  Try: Candidate to test: CREATE INDEX CONCURRENTLY ON orders (bucket), or add these columns to the index in use.
These are leads from one run. Test a fix on realistic data before relying on it.

To check a change, compare the plans from before and after:

slowplan compare before.txt after.txt

On a real example in examples/, adding the index that slowplan suggested took a query from about 25 ms to 0.1 ms.

Add --json for JSON, or --fail-on high to exit 1 in CI. Use - to read from stdin.

What it finds

RuleFinds
PG101A sequential scan throwing away most of the rows it reads
PG102An index that doesn't cover the whole filter
PG103A join producing rows and then throwing them away
PG104A bitmap recheck throwing away many rows
PG105Row estimates off by 10 times or more
PG106A nested loop's inner side running 1,000 times or more
PG107A sort spilling to disk
PG108A hash table split into batches on disk
PG109Fewer parallel workers than planned
PG110An index-only scan still visiting the table often
PG111A bitmap that became lossy
PG112Reading about 80 MB or more from outside shared buffers
PG113Planning slower than running the query
PG114JIT taking 100 ms or more

Severity comes from the share of the query's time: high is 20% or more, and low is under 5% or under 1 ms. These thresholds are judgment calls.

MCP tools

ToolDoes
postgres_plan_reviewReviews one plan, from text or a file
postgres_plan_compareCompares plans from before and after a change

Limits

  • Suggested indexes are candidates. A plan shows one query with one set of values, and not your other indexes or what an index costs on writes. Test on realistic data.
  • One run isn't a benchmark. A cold cache or a busy server changes timing.
  • It can't see locks, network time, or anything outside the plan. A plan with estimates only has nothing measured, and slowplan says so.
  • Times under parallel plans are estimates, because Postgres reports averages across workers.
  • PostgreSQL only. Text plans from other tools, or heavily edited ones, may not parse. JSON is the most reliable.
  • Plans can hold values from your query. slowplan stays on your machine, but your MCP client sends tool results to its model.

FAQ

How do I read EXPLAIN ANALYZE output? Give it to slowplan, which shows where the time goes.

Why is Postgres doing a sequential scan? Often there's no useful index, or the filter keeps so many rows that an index wouldn't help. PG101 shows how many rows were thrown away.

How do I find out if a sort or hash is using disk? PG107 and PG108 flag them.

How is this different from pev2 or postgres-mcp? pev2 is a visualizer for people. postgres-mcp connects to a live database. slowplan gives an agent ranked findings from plan text, with no database access.

Tested on

PG101, PG102, PG104 to PG112 fired on real plans from a PostgreSQL 17 database with made-up tables, which are in examples/ in both JSON and text. PG103, PG113 and PG114 are only tested on written examples. MCP tool calls were tested through the MCP Inspector. It hasn't been used on a real production query yet.

Contributing

Contributions are welcome, from people and from people working with AI agents. See CONTRIBUTING.md. Good first issues are listed here.

AI disclosure

This project was largely generated with Claude Code and reviewed by its maintainer.

About me

I'm Giulliano Macedo, and I build developer tools at GoTech Solutions. Follow along or get in touch:

If slowplan found your slow query, a star helps others find it.


Built by Giulliano Macedo, GoTech Solutions · LinkedIn · X

来源:README.md,提交 54491fa

工具

2

postgres_plan_compare

Compare two PostgreSQL query plans

Compares EXPLAIN output from before and after a change, such as a new index, and shows the timing change and which problems were fixed, remain or are new. It never connects to a database.

输入参数afterbeforeafter_pathbefore_path

postgres_plan_review

Review a PostgreSQL query plan

Finds why a PostgreSQL query is slow from its EXPLAIN output, in text or JSON: where the time goes, and problems such as sequential scans throwing away rows, wrong row estimates, sorts and hashes spilling to disk, and nested loops run many times. Use after running EXPLAIN (ANALYZE, BUFFERS). It only reads the text you give it and never connects to a database. Suggested indexes are candidates to test.

输入参数pathplan

版本历史

1
  1. v0.1.0最新Nov 1, 2026

评分

已满足适用检查项的 90%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分
  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具必需15 分
  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分