Installing PostgreSQL on Linux Distros.

Installing PostgreSQL on Linux Distros.

Part One

As more businesses, institutions, and organizations move online, strategic decisions are made about the use of appropriate technology. The use of the right technology minimizes costs and improves efficiency, which is critical for business and organizational growth.

While the internet is the destination of everything business and social interactions, organizations and developers are faced with the critical decisions of better infrastructure that will be useful in other to rip the full benefits of their online investments.

Software and web developers now more than ever, must be conscious of the kind of stuck choices they make. The decisions about the security and scalability of software solutions have never been crucial until now.

Among many decisions, developers must choose the appropriate database management systems (DBMS) that are secure and scalable at all levels of business growth. There are several DBMS but this article is focused on how to install and set up a PostgreSQL database management system.

PostgreSQL is a robust, Object-relational database system developed and maintained by a strong and vibrant open source community. PostgreSQL is noted for its reliability, feature robustness, and performance.

This article is the first in a series of articles towards designing a Car Rental DBMS using PostgreSQL. We shall first deal with how to install PostgreSQL on Linux, macOS, and Windows.

To Install PostgreSQL on Linux Machines

The popular Linux distros can easily be grouped into Debian/Ubuntu and Red Hat/CentOS. So we shall discuss how to install Postgres on these two distros.

Most Debian distros come with preinstalled PostgreSQL. But the ‘snapshot’ version is more stable and supported and maintained throughout the lifespan of the given distro.

There is also an apt version maintained by the PostgreSQL Project team with full support and continuous updates.

Let us first check the version of the preinstalled Postgres. To do that you run the following script in the terminal.

pan@admin:~$ psql --version

The output will look something like the below.

psql (PostgreSQL) 12.5

At the time of writing this article, version 12.5 was what was installed on my computer.

As a matter of practice, you should always update your OS and upgrade if possible before any major installations. Run the following to update and upgrade your Linux before any installations.

pan@admin:~$ sudo apt update && sudo apt upgrade

You can upgrade the preinstalled Postgres on any Debian distribution by simply running the following scripts in the terminal. If you are not using root access precede your script by a sudo argument.

pan@admin:~$ sudo apt-get install PostgreSQL-12

This will update say your Postgres version 9.6.20 to the latest version 12. And remember to update your repositories after the installation by running the updates command in your terminal.

To install from an Apt Repository Maintained by PostgreSQL Project Team.

To have a successful installation and be able to update and upgrade your Postgres DBMS from the progress Project, follow the following steps;

Create the file repository configuration by running the following script.

pan@admin:~$ sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

Import the repository signing key.

pan@admin:~$ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

Update package lists.

pan@admin:~$ sudo apt-get update

Install the latest version of PostgreSQL.

pan@admin:~$ sudo apt-get -y install postgresql

If you want a specific version, you can specify it by indicating it in the script. Assuming we wanted to install version 12 instead;

pan@admin:~$ sudo apt-get -y install postgresql-12

Red Hat Enterprise, CentOS, Scientific, or Oracle Version 8 from yam Repositories.

Install the repository RPM.

pan@admin:~$ sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm

Disable the built-in PostgreSQL module.

pan@admin:~$ sudo dnf -qy module disable postgresql

Install PostgreSQL.

pan@admin:~$ sudo dnf install -y postgresql13-server

Optionally initialize databases.

pan@admin:~$ sudo /usr/pgsql-13/bin/postgresql-13-setup initdb

pan@admin:~$ sudo systemctl enable postgresql-13 pan@admin:~$ sudo systemctl start postgresql-13

Post Installation Activities on Red Hat Distros

Red Hat's internal policies do not allow automatic access to PostgreSQL after installation. To initialize the PostgreSQL database system, you need to complete the installation by performing the following setup activities.

For RHEL/CentOS/SL/OL6

service postgresql initdb

chkconfig postgresql on

For RHEL / CentOS / SL / OL 7, 8 Or Fedora 31 And Later Derived Distributions

postgresql-setup --initdb

systemctl enable postgresql.service

systemctl start postgresql.service

You can also simply download it from the PostgreSQL Project website and do the manual installation on any of the Red Hat distros if you are not a fan of the terminal.