How to install PostgreSQL in CentOS Linux

PostgreSQL project provides a repository of packages of all supported versions for the most common distributions.Below are the steps for installing PostgreSQL in Linux CentoS 7.

Details

  • PostgreSQL : Version 12
  • Platform : CentOs 7
  • Architecture : x86_64
  • Steps: Run below commnds with sudo priviliges for installation.
    • Install the repository RPM
    • sudo yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
    • Install the client packages
    • sudo yum install postgresql12
    • Install the server packages
    • sudo yum install postgresql12-server
    • Initialize the database and enable automatic start
    • sudo /usr/pgsql-12/bin/postgresql-12-setup initdb
      sudo systemctl enable postgresql-12
      sudo systemctl start postgresql-12

    After installation follow below steps to login to PostgreSQL.By default a user with name "postgres" is created after installtation.

    • Switch to postrges user.
    • sudo su - postgres
    • Switch to psql — PostgreSQL interactive terminal
    • psql
    • Create new database
    • CREATE DATABASE test_db;
    • Switch to test_db
    • \c test_db

    Categories: Linux