Saturday, November 16, 2024
Google search engine
HomeData Modelling & AIHow To Install PostgreSQL 13 on CentOS 7 | RHEL 7

How To Install PostgreSQL 13 on CentOS 7 | RHEL 7

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.

Update your system.

sudo yum -y update

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

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
...
repo id                                                               repo name                                                                                             status
base/7/x86_64                                                         CentOS-7 - Base                                                                                       10,072
epel/x86_64                                                           Extra Packages for Enterprise Linux 7 - x86_64                                                        13,767
extras/7/x86_64                                                       CentOS-7 - Extras                                                                                        518
pgdg-common/7/x86_64                                                  PostgreSQL common RPMs for RHEL / CentOS 7 - x86_64                                                      468
pgdg11/7/x86_64                                                       PostgreSQL 11 for RHEL / CentOS 7 - x86_64                                                             1,556
pgdg12/7/x86_64                                                       PostgreSQL 12 for RHEL / CentOS 7 - x86_64                                                             1,202
pgdg13/7/x86_64                                                       PostgreSQL 13 for RHEL / CentOS 7 - x86_64                                                               957
pgdg14/7/x86_64                                                       PostgreSQL 14 for RHEL / CentOS 7 - x86_64                                                               693
pgdg15/7/x86_64                                                       PostgreSQL 15 for RHEL / CentOS 7 - x86_64                                                               401
updates/7/x86_64                                                      CentOS-7 - Updates                                                                                     5,165
repolist: 34,799

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

$ sudo yum search postgresql13
...
=========================================================================== 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-odbc.x86_64 : PostgreSQL ODBC driver
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

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 <[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 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
     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.geeksforgeeks.org systemd[1]: Starting PostgreSQL 13 database server...
Jul 09 23:35:30 centos-01.geeksforgeeks.org 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.geeksforgeeks.org 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.geeksforgeeks.org 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'
#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 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|RHEL 7 machine.

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

For more reading refer to the PostgreSQL Administration documentation.

Books for Learning PostgreSQL database:

RELATED ARTICLES

Most Popular

Recent Comments