How to do it…

On each platform there is a specific command to start the server.

If you are using a modern Linux distribution, you are probably using systemd. In this case, PostgreSQL can be started with the following command:

systemctl start SERVICEUNIT

This must be issued with OS superuser privileges, after replacing SERVICEUNIT with the appropriate systemd service unit name.

The systemctl command must always be issued with operating system superuser privileges. Remember, throughout this book we will always prepend systemctl invocations with sudo.

There are a couple of things to keep in mind:

As mentioned previously, the service unit name depends on what distribution you are using. Precisely:

postgresql@RELEASE-CLUSTERNAME 
sudo systemctl start postgresql
sudo systemctl start postgresql@10-main
sudo systemctl start postgresql
sudo systemctl start postgresql-10

As noted previously, systemctl is part of systemd, which is only available on Linux and is normally used by most of the recent distributions.
The following commands can be used where systemd is not available:

pg_ctlcluster 10 main start
This command will also work when systemd is available; it will just redirect the start request to systemctl and print a message on the screen, so that the next time you will remember to use systemctl directly.
service postgresql start
net start postgres
pg_ctl -D $PGDATA start

where PGDATA is set to the data directory path.

In fact, this command works on most distributions, including macOS, Solaris, and FreeBSD, although: