Skip to the content
Know your tech before you buy it. Makers: get listed from $49/mo

pgFormatter

github.com

  • Free plan
  • Linux
  • Web
  • API
  • Self-hosted
7.2 Club score Visit github.com

What pgFormatter is

pgFormatter is free software for formatting PostgreSQL SQL queries and PL/pgSQL code, with support for SQL-92, SQL-99, SQL-2003, SQL-2008, SQL-2011, and PostgreSQL syntax. The project also says it works with other databases. It can run in a console or as a CGI application, producing text or HTML according to its environment; a CGI request with an Accept: application/json header can return JSON, though the API can be disabled in the CGI configuration. Formatting controls cover keyword, function, identifier, and type case, indentation, query wrapping, and comma placement. The --anonymize option obscures query literals before formatting. The online demo limits SQL queries to ten thousand characters. Installation options documented by the project include a GitHub source tarball and Docker. The README also describes Vim and (Neo)Vim use, links to Atom and Visual Studio Code integrations, and explains pre-commit setup for SQL files. For other databases, custom lists can cover user-defined functions and keywords the formatter cannot detect automatically. It is distributed under the PostgreSQL Licence.

Who it suits

pgFormatter is suited to developers who want to format PostgreSQL or PL/pgSQL code from a console, CGI setup, editor, or pre-commit workflow. Teams working with other databases can add custom lists for functions and keywords.

Good to know, and what to watch

  • Formats PostgreSQL queries and PL/pgSQL.
  • Offers controls for case, indentation, and wrapping.
  • Can obscure query literals before formatting.
  • Supports CGI JSON responses.
  • Editor and pre-commit integrations are documented.
  • Online demo limits queries to ten thousand characters.
  • Other-database functions and keywords need custom lists.
  • CGI JSON API can be disabled.

pgFormatter

Free

Free plan

The verdict

pgFormatter offers configurable SQL formatting across console and CGI workflows, with integrations for editors and pre-commit use. Note the demo's query limit and the need for custom lists when using other databases.

What the maker publishes

Anonymization
The command line option --anonymize obscures query literals before formatting. source
Docker
The project documents building a Docker image and piping SQL input to a container running pgFormatter. source
Editor integrations
The README describes use with Vim and (Neo)Vim and links to Atom and Visual Studio Code integrations. source
Formatting options
Options include changing keyword, function, identifier, and type case; adjusting indentation; wrapping queries; and choosing comma placement. source
Installation
The README documents installation from a GitHub source tarball using Perl Makefile.PL, make, and make install. source
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. source
Maker and license
The README credits Gilles Darold as the original author and says pgFormatter is free software distributed under the PostgreSQL Licence. source
Online demo limit
The README describes an online demo that limits SQL queries to ten thousand characters. source
Other databases
The project says pgFormatter also works with other databases. source
Pre-commit integration
The README documents configuring pgFormatter as a pre-commit hook for SQL files. source
Purpose
pgFormatter beautifies PostgreSQL SQL queries and PL/pgSQL code, and supports keywords from several SQL standards as well as PostgreSQL-specific keywords. source
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. source
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. source
Ways to run
It can run as a console program or a CGI application, producing text or HTML based on its environment. source

Checked against the maker's pages on 30 Sept 2026.