Postgresql service failed because the control process exited with an error code

  • Post last modified:April 27, 2021
  • Reading time:2 mins read

PostgreSQL is a free and open-source, community-driven, standard-compliant, and most popular object-relational database management system. It is used by popular IT companies like Uber, Netflix, Instagram, Spotify, etc.

Getting error while starting PostgreSQL daemon
Getting error while starting PostgreSQL daemon

Recently I installed PostgreSQL and getting an error while running daemon. This is mainly because PostgreSQL not getting sufficient permission to create the folder required to store database information.

Step 1:

First, we have to log in as a PostgreSQL user by executing the following command and ensuring that your Linux user account has SUDO privileges before executing it.

$ sudo -iu postgres

Now you will enter into PostgreSQL terminal.

Step 2:

In my case, the error has occurred because I do not initialize the database cluster. Due to this, PostgreSQL not functioning properly, and I am getting an error while running PostgreSQL.

To initialize the database cluster, type the following command into your PostgreSQL terminal.

[postgres]$ initdb -D /var/lib/postgres/data

-D: is used to define where the database cluster must be stored. I am using the default PostgreSQL location. If you wish to use a different location, change it with a different path.

Step 3:

It is not a mandatory but important step. When you are done with step 2, it will, by default, create a database cluster for locale and encoding from your current environment using $LANG path value.

Depending upon your system setting and use cases, this might not be what you want. I suggest you override the defaults using the below command into the PostgreSQL terminal.

[postgres]$ initdb --locale=en_US.UTF-8 -E UTF8 -D /var/lib/postgres/data

Now try to start the PostgreSQL daemon again to check it started or not. If you are still facing the same issue, then let me know in the comment section.

Like what you read? Please share it with others.
  • 1
    Share
guest
0 Comments
Inline Feedbacks
View all comments