Linux, Windows, Virtualization, OpenSource & Blogging

Install PostgreSQL 9.6 on CentOS 7 / RHEL 7


PostgreSQL is an object-relational database management system (ORDBMS) available for many platforms including Linux, FreeBSD, Solaris, Microsoft Windows and Mac OS X. It is released under the PostgreSQL License, which is a MIT-style license, a free and open source software.

PostgreSQL is developed by the PostgreSQL Global Development Group, consisting of a handful of community volunteers employed and supervised by companies such as Red Hat and EnterpriseDB.

The vast majority of Linux distributions have PostgreSQL available in supplied packages.

Here is the tutorial about installing PostgreSQL 9.6 on CentOS 7 / RHEL 7.

Open Terminal ( Applications —> System Tools —> Terminal).

Switch to the root user.

$ su -

Install PostgreSQL 9.6

PostgreSQL publishes rpm packages for all Linux platforms, and their packages are fresher than those available in the OS repositories.

So, you need to add the repository on your machine by installing repo rpm.

rpm -Uvh

Install PostgreSQL 9.6 using yum command.

yum install -y postgresql96 postgresql96-server

Initialize PostgreSQL 9.6 server

After installing PostgreSQL, you need to initialize it before using for the first time.

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

PostgreSQL data is typically found /var/lib/pgsql/9.6/data/ directory.

Start PostgreSQL server

To start PostgreSQL service, run:

systemctl start postgresql-9.6.service

To enable PostgreSQL on system startup, run:

systemctl enable postgresql-9.6.service

To check the status of PostgreSQL service, run:

systemctl status postgresql-9.6.service


 postgresql-9.6.service - PostgreSQL 9.6 database server
   Loaded: loaded (/usr/lib/systemd/system/postgresql-9.6.service; disabled; vendor preset: disabled)
   Active: active (running) since Mon 2017-09-18 15:55:43 UTC; 8min ago
  Process: 21463 ExecStartPre=/usr/pgsql-9.6/bin/postgresql96-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
 Main PID: 21469 (postmaster)
   CGroup: /system.slice/postgresql-9.6.service
           ├─21469 /usr/pgsql-9.6/bin/postmaster -D /var/lib/pgsql/9.6/data/
           ├─21472 postgres: logger process   
           ├─21474 postgres: checkpointer process   
           ├─21475 postgres: writer process   
           ├─21476 postgres: wal writer process   
           ├─21477 postgres: autovacuum launcher process   
           └─21478 postgres: stats collector process   

Sep 18 15:55:43 postc7 systemd[1]: Starting PostgreSQL 9.6 database server...
Sep 18 15:55:43 postc7 postmaster[21469]: < 2017-09-18 15:55:43.989 UTC > LOG:  redirecting log output to logging collector process
Sep 18 15:55:43 postc7 postmaster[21469]: < 2017-09-18 15:55:43.989 UTC > HINT:  Future log output will appear in directory "pg_log".
Sep 18 15:55:43 postc7 systemd[1]: Started PostgreSQL 9.6 database server.

Confirm the PostgreSQL listening on port 5432 using netstat command.

netstat -antup | grep 5432


tcp        0      0  *               LISTEN      21051/postmaster    
tcp6       0      0 :::5432                 :::*                    LISTEN      21051/postmaster 

READ: netstat command not found on CentOS 7 / RHEL 7 – Quick Fix

Access PostgreSQL server

To create a database, log in as postgres (Linux user). Login from the root user or reset the password of postgres user for login.

# su -l postgres

Access Database using the psql command, an interactive front-end terminal for PostgreSQL database.

$ psql


-bash-4.2$ psql 
psql (9.6.5)
Type "help" for help.


Set password for postgres (Database administrator) user.

postgres=# \password

That’s all!. You have successfully installed the PostgreSQL 9.6 on CentOS 7 / RHEL 7.


You might also like
  • xander

    Timely and concise. Just what I needed. Thanks!

  • Richard

    Thanks! It works!

  • Ken

    I just spent 3 days trying to get the postgresql server running on CentOS 7 until I found this tutorial! Got it up and running with this!

    Thank you for the step by step instructions!

  • cornelio

    Timely and concise. Just what I needed. Thanks!

  • rattlytocho

    thanks all work fine

  • Elio Pez

    Great! Thanks! Working Sept 2017 :)! thumbs up 😀

Install PostgreSQL 9.6 on CentOS 7 / RHEL 7