You can support us by downloading this article as PDF from the Link below. Download the guide as PDF

In this guide we will explore the installation of PostgreSQL 13 on CentOS 8 | RHEL 8 Linux server. PostgreSQL is a powerful, open source object-relational database system that safely store and scale the most complicated data workloads. The PostgreSQL database system is designed to assure users reliability, data integrity, robust feature set and extensibility. There is a large community behind its development to ensure innovation and strong reputation.

Install PostgreSQL 13 on CentOS 8 | RHEL 8

As of this article update PostgreSQL 13 is available running production workloads. All the software packages are available in the YUM repository supported officially by PostgreSQL team the installation process is simplified.

Before you start the installation ensure you’re running the latest release of CentOS 8 | RHEL 8 Linux system. You can run the yum update command to pull the latest updates.

sudo yum -y update
sudo systemctl reboot

Once the system is rebooted begin installation of PostgreSQL 13 on CentOS 8 | RHEL 8 server.

Step 1: Add PostgreSQL Yum Repository

The YUM repository supports both CentOS and RHEL family of Linux distributions. Once it is added, it will provide automatic updates for all supported versions of PostgreSQL throughout the support lifetime of PostgreSQL.

Run the following commands to add the repository that provides PostgreSQL packages to your CentOS / RHEL 8 server.

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

Accept installation when prompted by pressing the y key in your keyboard.

Dependencies resolved.
==================================================================================================================================================================
 Package                                     Architecture                      Version                              Repository                               Size
==================================================================================================================================================================
Installing:
 pgdg-redhat-repo                            noarch                            42.0-11                              @commandline                             11 k

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

Total size: 11 k
Installed size: 11 k
Is this ok [y/N]: y

Step 2: Install PostgreSQL 13 on CentOS 8 | RHEL 8

We need to disable the PostgreSQL AppStream repository on CentOS 8 | RHEL 8 Linux which contains some other version of PostgreSQL.

sudo dnf -qy module disable postgresql

Enable PostgreSQL 13 testing repository.

sudo dnf -y install dnf-utils
sudo yum-config-manager --enable pgdg13-updates-testing

Confirm the list of enabled repositories.

# dnf repolist
repo id                                                        repo name
AppStream                                                      CentOS-8 - AppStream
BaseOS                                                         CentOS-8 - Base
extras                                                         CentOS-8 - Extras
pgdg-common                                                    PostgreSQL common RPMs for RHEL/CentOS 8 - x86_64
pgdg10                                                         PostgreSQL 10 for RHEL/CentOS 8 - x86_64
pgdg11                                                         PostgreSQL 11 for RHEL/CentOS 8 - x86_64
pgdg12                                                         PostgreSQL 12 for RHEL/CentOS 8 - x86_64
pgdg13-updates-testing                                         PostgreSQL 13 for RHEL/CentOS 8 - x86_64 - Updates testing
pgdg95                                                         PostgreSQL 9.5 for RHEL/CentOS 8 - x86_64
pgdg96                                                         PostgreSQL 9.6 for RHEL/CentOS 8 - x86_64

Check to see if PostgreSQL 13 packages are available on the repository.

$ sudo yum search postgresql13
Last metadata expiration check: 0:08:33 ago on Thu 09 Jul 2020 11:18:26 PM CEST.
=============================================================== Name Exactly Matched: postgresql13 ===============================================================
postgresql13.x86_64 : PostgreSQL client programs and libraries
=================================================================== Name Matched: postgresql13 ===================================================================
postgresql13-docs.x86_64 : Extra documentation for PostgreSQL
postgresql13-libs.x86_64 : The shared libraries required for any PostgreSQL clients
postgresql13-test.x86_64 : The test suite distributed with PostgreSQL
postgresql13-devel.x86_64 : PostgreSQL development header files and libraries
postgresql13-pltcl.x86_64 : The Tcl procedural language for PostgreSQL
postgresql13-plperl.x86_64 : The Perl procedural language for PostgreSQL
postgresql13-server.x86_64 : The programs needed to create and run a PostgreSQL server
postgresql13-contrib.x86_64 : Contributed source and binaries distributed with PostgreSQL
postgresql13-llvmjit.x86_64 : Just-in-time compilation support for PostgreSQL
postgresql13-plpython3.x86_64 : The Python3 procedural language for PostgreSQL

Now install PostgreSQL 13 packages on your CentOS 8 | RHEL 8 server – both server and client.

sudo dnf install postgresql13-server

Agree to install if you’re okay with it.

Dependencies resolved.
==================================================================================================================================================================
 Package                                  Architecture                Version                                   Repository                                   Size
==================================================================================================================================================================
Installing:
 postgresql13-server                      x86_64                      13-beta2_1PGDG.rhel8                      pgdg13-updates-testing                      6.1 M
Installing dependencies:
 libicu                                   x86_64                      60.3-2.el8_1                              BaseOS                                      8.8 M
 postgresql13                             x86_64                      13-beta2_1PGDG.rhel8                      pgdg13-updates-testing                      1.6 M
 postgresql13-libs                        x86_64                      13-beta2_1PGDG.rhel8                      pgdg13-updates-testing                      431 k

Transaction Summary
==================================================================================================================================================================
Install  4 Packages

Total download size: 17 M
Installed size: 65 M
Is this ok [y/N]: y

GPG key repository is also required.

Total                                                                                                                              12 MB/s |  17 MB     00:01
warning: /var/cache/dnf/pgdg13-updates-testing-20e9d036368b4178/packages/postgresql13-13-beta2_1PGDG.rhel8.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY
PostgreSQL 13 for RHEL/CentOS 8 - x86_64 - Updates testing                                                                        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

Step 3: Initialize and start database service

PostgreSQL database initialization is required before you can use the database server.

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

The database main configuration file is  /var/lib/pgsql/13/data/postgresql.conf

$ ls  /var/lib/pgsql/13/data/
base    pg_commit_ts  pg_ident.conf  pg_notify    pg_snapshots  pg_subtrans  PG_VERSION  postgresql.auto.conf
global  pg_dynshmem   pg_logical     pg_replslot  pg_stat       pg_tblspc    pg_wal      postgresql.conf
log     pg_hba.conf   pg_multixact   pg_serial    pg_stat_tmp   pg_twophase  pg_xact

Start the PostgreSQL database server and set it to start at boot.

$ sudo systemctl enable --now postgresql-13
Created symlink /etc/systemd/system/multi-user.target.wants/postgresql-13.service → /usr/lib/systemd/system/postgresql-13.service.

Check the service status to confirm it is running.

$ 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 Thu 2020-07-09 23:35:30 CEST; 37s ago
     Docs: https://www.postgresql.org/docs/13/static/
  Process: 1860 ExecStartPre=/usr/pgsql-13/bin/postgresql-13-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
 Main PID: 1865 (postmaster)
    Tasks: 8 (limit: 12210)
   Memory: 17.3M
   CGroup: /system.slice/postgresql-13.service
           ├─1865 /usr/pgsql-13/bin/postmaster -D /var/lib/pgsql/13/data/
           ├─1867 postgres: logger
           ├─1869 postgres: checkpointer
           ├─1870 postgres: background writer
           ├─1871 postgres: walwriter
           ├─1872 postgres: autovacuum launcher
           ├─1873 postgres: stats collector
           └─1874 postgres: logical replication launcher

Jul 09 23:35:30 centos-01.computingforgeeks.com systemd[1]: Starting PostgreSQL 13 database server...
Jul 09 23:35:30 centos-01.computingforgeeks.com postmaster[1865]: 2020-07-09 23:35:30.180 CEST [1865] LOG:  redirecting log output to logging collector process
Jul 09 23:35:30 centos-01.computingforgeeks.com postmaster[1865]: 2020-07-09 23:35:30.180 CEST [1865] HINT:  Future log output will appear in directory "log".
Jul 09 23:35:30 centos-01.computingforgeeks.com systemd[1]: Started PostgreSQL 13 database server.

Step 4: Set PostgreSQL admin user’s password

Update the PostgreSQL admin user password.

$ sudo su - postgres 
]$ psql -c "alter user postgres with password 'StrongDBPassword'"
ALTER ROLE

Step 5: Enabling remote Database connections (Optional)

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

$ sudo vi /var/lib/pgsql/13/data/postgresql.conf
# line 59
listen_addresses = '192.168.10.10'

Also set PostgreSQL to accept remote connections

$ sudo vi /var/lib/pgsql/13/data/pg_hba.conf

# Accept from anywhere (not recommended)
host all all 0.0.0.0/0 md5

# Accept from trusted subnet (Recommended setting)
host all all 192.168.18.0/24 md5

Restart the database service after saving the changes.

sudo systemctl restart postgresql-13

Test connection using the psql command while providing username and optionally database name.

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

Step 6: Install pgAdmin 4 Web interface

pgAdmin is the leading Open Source feature-rich PostgreSQL administration and development platform that runs on Linux, Unix, Mac OS X, and Windows. Here is the link for the installation of pgAdmin4 on CentOS.

How To Install pgAdmin 4 on CentOS 8 Linux

Read the official documentation for more in-depth knowledge on PostgreSQL database administration.

You can support us by downloading this article as PDF from the Link below. Download the guide as PDF