Unable to start posgtresql, the reason isn't clear

93,299

Solution 1

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

Solution 2

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
Share:
93,299

Related videos on Youtube

Matudi
Author by

Matudi

Updated on September 18, 2022

Comments

  • Matudi
    Matudi over 1 year

    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?

    • Craig Ringer
      Craig Ringer almost 8 years
      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.
    • Jeff Schaller
      Jeff Schaller almost 8 years
      does this archlinux link get you any closer?
    • Matudi
      Matudi almost 8 years
      @CraigRinger, it doesn't exist.
  • Wedge Martin
    Wedge Martin over 6 years
    Depending on version, this may need to be initdb -D '/var/lib/pgsql/data'
  • Chalist
    Chalist over 4 years
    If you had a few databases, this will create fresh Postgresql server without old databases!
  • Akash Pagar
    Akash Pagar almost 4 years
    step4: how to start the service in root?
  • Akash Pagar
    Akash Pagar almost 4 years
    yes. it worked. by logged in using sudo -i -u postgres start service using pg_ctl -D /var/lib/postgres/data -l logfile start
  • AlxVallejo
    AlxVallejo over 2 years
    postgresql-setup: command not found
  • AlxVallejo
    AlxVallejo over 2 years
    -bash: initdb: command not found
  • MasterOfNone
    MasterOfNone about 2 years
    This worked for me in a current and up-to-date RHEL 8.5 server.