I've installed postgresql by pacman. Now I'm trying to run it:

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

And then:

    $ sudo systemctl status postgresql
    ● postgresql.service - PostgreSQL database server
       Loaded: loaded (/usr/lib/systemd/system/postgresql.service; disabled; vendor preset: disabled)
       Active: failed (Result: exit-code) since Sun 2016-07-10 15:30:47 UTC; 17s ago
      Process: 19468 ExecStartPre=/usr/bin/postgresql-check-db-dir ${PGROOT}/data (code=exited, status=1/FAILURE)

    Jul 10 15:30:47 my_comp systemd[1]: Starting PostgreSQL database server...
    Jul 10 15:30:47 my_comp systemd[1]: postgresql.service: Control process exited, code=exited status=1
    Jul 10 15:30:47 my_comp systemd[1]: Failed to start PostgreSQL database server.
    Jul 10 15:30:47 my_comp systemd[1]: postgresql.service: Unit entered failed state.
    Jul 10 15:30:47 my_comp systemd[1]: postgresql.service: Failed with result 'exit-code'.

What's wrong with it?

  • 3
    Take a look at PostgreSQL's log files to see. It's a pity that the systemd output doesn't point to them, or that PostgreSQL on this system isn't configured to output its logs to systemd. Jul 10, 2016 at 12:22
  • does this archlinux link get you any closer?
    – Jeff Schaller
    Jul 10, 2016 at 14:38
  • @CraigRinger, it doesn't exist.
    – Matudi
    Jul 10, 2016 at 17:59

4 Answers 4


Following step solved your problem

step 1: create the data directory (acordingly with the PGROOT variable set before in the config file)

sudo mkdir /var/lib/postgres/data

Step 2: set /var/lib/postgres/data ownership to user 'postgres'

chown postgres /var/lib/postgres/data

Step 3: As user 'postgres' start the database.

sudo -i -u postgres
initdb  -D '/var/lib/postgres/data'

Step 4: Start the service as root

  • 2
    Depending on version, this may need to be initdb -D '/var/lib/pgsql/data' Aug 25, 2017 at 16:44
  • If you had a few databases, this will create fresh Postgresql server without old databases!
    – Chalist
    Dec 13, 2019 at 3:40
  • step4: how to start the service in root? Jun 5, 2020 at 7:35
  • yes. it worked. by logged in using sudo -i -u postgres start service using pg_ctl -D /var/lib/postgres/data -l logfile start Jun 5, 2020 at 13:00
  • This does start the database successfully, but when I run systemctl status postgresql.service, I still get the same error as provided by OP. What is happening here?
    – Jason Goal
    Jan 21, 2023 at 2:05

run these commands as said on /usr/share/doc/postgresql/README.rpm-dist as root user

postgresql-setup --initdb
systemctl restart postgresql.service
systemctl enable postgresql.service
  • postgresql-setup: command not found
    – AlxVallejo
    Sep 25, 2021 at 18:18
  • This worked for me in a current and up-to-date RHEL 8.5 server. Mar 10, 2022 at 16:09

The logging you shared includes this line:

/usr/bin/postgresql-check-db-dir ${PGROOT}/data (code=exited, status=1/FAILURE)

What is $PGROOT set to? Does $PGROOT/data exist? Does this directory have any files init? If not, you may need to run initdb on the directory.

To initialize, create an empty data directory as root, then use chown to assign ownership of that directory to the database user account, then su to become the database user to run initdb /path/to/data.


After setting a password for the postgres user:

$ sudo passwd postgres 

run the following command:

$ su - postgres -c "initdb --locale en_US.UTF-8 -D '/var/lib/postgres/data'"
  • -bash: initdb: command not found
    – AlxVallejo
    Sep 25, 2021 at 18:18

You must log in to answer this question.

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