How can I install PostgreSQL 11 on CentOS 8 / RHEL 8 Linux?. PostgreSQL is an object-relational database management system based on POSTGRES 4.2, developed at the University of California at Berkeley Computer Science Department. PostgreSQL offers many modern features of SQL such as:

  • complex queries
  • foreign keys
  • triggers
  • updatable views
  • transactional integrity
  • multiversion concurrency control

PostgreSQL project provides a repository of packages of all supported versions for the most common distributions. Among the distributions supported are all Red Hat family of which includes CentOS, Fedora, Scientific Linux, Oracle Linux and Red Hat Enterprise Linux.

For PostgreSQL 12, check Installing PostgreSQL 12 on CentOS / RHEL 8

The version of PostgreSQL available on CentOS 8 / RHEL 8 officially maintained modular repository is 10 and 9.6. We’ll add PostgreSQL Yum Repository which hosts all recent releases.

Step 1: Add PostgreSQL Yum Repository

The PostgreSQL Yum Repository will integrate with your normal systems and patch management, and provide automatic updates for all supported versions of PostgreSQL throughout the support lifetime of PostgreSQL.

It can be added to CentOS / RHEL 8 system by running the command below:

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

View package details with:

$ rpm -qi pgdg-redhat-repo
Name        : pgdg-redhat-repo
Version     : 42.0
Release     : 4
Architecture: noarch
Install Date: Mon 16 Sep 2019 04:17:45 PM EDT
Group       : System Environment/Base
Size        : 6915
License     : PostgreSQL
Signature   : DSA/SHA1, Tue 16 Apr 2019 11:44:04 PM EDT, Key ID 1f16d2e1442df0f8
Source RPM  : pgdg-redhat-repo-42.0-4.src.rpm
Build Date  : Tue 16 Apr 2019 11:44:04 PM EDT
Build Host  : koji-rhel8-x86-64-pgbuild
Relocations : (not relocatable)
Vendor      : PostgreSQL Global Development Group
URL         : https://yum.postgresql.org
Summary     : PostgreSQL PGDG RPMs- Yum Repository Configuration for Red Hat / CentOS / Scientific Linux
Description :
This package contains yum configuration for Red Hat Enterprise Linux, CentOS
and Scientific Linux. and also the GPG key for PGDG RPMs.

Step 2: Install PostgreSQL 11 on CentOS 8 / RHEL 8 Linux system

Disable postgresql module.

$ sudo dnf module disable postgresql
Updating Subscription Management repositories.
Last metadata expiration check: 0:03:10 ago on Mon 16 Sep 2019 04:30:11 PM EDT.
Dependencies resolved.
===================================================================================================================================================
 Package                            Arch                              Version                             Repository                          Size
===================================================================================================================================================
Disabling module streams:
 postgresql                                                           10                                                                          

Transaction Summary
===================================================================================================================================================

Is this ok [y/N]: y
Complete!

Then clean yum cache and install PostgreSQL 11 on CentOS 8 / RHEL 8.

sudo dnf clean all

Finally install PostgreSQL 11 server and client packages on CentOS 8 / RHEL 8 by running the commands below.

sudo dnf -y install postgresql11-server postgresql11

Minor version details can be checked using dnf command.

$ dnf info postgresql11-server postgresql11

Step 3: Initialize the database and enable automatic start

After installation, database initialization is required before service can be started.

sudo /usr/pgsql-11/bin/postgresql-11-setup initdb
sudo systemctl enable --now postgresql-11

Confirm that the service is started without any errors.

$ sudo systemctl status postgresql-11
● postgresql-11.service - PostgreSQL 11 database server
   Loaded: loaded (/usr/lib/systemd/system/postgresql-11.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2019-09-16 16:41:09 EDT; 7s ago
     Docs: https://www.postgresql.org/docs/11/static/
  Process: 14929 ExecStartPre=/usr/pgsql-11/bin/postgresql-11-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
 Main PID: 14936 (postmaster)
    Tasks: 8 (limit: 24024)
   Memory: 16.9M
   CGroup: /system.slice/postgresql-11.service
           ├─14936 /usr/pgsql-11/bin/postmaster -D /var/lib/pgsql/11/data/
           ├─14937 postgres: logger   
           ├─14939 postgres: checkpointer   
           ├─14940 postgres: background writer   
           ├─14941 postgres: walwriter   
           ├─14942 postgres: autovacuum launcher   
           ├─14943 postgres: stats collector   
           └─14944 postgres: logical replication launcher   

Sep 16 16:41:09 rhel8.novalocal systemd[1]: Starting PostgreSQL 11 database server...
Sep 16 16:41:09 rhel8.novalocal postmaster[14936]: 2019-09-16 16:41:09.501 EDT [14936] LOG:  listening on IPv6 address "::1", port 5432
Sep 16 16:41:09 rhel8.novalocal postmaster[14936]: 2019-09-16 16:41:09.501 EDT [14936] LOG:  listening on IPv4 address "127.0.0.1", port 5432
Sep 16 16:41:09 rhel8.novalocal postmaster[14936]: 2019-09-16 16:41:09.505 EDT [14936] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQ>
Sep 16 16:41:09 rhel8.novalocal postmaster[14936]: 2019-09-16 16:41:09.511 EDT [14936] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
Sep 16 16:41:09 rhel8.novalocal postmaster[14936]: 2019-09-16 16:41:09.521 EDT [14936] LOG:  redirecting log output to logging collector process
Sep 16 16:41:09 rhel8.novalocal postmaster[14936]: 2019-09-16 16:41:09.521 EDT [14936] HINT:  Future log output will appear in directory "log".
Sep 16 16:41:09 rhel8.novalocal systemd[1]: Started PostgreSQL 11 database server.

PostgreSQL 11 file is:

/var/lib/pgsql/11/data/postgresql.conf

Read through the file to see which settings you can turn on/off. The service should be restarted whenever changes are committed.

Step 4: 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
[[email protected] ~]$

Create a test user and database

[[email protected] ~]$ psql
psql (11.5)
Type "help" for help.

postgres-# createuser test_user
postgres-# alter user test_user with password 'MyDBpassword';
postgres=# createdb test_db -O test_user
postgres=# grant all privileges on database test_db to test_user;
GRANT

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

$ psql -U test_user -h localhost -d test_db

Installation for other systems:

How to install PostgreSQL 11 on CentOS 7

How to Install PostgreSQL 11 on Debian 10 (Buster)

How to Install PostgreSQL 11 on FreeBSD 12

How to Install PostgreSQL 11 on Debian 9 / Debian 8

Install PostgreSQL 11 on Ubuntu 18.04 / Ubuntu 16.04

How to install PostgreSQL 11 on Fedora 30/29/28