How to install PostgreSQL 13 on CentOS 7

You can download this article in PDF format to support us through the following link.

Download the guide in PDF format

turn off


PostgreSQL is an object relational database management system based on POSTGRES 4.2. PostgreSQL 13 has been released in Beta for testing purposes and does not run production workloads. PostgreSQL runs on all major Linux operating systems and has been acidIt has been compatible since 2001. In addition, it has powerful add-ons, such as popular Postal Geographic Information System Geospatial database extension program. This guide will guide you through the installation of PostgreSQL 13 on CentOS 7.

The PostgreSQL development team provides pre-built software packages for RHEL and Debian based systems in the online YUM and APT repositories, respectively. Supported distributions include all Red Hat series, including CentOS, Fedora, Scientific Linux, Oracle Linux and Red Hat Enterprise Linux. We can now start installing PostgreSQL 13 on CentOS 7.

How to install PostgreSQL 13 on CentOS 7

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

Step 1: Add PostgreSQL Yum repository to CentOS 7

The PostgreSQL Yum repository will integrate with your regular system and patch management, and provide automatic updates for all supported PostgreSQL versions throughout the PostgreSQL support lifecycle. Run the following command to add the PostgreSQL 13 repository to the CentOS 7 Linux computer.

sudo yum -y install

I recommend that you perform a 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 continue to install PostgreSQL13 on CentOS 7. As mentioned earlier, as of this writing, the PostgreSQL 13 software package is not stable, so it can be used in the test repository.

Enable the PostgreSQL 13 test library.

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:
 * extras:
 * updates:
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 if there is PostgreSQL 13 software package in the repository.

$ sudo yum search postgresql13
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base:
 * extras:
 * updates:
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 the PostgreSQL 13 package on CentOS 7.

sudo yum -y install postgresql13-server

When asked by the installer, import the GPG key.

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 the database service

After a fresh installation of PostgreSQL 13 on CentOS 7, it needs to be initialized.

$ 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 that 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.

After restarting the system, enable the service to start.

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

Step 4: Set the password of the PostgreSQL administrator user

Update the PostgreSQL administrator user password.

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

Step 5: Enable remote database connection (optional)

Edit file /var/lib/pgsql/13/data/postgresql.conf And set the “listening address” to the server IP address or “*All interfaces.

$ sudo vi /var/lib/pgsql/13/data/postgresql.conf
# line 59
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

After saving the changes, restart the database service.

sudo systemctl restart postgresql-13

Use the psql command to test the connection, and provide the user name and optional database name.

$ psql -U  -h  -p 5432 

Step 6: Install pgAdmin 4 web interface

pgAdmin is an open source tool for managing PostgreSQL database servers. Use the following guide to install and use pgAdmin4 on a CentOS 7 computer.

How to install pgAdmin 4 on CentOS 7

We have finished installing PostgreSQL 13 on the CentOS 7 server or Workstation. For more information, please refer to PostgreSQL management documentation.


You can download this article in PDF format to support us through the following link.

Download the guide in PDF format

turn off