end0tknr's kipple - web写経開発

太宰府天満宮の狛犬って、妙にカワイイ

install postgres 12.3 from source code to centos8

前準備 : yum install systemd-devel

centos8ですので、自動起動には systemd (systemctl)を使用します。 postgresでは、systemd による自動起動を行う場合、 configure時に「--with-systemd」を指定します。

更に「--with-systemd」は「systemd-devel」を必要とします。

$ sudo yum install systemd-devel

上記を行わないと、以下のようなerrorとなります。

$ ./configure --with-systemd
  :
configure: error: header file <systemd/sd-daemon.h> is required for systemd support

download source code , build , install ...

wget https://ftp.postgresql.org/pub/source/v12.3/postgresql-12.3.tar.gz
tar -xvf postgresql-12.3.tar.gz
cd postgresql-12.3
less INSTALL

./configure --with-systemd
make
make check
$ su
# make install
# adduser postgres
# mkdir /usr/local/pgsql/data
# chown postgres /usr/local/pgsql/data
# su - postgres
$ /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
$ /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
$ /usr/local/pgsql/bin/createdb test
$ /usr/local/pgsql/bin/psql test

systemd (systemctl)による自動起動

参考url https://www.postgresql.jp/document/12/html/server-start.html

$ sudo vi /etc/systemd/system/postgresql.service

[Unit]
Description=PostgreSQL database server
Documentation=man:postgres(1)

[Service]
Type=notify
User=postgres
ExecStart=/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data
ExecReload=/bin/kill -HUP $MAINPID
KillMode=mixed
KillSignal=SIGINT
TimeoutSec=0

[Install]
WantedBy=multi-user.target

$ sudo systemctl enable postgresql
Created symlink /etc/systemd/system/multi-user.target.wants/postgresql.service → /etc/systemd/system/postgresql.service.
$ sudo systemctl start postgresql