Bobcares

How to install PostgreSQL on Centos 7?

by | Oct 13, 2020

Webmasters can perform the install of PostgreSQL on Centos either from the default Centos repositories or from the Postgres repositories.

As a part of our Server Management Services, we help our Customers with software installations regularly.

Let us today discuss the steps to Install PostgreSQL on Centos.

Install PostgreSQL on Centos

Postgres can be installed using default Centos repositories. To install from the Centos repositories, simply run:

$ sudo yum install postgresql-server postgresql-contrib

Now, initialize your Postgres database and start PostgreSQL:

$ sudo postgresql-setup initdb
$ sudo systemctl start postgresql

Optionally, we can also configure PostgreSQL to start on boot with the command below:

$ sudo systemctl enable postgresql

Install PostgreSQL on Centos from Postgres repository

Sometimes, the version that is available in the CentOS 7 Base repository is obsolete. Therefore, we can use the official Postgres repository.

Here, initially, we need to exclude the search for postgresql packages from the CentOS-Base repository. Otherwise, dependencies might resolve to the postgresql supplied by the base repository.

Open the repository configuration file using any text editor.

$ sudo vi /etc/yum.repos.d/CentOS-Base.repo

Find the [base] and [updates] sections, and insert the exclude=postgresql* line in both sections. As a result, the file will look like the following, with new lines highlighted:

...
[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

exclude=postgresql*

#released updates
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
exclude=postgresql*
...

Once finished, save and exit the file.

Now, install a repository configuration package using the official PostgreSQL repository for CentOS:

$ sudo yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

When given the prompt, confirm the installation with y.

The PostgreSQL repository includes information for all available PostgreSQL releases. We can view all available packages and versions using the following command:

$ yum list postgresql*

Choose and install the desired version of PostgreSQL. In this article, let us use the PostgreSQL 11 release.

To install the PostgreSQL server, use the following command:

$ sudo yum install postgresql11-server

During the installation process, we will be asked about importing a GPG key. Confirm it with y so the installation can complete.

Now that the software is installed, we will perform some initialization steps to prepare a new database cluster for PostgreSQL.

Creating a New PostgreSQL Database Cluster

We have to create a new PostgreSQL database cluster before we can use the Postgres database. Creating a database cluster consists of creating the directories to place the database data, generating the shared catalog tables, and creating the template1 and postgres databases.

Create a new PostgreSQL database cluster with initdb:

$ sudo /usr/pgsql-11/bin/postgresql-11-setup initdb

You will see the following output:

Initializing database … OK

Now start and enable PostgreSQL using systemctl:

$ sudo systemctl start postgresql-11
$ sudo systemctl enable postgresql-11

This will give the following output:

Created symlink from /etc/systemd/system/multi-user.target.wants/postgresql-11.service to /usr/lib/systemd/system/postgresql-11.service.

At this stage, PostgreSQL is up and running on the server.

[Need any further assistance to install PostgreSQL on Centos? – We’re available 24*7]

 

Conclusion

In short, PostgreSQL installation can be performed either from the default Centos repositories or from the Postgres repositories. Today, we saw how our Support Engineers install PostgreSQL on Centos.

 

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

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

Never again lose customers to poor
server speed! Let us help you.