# PostgreSQL Installation on Linux (RPM approach)

In 
Published 2022-12-03

This tutorial explains to you how to install the PostgreSQL database on Linux (RHL- Red Hat Linux, OEL -Oracle Enterprise Linux, CentOS). PostgreSQL installation on Linux is easy. This tutorial contains a step-by-step approach for PostgreSQL 9.6 on CentOS 6 using the RPM pakages.

In order to install the PostgreSQL database on Linux (Red Hat/ CentOS/ Oracle Enterprise Linux) you can download the RPM packages (for the PostgreSQL database) from here and install them. The RPM approach is when you have no Internet connection on that machine (server).

In my case, I want to install PostgreSQL 9.6 on CentOS 6 (64-bit), so I will choose "RHEL/CentOS/Scientific Linux/Oracle Linux 6 - x86_64" and I will go here. I will click on "PostgreSQL Database Server 9.6 PGDG". From here I will download:

  • postgresql96 - PostgreSQL client programs and libraries
  • postgresql96-contrib - Contributed source and binaries distributed with PostgreSQL
  • postgresql96-libs - The shared libraries required for any PostgreSQL clients
  • postgresql96-server - The programs needed to create and run a PostgreSQL server

Put all these files on the Linux machine on a "stage" directory. In my case, I will put them in /u01/stage :

From here connected with root user, I will install the RPM packages using the following commands:

rpm -ivh postgresql96-libs-9.6.1-1PGDG.rhel6.x86_64.rpm
rpm -ivh postgresql96-9.6.1-1PGDG.rhel6.x86_64.rpm
rpm -ivh postgresql96-contrib-9.6.1-1PGDG.rhel6.x86_64.rpm
rpm -ivh postgresql96-server-9.6.1-1PGDG.rhel6.x86_64.rpm

After installing PostgreSQL server, It's required to initialize the database it before using first time. To initialize database use below command:

service postgresql-9.6 initdb

If you want PostgreSQL to start automatically when the OS starts, do the following:

chkconfig postgresql-9.4 on

For RHEL 7+ use systemctl enable postgresql-9.6.service instead.

Now, start the PostgreSQL database after installation and initialization:

service postgresql-9.6 start

Now the PostgreSQL database is installed, running and ready to be used.

In order to remove the PostgrSQL installation you can run the following command:

# yum erase postgresql96*