Created
July 23, 2021 16:48
-
-
Save abishekmuthian/448f86ee459bec0e06a5923d0003b854 to your computer and use it in GitHub Desktop.
Postgres systemd start script when not compiled for systemd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
When postgres was not compiled with systemd support, this start script will work. | |
Source: https://itectec.com/unixlinux/linux-systemd-postgresql-start-script/ | |
/usr/lib/systemd/system/postgresql.service |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sudo systemctl daemon-reload # load the updated service file from disk | |
$ sudo systemctl enable postgresql | |
$ sudo systemctl start postgresql |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment