체계화 된 postgresql 시작 스크립트 실행할 수 있습니다. # service postgresql92 start 그러나

postgresql을 두 번째 서버에 설치하는 중입니다.

이전에는 postgresql을 설치하고 제공된 스크립트를 사용했습니다.

./contrib/start-scripts/linux

올바른 디렉토리에 배치

# cp ./contrib/start-scripts/linux /etc/rc.d/init.d/postgresql92
# chmod 755 /etc/rc.d/init.d/postgresql92

그런 다음 예상대로 실행할 수 있습니다.

# service postgresql92 start

그러나 새 컴퓨터는 Systemd를 사용하고 있으며 완전히 다른 방법이 있습니다.

나는 이것을 해킹하고 무언가를 망치고 싶지 않아서 누군가가 같은 결과를 얻는 방법의 올바른 방향으로 나를 가리킬 수 있는지 궁금해하고 있었다.



답변

소스에서 설치하는 경우 소스 설치와 작동하는 시스템 단위 파일을 추가해야합니다. RHEL, Fedora 내 장치 파일은 다음과 같습니다.

/usr/lib/systemd/system/postgresql.service

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

[Service]
Type=forking

User=postgres
Group=postgres

# 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
# ... but allow it still to be effective for child processes
# (note that these settings are ignored by Postgres releases before 9.5)
Environment=PG_OOM_ADJUST_FILE=/proc/self/oom_score_adj
Environment=PG_OOM_ADJUST_VALUE=0

# Maximum number of seconds pg_ctl will wait for postgres to start.  Note that
# PGSTARTTIMEOUT should be less than TimeoutSec value.
Environment=PGSTARTTIMEOUT=270

Environment=PGDATA=/usr/local/pgsql/data


ExecStart=/usr/local/pgsql/bin/pg_ctl start -D ${PGDATA} -s -w -t ${PGSTARTTIMEOUT}
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.
# Ideally, the timeout for starting PostgreSQL server should be handled more
# nicely by pg_ctl in ExecStart, so keep its timeout smaller than this value.
TimeoutSec=300

[Install]
WantedBy=multi-user.target

그런 다음 시작시 서비스를 활성화하고 PostgreSQL 서비스를 시작하십시오.

$ sudo systemctl daemon-reload # load the updated service file from disk
$ sudo systemctl enable postgresql
$ sudo systemctl start postgresql


답변

# systemctl start postgresql.service

일부 환경 번역 할 service <name> startsystemctl start <name>.service,하지만 당신은에 의존 할 필요가 없습니다.


답변

위의 systemctl 단위 파일을 게시하면 많은 도움이되지만 필요한 파일을 만들려면 다음과 같이하십시오.

/etc/systemd/system/postgresql92.service
systemctl enable postgresql92.service
systemctl start postgresql92.service

설치에 따라 binay pg_ctl 경로를 변경하고 다른 인스턴스를 실행하려면 기본 청취 포트도 변경해야합니다.

ExecStart=/usr/local/pgsql/bin/pg_ctl -o "-p 5489"


답변