2023 · Sole author

pgwatch — Postgres slow-query CLI

A terminal tool that streams pg_stat_statements into a live table and lets you pin queries to a hotlist. Open source, ~600 stars.

stack
Rust, Postgres, crossterm
tags
cli, postgres, developer-tools
status
shipped

Code

Why

pg_stat_statements is gold but the query interface for it is awful. Every team I’ve worked on ended up with a one-off SQL snippet pinned in someone’s wiki. I wanted the htop of Postgres.

Design

A single binary, no daemon. Connects via DATABASE_URL, polls pg_stat_statements on a configurable interval, diffs the snapshot, and renders top-N by configurable cost metric. Pinned queries persist across runs in ~/.pgwatch.toml.

What it taught me

The hardest part wasn’t the query layer or the terminal rendering — it was the diffing strategy across snapshots when pg_stat_statements resets behind your back. The diff module handles four distinct reset scenarios.