yum 설치가 아닌 source 설치를 했을 때는 postgresql 기동 관련 service 설정을 따로해줘야합니다.
이번 글에서는 centos6 / 7 에서 각각 service 등록하는 방법을 알아보겠습니다.
설치한 path는 환경에 맞게 수정하시면 됩니다.
postgres service 등록 - centos6
irteamsu) sudo vi /etc/init.d/postgres
#!/bin/bash
# chkconfig:2345 90 20
# Installation prefix
prefix=/home1/irteam/psql/engn/postgresql-11.7
# Data directory
PGDATA="/home1/irteam/psql/engn/PGSQL"
# Who to run the postmaster as, usually "postgres". (NOT "root")
PGUSER=irteam
# Where to keep a log file
PGLOG="/home1/irteam/psql/logs/testdb/error_log/alert_testdb.log"
# Check for echo -n vs echo \c
if echo '\c' | grep -s c >/dev/null 2>&1 ; then
ECHO_N="echo -n"
ECHO_C=""
else
ECHO_N="echo"
ECHO_C='\c'
fi
# The path that is to be used for the script
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/home1/irteam/psql/engn/postgresql-11.7/bin/
# What to use to start up the postmaster (we do NOT use pg_ctl for this,
# as it adds no value and can cause the postmaster to misrecognize a stale
# lock file)
DAEMON="$prefix/bin/postmaster"
# What to use to shut down the postmaster
PGCTL="$prefix/bin/pg_ctl"
set -e
# Only start if we can find the postmaster.
test -x $DAEMON || exit 0
# Parse command line parameters.
case $1 in
start)
$ECHO_N "Starting PostgreSQL: "$ECHO_C
su - $PGUSER -c "$DAEMON -i -D $PGDATA" >>$PGLOG 2>&1 &
echo "ok"
;;
stop)
echo -n "Stopping PostgreSQL: "
su - $PGUSER -c "$PGCTL stop -D '$PGDATA' -s -m fast"
echo "ok"
;;
restart)
echo -n "Restarting PostgreSQL: "
su - $PGUSER -c "$PGCTL stop -D '$PGDATA' -s -m fast -w"
su - $PGUSER -c "$DAEMON -D $PGDATA" >>$PGLOG 2>&1 &
echo "ok"
;;
reload)
echo -n "Reload PostgreSQL: "
su - $PGUSER -c "$PGCTL reload -D '$PGDATA' -s"
echo "ok"
;;
status)
su - $PGUSER -c "$PGCTL status -D '$PGDATA'"
;;
*)
# Print help
echo "Usage: $0 {start|stop|restart|reload|status}" 1>&2
exit 1
;;
esac
exit $?
postgresql systemctl 등록 - centos7
irteamsu) sudo vi /usr/lib/systemd/system/postgresql.service
[Unit]
Description=PostgreSQL 9.6.19
After=syslog.target
After=network.target
[Service]
Type=forking
User=irteam
Group=irteam
# Note: avoid inserting whitespace in these Environment= lines, or you may
# break postgresql-setup.
# Location of database directory
Environment=PGDATA=/home1/irteam/psql/engn/PGSQL
Environment=POSTGRES_HOME=/home1/irteam/psql/engn/postgresql-9.6.19
# 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
ExecStart=/home1/irteam/psql/engn/postgresql-9.6.19/bin/pg_ctl start -D "${PGDATA}" -s -w -t 300
ExecStop=/home1/irteam/psql/engn/postgresql-9.6.19/bin/pg_ctl stop -D "${PGDATA}" -s -m fast
ExecReload=/home1/irteam/psql/engn/postgresql-9.6.19/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
### systemctl enable
$ sudo systemctl enable postgresql.service
$ sudo systemctl start postgresql.service
$ sudo systemctl stop postgresql.service