How To Install PostgreSQL 13 on CentOS 7 | RHEL 7

Posted on 292 views

PostgreSQL is an object-relational database management system based on POSTGRES 4.2. PostgreSQL 13 has been released for general public use and for Production use. PostgreSQL runs on all major Linux operating systems and has been ACID-compliant since 2001. Additionally it has powerful add-ons such as the popular PostGIS geospatial database extender. This guide will walk you through the installation of PostgreSQL 13 on CentOS 7|RHEL 7.

PostgreSQL development team provides pre-built packages in an online YUM and APT repository for both RHEL and Debian based systems respectively. Among the distributions supported are all Red Hat family of which includes CentOS, Fedora, Scientific Linux, Oracle Linux and Red Hat Enterprise Linux. We can now start the installation of PostgreSQL 13 on CentOS 7|RHEL 7.

How To Install PostgreSQL 13 on CentOS 7|RHEL 7

Use the steps below to install PostgreSQL 13 on CentOS 7|RHEL 7 Linux. We recently created a separate article on the installation of PostgreSQL 13 on CentOS / RHEL 8 systems.

Step 1: Add PostgreSQL Yum Repository to CentOS 7|RHEL 7

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. Run the following commands to add PostgreSQL 13 repository to your Linux machine.

sudo yum -y install

I recommend you perform system reboot after adding the repository.

sudo yum -y update 
sudo reboot

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

After successfully adding the repository, you can proceed to install PostgreSQL 13 on CentOS 7|RHEL 7.

Confirm the list of enabled repositories.

$ sudo yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base:
 * extras:
 * updates:
repo id               repo name                                           status
base/7/x86_64         CentOS-7 - Base                                     10,070
extras/7/x86_64       CentOS-7 - Extras                                      413
pgdg-common/7/x86_64  PostgreSQL common RPMs for RHEL/CentOS 7 - x86_64      360
pgdg10/7/x86_64       PostgreSQL 10 for RHEL/CentOS 7 - x86_64               789
pgdg11/7/x86_64       PostgreSQL 11 for RHEL/CentOS 7 - x86_64               838
pgdg12/7/x86_64       PostgreSQL 12 for RHEL/CentOS 7 - x86_64               414
pgdg13/7/x86_64       PostgreSQL 13 for RHEL/CentOS 7 - x86_64               140
pgdg95/7/x86_64       PostgreSQL 9.5 for RHEL/CentOS 7 - x86_64              698
pgdg96/7/x86_64       PostgreSQL 9.6 for RHEL/CentOS 7 - x86_64              759
updates/7/x86_64      CentOS-7 - Updates                                   1,134
repolist: 15,615

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

$ sudo yum search postgresql13
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base:
 * extras:
 * updates:
========================== N/S matched: postgresql13 ===========================
postgresql13.x86_64 : PostgreSQL client programs and libraries
postgresql13-contrib.x86_64 : Contributed source and binaries distributed with
                            : PostgreSQL
postgresql13-devel.x86_64 : PostgreSQL development header files and libraries
postgresql13-docs.x86_64 : Extra documentation for PostgreSQL
postgresql13-libs.x86_64 : The shared libraries required for any PostgreSQL
                         : clients
postgresql13-llvmjit.x86_64 : Just-in-time compilation support for PostgreSQL
postgresql13-plperl.x86_64 : The Perl procedural language for PostgreSQL
postgresql13-plpython3.x86_64 : The Python3 procedural language for PostgreSQL
postgresql13-pltcl.x86_64 : The Tcl procedural language for PostgreSQL
postgresql13-server.x86_64 : The programs needed to create and run a PostgreSQL
                           : server
postgresql13-test.x86_64 : The test suite distributed with PostgreSQL

Name and summary matches only, use "search all" for everything.

Now install PostgreSQL 13 packages on your CentOS 7|RHEL 7.

sudo yum -y install postgresql13 postgresql13-server

Import GPG key when asked by the installer.

Total                                                                                                                             7.0 MB/s |  15 MB  00:00:02
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
Importing GPG key 0x442DF0F8:
 Userid     : "PostgreSQL RPM Building Project "
 Fingerprint: 68c9 e2b9 1a37 d136 fe74 d176 1f16 d2e1 442d f0f8
 Package    : pgdg-redhat-repo-42.0-11.noarch (@/pgdg-redhat-repo-latest.noarch)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
Is this ok [y/N]: y

Step 3: Initialize and start database service

After fresh installation of PostgreSQL 13 its initialization is required.

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

Start the PostgreSQL database service.

sudo systemctl start postgresql-13

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
  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 systemd[1]: Starting PostgreSQL 13 database server...
Jul 09 23:35:30 postmaster[1865]: 2020-07-09 23:35:30.180 CEST [1865] LOG:  redirecting log output to logging collector process
Jul 09 23:35:30 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 systemd[1]: Started PostgreSQL 13 database server.

Enable the service to start when the system is reboted.

$ sudo systemctl enable postgresql-13
Created symlink from /etc/systemd/system/ to /usr/lib/systemd/system/postgresql-13.service.

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'"

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 = ''
#listen_addresses = '*'

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 md5

# Accept from trusted subnet (Recommended setting)
host all all 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  -h  -p 5432 

Step 6: Install pgAdmin 4 Web interface

pgAdmin is an Open Source tool for administering PostgreSQL database server. Use our guide below to install and use pgAdmin4 on CentOS 7|RHEL 7 machine.

We have completed installation of PostgreSQL 13 on CentOS 7|RHEL 7 server or Workstation.

Gravatar Image
A systems engineer with excellent skills in systems administration, cloud computing, systems deployment, virtualization, containers, and a certified ethical hacker.