Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Databases»PostgreSQL»How to Install PostgreSQL on CentOS/RHEL 7

    How to Install PostgreSQL on CentOS/RHEL 7

    By RahulOctober 3, 20172 Mins ReadUpdated:April 20, 2022

    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.

    Advertisement

    Step 1 – Add 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 – Install 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 – Initialize 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.

    pg_data postgres PostgreSQL psql
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    How to Install Postgres on MacOS

    How To Install PostgreSQL on MacOS

    How to Allow Remote Connections in Postgres

    How To Configure PostgreSQL to Allow Remote Connections

    Check the PostgreSQL Version

    How to Check the PostgreSQL Version

    View 15 Comments

    15 Comments

    1. Bill K. on February 14, 2019 3:18 pm

      Great Article,! one slight update, yum repository for RHEL7 should be:
      ## CentOS/RHEL – 7
      rpm -Uvh https://yum.postgresql.org/10/redhat/rhel-7-x86_64/pgdg-redhat10-10-2.noarch.rpm

      Reply
    2. George on October 26, 2018 6:34 pm

      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!

      Reply
      • Prathamesh Keshav Shilkar on April 23, 2021 9:22 am

        Yes, You need to have root user access to start PostgreSQL service

        Reply
    3. Jay on November 2, 2017 2:02 pm

      Thanks buddy… Just installed Postgresql 10 on CentOS system

      Reply
    4. Nikhil Kulshrestha on August 10, 2017 7:26 pm

      service postgresql-9.6 initdb

      this command is showing failed

      Reply
      • Rahul K. on October 11, 2017 10:35 am

        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

        Reply
    5. Dave on May 8, 2017 10:13 pm

      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

      Reply
    6. Ashish Sharma on March 25, 2017 9:18 pm

      Last command should be

      postgres=# password postgres

      Reply
      • Rahul K. on March 26, 2017 3:13 am

        Thanks Ashish,

        Tutorials has been updated.

        Reply
    7. SG on August 28, 2016 11:31 am

      your final command

      postgres=# password postgres

      How does that work?

      Reply
      • Ashish Sharma on March 25, 2017 9:19 pm

        postgres=# password postgres

        Reply
    8. Ajayakumar BS on March 4, 2016 12:44 am

      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

      Reply
      • saïd on April 9, 2017 1:42 am

        I totally agrre. It is too dangerous to run as a root user !!!

        Reply
        • Rahul K. on April 10, 2017 9:27 am

          Hi said/Ajayakumar,

          Thanks for your views. I have updated tutorial as per suggestion of Ajayakumar BS.

          Reply
    9. ALZ on February 15, 2016 9:02 am

      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

      Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Error: EACCES: permission denied, scandir (Resolved)
    • How To Install Python 3.11 on Ubuntu 22.04 / 20.04
    • How to Install Python 3.11 on Amazon Linux 2
    • An Introduction to the “./configure” Command: Compiling Source Code in Linux
    • How to Install PHP 8.x on Pop!_OS
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.