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

PostgreSQL is an object-relational database management system based on POSTGRES 4.2. PostgreSQL 13 has been released in Beta for testing purposes and not running Production workloads. 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.

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.

How To Install PostgreSQL 13 on CentOS 7

Use the steps below to install PostgreSQL 13 on CentOS 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

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 CentOS 7 Linux machine.

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

I recommend you perform system reboot after adding the repository.

sudo yum -y update 
sudo reboot

Step 2: Install PostgreSQL 13 on CentOS 7

After successfully adding the repository, you can proceed to install PostgreSQL 13 on CentOS 7. As stated earlier, the packages for PostgreSQL 13 as of this writing are not stable hence available in testing repository.

Enable PostgreSQL 13 testing repository.

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

Confirm the list of enabled repositories.

$ sudo yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.plustech.de
 * extras: mirror1.hs-esslingen.de
 * updates: mirror.imt-systems.com
repo id                                                         repo name                                                                                   status
base/7/x86_64                                                   CentOS-7 - Base                                                                             10,070
extras/7/x86_64                                                 CentOS-7 - Extras                                                                              412
pgdg-common/7/x86_64                                            PostgreSQL common RPMs for RHEL/CentOS 7 - x86_64                                              300
pgdg10/7/x86_64                                                 PostgreSQL 10 for RHEL/CentOS 7 - x86_64                                                       647
pgdg11/7/x86_64                                                 PostgreSQL 11 for RHEL/CentOS 7 - x86_64                                                       658
pgdg12/7/x86_64                                                 PostgreSQL 12 for RHEL/CentOS 7 - x86_64                                                       354
pgdg13-updates-testing/7/x86_64                                 PostgreSQL 13 for RHEL/CentOS 7 - x86_64 - Updates testing                                      25
pgdg95/7/x86_64                                                 PostgreSQL 9.5 for RHEL/CentOS 7 - x86_64                                                      586
pgdg96/7/x86_64                                                 PostgreSQL 9.6 for RHEL/CentOS 7 - x86_64                                                      623
updates/7/x86_64                                                CentOS-7 - Updates                                                                             890
repolist: 14,565

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: mirror.plustech.de
 * extras: mirror1.hs-esslingen.de
 * updates: mirror.imt-systems.com
pgdg-common                                                                                                                                | 2.9 kB  00:00:00
pgdg10                                                                                                                                     | 3.6 kB  00:00:00
pgdg11                                                                                                                                     | 3.6 kB  00:00:00
pgdg12                                                                                                                                     | 3.6 kB  00:00:00
pgdg13-updates-testing                                                                                                                     | 3.6 kB  00:00:00
pgdg95                                                                                                                                     | 3.6 kB  00:00:00
pgdg96                                                                                                                                     | 3.6 kB  00:00:00
(1/2): pgdg13-updates-testing/7/x86_64/group_gz                                                                                            |  246 B  00:00:00
(2/2): pgdg13-updates-testing/7/x86_64/primary_db                                                                                          |  17 kB  00:00:00
=================================================================== 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.

sudo yum -y install 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 <[email protected]>"
 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 on CentOS 7 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
     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.

Enable the service to start when the system is reboted.

$ sudo systemctl enable postgresql-13
Created symlink from /etc/systemd/system/multi-user.target.wants/postgresql-13.service 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'"
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 = '172.20.11.11'

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 172.20.11.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 an Open Source tool for administering PostgreSQL database server. Use our guide below to install and use pgAdmin4 on CentOS 7 machine.

How To Install pgAdmin 4 on CentOS 7

We have completed installation of PostgreSQL 13 on CentOS 7 server or Workstation. For more reading refer to the PostgreSQL Administration documentation.

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