Freedom251 › SQL Linters and Formatters
PgSanity

What PgSanity is
PgSanity is a free Python package that checks PostgreSQL SQL files for syntax problems. It places plain SQL into an embedded SQL form inside a C-like file, then uses ecpg, which relies on PostgreSQL’s parser, to identify errors. You can provide one filename or several; reported syntax errors include the file and line. With no filenames, PgSanity reads SQL from standard input, supporting interactive use or input piped from another command. It returns exit status 0 when the syntax looks good and 1 when it finds errors, allowing scripts to respond to the result. The project also provides a pre-commit hook named pgsanity_lint. PgSanity is intended for developers, information technology professionals, and system administrators. It supports PostgreSQL SQL and is designed for Linux and self-hosted use. Installation is available from PyPI with pip or uv, and through FreeBSD ports. The stated requirements are Python 3.9 or later and ecpg; the README lists dependency package names for Ubuntu/Debian, RHEL/CentOS, and Arch. PyPI lists the license as MIT and names Mark Drago as the sole maintainer and author. The README directs users to the GitHub project to report problems, including incorrect syntax results.
Who it suits
PgSanity suits developers, IT professionals, and system administrators who need to check PostgreSQL SQL files. Its filename, standard-input, exit-status, and pre-commit options fit command-line and development workflows.
What it does well
- Checks one or multiple SQL filenames and identifies errors by file and line.
- Reads SQL from standard input when no filenames are provided.
- Returns distinct exit statuses for clean syntax and errors.
- Includes a pre-commit hook named pgsanity_lint.
- Installable with pip or uv, and available through FreeBSD ports.
What to know first
- Requires Python 3.9 or later and ecpg.
- Supports PostgreSQL SQL only.
- Designed for Linux and self-hosted use.
Plans
| Plan | Billed and limits | Price |
|---|---|---|
| Free | Open-source Python package · requires Python ≥3.9 and ecpg | Free |
As github.com lists them, read 4 Oct 2026. The maker's own page has the final word.
Getting started
- Open the PgSanity GitHub project page.
- Install Python 3.9 or later and ecpg.
- Install the package from PyPI with pip or uv, or use FreeBSD ports.
- Run it with one or more SQL filenames, or provide SQL through standard input.
- Add the pgsanity_lint pre-commit hook if it fits your workflow.
Verdict
Choose PgSanity if you need a free, MIT-licensed way to check PostgreSQL SQL files from a command line or pre-commit workflow. Its use requires Python 3.9 or later and ecpg, so another option may suit environments that cannot provide those dependencies or need a different SQL dialect.
Questions
How much does PgSanity cost?
The Free plan costs nothing. It is an open-source Python package, and PyPI lists its license as MIT.
What does PgSanity check?
It checks SQL syntax for PostgreSQL. It wraps SQL in an embedded SQL form and uses ecpg, which uses PostgreSQL’s parser.
What does it need to run?
The stated dependencies are Python 3.9 or later and ecpg. The README lists package names for Ubuntu/Debian, RHEL/CentOS, and Arch.
How can I install it?
It can be installed from PyPI with pip or uv, and is also available through FreeBSD ports.
Who maintains PgSanity?
PyPI lists Mark Drago as the sole maintainer and author. The README directs users to GitHub to report problems.
Facts from PgSanity's own pages
- Dependencies
- The stated dependencies are Python 3.9 or later and ecpg; the README lists package names for Ubuntu/Debian, RHEL/CentOS, and Arch. · github.com, 4 Oct 2026
- Distribution
- The project is installable from PyPI with pip or uv and is also available through FreeBSD ports. · github.com, 4 Oct 2026
- Exit codes
- It exits with status 0 when SQL syntax looks good and 1 when errors are found. · github.com, 4 Oct 2026
- File input
- It accepts one or multiple filenames and reports syntax errors with file and line information. · github.com, 4 Oct 2026
- How it works
- It wraps bare SQL as embedded SQL in a C-like file and uses ecpg, which uses PostgreSQL’s parser, to report syntax errors. · github.com, 4 Oct 2026
- Intended audience
- PyPI classifies the intended audience as developers, information technology, and system administrators. · pypi.org, 4 Oct 2026
- License
- PyPI lists the project’s license expression as MIT. · pypi.org, 4 Oct 2026
- Maintainer
- PyPI lists Mark Drago as the project’s sole maintainer and author. · pypi.org, 4 Oct 2026
- Purpose
- PgSanity checks the syntax of PostgreSQL SQL files. · github.com, 4 Oct 2026
- Security reporting
- The README directs users to report problems, including incorrect syntax results, through the GitHub repository. · github.com, 4 Oct 2026
- Standard input
- When no filenames are provided, it reads SQL from stdin for interactive use or piping. · github.com, 4 Oct 2026
- Support
- The README points users to the GitHub project page to report problems. · github.com, 4 Oct 2026
- Workflow integration
- The repository provides a pre-commit hook with the id pgsanity_lint. · github.com, 4 Oct 2026
Where PgSanity stands on Freedom251
- SQL Linters and Formatters#6 of 26