Postgresql – Ideal way to start ‘Database Server’ in PostgreSQL 11

postgresql

PostgreSQL version : 11.2
OS : RHEL 7.5

I am new to PostgreSQL.
I would like to know which is the ideal way to start 'Database server' . In Oracle world, we call this starting the instance.

Should I be using Option A or Option B ?

Option A. As root user , run

# systemctl start postgresql-11

Option B. As postgres user, run

$ postgres -D /var/lib/pgsql/11/data

NB: For Option B, PostgreSQL 11's official doc mentions a different directory (/usr/local/pgsql/data) as shown below . Maybe the doc not updated.

$ postgres -D /usr/local/pgsql/data

https://www.postgresql.org/docs/11/server-start.html

Best Answer

I would prefer option A.

Using systemctl ensures the service is properly (re)started when the computer is (re)started.

As far as the location of the data directory is concerned: the manual shows some defaults. The actual location of the data directory is essentially driven by the packager that built the RPM (or whatever package the OS uses) and the standards the distribution expects or uses. You could also put it under /databasedata/postgres/pg11/data if you want, or /very/important/data/postgres