Postgresql の開発環境を構築する。
ソースコードの入手
postgresql のソースコードは git 上で管理されており `https://git.postgresql.org/git/postgresql.git` に存在するので、これを拾ってくる。
必要なライブラリのインストール
そのままではビルドが通らないので、ビルドに必要な開発パッケージをインストールする。
(https://wiki.postgresql.org/wiki/Compile_and_Install_from_source_code)
$ sudo apt-get install build-essential libreadline-dev zlib1g-dev flex bison libxml2-dev libxslt-dev libssl-dev libxml2-utils xsltproc ccacheビルド
ライブラリのインストールが済んだら、 ./configure コマンドを発行して問題が起きないか確認する。個人的な話だが、手動でビルドしたプログラムは ~/.usr に配置するようにしたいので、その設定も行う。(もちろん PATH は通してある)
$ ./configure --prefix="${HOME}/.usr"
$ make
$ make installconfigure: error: ICU library not found が発生する
master ブランチが 17devel の作業を行っているとき、 ./configure を実行したら configure: error: ICU library not found が発生した。正確には、 ICU はあるけれども icu-uc と icu-i18n がないよ、という内容。 (ICU すらないといわれた場合、 libicu-dev をインストールする必要がある)
checking whether to build with ICU support... yes
checking for icu-uc icu-i18n... no
configure: error: ICU library not found
If you have ICU already installed, see config.log for details on the
failure. It is possible the compiler isn't looking in the proper directory.
Use --without-icu to disable ICU support.ICU 自体は見つかるのに icu-uc と icu-i18n が見つからないらしいけどなんでだろう…… と思ったら、ここ (https://stackoverflow.com/questions/76477533/installing-age-pg16-beside-postgresql-v16beta1-giving-bison-is-missing-while-it) に解決策があった。
$ sudo apt update
$ sudo apt install libicu-dev pkgconf確認
$ ls -1 ~/.usr/bin/
clusterdb
createdb
# --- OMMITED ---
postgres
psql
reindexdb
vacuumdb
$ ls -1 ~/.usr/lib/
libecpg.a
libecpg_compat.a
# --- OMMITED ---
libpq.a
libpq.so
libpq.so.5
libpq.so.5.17
pkgconfig
postgresql
$ psql
psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file or directory
Is the server running locally and accepting connections on that socket?サーバー自体はまだ起動していないので応答しないが、 psql はちゃんと読み込めているみたい。
command not found が発生する
ソフトウェアにパスが通ってない可能性がある。 ~/.bashrc などに export PATH=/home/username/.usr/bin:$PATH などの記述をする必要がある。 source ~./bashrc で設定を読み直し、 which psql などで意図した位置のファイルが見えることを確認する。
cannot open shared object file が発生する
共有ライブラリにパスが通っていない可能性がある。 ~/.bashrc などに export LD_LIBRARY_PATH=/home/username/.usr/lib:$LD_LIBRARY_PATH などの記述をする。 ( LD_LIBRARY_PATH を正しく設定する)
最後に
./postgres/src ディレクトリ以下には postgresql のソースコードが存在するので、煮るなり焼くなりして改造できる。
git 上では 1日 10コミット程度ツリーが進んでいるので、それを追いかけるのも悪くない。