Without a doubt, PostgreSQL is the world’s most advanced open source database system. And with the release of PostgreSQL 13 there are significant improvements to the indexing and lookup system that benefit large databases, and faster response times for queries that use aggregates or partitions. In this guide we will help you install PostgreSQL 13 on Rocky Linux 8 | AlmaLinux 8.

By installing and running PostgreSQL 13 you get better data management experience for your workloads, both big and small. Additionally, you get security enhancements, optimizations for daily administration and more conveniences for application developers and DBAs.

PostgreSQL is a relational database management system known for its robustness and reliability. With over 25 years of open source development from a global developer community you’re assured of stability and bug fixes in your database lifecycle. In the next sections we describe how you can install PostgreSQL 13 on Rocky Linux 8 | AlmaLinux 8.

Step 1: Update System

Update your Rocky Linux 8 | AlmaLinux 8 system before you start the installation of PostgreSQL 13 on Rocky Linux 8 | AlmaLinux 8:

sudo dnf -y update

Watch the upgrade process and reboot if required. Also confirm the release if 8.x.

$ cat /etc/os-release
VERSION="8.3 (Purple Manul)"
ID_LIKE="rhel centos fedora"
PRETTY_NAME="AlmaLinux 8.3 (Purple Manul)"


Step 2: Add PostgreSQL Repository

The AppStream modules have PostgreSQL server 9.6, 10 and 12.

$ dnf module list postgresql
Last metadata expiration check: 4:19:40 ago on Wed 05 May 2021 03:23:56 PM EAT.
AlmaLinux 8 - AppStream
Name                              Stream                        Profiles                                 Summary
postgresql                        9.6                           client, server [d]                       PostgreSQL server and client module
postgresql                        10 [d]                        client, server [d]                       PostgreSQL server and client module
postgresql                        12                            client, server [d]                       PostgreSQL server and client module

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

To install PostgreSQL 13 on Rocky Linux 8 | AlmaLinux 8 we’ll need to add the official repositories:

sudo dnf -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm

Installation output:

pgdg-redhat-repo-latest.noarch.rpm                                                                                                9.7 kB/s |  12 kB     00:01
Dependencies resolved.
 Package                                     Architecture                      Version                              Repository                               Size
 pgdg-redhat-repo                            noarch                            42.0-17                              @commandline                             12 k

Transaction Summary
Install  1 Package

Total size: 12 k
Installed size: 11 k
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                          1/1
  Installing       : pgdg-redhat-repo-42.0-17.noarch                                                                                                          1/1
  Verifying        : pgdg-redhat-repo-42.0-17.noarch                                                                                                          1/1



Step 3: Install PostgreSQL 13 on Rocky Linux 8 | AlmaLinux 8

Once the repository has been added disable default PostgreSQL module

sudo dnf -qy module disable postgresql

Then install PostgreSQL 13 Server and Client on Rocky Linux 8 | AlmaLinux 8:

sudo dnf -y install postgresql13 postgresql13-server

Step 4: Initialize and start database service

After installation, you’ll need to initialize database instance before starting the service.

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

This will generate initial data and main configuration file which is written to: /var/lib/pgsql/13/data/postgresql.conf

The start and enable the PostgreSQL 13 database service.

sudo systemctl enable --now postgresql-13

Confirm PostgreSQL service is in running state:

$ systemctl status postgresql-13
● postgresql-13.service - PostgreSQL 13 database server
   Loaded: loaded (/usr/lib/systemd/system/postgresql-13.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2021-05-05 20:14:37 EAT; 2min 14s ago
     Docs: https://www.postgresql.org/docs/13/static/
  Process: 4651 ExecStartPre=/usr/pgsql-13/bin/postgresql-13-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
 Main PID: 4657 (postmaster)
    Tasks: 8 (limit: 23400)
   Memory: 18.2M
   CGroup: /system.slice/postgresql-13.service
           ├─4657 /usr/pgsql-13/bin/postmaster -D /var/lib/pgsql/13/data/
           ├─4658 postgres: logger
           ├─4660 postgres: checkpointer
           ├─4661 postgres: background writer
           ├─4662 postgres: walwriter
           ├─4663 postgres: autovacuum launcher
           ├─4664 postgres: stats collector
           └─4665 postgres: logical replication launcher

May 05 20:14:37 almalinux.techviewleo.com systemd[1]: Starting PostgreSQL 13 database server...
May 05 20:14:37 almalinux.techviewleo.com postmaster[4657]: 2021-05-05 20:14:37.360 EAT [4657] LOG:  redirecting log output to logging collector process
May 05 20:14:37 almalinux.techviewleo.com postmaster[4657]: 2021-05-05 20:14:37.360 EAT [4657] HINT:  Future log output will appear in directory "log".
May 05 20:14:37 almalinux.techviewleo.com systemd[1]: Started PostgreSQL 13 database server.

Set PostgreSQL admin user

$ sudo su - postgres 
~]$ psql -c "alter user postgres with password '[email protected]'" 

Step 5: Enable remote access (Optional)

If you have applications that will connect to the server over network you can edit the configuration and set Listen address to your server IP address or “*” for all interfaces.

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

Also set PostgreSQL to accept remote connections

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

# Accept from trusted subnet
host all all md5

After making the changes you need to restart database service:

sudo systemctl restart postgresql-13

Test database remote connections by passing the IP address of your server to psql command.

$ psql -U <dbuser> -h <serverip> -p 5432 <dbname>

Recommended books:

PostgreSQL: Up and Running: A Practical Guide to the Advanced Open Source Database

$18.35  in stock
as of June 18, 2021 5:22 pm

Mastering PostgreSQL 13: Build, administer, and maintain database applications efficiently with PostgreSQL 13, 4th Edition

$39.99  in stock
5 new from $39.99
4 used from $48.39
Free shipping
as of June 18, 2021 5:22 pm

Learn PostgreSQL: Build and manage high-performance database solutions using PostgreSQL 12 and 13

$31.99  in stock
as of June 18, 2021 5:22 pm

That’s it. You now have PostgreSQL 13 database server installed in your Rocky Linux 8 and AlmaLinux 8 system. Also check our guide on the installation of MariaDB database server:

Install MySQL 8 on Rocky Linux | AlmaLinux 8