Security TECHONOLGY Web Hosting

How To Install PostgreSQL 12 on CentOS 7 / CentOS 8

Written by Alex

How To Install PostgreSQL 12 on CentOS 7 / CentOS 8

This guide will walk you thru the steps to install PostgreSQL CentOS 7 / CentOS 8 Linux server?.PostgreSQL is an object-relational direction system supported by POSTGRES 4.2. PostgreSQL 12 is used for Production use by Developers and Database Administrators. Go through this article to Install PostgreSQL 12 on CentOS 7 / Centos 8.

Database server PostgreSQL provides a repository of packages of all supported versions for the foremost common distributions. Among the distributions supported are all Red Hat families.

Which incorporates CentOS, Fedora, Scientific Linux, Oracle Linux, and Red Hat Enterprise Linux.

Add PostgreSQL Yum Repository In the CentOS 7 and CentOS 8.

CentOS 8:

# sudo yum -y install

CentOS 7:

# sudo yum -y install

Now Install PostgreSQL 12 on CentOS 8 / CentOS 7

CentOS 8:

First Disable built-in PostgreSQL module:

# sudo dnf -qy module disable postgresql

Then Install both client and server packages:

# sudo dnf -y install postgresql12 postgresql12-server

CentOS 7:

# sudo yum -y install epel-release yum-utils
# sudo yum-config-manager --enable pgdg12
# sudo yum install postgresql12-server postgresql12

Then Initialize PostgreSQL and start database service

# sudo /usr/pgsql-12/bin/postgresql-12-setup initdb

The main configuration file of Postgresql  is written in this location: /var/lib/pgsql/12/data/postgresql.conf

Enable service on system startup:

# sudo systemctl enable --now postgresql-12

TO check service start status check below:


Install PostgreSQL 12 on CentOS 7


If you have a firewall running on the system then you need to add in firewall rule with the below command.

# sudo firewall-cmd --add-service=postgresql --permanent
# sudo firewall-cmd --reload

Change password of admin user:

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

Also, you have to change listen to address in the main configuration file in PostgreSQL. Open the main configuration file in the vim editor or any editor and change listen to address.

vi /var/lib/pgsql/12/data/postgresql.conf

Do connection setting like this:



Make configuration in  pg_hba.conf for accepting remote connection or a tool like PGadmin. Check the below configuration.

sudo vim /var/lib/pgsql/12/data/pg_hba.conf
# Accept from anywhere
host all all md5

# Accept from trusted subnet
host all all md5

Restart the Postgresql service after the configuration change.

# sudo systemctl restart postgresql-12

Connecting to a remote database using the command line.

# psql -U <dbuser> -h <serverip> -p 5432 <dbname>


About the author


Leave a Comment