Skip to content

How to Install PostgreSQL on CentOS/RHEL 7

How to Install PostgreSQL 10 on CentOS/RHEL 7/6 and Fedora 28/27/26 Systems using yum package manager, Installing PostgreSQL on Linux based system.

Steps
3
Category
Databases
Covers
CentOS, PostgreSQL, RHEL
On this page 3 steps

PostgreSQL 10 Released. PostgreSQL is an open-source object-relational, highly scalable, SQL-compliant database management system. PostgreSQL is developed at the University of California at Berkeley Computer Science Department. This article will help you to install PostgreSQL 10 on CentOS, RHEL and Fedora Systems.

Step 1 of 3Add Postgres Yum Repository

The first step is to install PostgreSQL repository in your system, Use one of below commands as per your system architecture and operating system.

## CentOS/RHEL - 7
rpm -Uvh https://yum.postgresql.org/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm

## CentOS/RHEL - 6
rpm -Uvh https://yum.postgresql.org/10/redhat/rhel-6-x86_64/pgdg-redhat10-10-2.noarch.rpm

For more details visit PostgreSQL repositories link page where you can get repository package rpm for various operating systems.

Step 2 of 3Install PostgreSQL 10 Server

After enabling PostgreSQL yum repository in your system use following command to install PostgreSQL 10 on your system with yum package manager.

yum install postgresql10-server postgresql10

Step 3 of 3Initialize PGDATA

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

/usr/pgsql-10/bin/postgresql-10-setup initdb

Above command will take some time to initialize PostgreSQL first time. PGDATA environment variable contains the path of data directory.

PostgreSQL data directory Path: /var/lib/pgsql/10/data/

Setp 4 – Start PostgreSQL Server

To start PostgreSQL service using the following command as per your operating systems. Also, enable PostgreSQL service to autostart on system boot.

For CentOS/RHEL 7 and Fedora

systemctl start postgresql-10.service
systemctl enable postgresql-10.service

For CentOS/RHEL 6

service postgresql-10 start
chkconfig postgresql-10 on
Step 5 – Verify PostgreSQL Installation

After completing above steps, you have installed PostgreSQL 10 on your server, Let’s log in to postfix to verify that installation completed successfully.

su - postgres -c "psql"

psql (10.0)
Type "help" for help.
postgres=#

You may create a password for user postgres for security purpose.

postgres=# \password postgres

Congratulation’s! You have successfully installed PostgreSQL Server. Read below article to install phpPgAdmin.

How to Install phpPgAdmin on CentOS using Yum

Thanks for using this tutorial for installing PostgreSQL 10 on CentOS/RHEL 7/6 and Fedora 28/27/26 systems.

Rahul

Rahul Kumar is the founder and chief editor of TecAdmin.net. A Red Hat Certified Engineer (RHCE), he has worked in IT since 2009, with hands-on experience in Linux system administration, DevOps, web hosting, cloud platforms and automation. He started TecAdmin in 2013 to share practical, step-by-step guides, and leads its editorial work with one aim: making technical learning clear and useful for sysadmins, developers and beginners alike.

15 Comments

  1. Hi Rahul,

    Great!
    I can install postgresql in RHEL 7.5!!

    A hard Question: I want to restart my postgresql with “service postgresql restart” command, Should I have root profile? Or with my postgres account?

    Greetings!

    1. Hi Nikhil, Please use below command ti initialize PostgreSQL database.

      For PostgreSQL 9.6:
      # /usr/pgsql-9.6/bin/postgresql96-setup initdb

      For PostgreSQL 10:
      # /usr/pgsql-10/bin/postgresql-10-setup initdb

  2. Nice site. Laid out very well.

    This worked for me in Fedora 25 for PostgreSQL 9.6:

    Initializing PGDATA

    # /usr/pgsql-9.6/bin/postgresql96-setup initdb

  3. initdb should be executed as postgres user.
    # su – postgres
    $/usr/pgsql-9.5/bin/initdb -D /var/lib/pgsql/9.5/data

    or

    # service postgresql-9.5 initdb

  4. I was not able to initdb on my CentOS 6.7 with next command:
    > Initializing PGDATA
    # /usr/pgsql-9.5/bin/postgresql95-setup initdb

    instead for me worked following:
    # service postgresql-9.5 initdb

Leave a Reply

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


Back to top