I'm in the process of installing postgresql onto a second server

Previously I installed postgresql and then used the supplied script


Placed into the correct dir

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

Which I could then execute as expected with

# service postgresql92 start

However the new machine is using Systemd and it looks like there is a completely different way to do this

I don't want to hack at this and ruin something so I was wondering if anyone out there could point me in the right direction of how to achieve the same result


When installing from source, you will need to add a systemd unit file that works with the source install. For RHEL, Fedora my unit file looks like:


Description=PostgreSQL database server



# 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
# ... but allow it still to be effective for child processes
# (note that these settings are ignored by Postgres releases before 9.5)

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


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.


Then enable the service on startup and start the PostgreSQL service:

$ sudo systemctl daemon-reload # load the updated service file from disk
$ sudo systemctl enable postgresql
$ sudo systemctl start postgresql
| improve this answer | |
# systemctl start postgresql.service

Some environments would translate service <name> start to systemctl start <name>.service, but you don't have to rely on it.

| improve this answer | |
  • But where would I place the postgresql92 script? – TheLovelySausage Aug 6 '15 at 4:57
  • You don't use it anymore in systemd. Your distribution should provide you with the postgresql systemd service file so that youcan start the service. – Emeric Aug 6 '15 at 5:12
  • The postgresql was installed from source though, not using dnf because I need to install 3 versions of postgres in specific directories, is it possible to use the supplied start-scripts linux file to start postgresql? – TheLovelySausage Aug 6 '15 at 7:23
  • My distribution adds this script as /usr/lib/systemd/system/postgresql.service. The start-scripts provided by postgresql seem to only cover SysV. – Emeric Aug 6 '15 at 7:46
  • did you install postgres using dnf or yum? – TheLovelySausage Aug 6 '15 at 7:55

Posted systemctl unit file above help me a lot but to create the one you need you just have to put it on :

systemctl enable postgresql92.service
systemctl start postgresql92.service

Think about changing binay pg_ctl path according to your install, and if you want to run another instance, you must also change default listening port :

ExecStart=/usr/local/pgsql/bin/pg_ctl -o "-p 5489"
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.