- Home
- SQL Linters and Formatters
- PgSanity
PgSanity
What it is
PgSanity is a free Python package that checks PostgreSQL SQL files for syntax errors on Linux or self-hosted systems. It wraps plain SQL in an embedded form inside a C-like file, then uses ecpg and PostgreSQL’s parser to identify problems. You can provide one filename or several, with errors reported alongside file and line information. Running it without filenames reads SQL from standard input for interactive use or piping. PgSanity exits with status 0 when syntax looks good and 1 when errors are found, allowing scripts to react to the result. A pre-commit hook named pgsanity_lint supports development workflows. Installation is available through PyPI with pip or uv, and through FreeBSD ports. Requirements include Python 3.9 or later and ecpg. PyPI lists MIT licensing and identifies developers, IT professionals, and system administrators as intended users. Mark Drago is listed as sole maintainer and author.
For and against
For
- Checks PostgreSQL SQL syntax
- Reports file and line information
- Reads files or standard input
- Provides script-friendly exit statuses
- Includes a pre-commit hook
Against
- Requires Python 3.9 or later
- Requires ecpg installation
- Supports PostgreSQL SQL only
- Linux or self-hosted platforms are listed
The verdict
PgSanity is a focused syntax checker with file, stdin, scripting, and pre-commit workflows. Its usefulness depends on having Python and ecpg available in the target environment.
Who it suits
PgSanity suits developers, IT professionals, and system administrators checking PostgreSQL SQL in Linux or self-hosted workflows. It is especially relevant when command-line checks or pre-commit validation are needed.
Plans and prices
Free
Open-source Python package · requires Python ≥3.9 and ecpg
Read 4 Oct 2026 · github.com
On the record
- 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 · read 4 Oct 2026
- Distribution
- The project is installable from PyPI with pip or uv and is also available through FreeBSD ports.github.com · read 4 Oct 2026
- Exit codes
- It exits with status 0 when SQL syntax looks good and 1 when errors are found.github.com · read 4 Oct 2026
- File input
- It accepts one or multiple filenames and reports syntax errors with file and line information.github.com · read 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 · read 4 Oct 2026
- Intended audience
- PyPI classifies the intended audience as developers, information technology, and system administrators.pypi.org · read 4 Oct 2026
- License
- PyPI lists the project’s license expression as MIT.pypi.org · read 4 Oct 2026
- Maintainer
- PyPI lists Mark Drago as the project’s sole maintainer and author.pypi.org · read 4 Oct 2026
- Purpose
- PgSanity checks the syntax of PostgreSQL SQL files.github.com · read 4 Oct 2026
- Security reporting
- The README directs users to report problems, including incorrect syntax results, through the GitHub repository.github.com · read 4 Oct 2026
- Standard input
- When no filenames are provided, it reads SQL from stdin for interactive use or piping.github.com · read 4 Oct 2026
- Support
- The README points users to the GitHub project page to report problems.github.com · read 4 Oct 2026
- Workflow integration
- The repository provides a pre-commit hook with the id pgsanity_lint.github.com · read 4 Oct 2026