This guide is for installation of PostgreSQL 11 on Fedora 31/30/29. PostgreSQL is a powerful open source relational database system with a strong reputation for reliability, feature robustness, and performance.

Key PostgreSQL 11 Enhancements:

  • Improvements to partitioning functionality
  • SQL stored procedures that support embedded transactions
  • Improvements to parallelism
  • Window functions now support all framing options shown in the SQL:2011 standard
  • Optional Just-in-Time (JIT) compilation for some SQL code, speeding evaluation of expressions
  • Performance improvements, including the ability to avoid a table rewrite for ALTER TABLE … ADD COLUMN with a non-null column default
  • Covering indexes can now be created, using the INCLUDE clause of CREATE INDEX

Read more about PostgreSQL 11 new features on the Release page. Use the steps below to install PostgreSQL 11 on your Fedora 31/30/29 system. For those new to Fedora, we have an installation guide:

How To Install Fedora – Step by Step With Screenshots

The default version available on Fedora Repository and Modular Repository is 10.x. Check our guide to understand How to use Fedora Modular Repository

For CentOS 7, use: How to install PostgreSQL 11 on CentOS 7

Step 1: Update System

Ensure system packages are up to date:

sudo dnf install -y bash-completion vim
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

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

Fedora 31:

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

Fedora 30:

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

For Fedora 29:

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

When prompted to confirm installation, press the key.

...................................
Dependencies resolved.
================================================================================
 Package                 Architecture  Version        Repository           Size
================================================================================
Installing:
 pgdg-fedora-repo        noarch        42.0-4         @commandline        9.6 k

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

Total size: 9.6 k
Installed size: 9.1 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-4.noarch                         1/1 
  Verifying        : pgdg-fedora-repo-42.0-4.noarch                         1/1 

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

Complete!

Step 3: Install PostgreSQL Server and Client packages

After adding PostgreSQL Yum Repository, install PostgreSQL Server / Client packages:

$ sudo dnf install postgresql11-server postgresql11
PostgreSQL 11 30 - x86_64                                                                                                                                             22 kB/s | 138 kB     00:06    
PostgreSQL 10 30 - x86_64                                                                                                                                             18 kB/s | 130 kB     00:07    
PostgreSQL 9.6 30 - x86_64                                                                                                                                            16 kB/s | 128 kB     00:07    
PostgreSQL 9.5 30 - x86_64                                                                                                                                            20 kB/s | 120 kB     00:06    
PostgreSQL 9.4 30 - x86_64                                                                                                                                            16 kB/s | 111 kB     00:06    
Last metadata expiration check: 0:00:01 ago on Mon 06 May 2019 10:47:09 AM EAT.
Dependencies resolved.
=====================================================================================================================================================================================================
 Package                                                Architecture                              Version                                            Repository                                 Size
=====================================================================================================================================================================================================
Installing:
 postgresql11                                           x86_64                                    11.2-2PGDG.f30                                     pgdg11                                    1.7 M
 postgresql11-server                                    x86_64                                    11.2-2PGDG.f30                                     pgdg11                                    4.9 M
Installing dependencies:
 postgresql11-libs                                      x86_64                                    11.2-2PGDG.f30                                     pgdg11                                    375 k

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

Total download size: 6.9 M
Installed size: 32 M
Is this ok [y/N]: y
Downloading Packages:
(1/3): postgresql11-libs-11.2-2PGDG.f30.x86_64.rpm                                                                                                                    75 kB/s | 375 kB     00:05    
(2/3): postgresql11-11.2-2PGDG.f30.x86_64.rpm                                                                                                                        274 kB/s | 1.7 MB     00:06    
(3/3): postgresql11-server-11.2-2PGDG.f30.x86_64.rpm                                                                                                                 208 kB/s | 4.9 MB     00:23    
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                296 kB/s | 6.9 MB     00:23     
warning: /var/cache/dnf/pgdg11-cde8ad453ae6cd5b/packages/postgresql11-11.2-2PGDG.f30.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY
PostgreSQL 11 30 - x86_64                                                                                                                                            1.6 MB/s | 1.7 kB     00:00    
Importing GPG key 0x442DF0F8:
 Userid     : "PostgreSQL RPM Building Project <[email protected]>"
 Fingerprint: 68C9 E2B9 1A37 D136 FE74 D176 1F16 D2E1 442D F0F8
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
Is this ok [y/N]: y
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                                             1/1 
  Installing       : postgresql11-libs-11.2-2PGDG.f30.x86_64                                                                                                                                     1/3 
  Running scriptlet: postgresql11-libs-11.2-2PGDG.f30.x86_64                                                                                                                                     1/3 
  Installing       : postgresql11-11.2-2PGDG.f30.x86_64                                                                                                                                          2/3 
  Running scriptlet: postgresql11-11.2-2PGDG.f30.x86_64                                                                                                                                          2/3 
  Running scriptlet: postgresql11-server-11.2-2PGDG.f30.x86_64                                                                                                                                   3/3 
  Installing       : postgresql11-server-11.2-2PGDG.f30.x86_64                                                                                                                                   3/3 
  Running scriptlet: postgresql11-server-11.2-2PGDG.f30.x86_64                                                                                                                                   3/3 
  Verifying        : postgresql11-11.2-2PGDG.f30.x86_64                                                                                                                                          1/3 
  Verifying        : postgresql11-libs-11.2-2PGDG.f30.x86_64                                                                                                                                     2/3 
  Verifying        : postgresql11-server-11.2-2PGDG.f30.x86_64                                                                                                                                   3/3 

Installed:
  postgresql11-11.2-2PGDG.f30.x86_64                           postgresql11-server-11.2-2PGDG.f30.x86_64                           postgresql11-libs-11.2-2PGDG.f30.x86_64                          

Complete!

Confirm the installed package:

$ rpm -qi postgresql11-server
Name        : postgresql11-server
Version     : 11.2
Release     : 2PGDG.f30
Architecture: x86_64
Install Date: Mon 06 May 2019 10:49:47 AM EAT
Group       : Applications/Databases
Size        : 21514298
License     : PostgreSQL
Signature   : DSA/SHA1, Mon 01 Apr 2019 08:32:00 PM EAT, Key ID 1f16d2e1442df0f8
Source RPM  : postgresql11-11.2-2PGDG.f30.src.rpm
Build Date  : Mon 01 Apr 2019 08:31:35 PM EAT
Build Host  : koji-fedora30-x86-64-pgbuild
Relocations : (not relocatable)
Vendor      : PostgreSQL Global Development Group
URL         : https://www.postgresql.org/
Summary     : The programs needed to create and run a PostgreSQL server
Description :
PostgreSQL is an advanced Object-Relational database management system (DBMS).
The postgresql11-server package contains the programs needed to create
and run a PostgreSQL server, which will in turn allow you to create
and maintain PostgreSQL databases.

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-11/bin/postgresql-11-setup initdb
Initializing database ... OK

Then start and enable the service to start on boot

sudo systemctl start postgresql-11
sudo systemctl enable postgresql-11

Confirm service status.

$ sudo systemctl status postgresql-11
● postgresql-11.service - PostgreSQL 11 database server
   Loaded: loaded (/usr/lib/systemd/system/postgresql-11.service; disabled; vendor preset: disabled)
   Active: active (running) since Mon 2019-05-06 10:52:19 EAT; 30s ago
     Docs: https://www.postgresql.org/docs/11/static/
  Process: 12779 ExecStartPre=/usr/pgsql-11/bin/postgresql-11-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
 Main PID: 12784 (postmaster)
    Tasks: 8 (limit: 2323)
   Memory: 15.7M
   CGroup: /system.slice/postgresql-11.service
           ├─12784 /usr/pgsql-11/bin/postmaster -D /var/lib/pgsql/11/data/
           ├─12785 postgres: logger   
           ├─12787 postgres: checkpointer   
           ├─12788 postgres: background writer   
           ├─12789 postgres: walwriter   
           ├─12790 postgres: autovacuum launcher   
           ├─12791 postgres: stats collector   
           └─12792 postgres: logical replication launcher   

May 06 10:52:19 myregistry.local systemd[1]: Starting PostgreSQL 11 database server...
May 06 10:52:19 myregistry.local postmaster[12784]: 2019-05-06 10:52:19.739 EAT [12784] LOG:  listening on IPv6 address "::1", port 5432
May 06 10:52:19 myregistry.local postmaster[12784]: 2019-05-06 10:52:19.740 EAT [12784] LOG:  listening on IPv4 address "127.0.0.1", port 5432
May 06 10:52:19 myregistry.local postmaster[12784]: 2019-05-06 10:52:19.742 EAT [12784] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
May 06 10:52:19 myregistry.local postmaster[12784]: 2019-05-06 10:52:19.743 EAT [12784] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
May 06 10:52:19 myregistry.local postmaster[12784]: 2019-05-06 10:52:19.752 EAT [12784] LOG:  redirecting log output to logging collector process
May 06 10:52:19 myregistry.local postmaster[12784]: 2019-05-06 10:52:19.752 EAT [12784] HINT:  Future log output will appear in directory "log".
May 06 10:52:19 myregistry.local systemd[1]: Started PostgreSQL 11 database server.

PostgreSQL 11 config file is/var/lib/pgsql/11/data/postgresql.conf

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 Acess to PostgreSQL

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

listen_addresses = '*'

Also set PostgreSQL to accept remote connections

$ sudo vim /var/lib/pgsql/11/data/pg_hba.conf

# Accept from anywhere
host all all 0.0.0.0/0 md5

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

Restart service

sudo systemctl restart postgresql-11

Step 6: Set PostgreSQL admin user’s password

Set PostgreSQL admin user

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

Create a test user and database

[[email protected] ~]$ createuser test_user
[[email protected] ~]$ createdb test_db -O test_user
[[email protected] ~]$ grant all privileges on database test_db to test_user;

Login as a test_user  user try to create a table on the Database.

$ psql -U test_user -h localhost -d test_db

Step 7: Install pgAdmin 4

Install pgAdmin 4 on CentOS 7 / Fedora to administer your PostgreSQL from a web interface.

Also read:

Using SQLPad – Web-based SQL editor for MySQL / PostgreSQL / SQL Server

How to Install TimescaleDB on Ubuntu 18.04 LTS

How to Install Apache Tomcat 9 on CentOS 7 / Fedora

How to Install Django on Fedora

How to install LAMP Stack on Fedora

Install and Configure phpMyAdmin on Fedora

How to install Docker on Fedora

How to install MySQL 8.0 on Fedora