explaingit

losefor/pg-explain

Analysis updated 2026-05-18

2TypeScriptAudience · developerComplexity · 3/5LicenseSetup · easy

TLDR

A CLI and web tool that turns PostgreSQL query plans into readable reports and flags performance problems with concrete fixes.

Mindmap

mindmap
  root((pg-explain))
    What it does
      Reads EXPLAIN output
      Detects anti-patterns
      Suggests concrete fixes
    Tech stack
      TypeScript
      Node.js
      PostgreSQL
    Use cases
      Debug slow queries
      Catch regressions in CI
      Monitor live lock contention
    Audience
      Developers
      Database admins

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Turn a PostgreSQL EXPLAIN ANALYZE output into a plain language report with concrete fixes.

USE CASE 2

Catch query plan regressions automatically in a CI pipeline by diffing two plans.

USE CASE 3

Connect to a live database and safely run EXPLAIN to diagnose a slow query.

USE CASE 4

Monitor live database lock contention to find what is blocking what.

What is it built with?

TypeScriptNode.jsPostgreSQL

How does it compare?

losefor/pg-explainadun-denton/chinvatagbara286/saint-cms
Stars222
LanguageTypeScriptTypeScriptTypeScript
Setup difficultyeasymoderateeasy
Complexity3/54/52/5
Audiencedeveloperdeveloperdeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 5min

Requires Node.js version 22 or newer, connecting to a live database needs the optional pg driver.

Use freely for any purpose, including commercial use, as long as you keep the copyright notice.

In plain English

pg-explain, distributed as the npm package pgexplain, takes the technical output PostgreSQL databases produce when you ask them to explain how they will run a query, and turns it into a human readable report. Database query plans are usually dense and full of jargon, so most tools that display them simply show you the raw tree of steps without telling you whether anything is actually wrong. This tool goes further by running an advisor over the plan that looks for known problem patterns, and for each one it finds it explains what happened, why it matters, and exactly how to fix it, often including a ready to copy SQL command such as the specific index to create. The tool can detect eighteen different kinds of query plan problems, including scans that read far more of a table than needed, sorts and other operations that spill to disk because they ran out of memory, tables whose statistics are outdated and are causing the database to misjudge how much data a step will touch, and risky database changes that could lock a table for longer than expected. It can also show a live snapshot of which database operations are currently blocked and waiting on each other. It works as a command line tool that can read a saved plan from a file, accept one piped in from the terminal, connect directly to a database and safely run a query in read only mode, or compare two plans against each other to catch a performance regression, which is useful in an automated testing pipeline. Reports can be produced in several formats including plain terminal output, Markdown, HTML, and JSON. There is also an optional local web interface called Studio that runs entirely on your own computer, showing an interactive, color coded diagram of the query plan, a history of past runs, and side by side comparisons between them. Any saved database passwords are stored using your operating system's secure credential storage when available. The tool requires Node.js version 22 or newer and is released under the MIT license.

Copy-paste prompts

Prompt 1
Help me install pgexplain and run it on a saved EXPLAIN ANALYZE JSON plan to generate a Markdown report.
Prompt 2
Explain what pg-explain's PGX_STALE_STATISTICS finding means and how to fix it.
Prompt 3
Show me how to use pg-explain diff to catch query plan regressions in a CI pipeline.
Prompt 4
Walk me through launching pg-explain studio locally to explore a query plan visually.

Frequently asked questions

What is pg-explain?

A CLI and web tool that turns PostgreSQL query plans into readable reports and flags performance problems with concrete fixes.

What language is pg-explain written in?

Mainly TypeScript. The stack also includes TypeScript, Node.js, PostgreSQL.

What license does pg-explain use?

Use freely for any purpose, including commercial use, as long as you keep the copyright notice.

How hard is pg-explain to set up?

Setup difficulty is rated easy, with roughly 5min to a first successful run.

Who is pg-explain for?

Mainly developer.

Open on GitHub → Explain another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.