how to install PostgreSQL

Install And Configure PostgreSQL Database on CentOS 7

At this time, we are going to install and configure the PostgreSQL database on our CentOS 7 which is running on VM environment. There are two repositories that can be used as sources for the Postgres database installation, namely: CentOS repository and PostgreSQL repository . This article will use PostgreSQL repository as software sources.

PostgreSQL is a free and open-source relational database management system (RDBMS) emphasizing extensibility and technical standards compliance. PostgreSQL was developed by PostgreSQL Global Development Group and is distributed freely according to the BSD license agreement. Like mysql, postgres is a favorite choice of developers in building applications from small-scale applications to high workload enterprise applications.

PostgreSQL Installation

The latest stable version of PostgreSQL is version 12.0 which was released on 03 October 2019. At this article, the installation process will be divided into three stages:

The PostgreSQL Repository has been ready on postgresql.org website. The guidelines can be followed on this website, as screen shot below, read and enter the questions with the appropriate answers.

how to install postgresql on centos 7 : repository website

1. Prerequisite

Before continuing the first step, as alwasy on Linux environment we have to update our CentOS 7 environment by typing the command below.

[ramans@localhost ~]$ sudo yum update
how to install postgresql on centos 7 : update centos 7 repository



2. Download PostgreSQL from Repository

The PostgreSQL source could be download from official source located on https://www.postgresql.org/download. You must select the platfrom target as ‘Redhat Enterprise, CentOS, Scientific or Oracle version 7 suitable with our CentOS 7 platform‘ and select architecture as ‘x86_64‘, we got the repository RPM as below :

yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
how to install postgresql on centos 7 : download postgresql

3. Install PostgreSQL

After the RPM file has been dowloaded to our repository, then we install PostgreSQL for client and server. The first, must be the client and then for the server as recommendation.

[ramans@localhost ~]$ yum install postgresql12
how to install postgresql on centos 7 : install postgresql 12
Install PostgreSQL client
[ramans@localhost ~]$ yum install postgresql12-server 
Install PostgreSQL server

The last installation process is to initialize the database and enable it to automatically start.

[ramans@localhost ~]$ /usr/pgsql-12/bin/postgresql-12-setup initdb 
[ramans@localhost ~]$ systemctl enable postgresql-12 
[ramans@localhost ~]$ systemctl start postgresql-12 

4. Verify The PostgreSQL Installation

The last process is to verify the installation, we can try to connect to the PostgreSQL database server from any client application e.g., psql and pgAdmin, ussualy through the psql program. We tried by creating new database and new database user, the command is as below:

[ramans@localhost ~]$ sudo su - postgres
-bash-4.2$ psql
postgres=# \l
postgres=# create database rapdb;
postgres=# create user rapusr;
create new DB and user on PostgreSQL
create new DB and user on PostgreSQL

This is the last step, you can try this at your environment. Have a nice day !

Share this article via :

Leave a Reply

Your email address will not be published. Required fields are marked *