5

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?

  • 2
    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. – Craig Ringer Jul 10 '16 at 12:22
  • does this archlinux link get you any closer? – Jeff Schaller Jul 10 '16 at 14:38
  • @CraigRinger, it doesn't exist. – Matudi Jul 10 '16 at 17:59
8

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

  • Depending on version, this may need to be initdb -D '/var/lib/pgsql/data' – Wedge Martin Aug 25 '17 at 16:44
0

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.

0

After setting a password for the postgres user:

$ sudo passwd postgres 

run the fallowing command:

$ su - postgres -c "initdb --locale en_US.UTF-8 -D '/var/lib/postgres/data'"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.