A Complete Tutorial to Install PostgreSQL Server on Fedora 31

PostgreSQL has been a crucial part of my work. I have been using this software for the last few years and personally I am pretty satisfied. In this article, I am going to share with you how to install PostgreSQL Server on Fedora 31. Fedora 31 is a great Linux distribution. It is very fast, lightweight and easy to use. I will try to give a complete step by step how to get PostgreSQL up and running on Fedora 31.

Steps to Install PostgreSQL Server on Fedora 31

Step 1. Update Fedora

The first thing to do is to update the system. Use the following command to update Fedora 31.

sudo dnf update -y

In some cases, you may need to reboot your system to complete the update process.

sudo reboot

Step 2. Configure the PostgreSQL Repository on Fedora 31

Now we are going to add the PostgreSQL repository for Fedora 31. Paste the following command in Terminal

sudo dnf install https://download.postgresql.org/pub/repos/yum/reporpms/F-31-x86_64/pgdg-fedora-repo-latest.noarch.rpm

Press y to confirm the installation.

So at this point, we have successfully added the repository for PostgreSQL on Fedora 31. Now continue to the next step

Step 3. Install PostgreSQL Server

Now we are ready to install the PostgreSQL Server in our system. Use the following command:

sudo dnf install postgresql12 postgresql12-server

The latest version of PostgreSQL 12 is available when this article is written.

Again, you will need to confirm the installation. Wait until the installation process completes.

Step 4. Initialize PostgreSQL Database

Now we continue the process of the database initialization and automatic start service. First, let’s initialize the database using this command.

sudo /usr/pgsql-12/bin/postgresql-12-setup initdb

Make sure you see the following result

[dhani@localhost bin]$ sudo /usr/pgsql-12/bin/postgresql-12-setup initdb
[sudo] password for dhani: 
Initializing database … OK

Now start the PostgreSQL Service and enable the automatic start during boot

sudo systemctl start postgresql-12
sudo systemctl enable postgresql-12


[dhani@localhost bin]$ sudo systemctl enable postgresql-12
 Created symlink /etc/systemd/system/multi-user.target.wants/postgresql-12.service → /usr/lib/systemd/system/postgresql-12.service.

Check the service status

sudo systemctl status postgresql-12


Configure PostgreSQL through firewall

If you have the firewall enabled, you must allow PostgreSQL service through the firewall.

sudo firewall-cmd --add-service=postgresql --permanent
sudo firewall-cmd --reload

Step 5. Enable Remote Access to PostgreSQL Server

Well, I am pretty sure that you want your server is accessible from the network. This section will guide you how to enable remote access to PostgreSQL Server.

First, we need to edit the configuration file called postgresql.conf. This file is located under /var/lib/pgsql/12/data/ directory.

sudo nano /var/lib/pgsql/12/data/postgresql.conf

Now, find the following section in the configuration file:

#listen_addresses = 'localhost' 

And then, change it into this one

listen_addresses = '*' 

Then, we need to edit the pg_hba.conf file.

sudo nano /var/lib/pgsql/12/data/pg_hba.conf. Add the following line to the end of the file.

host    all             all             md5

The line above will allow PostgreSQL Server to be accessed from anywhere, even from the internet.

Finally, restart the service

sudo systemctl restart postgresql-12

Step 6. Change the PostgreSQL admin password

We need to switch to postgres user first

sudo su – postgres

And then execute this command

psql -c "alter user postgres with password 'StrongPassword'"

Change the StrongPassword with your new password and you are set.


Leave a Reply

Your email address will not be published. Required fields are marked *