I am working on Ubuntu 16.04 and am confused in postgresql service files.

I installed the postgresql deb package from repo and it gave me 3 files to start the service: - /etc/init.d/postgresql - /lib/systemd/system/postgresql.service - /lib/systemd/system/[email protected]

I tried to google to understand the differences between them. Till now only thing I learnt is that init.d was the old method of starting the services while systemd is the new one

So in my case when I invoke the following what makes the service start ?

# service postgresql start

I tried adding an exit 0 in start function of init.d but still the service starts. So that script is redundant ?

I need to change some configs in the start invocation of the service and don't know if I should make change in .service file or @.service file

Contents of .service file are:

# cat /lib/systemd/system/postgresql.service

 Description=PostgreSQL RDBMS



What is the /bin/true for ? The actual code to start the service appears in @.service file

Which is used when ?

This is totally confusing me :(

1 Answer 1


Welcome to Ask Ubuntu.

There have been 3 init systems on Ubuntu. New systems are backwards compatible, but old systems are not forward compatible.

Software projects often package scripts for multiple init systems, since they may run on multiple systems. Ubuntu in turn installs multiple styles of init files, even though they are all not used, which is the case here.

The init.d file you found is the oldest style of init script, "SysvInit".

The "service" command you found is used for both "SysVinit" and "Upstart" init scripts, but on a systemd-based system, calls to use it effectively get redirected to systemd-equivalent commands, which is why modifying the "init.d" script had no effect.

The postgresql.service file you found is there you can manage a virtual "postgresql" service, which will start and stop all PostgreSQL services at the same time, without mentioning a particular version. You can see hints of what the file is for in the "@.service" file you found:


This seems like a poor use of a .service file. Using a .target unit is a more natural way to group together a collection of services. You can check out man systemd.directives to find the document entries for all these directives if you want to understand their details.

The [email protected] file is a "template" file, so that multiple instances of PostgreSQL can be run on the same server with different versions, but started and stopped in a consistent manner. This is the file to focus on. As a comment in the file suggests, you can use it to start a particular version of PostgreSQL, like:

 systemctl start [email protected]
 systemctl stop [email protected]
 systemctl restart [email protected]

Of course, you actually need to have the version of PostgreSQL installed that you are attempting to start or stop!

So, the PostgreSQL systemd setup allows you start or stop all PostgreSQL clusters at once, or stop and start a particular cluster.

For your use, focus on the systemd .service files and the systemctl service command. There's no need to use the init.d or service commands when systemd .service files are provided.

See Also: SysV, Upstart and systemd init script coexistence.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .