We are committed to provide service 24 X 7

Deals, Shopping, Training, Tools

Learn how to – Install PostgreSQL 11 on CentOS 8 / RHEL 8

Learn how to – Install PostgreSQL 11 on CentOS 8 / RHEL 8.

How can I install PostgreSQL 11 on CentOS 8 / RHEL 8 Linux?. PostgreSQL is an object-relational database management system based on POSTGRES 4.2, developed at the University of California at Berkeley Computer Science Department. PostgreSQL offers many modern features of SQL such as:

  • complex queries
  • foreign keys
  • triggers
  • updatable views
  • transactional integrity
  • multiversion concurrency control

PostgreSQL project provides a repository of packages of all supported versions for the most common distributions. Among the distributions supported are all Red Hat family of which includes CentOS, Fedora, Scientific Linux, Oracle Linux and Red Hat Enterprise Linux.

For PostgreSQL 12, check Installing PostgreSQL 12 on CentOS / RHEL 8

The version of PostgreSQL available on CentOS 8 / RHEL 8 officially maintained modular repository is 10 and 9.6. We’ll add PostgreSQL Yum Repository which hosts all recent releases.

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.

It can be added to CentOS / RHEL 8 system by running the command below:

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

View package details with:

$ rpm -qi pgdg-redhat-repo
Name        : pgdg-redhat-repo
Version     : 42.0
Release     : 24
Architecture: noarch
Install Date: Thu May  5 23:42:32 2022
Group       : Unspecified
Size        : 11993
License     : PostgreSQL
Signature   : DSA/SHA1, Wed Mar 16 12:50:24 2022, Key ID 1f16d2e1442df0f8
Source RPM  : pgdg-redhat-repo-42.0-24.src.rpm
Build Date  : Wed Mar 16 12:50:00 2022
Build Host  : koji-rhel8-x86-64-pgbuild
Relocations : (not relocatable)
Vendor      : PostgreSQL Global Development Group
URL         : https://yum.postgresql.org

Step 2: Install PostgreSQL 11 on CentOS 8 / RHEL 8

Disable postgresql module.

$ sudo dnf module -y disable postgresql
Updating Subscription Management repositories.
Last metadata expiration check: 0:03:10 ago on Mon 16 Sep 2019 04:30:11 PM EDT.
Dependencies resolved.
===================================================================================================================================================
 Package                            Arch                              Version                             Repository                          Size
===================================================================================================================================================
Disabling module streams:
 postgresql                                                           10                                                                          

Transaction Summary
===================================================================================================================================================

Is this ok [y/N]: y
Complete!

Then clean yum cache and install PostgreSQL 11 on CentOS 8 / RHEL 8.

sudo dnf clean all

Finally install PostgreSQL 11 server and client packages on CentOS 8 / RHEL 8 by running the commands below.

sudo dnf -y install postgresql11-server postgresql11

Minor version details can be checked using dnf command.

dnf info -y postgresql11-server postgresql11

Step 3: Initialize the database and enable automatic start

After installation, database initialization is required before service can be started.

sudo /usr/pgsql-11/bin/postgresql-11-setup initdb
sudo systemctl enable --now postgresql-11

Confirm that the service is started without any errors.

$ systemctl status postgresql-11
 postgresql-11.service - PostgreSQL 11 database server
   Loaded: loaded (/usr/lib/systemd/system/postgresql-11.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2019-09-16 16:41:09 EDT; 7s ago
     Docs: https://www.postgresql.org/docs/11/static/
  Process: 14929 ExecStartPre=/usr/pgsql-11/bin/postgresql-11-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
 Main PID: 14936 (postmaster)
    Tasks: 8 (limit: 24024)
   Memory: 16.9M
   CGroup: /system.slice/postgresql-11.service
           ├─14936 /usr/pgsql-11/bin/postmaster -D /var/lib/pgsql/11/data/
           ├─14937 postgres: logger   
           ├─14939 postgres: checkpointer   
           ├─14940 postgres: background writer   
           ├─14941 postgres: walwriter   
           ├─14942 postgres: autovacuum launcher   
           ├─14943 postgres: stats collector   
           └─14944 postgres: logical replication launcher   

Sep 16 16:41:09 rhel8.novalocal systemd[1]: Starting PostgreSQL 11 database server...
Sep 16 16:41:09 rhel8.novalocal postmaster[14936]: 2019-09-16 16:41:09.501 EDT [14936] LOG:  listening on IPv6 address "::1", port 5432
Sep 16 16:41:09 rhel8.novalocal postmaster[14936]: 2019-09-16 16:41:09.501 EDT [14936] LOG:  listening on IPv4 address "127.0.0.1", port 5432
Sep 16 16:41:09 rhel8.novalocal postmaster[14936]: 2019-09-16 16:41:09.505 EDT [14936] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQ>
Sep 16 16:41:09 rhel8.novalocal postmaster[14936]: 2019-09-16 16:41:09.511 EDT [14936] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
Sep 16 16:41:09 rhel8.novalocal postmaster[14936]: 2019-09-16 16:41:09.521 EDT [14936] LOG:  redirecting log output to logging collector process
Sep 16 16:41:09 rhel8.novalocal postmaster[14936]: 2019-09-16 16:41:09.521 EDT [14936] HINT:  Future log output will appear in directory "log".
Sep 16 16:41:09 rhel8.novalocal systemd[1]: Started PostgreSQL 11 database server.

PostgreSQL 11 configuration file is:

ls /var/lib/pgsql/11/data/postgresql.conf

Read through the file to see which settings you can turn on/off. The service should be restarted whenever changes are committed.

Step 4: Set PostgreSQL admin user’s password

Set PostgreSQL admin user

$ sudo su - postgres 
[postgres@rhel8 ~]$ psql -c "alter user postgres with password 'StrongPassword'" 
ALTER ROLE
[postgres@rhel8 ~]$

Create a test user and database

[postgres@rhel8 ~]$ psql
psql (11.15)
Type "help" for help.

postgres-# createuser test_user
postgres-# alter user test_user with password 'MyDBpassword';
postgres=# createdb test_db -O test_user
postgres=# grant all privileges on database test_db to test_user;
GRANT

Login as a test_user  user try to create a table on the Database.

$ psql -U test_user -h localhost -d test_db

Step 5: 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 8.

Best Video courses to Learn PostgreSQL Database:

Cart

Your Cart is Empty

Back To Shop