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.
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.
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.
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.
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.
Innovative tech mind with 10 years of experience working as a computer programmer, web developer, and security researcher. Capable of working with a variety of technology and software solutions, and managing databases.