How to install and use pgindent

pgindent maintains the uniform layout style of postgresql related source code.

Installation

I assume that (1) Postgres is installed in /usr/local/pgsql (2) PostgreSQL’s source code is located in/usr/local/src/postgresql

Details are described in src/tools/pgindent/README.

1. Install pg_bsd_indent

You can do the following operations anywhere.

$ git clone https://git.postgresql.org/git/pg_bsd_indent.git
$ cd pg_bsd_indent/
$ make PG_CONFIG=/usr/local/pgsql/bin/pg_config 
$ cp pg_bsd_indent /usr/local/bin

2. Install Perl-Tidy

You can do the following operations anywhere. Note that you must download version 20170521, don’t use other versions.

$ wget https://cpan.metacpan.org/authors/id/S/SH/SHANCOCK/Perl-Tidy-20170521.tar.gz
$ tar xvfz Perl-Tidy-20170521.tar.gz 
$ cd Perl-Tidy-20170521
$ perl Makefile.PL 
$ make
$ make test
$ make install

3. Install typedefs

Change to the top of the source code tree, and issue the following wget command.

$ cd /usr/local/src/postgresql
$ wget -O src/tools/pgindent/typedefs.list https://buildfarm.postgresql.org/cgi-bin/typedefs.pl

Usage

$ cd /usr/local/src/postgresql
$ ./src/tools/pgindent/pgindet

If you make an extension that is located in the contrib sub-directory, do the following command.

$ cd /usr/local/src/postgresql/contirb/your_extension
$ ../../src/tools/pgindent/pgindent