Saturday, October 24, 2026 4,350 lists 78,096 records on file
List your app or device

  1. Home
  2. SQL Linters and Formatters
  3. pgFormatter

pgFormatter

What it is

pgFormatter is a free formatter for PostgreSQL SQL queries and PL/pgSQL code, with support for several SQL standards and PostgreSQL-specific keywords. The project says it also works with other databases. It can run as a console program or CGI application, producing text or HTML according to its environment; a CGI request with an Accept: application/json header can return JSON, although the API can be disabled in CGI configuration. Formatting controls include keyword, function, identifier, and type case, indentation, query wrapping, and comma placement. The command-line --anonymize option obscures query literals before formatting. The project documents installation from a GitHub source tarball, Docker image builds, and piping SQL input into a running container. It also describes use with Vim and (Neo)Vim, links to Atom and Visual Studio Code integrations, and documents a pre-commit hook for SQL files. The online demo limits SQL queries to ten thousand characters. For other databases, pgFormatter does not automatically identify user-defined functions or keywords, but users can provide custom lists. It is free software distributed under the PostgreSQL Licence.

For and against

For

  • Formats PostgreSQL queries and PL/pgSQL code.
  • Offers controls for case, indentation, wrapping, and commas.
  • Can obscure query literals before formatting.
  • Includes editor and pre-commit integration options.
  • Free software under the PostgreSQL Licence.

Against

  • Online demo limits queries to ten thousand characters.
  • Other databases' custom functions and keywords need lists.

The verdict

pgFormatter provides configurable formatting and several ways to fit into SQL workflows. Users working with other databases should account for the need to maintain custom function and keyword lists.

Who it suits

pgFormatter suits developers who want to format PostgreSQL SQL or PL/pgSQL from a console, CGI setup, editor, or pre-commit workflow. It can also be used with other databases when users supply custom lists for functions or keywords it cannot identify automatically.

Plans and prices

pgFormatter

Free

Free software distributed under the PostgreSQL Licence

Every plan, in full

On the record

Anonymization
The command line option --anonymize obscures query literals before formatting.github.com · read 30 Sep 2026
Docker
The project documents building a Docker image and piping SQL input to a container running pgFormatter.github.com · read 30 Sep 2026
Editor integrations
The README describes use with Vim and (Neo)Vim and links to Atom and Visual Studio Code integrations.github.com · read 30 Sep 2026
Formatting options
Options include changing keyword, function, identifier, and type case; adjusting indentation; wrapping queries; and choosing comma placement.github.com · read 30 Sep 2026
Installation
The README documents installation from a GitHub source tarball using Perl Makefile.PL, make, and make install.github.com · read 30 Sep 2026
JSON API
When called as a CGI application with an Accept: application/json header, pgFormatter can return a JSON response; the API can be disabled in its CGI configuration.github.com · read 30 Sep 2026
Maker and license
The README credits Gilles Darold as the original author and says pgFormatter is free software distributed under the PostgreSQL Licence.github.com · read 30 Sep 2026
Online demo limit
The README describes an online demo that limits SQL queries to ten thousand characters.github.com · read 30 Sep 2026
Other databases
The project says pgFormatter also works with other databases.github.com · read 30 Sep 2026
Pre-commit integration
The README documents configuring pgFormatter as a pre-commit hook for SQL files.github.com · read 30 Sep 2026
Purpose
pgFormatter beautifies PostgreSQL SQL queries and PL/pgSQL code, and supports keywords from several SQL standards as well as PostgreSQL-specific keywords.github.com · read 30 Sep 2026
Security and privacy
The anonymization option is described as useful for hiding confidential data before formatting; the repository page opened did not state security certifications or compliance claims.github.com · read 30 Sep 2026
Support and limits
The README notes that pgFormatter cannot detect user-defined functions or keywords for other databases automatically, but allows custom lists for them.github.com · read 30 Sep 2026
Ways to run
It can run as a console program or a CGI application, producing text or HTML based on its environment.github.com · read 30 Sep 2026

The review

pgFormatter is a free formatter for PostgreSQL queries and PL/pgSQL code, with support for multiple SQL standards. It is best suited to developers and teams that want one configurable formatter across command-line, editor, web, and automated workflows. The strongest case is its integration flexibility; projects spanning other databases must be prepared to maintain their own function and keyword definitions.

Overview

pgFormatter runs either as a console program or as a CGI application, emitting text or HTML according to its operating environment. A CGI request carrying an Accept: application/json header can produce JSON, so the formatter can sit behind a service as well as in a local shell. Administrators can disable that API in the CGI configuration when an endpoint is not appropriate.

Dialect coverage includes SQL-92, SQL-99, SQL-2003, SQL-2008, SQL-2011, and PostgreSQL. The project also says it works with other databases, but it cannot automatically identify their user-defined functions or keywords. That is a manageable limitation for controlled codebases, but a real maintenance cost for teams sharing one style setup across several database products.

Key features

Formatting controls include the case used for keywords, functions, identifiers, and types, plus indentation, query wrapping, and comma placement. These choices let a team encode its preferred layout instead of accepting a single opinionated output. Automatic fixes and a configuration file make the same rules repeatable, which is important when formatting is part of code review or a build process.

Editor support is documented for Vim and (Neo)Vim, with integrations linked for Atom and Visual Studio Code. pgFormatter can also be configured as a pre-commit hook for SQL files, giving repositories a way to normalize changes before they are committed. Those integrations make it more useful in a team workflow than a formatter that only runs on demand.

The command-line --anonymize option obscures query literals before formatting. That is useful when SQL may contain confidential values, although it should be treated as a data-hiding aid rather than a security or compliance guarantee. The online demonstration limits input to 10,000 characters, so larger statements belong in the installed tool or another automated route.

Installation is documented from a GitHub source tarball with Perl Makefile.PL, make, and make install. The project also documents building a Docker image and piping SQL into a container, giving operators a reproducible deployment option when a host installation is undesirable.

Pricing

pgFormatter costs nothing. It is free software distributed under the PostgreSQL Licence, with no paid tier or free trial to manage. That makes it suitable for individual developers and teams that can operate their own tooling, but it also means there is no commercial plan described with hosted service terms or vendor-provided capacity.

Platforms

The listed platforms are API, Linux, self-hosted, and web. Console, CGI, Docker, editor, and pre-commit usage gives Linux and self-managed environments the broadest fit. The web presence is useful for short examples, while the 10,000-character demonstration limit makes it less suitable for very large scripts.

Who it's for

Choose pgFormatter for PostgreSQL-focused development where style needs to be configurable and enforceable in editors, repositories, or CI/CD. It is particularly well matched to teams already comfortable with self-hosted software and to developers who want both local command-line use and an API-shaped CGI option.

Look elsewhere if you need automatic recognition of proprietary or non-PostgreSQL functions without maintaining custom lists, or if your priority is a fully hosted formatter with a published service plan. The free license removes budget friction, but deployment and ongoing configuration remain your responsibility.

Pros and cons

Pros

  • Deep PostgreSQL focus: PostgreSQL and PL/pgSQL are the primary targets, with additional SQL-standard dialect coverage.
  • Many integration paths: Console, CGI, JSON responses, Docker, editor integrations, pre-commit hooks, and CI/CD support cover both personal and team workflows.
  • Useful style control: Case, indentation, wrapping, and comma-placement settings can match an existing project convention.
  • Privacy-minded option: Literal anonymization can hide confidential values before formatting.
  • No license cost: The software is free under the PostgreSQL Licence.

Cons

  • Cross-database upkeep: Other databases' custom functions and keywords require user-maintained lists.
  • Self-managed setup: Source installation, Docker, or CGI deployment puts operation and configuration on the user.
  • Demo size ceiling: The online demonstration accepts queries up to 10,000 characters.
  • No stated compliance claims: Anonymization is provided, but no security certifications or compliance claims are made.

Alternatives

Squawk is another free option with a notably broad platform range, including Android, iOS, macOS, Windows, extensions, API, web, and self-hosting; pick it when device coverage matters more than pgFormatter's PostgreSQL-centered configuration.

SQLCheck is a free Linux, macOS, and Windows command-line tool; choose it when a cross-platform CLI and its Joy Arulraj project are the priority.

sqlfmt offers a free browser formatter running through WebAssembly with no installation, making it preferable for quick browser-based formatting.

Poor SQL is a free, open-source AGPL formatter with online and offline modes plus SSMS/Visual Studio and command-line options; select it for Microsoft-oriented tooling.

Sleek is a free open-source formatter for extension, Linux, macOS, and Windows users; it is a straightforward alternative when those desktop targets are the requirement.

sqlfmt has a free tier with 20 analyses per day, all five dialects, live formatting, and saved snippets and history; choose it for a hosted workflow with those explicit usage limits.

SQLint is a free MIT-licensed Python package for Standard SQL (BigQuery) parsing and linting, better suited when BigQuery validation is the central need.

Sqruff is another free SQL tooling option.

Verdict

pgFormatter is a strong recommendation for PostgreSQL developers who want free, configurable formatting that can move from an editor to pre-commit and CI/CD workflows. Its broad run modes and precise style controls are the main reasons to choose it. Look elsewhere when you need a hosted, turnkey experience or automatic cross-database vocabulary detection without maintaining custom configuration.

Alternatives to pgFormatter

Every alternative, ranked