How to install PostgreSQL 13 on Fedora

In this article, we will see how to install PostgreSQL 13 on Fedora step by step.

What is PostgreSQL?

PostgreSQL is a powerful, open source object-relational database system with over 30 years of active development that has earned it a strong reputation for reliability, feature robustness, and performance.

Steps to install PostgreSQL 13 on Fedora:

1. Update the packages on Fedora.

sudo dnf update -y

How to install PostgreSQL 13 on Fedora

2. Add the PostgreSQL Yum Repository

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

3. Install PostgreSQL 13 using below command.

sudo dnf install -y postgresql13-server

[r2schools@localhost ~]$ sudo dnf install -y postgresql13-server PostgreSQL common RPMs for Fedora 33 - x86_64   126 kB/s | 258 kB     00:02     PostgreSQL 13 for Fedora 33 - x86_64             85 kB/s | 163 kB     00:01     PostgreSQL 12 for Fedora 33 - x86_64            101 kB/s | 191 kB     00:01     PostgreSQL 11 for Fedora 33 - x86_64             94 kB/s | 192 kB     00:02     PostgreSQL 10 for Fedora 33 - x86_64             66 kB/s | 128 kB     00:01     PostgreSQL 9.6 for Fedora 33 - x86_64            49 kB/s |  88 kB     00:01     PostgreSQL 9.5 for Fedora 33 - x86_64           347  B/s | 506  B     00:01     Dependencies resolved. ================================================================================  Package                   Architecture Version              Repository    Size ================================================================================ Installing:  postgresql13-server       x86_64       13.1-1PGDG.f33       pgdg13       5.8 M Installing dependencies:  postgresql13              x86_64       13.1-1PGDG.f33       pgdg13       1.4 M  postgresql13-libs         x86_64       13.1-1PGDG.f33       pgdg13       789 k Transaction Summary ================================================================================ Install  3 Packages Total download size: 7.9 M Installed size: 32 M Downloading Packages: (1/3): postgresql13-libs-13.1-1PGDG.f33.x86_64. 160 kB/s | 789 kB     00:04     (2/3): postgresql13-13.1-1PGDG.f33.x86_64.rpm   273 kB/s | 1.4 MB     00:05     (3/3): postgresql13-server-13.1-1PGDG.f33.x86_6 464 kB/s | 5.8 MB     00:12     -------------------------------------------------------------------------------- Total                                           632 kB/s | 7.9 MB     00:12     warning: /var/cache/dnf/pgdg13-5b69a3a370fb59a8/packages/postgresql13-13.1-1PGDG.f33.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY PostgreSQL 13 for Fedora 33 - x86_64            1.4 MB/s | 1.7 kB     00:00     Importing GPG key 0x442DF0F8:  Userid     : "PostgreSQL RPM Building Project "  Fingerprint: 68C9 E2B9 1A37 D136 FE74 D176 1F16 D2E1 442D F0F8  From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG Key imported successfully Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction   Preparing        :                                                        1/1   Installing       : postgresql13-libs-13.1-1PGDG.f33.x86_64                1/3   Running scriptlet: postgresql13-libs-13.1-1PGDG.f33.x86_64                1/3   Installing       : postgresql13-13.1-1PGDG.f33.x86_64                     2/3   Running scriptlet: postgresql13-13.1-1PGDG.f33.x86_64                     2/3   Running scriptlet: postgresql13-server-13.1-1PGDG.f33.x86_64              3/3   Installing       : postgresql13-server-13.1-1PGDG.f33.x86_64              3/3   Running scriptlet: postgresql13-server-13.1-1PGDG.f33.x86_64              3/3   Verifying        : postgresql13-13.1-1PGDG.f33.x86_64                     1/3   Verifying        : postgresql13-libs-13.1-1PGDG.f33.x86_64                2/3   Verifying        : postgresql13-server-13.1-1PGDG.f33.x86_64              3/3 Installed:   postgresql13-13.1-1PGDG.f33.x86_64                                               postgresql13-libs-13.1-1PGDG.f33.x86_64                                         postgresql13-server-13.1-1PGDG.f33.x86_64                                     Complete!

4. Initialize the database

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

5. Enable automatic start. By enabling automatic start, PostgreSQL service starts whenever Fedora system starts which means no need to start PostgreSQL when Fedora system starts.

sudo systemctl enable postgresql-13

6. Lets start PostgreSQL 13 on Fedora.

sudo systemctl start postgresql-13

7. Lets verify the PostgreSQL status.

sudo systemctl status postgresql-13

8. Now connect to postgreSQL

sudo su - postgres psql

9. Change the password for the PostgreSQL superuser ‘postgres’.

alter user postgres with password 'admin@123';

10. Create user and database.

create user james with password 'james@123'; create database r2schools;

11. Enable remote Access to PostgreSQL

Edit the file /var/lib/pgsql/13/data/postgresql.conf and set Listen address to your server IP address or “*” for all interfaces.

12. Also set PostgreSQL to accept remote connections

# Accept connections from anywhere sudo vi /var/lib/pgsql/11/data/pg_hba.conf host all all 0.0.0.0/0 md5

13. Now. connect with newly created user.

psql -U james -h localhost -d postgres

So in this article, we have shown how to install PostgreSQL 13 on Fedora step by step and performed post installation steps.