# PostgreSQL Installation on Linux (YUM approach)

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 yum repository.

When you have access to the Internet, installing PostgreSQL on Linux is easier. In my case I want to install PostgreSQL 9.6 on CentOS 6. The installation is similar on Red Hat or Oracle Enterprise Linux 6. When you have access to the Internet you can use YUM command in order to install PostgreSQL on Linux. When no internet is available on the Linux machine, you can use the PostgreSQL RPM installation approach.

Here are the steps for installing the PostgreSQL on Linux, using the yum command:

  1. Check the default PostgreSQL version in your YUM repository
# yum list postgresql

  1. Exclude the PostgreSQL from the yum supplied repository, by editing /etc/yum.repos.d/CentOS-Base.repo file.

Under "base" and "updates" sections you have to add the following line:"exclude=postgresql*"

Now you can run "yum list postgresql" again:

  1. Download the PGDG file from here. In my case, the PGDG file is pgdg-centos96-9.6-3.noarch.rpm and put it on Linux machine in a stage directory:

and install the PGDG RPM file:

# yum install pgdg-centos96-9.6-3.noarch.rpm
  1. Start the PostgreSQL database installation using YUM command:
# yum install postgresql96-server

... and you will see something like this:

Here you can type "y" + ENTER.

Some packages will be downloaded and installed.

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   (for CentOS 6)

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

At this moment you can use the PostgreSQL database !

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

# yum erase postgresql96*