PgSanity review
A focused PostgreSQL syntax checker for command-line and pre-commit workflows.
Reviewed by iTechGuides Editors · Editorial team · Updated Oct 2026
PgSanity is an open-source command-line utility for checking PostgreSQL SQL syntax. It is aimed at developers and teams that want a focused validation step for SQL files, scripts, or pre-commit workflows. The tool uses ecpg, which relies on PostgreSQL’s parser, to identify syntax errors and report their locations and messages. It accepts one or multiple filenames, or reads SQL from standard input when no filenames are supplied. PgSanity runs on Linux and is distributed through pip or uv.
Its main strength is parser alignment: checks use PostgreSQL’s own parsing path rather than a generic SQL interpretation. That makes the tool a focused fit for PostgreSQL repositories where syntax validation matters more than a broad database-linting feature set. Exit status 0 indicates valid syntax, while status 1 indicates that errors were found, giving command-line workflows a clear result to act on. The pre-commit integration also places checks directly into a source-control workflow, while standard input support can suit pipelines and generated SQL.
Setup is oriented toward command-line environments and requires Python and ecpg, so teams should account for those dependencies when preparing development systems or automation. PgSanity stays narrow: it checks syntax but does not provide verified SQL formatting or autofix, and its published positioning does not extend to editor or broader CI capabilities. Choose it when PostgreSQL-only syntax checks, file handling, standard input, and pre-commit integration are the priority. Choose a broader SQL tool instead when formatting, automatic corrections, editor integration, or wider workflow coverage are central requirements.
PgSanity pros and cons
- Where it wins
- Uses PostgreSQL’s parser for focused syntax checks
- Accepts multiple files or SQL from standard input
- Reports error locations and works as a pre-commit hook
- Where it doesn't
- Supports PostgreSQL syntax rather than multiple SQL dialects
- Requires Python and ecpg for installation and operation
- Does not provide verified formatting, autofix, editor, or CI breadth
PgSanity fact sheet, pricing and score →
Advertiser disclosure: iTechGuides is reader-supported. Vendors can pay for top positions in our rankings and for a place on other products' pages, and we may earn a commission when you click some links. Bought places stand at the number bought; this page and our disclosure say so. Paying vendors may get a fuller, more detailed review from our editors, and that review can change their score. How we rank.
Last updated · How we research and update