postgresql-logo

This is guide, howto install PostgreSQL 18.1 / 17.7 / 16.11 database server on Fedora 43/42 and RHEL/CentOS/Rocky/Alma 10/9/8. The guide shows how to install PostgreSQL 18.1 / 17.7 / 16.11 from the PostgreSQL Global Development Group (PGDG) repositories and also how to install the distro-provided package where appropriate. Use the detection commands in the installation section to list available majors in your enabled repositories.

Check video guide howto install PostgreSQL on Fedora / Rocky (example older recordings):

Support inttf:

Buy Me a Coffee:

Check video guide howto install PostgreSQL 14/13/12 on Rocky Linux 8.5 using PostgreSQL’s own dnf repo:

Support inttf:

Buy Me a Coffee:

Note: If you are upgrading PostgresSQL (from earlier version), then make sure that you backup (dump and copy) your database and configs.

1. Install PostgreSQL 18.1 / 17.7 / 16.11 on Fedora 43/42 and RHEL/CentOS/Rocky/Alma 10/9/8

1.1 Change root user

su -
## OR ##
sudo -i

1.2 Exclude Fedora, CentOS, Red Hat (RHEL) and Rocky Linux own PostgreSQL Packages

This is important step to get PostgreSQL repository working properly. Exclude PostgreSQL packages from the repository of the distro.

Fedora 43/42

If you plan to use the PGDG repository to install a newer major PostgreSQL release, exclude the distro PostgreSQL packages so they don’t conflict — use dnf config-manager (safer and script-friendly) instead of editing repo files by hand.

# install helper if needed
dnf install -y dnf-plugins-core

# set excludes persistently (idempotent)
dnf config-manager --save --setopt=fedora.exclude=postgresql*
dnf config-manager --save --setopt=updates.exclude=postgresql*

# verify
dnf repoinfo fedora | grep -i exclude || true
dnf repoinfo updates | grep -i exclude || true

To revert:

dnf config-manager --save --setopt=fedora.exclude=
dnf config-manager --save --setopt=updates.exclude=

CentOS / Red Hat (RHEL) / Rocky Linux

Disable or avoid distro PostgreSQL packages (recommended):

If you plan to install PostgreSQL from the PGDG repository you must ensure distro PostgreSQL packages or module streams do not interfere. The correct steps depend on the OS major (EL10 vs EL9/EL8).

# detect OS and DNF version (helpful to choose the right method)
. /etc/os-release && echo "$ID $VERSION_ID"
dnf --version | head -n1

EL 10 / Rocky/Alma 10 (DNF5; modularity removed/deprecated)

DNF5 removed modularity; the dnf module subcommand is not available on EL10 and attempts to use it will fail. For EL10 use the following approach instead:

# remove any installed distro packages (backup DB and configs first)
dnf remove -y postgresql postgresql-server postgresql-libs || true

# persistently exclude distro packages from baseos/appstream
dnf config-manager --save --setopt=baseos.exclude=postgresql* --setopt=appstream.exclude=postgresql*

EL 8 / EL 9 (modularity present)

Use module commands to list, reset and disable streams:

# check available/active streams
dnf module list postgresql

# reset any enabled streams (safe)
dnf -qy module reset postgresql

# disable the module (disable all streams)
dnf -qy module disable postgresql --all

If you see errors that dnf module is not available, you’re likely on EL10 — follow the EL10 steps above. After this, continue with installing the PGDG repository and packages.

(These commands assume you are running as root.)

1.3 Install PGDG (PostgreSQL) repository

PGDG provides repositories for multiple major releases. Install the repo package that matches your distribution and major release.

Fedora 43 / Fedora 42

# Fedora 43 (PGDG repo)
dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/F-43-x86_64/pgdg-fedora-repo-latest.noarch.rpm

# Fedora 42 (PGDG repo)
dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/F-42-x86_64/pgdg-fedora-repo-latest.noarch.rpm

RHEL/CentOS/Rocky/Alma 10

# EL-10 (PGDG repo)
dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-10-x86_64/pgdg-redhat-repo-latest.noarch.rpm

RHEL/CentOS/Rocky/Alma 9

# EL-9 (PGDG repo)
dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm

RHEL/CentOS/Rocky/Alma 8

# EL-8 (PGDG repo) — kept for legacy systems
dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm

After installing the repo package, run dnf makecache to refresh metadata.

1.4 Install PostgreSQL (examples)

The examples below show how to install PostgreSQL 18.1 / 17.7 / 16.11 from PGDG. You can still list available majors if you wish to install a different supported major.

# Optional: list available PostgreSQL majors from enabled repos
dnf --showduplicates list 'postgresql*' | egrep "^postgresql[0-9]"

# Install PostgreSQL 18.1 (PGDG)
dnf install -y postgresql18 postgresql18-server

# Install PostgreSQL 17.7 (PGDG)
dnf install -y postgresql17 postgresql17-server

# Install PostgreSQL 16.11 (PGDG)
dnf install -y postgresql16 postgresql16-server

# Initialize and enable the service (see section 2 for initdb examples)
# PostgreSQL 18
/usr/pgsql-18/bin/postgresql-18-setup initdb
systemctl enable --now postgresql-18.service

# PostgreSQL 17
/usr/pgsql-17/bin/postgresql-17-setup initdb
systemctl enable --now postgresql-17.service

# PostgreSQL 16
/usr/pgsql-16/bin/postgresql-16-setup initdb
systemctl enable --now postgresql-16.service

# Alternatively, install distro-default package (module-managed):
dnf install -y postgresql-server

2. Configure PostgreSQL

2.1 Initialize the database cluster

Run the matching setup tool for the version you installed; distro helpers are available as a fallback.

# PGDG (PostgreSQL 18.1 / 17.7 / 16.11)
/usr/pgsql-18/bin/postgresql-18-setup initdb

# PGDG (PostgreSQL 17.7)
/usr/pgsql-17/bin/postgresql-17-setup initdb

# PGDG (PostgreSQL 16.11)
/usr/pgsql-16/bin/postgresql-16-setup initdb

# Or use the distro helper (if you installed the distro package)
postgresql-setup --initdb

2.2 Set PostgreSQL Server to Listen Addresses and Port

Open the postgresql.conf in your cluster data directory (example paths shown below for PostgreSQL 18.1 / 17.7 / 16.11):

# PGDG example path (PostgreSQL 18.1)
/var/lib/pgsql/18/data/postgresql.conf

# PGDG example path (PostgreSQL 17.7)
/var/lib/pgsql/17/data/postgresql.conf

# PGDG example path (PostgreSQL 16.11)
/var/lib/pgsql/16/data/postgresql.conf

# distro-default example path (may vary)
/var/lib/pgsql/data/postgresql.conf

Then add/uncomment/modify:

listen_addresses = '*'
port = 5432

If you want just localhost setup, then use following:

listen_addresses = 'localhost'
port = 5432

Or if you want use specific ip, then use following:

listen_addresses = '192.1.2.33'
port = 5432

2.3 Set PostgreSQL Permissions

Modify your cluster’s pg_hba.conf (host-based authentication) file; example paths shown below for PostgreSQL 18.1 / 17.7 / 16.11:

# PGDG example path (PostgreSQL 18.1)
/var/lib/pgsql/18/data/pg_hba.conf

# PGDG example path (PostgreSQL 17.7)
/var/lib/pgsql/17/data/pg_hba.conf

# PGDG example path (PostgreSQL 16.11)
/var/lib/pgsql/16/data/pg_hba.conf

# Example entries
host	all	all		        xx.xx.xx.xx/xx	scram-sha-256
host	all	all		10.20.4.0/24	scram-sha-256
host	test	testuser	127.0.0.1/32	scram-sha-256

See the PostgreSQL documentation for version 18 (or the corresponding docs for 17/16): https://www.postgresql.org/docs/18/auth-pg-hba-conf/

2.4 Start PostgreSQL Server and Autostart PostgreSQL on Boot

2.4.1 Fedora 43/42 and RHEL/CentOS/Rocky/Alma 10/9/8

# Start PostgreSQL 18.1 (PGDG)
systemctl start postgresql-18.service
# Start PostgreSQL 17.7 (PGDG)
systemctl start postgresql-17.service
# Start PostgreSQL 16.11 (PGDG)
systemctl start postgresql-16.service

# Enable PostgreSQL 18.1 to start on boot
systemctl enable postgresql-18.service
# Enable PostgreSQL 17.7 to start on boot
systemctl enable postgresql-17.service
# Enable PostgreSQL 16.11 to start on boot
systemctl enable postgresql-16.service

# Distro-default package fallback (module-managed):
systemctl start postgresql.service
systemctl enable postgresql.service

2.5 Create Test Database and Create New User

2.5.1 Change to postgres user

su - postgres

2.5.2 Create test database (as postgres user)

createdb test

2.5.3 Login test database (as postgres user)

psql test

2.5.4 Create New “testuser” Role with Superuser and Password

CREATE ROLE testuser WITH SUPERUSER LOGIN PASSWORD 'test';

2.5.5 Test Connection from localhost (as Normal Linux User)

psql -h localhost -U testuser test

3. Enable Remote Connections to PostgreSQL Server –> Open PostgreSQL Port (5432) on Iptables Firewall on Fedora 43/42 and Red Hat (RHEL)/CentOS/Rocky Linux/Alma Linux 10/9/8

3.1 List Your Active Firewalld Zones

firewall-cmd --get-active-zones

Example output:

public
  interfaces: wlp1s0

3.2 Add New Rule to Firewalld

You might have active zone like public, FedoraWorkstation, FedoraServer.

firewall-cmd --permanent --zone=public --add-service=postgresql

## OR ##

firewall-cmd --permanent --zone=public --add-port=5432/tcp

3.3 Restart firewalld.service

systemctl restart firewalld.service

4. Test remote connection

psql -h dbserver_name_or_ip_address -U testuser -W test

Note: You have to allow remote connections on pg_hba.conf, check step 2.3 and the PostgreSQL pg_hba.conf manual.