備忘録。自分で探すとき、いつも一旦hatenaを探してから自分のサイトにいくので、こちらにも書いておくことにした。
www.interdb.jp
インストール
前提として
(1) postgresは"/usr/local/pgsql"にインストールされている、 (2) PostgreSQLのソースコードは"/usr/local/src/postgresql"以下にあるとする。
詳細はsrc/tools/pgindent/README参照。
1. pg_bsd_indentをインストール
以下のようにしてpg_bsd_indentをどこか適当な場所にインストールする。
$ 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. Perl-Tidyをインストール
以下のように、Perl-Tidyをインストールする。バージョンは20170521以外ダメなようだ。
PG17devではPerl-Tidy-20230309を使うらしい。
$ wget https://cpan.metacpan.org/authors/id/S/SH/SHANCOCK/Perl-Tidy-20230309.tar.gz
$ tar xvfz Perl-Tidy-20230309.tar.gz
$ cd Perl-Tidy-20170521
$ perl Makefile.PL
$ make
$ make test
$ make install
3. typedefsをインストール
PostgreSQLのソースコードのトップディレクトリに移動し、以下のコマンドを実行する。
$ cd /usr/local/src/postgresql
$ wget -O src/tools/pgindent/typedefs.list https://buildfarm.postgresql.org/cgi-bin/typedefs.pl
Note
PG17devで試すと、以下のようなエラーが出る。
$ ../../src/tools/pgindent/pgindent
You do not appear to have pg_bsd_indent version 2.1.2 installed on your system.
が、pg_bsd_indentのTAGを調べると、version 2.1.1.までしかできていない。
$ ~/pg_bsd_indent$ git tag
REL_2_1_1
仕方ないので、pgindentの変数を変更して対処する。
#!/usr/bin/perl
# Copyright (c) 2021-2023, PostgreSQL Global Development Group
use strict;
use warnings;
use Cwd qw(abs_path getcwd);
use File::Find;
use File::Spec qw(devnull);
use File::Temp;
use IO::Handle;
use Getopt::Long;
# Update for pg_bsd_indent version
my $INDENT_VERSION = "2.1.1"; # "2.1.2"から"2.1.1"へ。
とりあえず動くのでヨシ。
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 .
Don't forget the last comma "."