Linux
Systemd postgresql 啟動腳本
我正在將 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,看起來有一種完全不同的方法可以做到這一點
我不想破解這個並破壞某些東西,所以我想知道是否有人可以指出我如何達到相同結果的正確方向
從源安裝時,您需要添加一個與源安裝一起使用的 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