Logo ← PostgreSQL Blog

Installing PostgreSQL on RHEL 7.8 VM

PostgreSQL is a powerful, open-source relational database system. In this guide, we’ll walk you through the installation process of…

Installing PostgreSQL on RHEL 7.8 VM

PostgreSQL is a powerful, open-source relational database system. In this guide, we’ll walk you through the installation process of PostgreSQL on a RHEL 7.8 VM.

Disabling Firewall

Firstly, let’s disable the firewall to ensure smooth communication during installation.

sudo firewall-cmd --state
sudo systemctl stop firewalld
sudo systemctl disable firewalld
sudo systemctl mask --now firewalld

Setting up Proxy

If you are behind a proxy, configure the system to use the proxy settings.

vi /etc/environment
http_proxy="http://kemal.oz%40itu.gov.tr:sifre123@proxy2.itu.gov.tr:8080"
https_proxy="https://kemal.oz%40itu.gov.tr:sifre123@proxy2.itu.gov.tr:8080"
ftp_proxy="ftp://kemal.oz%40itu.gov.tr:sifre123@proxy2.itu.gov.tr:8080"
vi /etc/yum.conf
proxy=http://proxy2.itu.gov.tr:8080
proxy_username=kemal.oz@itu.gov.tr
proxy_password=sifre123

Updating Hostname

Update the hostname in the /etc/hostname and /etc/hosts files.

cd /etc
vi hostname
postgres1
vi hosts
10.6.128.777 postgres1

Checking Internet Connection

Ensure that your internet connection is working.

ping -c 4 www.google.com
curl -is www.google.com | head -n 1
telnet www.google.com 80

Updating System

Update your system before installing PostgreSQL.

sudo yum -y update

Installing PostgreSQL

Install the PostgreSQL repository and PostgreSQL itself.

sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sudo yum install -y postgresql12-server
sudo /usr/pgsql-12/bin/postgresql-12-setup initdb
sudo systemctl enable postgresql-12
sudo systemctl start postgresql-12

Configuring PostgreSQL

Update the pg_hba.conf and postgresql.conf files for user access and configuration.

vi /var/lib/pgsql/12/data/pg_hba.conf
# Update user access permissions
vi /var/lib/pgsql/12/data/postgresql.conf
# Update configurations such as max connections, listen_addresses, etc.

Installing PostGIS

Before installing PostGIS, add the required repositories and disable the default PostgreSQL module.

yum -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum config-manager - set-enabled PowerTools
yum -qy module disable postgresql

Install PostGIS packages

yum list postgis*
yum install postgis33_12*

Verifying PostGIS Installation

After installation, verify the PostGIS package.

rpm -qi postgis33_12

Creating Database and User

Switch to the postgres user and create a database and user.

su postgres
psql
CREATE DATABASE cbs_db;
CREATE USER cbs_user WITH ENCRYPTED password 'test123';
GRANT ALL PRIVILEGES ON DATABASE cbs_db TO cbs_user;
ALTER ROLE "cbs_user" WITH LOGIN;
ALTER USER postgres password 'test123';

Enabling PostGIS Extensions

Finally, connect to the database and enable PostGIS extensions.

psql -d cbs_db
CREATE EXTENSION postgis;
CREATE EXTENSION postgis_raster;
CREATE EXTENSION postgis_topology;
CREATE EXTENSION postgis_sfcgal;
CREATE EXTENSION fuzzystrmatch;
CREATE EXTENSION address_standardizer;
CREATE EXTENSION address_standardizer_data_us;
CREATE EXTENSION postgis_tiger_geocoder;

Conclusion

You have successfully installed PostgreSQL and PostGIS on your RHEL 7.8 VM. You can now start building spatial databases and applications using PostGIS extensions.