PostgreSQL Installation — Linux
Multiple ways of installation of PostgreSQL database
In this article, I will try to help you with the easiest ways of installation PostgreSQL database.
PostgreSQL (or postgres) is open-source free to use relational database management system (RDBMS). It has reliability, feature robustness, and performance.
PostgreSQL installation
- Interactive installation by Software EDB
- Yum Repository Based Installation
- USING .RPM FILES
1. Interactive installation by Software EDB
EDB is a Company which provides paid support for postgreSQL database, and the paid version of postgreSQL DB is called as EDB advance server.
Here we are interested in downloading the open-source/free version so you can download the DB software from EDB official site according to your OS configuration.
At this moment, EDB is providing software till only version 10.11 for linux environment and if you want to install version 11 and higher then you need to make use of other installation methods which I have mentioned below.
After downloading you will get a file — -> postgresql-10.10–2-linux-x64.run
1.Here it will ask for the path where you want to install the Database software.
2. Second question is about components which you want to install, install it by your choice. I would recommend to install all components.
3. Next is asking about installation directory, remember this directory is your CLUSTER, you can create directory in advance and mention here. Don’t get confused with the word cluster, it is not related to redundancy & HA.
By default a new cluster named as DATA will be created.
It will create a new user called postgres, provide password of your choice.
Port- Each cluster has their unique port number, by default it is 5432.
4. Advanced options, if you would like to change some parameters for your database cluster. Recommended is [1] default.
A locale is a set of environmental variables that defines the language, country, and character encoding settings (or any other special variant preferences) for your applications and shell session on a Linux system.
5. This is the final step of installation, it will list all selected parameters and pre-installation summary. Press Enter to continue.
Congratulations! PostgreSQL has been installed on your system.
Basic Info
Installation of the software has been completed, as per the above installation a new cluster named as data has been created in the given directory /postgres/data.
pg_hba.conf and postgresql.conf are the 2 main important configuration files.
Psql- Utility which helps us to connect to the database.
Pg_ctl- Administration related to the cluster.
Now we will install using yum repositories
2. PostgreSQL Yum Repository Based Installation
The PostgreSQL yum repository integrate with your normal systems and patch management, and provide automatic updates for all supported versions of PostgreSQL throughout the support lifetime of PostgreSQL.
Here I am installing PostgreSQL on Linux RHEL 7 platform.
STEP 1- Install the repository RPM
yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
Or You can download the RPM file from https://yum.postgresql.org/repopackages.php for your respective OS details.
To find out your OS details
cat /etc/redhat-release
uname -m :
I have downloaded for RHEL 7 and the file name is pgdg-redhat-repo-latest.noarch.rpm
yum install pgdg-redhat-repo-latest.noarch.rpm
STEP 2- Install the client package
yum install postgresql11
STEP 3 — Install the server package
yum install postgresql11-server
STEP 4- Initialize DB and Autostart of Server
Congratulations! Your PostgreSQL DB has been installed, the steps below are initializing the database and enabling automatic start of PostgreSQL.
/usr/pgsql-11/bin/postgresql-11-setup initdbsystemctl enable postgresql-11systemctl start postgresql-11
Now, if you don’t want to make user of yum or if you have some restriction in downloading from linux server then you can download the RPM’s directly from
3. Installation using .RPM files for Version 11.5
This is our 3rd and another way of Installation, I prefer this way : )
3.1 CREATE USER
Switch to root and create postgres user
sudo -s
useradd postgres
passwd postgres
3.2 CREATE DIRECTORIES & CHANGE PERMISSION
mkdir /postgres/data
mkdir /postgres/wal
# Data directory- Where our first cluster will be created.
# Wal directory- Archive files directory.
# We need to change the permission of created directories
chown postgres:postgres /postgres/data
chown postgres:postgres /postgres/WAL
or use:
chown -R postgres:postgres /postgres
3.3 INSTALL THE RPM FILES
You can download from: https://yum.postgresql.org/rpmchart.php
As per your OS configuration, click on the link and download the RPM’s.
Click on
PostgreSQL Database Server 11 PGDG
Download these RPM’s as per your choice.
When you will click on these you will get list of RPM’s for all versions like 11.2, 11.3, 11.4, 11.5 and 11.6. I have downloaded RPM’s for 11.5.
After installing these RPM, the software has been installed and now we will create the cluster for the environment.
3.4 CREATE CLUSTER
cd /usr/pgsql-11/bin/
./postgresql-11-setup initdb
3.5 ENABLE, START & CHECK STATUS
systemctl enable postgresql-11.service
systemctl start postgresql-11.service
systemctl status postgresql-11.service
PostgreSQL server & Cluster has been created successfully.