Knowledgebase:
Postgress Database error: VPS/Dedicated Server
Posted by Ryan Mendonca on 30 September 2019 05:22:49 PM

In our VPS/Dedicated Server, the client has the option of installing PostgresSQL as a Database. 

However, at times we might encounter an error with PostgresSQL as mentioned below:

---------
$ 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.
---------

Also on restarting the service, you may encounter the error.

---------
$ 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'.
---------


The logging has reference to the error code:
---------
/usr/bin/postgresql-check-db-dir ${PGROOT}/data (code=exited, status=1/FAILURE)
---------

You need to follow the steps mentioned below:

Step 1: Create the data directory (accordingly 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.

(0 vote(s))
Helpful
Not helpful

Comments (0)