This is guide, howto install PostgreSQL 15/14/13/12 database server on Fedora 35/34/33, CentOS/Red Hat (RHEL)/Rocky Linux 8.5. This guide uses PostgreSQL own YUM repos, which are always up-to-date and stable releases are available instantly. You can use this guide to install any Postgresql versions, like 15, 14, 13, 12 etc.
Check video guide howto install PostgreSQL 14/13/12 on Fedora 35/34 using PostgreSQL’s own dnf repo:
Check video guide howto install PostgreSQL 14/13/12 on Rocky Linux 8.5 using PostgreSQL’s own dnf repo:
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 14 Database Server on Fedora 35/34/33, CentOS/Red Hat (RHEL)/Rocky Linux 8.5
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
Add exclude to /etc/yum.repos.d/fedora.repo file [fedora] section:
[fedora]
...
exclude=postgresql*
Add exclude to /etc/yum.repos.d/fedora-updates.repo file [updates] section:
[updates]
...
exclude=postgresql*
CentOS / Red Hat (RHEL) / Rocky Linux
Disable postgresql module:
dnf -qy module disable postgresql
1.3 Install PostgreSQL 14 Repository
Fedora 35/34/33
## Fedora 35/34/33 ##
dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/F-34-x86_64/pgdg-fedora-repo-latest.noarch.rpm
CentOS/RHEL/Rocky Linux 8
## CentOS/RHEL/Rocky Linux 8.5 - x86_64 - 64-bit ##
dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
1.4 Install PostgreSQL 14 using DNF/YUM
## Fedora 35/34/33 ##
dnf install -y postgresql14 postgresql14-server
## Centos/RHEL/Rocky Linux 8 ##
dnf install -y postgresql14 postgresql14-server
2. Configure PostgreSQL 14
2.1 Initialize Cluster with initdb Command
## Fedora 35/34/33 and CentOS/RHEL/Rocky 8.5 ##
/usr/pgsql-14/bin/postgresql-14-setup initdb
2.2 Set PostgreSQL Server to Listen Addresses and Set Port
Open /var/lib/pgsql/14/data/postgresql.conf file, and add/uncomment/modify following:
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 PostgreSQL /var/lib/pgsql/14/data/pg_hba.conf (host-based authentication) file:
# Local networks
host all all xx.xx.xx.xx/xx scram-sha-256
# Example
host all all 10.20.4.0/24 scram-sha-256
# Example 2
host test testuser 127.0.0.1/32 scram-sha-256
You can find more examples and full guide from PostgreSQL pg_hba.conf manual.
2.4 Start PostgreSQL Server and Autostart PostgreSQL on Boot
Fedora 35/34/33 and CentOS / Red Hat (RHEL) / Rocky Linux 8.5
## Start PostgreSQL 14 ##
systemctl start postgresql-14.service
## Start PostgreSQL 14 on every boot ##
systemctl enable postgresql-14.service
2.5 Create Test Database and Create New User
Change to postgres user
su - postgres
Create test database (as postgres user)
createdb test
Login test database (as postgres user)
psql test
Create New “testuser” Role with Superuser and Password
CREATE ROLE testuser WITH SUPERUSER LOGIN PASSWORD 'test';
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 35/34/33 and CentOS/Red Hat (RHEL)/Rocky Linux 8.5
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 PostgreSQL pg_hba.conf manual.
80 comments on “Install Postgresql 14 on Fedora 35/34/33, CentOS/RHEL/Rocky Linux 8.5”