Install PostgreSQL 12 on Fedora 36/35/34/33/32/31

Posted on 38 views

This guide will discuss the installation of PostgreSQL 12 on Fedora 36/35/34/33/32/31. PostgreSQL is an open source database server created to be reliable, robust, and for performance focused deployments. The PostgreSQL 12 was released for general use on 3rd October 2019 with many new features.

Check available guides if you’re using a different flavor of Linux:

Let’s get started with the install of PostgreSQL 12 on Fedora 36/35/34/33/32/31.

Step 1: Update Fedora System

Ensure system packages are up to date:

sudo dnf install -y vim bash-completion wget
sudo dnf update -y

Since you may have Kernel updates, it is recommended to reboot your system after an upgrade:

sudo reboot

Step 2: Add the PostgreSQL Yum Repository to Fedora

Add PostgreSQL Yum Repository to your Fedora system by running the below command:

Fedora 36:

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

Fedora 35:

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

Fedora 34:

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

Fedora 33:

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

Fedora 32:

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

Fedora 31:

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

Fedora 30:

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

When prompted to confirm installation, press the key.

Last metadata expiration check: 0:01:25 ago on Sat 12 Oct 2019 06:52:54 AM UTC.
pgdg-fedora-repo-latest.noarch.rpm                                                                                  21 kB/s | 9.7 kB     00:00    
Dependencies resolved.
===================================================================================================================================================
 Package                                  Architecture                   Version                        Repository                            Size
===================================================================================================================================================
Installing:
 pgdg-fedora-repo                         noarch                         42.0-5                         @commandline                         9.7 k

Transaction Summary
===================================================================================================================================================
Install  1 Package

Total size: 9.7 k
Installed size: 9.7 k
Is this ok [y/N]: y
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                           1/1 
  Installing       : pgdg-fedora-repo-42.0-21.noarch                                                                                            1/1 
  Verifying        : pgdg-fedora-repo-42.0-21.noarch                                                                                            1/1 

Installed:
  pgdg-fedora-repo-42.0-5.noarch                                                                                                                   

Complete!

Step 3: Install PostgreSQL 12 on Fedora 36/35/34/33/32/31

After the PostgreSQL Repository is added to Fedora system, install PostgreSQL 12 Server / Client packages:

sudo dnf install postgresql12-server postgresql12

Agree to the installation.

Last metadata expiration check: 0:01:17 ago on Sat 12 Oct 2019 07:00:29 AM UTC.
Dependencies resolved.
===================================================================================================================================================
 Package                                   Architecture                 Version                                 Repository                    Size
===================================================================================================================================================
Installing:
 postgresql12-server                       x86_64                       12.0-1PGDG.f30                          pgdg12                       5.1 M
Installing dependencies:
 postgresql12                              x86_64                       12.0-1PGDG.f30                          pgdg12                       1.5 M
 postgresql12-libs                         x86_64                       12.0-1PGDG.f30                          pgdg12                       393 k

Transaction Summary
===================================================================================================================================================
Install  3 Packages

Total download size: 7.0 M
Installed size: 32 M
Is this ok [y/N]: y

Step 4: Initialize the database and enable automatic start

Now that the database packages have been installed, Initialize the database by running the following command

$ sudo /usr/pgsql-12/bin/postgresql-12-setup initdb
Initializing database ... OK

Then start and enable the service to start on boot

sudo systemctl enable --now postgresql-12

Confirm service status.

$ systemctl status postgresql-12
 postgresql-12.service - PostgreSQL 12 database server
     Loaded: loaded (/usr/lib/systemd/system/postgresql-12.service; enabled; vendor preset: disabled)
     Active: active (running) since Wed 2022-05-18 16:25:08 EAT; 6s ago
       Docs: https://www.postgresql.org/docs/12/static/
    Process: 6062 ExecStartPre=/usr/pgsql-12/bin/postgresql-12-check-db-dir $PGDATA (code=exited, status=0/SUCCESS)
   Main PID: 6067 (postmaster)
      Tasks: 8 (limit: 4671)
     Memory: 16.9M
        CPU: 39ms
     CGroup: /system.slice/postgresql-12.service
             ├─6067 /usr/pgsql-12/bin/postmaster -D /var/lib/pgsql/12/data/
             ├─6068 "postgres: logger   "
             ├─6070 "postgres: checkpointer   "
             ├─6071 "postgres: background writer   "
             ├─6072 "postgres: walwriter   "
             ├─6073 "postgres: autovacuum launcher   "
             ├─6074 "postgres: stats collector   "
             └─6075 "postgres: logical replication launcher   "

May 18 16:25:08 fedora systemd[1]: Starting postgresql-12.service - PostgreSQL 12 database server...
May 18 16:25:08 fedora postmaster[6067]: 2022-05-18 16:25:08.416 EAT [6067] LOG:  starting PostgreSQL 12.11 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 12.0.1 20220413 (Red Hat 12.0.1-0), 64-bit
May 18 16:25:08 fedora postmaster[6067]: 2022-05-18 16:25:08.417 EAT [6067] LOG:  listening on IPv6 address "::1", port 5432
May 18 16:25:08 fedora postmaster[6067]: 2022-05-18 16:25:08.417 EAT [6067] LOG:  listening on IPv4 address "127.0.0.1", port 5432
May 18 16:25:08 fedora postmaster[6067]: 2022-05-18 16:25:08.418 EAT [6067] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
May 18 16:25:08 fedora postmaster[6067]: 2022-05-18 16:25:08.419 EAT [6067] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
May 18 16:25:08 fedora postmaster[6067]: 2022-05-18 16:25:08.428 EAT [6067] LOG:  redirecting log output to logging collector process
May 18 16:25:08 fedora postmaster[6067]: 2022-05-18 16:25:08.428 EAT [6067] HINT:  Future log output will appear in directory "log".
May 18 16:25:08 fedora systemd[1]: Started postgresql-12.service - PostgreSQL 12 database server.

If you have a running Firewall service and remote clients should connect to your database server, allow PostgreSQL service.

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

Step 5: Enable remote Access to PostgreSQL (Optional)

If you have Applications connecting to the database server over the network, edit the file /var/lib/pgsql/12/data/postgresql.conf and set Listen address to your server IP address or “*” for all interfaces.

$ sudo vim /var/lib/pgsql/12/data/postgresql.conf 
listen_addresses = '*'

Also set PostgreSQL to accept remote connections from allowed hosts.

$ sudo vim /var/lib/pgsql/12/data/pg_hba.conf
# Accept from anywhere
host all all 0.0.0.0/0 md5

# Accept from trusted subnet
host all all 10.10.10.0/24 md5

Restart PostgreSQL 12 service after making the change.

sudo systemctl restart postgresql-12

Step 6: Set PostgreSQL admin user’s password

Set PostgreSQL admin user password.

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

Where StrongPassword is the new password for postgres user.

Step 7: Install pgAdmin 4 Web Management

If you need an easy way for managing PostgreSQL database server (Similar to phpMyAdmin for MySQL), consider installing pgAdmin4.

Enjoy running PostgreSQL 12 on Fedora Linux.

coffee

Gravatar Image
A systems engineer with excellent skills in systems administration, cloud computing, systems deployment, virtualization, containers, and a certified ethical hacker.