PostgreSQL service start failed on CentOS 7 Installed PostgreSQL using:

sudo yum install postgresql-server postgresql-contrib


PostgreSQL version: 9.2.18

When start service:

sudo service postgresql start


Got error:

Redirecting to /bin/systemctl start  postgresql.service
Job for postgresql.service failed because the control process exited with error code. See "systemctl status postgresql.service" and "journalctl -xe" for details.


The journalctl -xe detail:

-- Unit postgresql.service has failed.
--
-- The result is failed.
 7月 19 04:17:04 node2 systemd[1]: Unit postgresql.service entered failed state.
 7月 19 04:17:04 node2 systemd[1]: postgresql.service failed.
 7月 19 04:17:04 node2 polkitd[19772]: Unregistered Authentication Agent for unix-process:27133:53830492 (system bus name :1.405, object path /org/freedesktop/PolicyKit1/AuthenticationA
 7月 19 04:19:33 node2 polkitd[19772]: Registered Authentication Agent for unix-process:27165:53845472 (system bus name :1.406 [/usr/bin/pkttyagent --notify-fd 5 --fallback], object pat
 7月 19 04:19:33 node2 systemd[1]: Starting PostgreSQL database server...
-- Subject: Unit postgresql.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit postgresql.service has begun starting up.
 7月 19 04:19:34 node2 pg_ctl[27187]: pg_ctl: could not start server
 7月 19 04:19:34 node2 pg_ctl[27187]: Examine the log output.
 7月 19 04:19:34 node2 systemd[1]: postgresql.service: control process exited, code=exited status=1
 7月 19 04:19:34 node2 systemd[1]: Failed to start PostgreSQL database server.
-- Subject: Unit postgresql.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit postgresql.service has failed.
--
-- The result is failed.
 7月 19 04:19:34 node2 systemd[1]: Unit postgresql.service entered failed state.
 7月 19 04:19:34 node2 systemd[1]: postgresql.service failed.
 7月 19 04:19:34 node2 polkitd[19772]: Unregistered Authentication Agent for unix-process:27165:53845472 (system bus name :1.406, object path /org/freedesktop/PolicyKit1/AuthenticationA
lines 2850-2910/2910 (END)


Run systemctl status PostgreSQL.service, got this information:

● postgresql.service - PostgreSQL database server
   Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Wed 2017-07-19 04:30:26 EDT; 42min ago
  Process: 27285 ExecStart=/usr/bin/pg_ctl start -D ${PGDATA} -s -o -p ${PGPORT} -w -t 300 (code=exited, status=1/FAILURE)
  Process: 27280 ExecStartPre=/usr/bin/postgresql-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
 Main PID: 26640 (code=exited, status=0/SUCCESS)
You have 3 steps before being abble to connect to a PostgreSQL Database:


Install PostgreSQL
Create the data cluster ($PGDATA)
Start the server


You already installed PostgreSQL, you need now to create the cluster. The initdb tool is what you need.

You will find documentation here.

It might be confusing because when you're under a debian based distros, apt and perl wrappers do every steps for you.