2018年5月14日月曜日

PostgreSQL9.6.9 ソースからのインストール 3/3

$ su -

ファイヤーウォールの設定
PostgreSQLへのアクセスを有効にします。
# firewall-cmd --add-service=postgresql --zone=public --permanent
# systemctl restart firewalld

SELinuxの設定
PostgreSQLへのアクセスを有効にします。
# setsebool -P postgresql_can_rsync on
# setsebool -P postgresql_selinux_transmit_client_label on
# setsebool -P selinuxuser_postgresql_connect_enabled on

確認
# getsebool -a | grep postgresql

自動起動設定
サービス定義ファイルを作成します。
#vi /usr/lib/systemd/system/postgresql.service
# It's not recommended to modify this file in-place, because it will be
# overwritten during package upgrades.  If you want to customize, the
# best way is to create a file "/etc/systemd/system/postgresql.service",
# containing
#   .include /lib/systemd/system/postgresql.service
#   ...make your changes here...
# For more info about custom unit files, see
# http://fedoraproject.org/wiki/Systemd#How_do_I_customize_a_unit_file.2F_add_a_custom_unit_file.3F

# For example, if you want to change the server's port number to 5433,
# create a file named "/etc/systemd/system/postgresql.service" containing:
#   .include /lib/systemd/system/postgresql.service
#   [Service]
#   Environment=PGPORT=5433
# This will override the setting appearing below.

# Note: changing PGPORT or PGDATA will typically require adjusting SELinux
# configuration as well; see /usr/share/doc/postgresql-*/README.rpm-dist.

# Note: do not use a PGDATA pathname containing spaces, or you will
# break postgresql-setup.

# Note: in F-17 and beyond, /usr/lib/... is recommended in the .include line
# though /lib/... will still work.

[Unit]
Description=PostgreSQL database server
After=network.target

[Service]
Type=forking

User=postgres
Group=postgres

# Port number for server to listen on
Environment=PGPORT=5432

# Location of database directory
Environment=PGDATA=/usr/local/pgsql/data

# Where to send early-startup messages from the server (before the logging
# options of postgresql.conf take effect)
# This is normally controlled by the global default set by systemd
# StandardOutput=syslog

# Disable OOM kill on the postmaster
OOMScoreAdjust=-1000

#ExecStartPre=/usr/local/pgsql/bin/postgresql-check-db-dir ${PGDATA} <=このモジュールは存在しないのでコメント
ExecStart=/usr/local/pgsql/bin/pg_ctl start -D ${PGDATA} -s -o "-p ${PGPORT}" -w -t 300
ExecStop=/usr/local/pgsql/bin/pg_ctl stop -D ${PGDATA} -s -m fast
ExecReload=/usr/local/pgsql/bin/pg_ctl reload -D ${PGDATA} -s

# Give a reasonable amount of time for the server to start up/shut down
TimeoutSec=300

[Install]
WantedBy=multi-user.target

EOF

サービスでの起動と停止
# systemctl start postgresql
# systemctl stop postgresql
# systemctl enable postgresql

最後に、PGAdmin等から接続出来るか確認します。