Linux, Windows, Virtualization, OpenSource & Blogging

Install PostgreSQL 10 on CentOS 7 / RHEL 7

6

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 10 on CentOS 7 / RHEL 7.

Open  a terminal ( Applications >> System Tools >> Terminal).

Switch to the root user.

$ su -

Install PostgreSQL 10 on CentOS 7

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 https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-1.noarch.rpm

Install PostgreSQL 10 using yum command.

yum install -y postgresql10-server postgresql10

Initialize PostgreSQL server

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

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

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

Start PostgreSQL server

To start PostgreSQL service, run:

systemctl start postgresql-10

To enable PostgreSQL on system startup, run:

systemctl enable postgresql-10

To check the status of PostgreSQL service, run:

systemctl status postgresql-10

Output:

 postgresql-10.service - PostgreSQL 10 database server
   Loaded: loaded (/usr/lib/systemd/system/postgresql-10.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2017-10-23 17:54:14 UTC; 6min ago
 Main PID: 1557 (postmaster)
   CGroup: /system.slice/postgresql-10.service
           ├─1557 /usr/pgsql-10/bin/postmaster -D /var/lib/pgsql/10/data/
           ├─1560 postgres: logger process   
           ├─1562 postgres: checkpointer process   
           ├─1563 postgres: writer process   
           ├─1564 postgres: wal writer process   
           ├─1565 postgres: autovacuum launcher process   
           ├─1566 postgres: stats collector process   
           └─1567 postgres: bgworker: logical replication launcher   

Oct 23 17:54:14 post systemd[1]: Starting PostgreSQL 10 database server...
Oct 23 17:54:14 post postmaster[1557]: 2017-10-23 17:54:14.578 UTC [1557] LOG:  listening on IPv6 address "::1", port 5432
Oct 23 17:54:14 post postmaster[1557]: 2017-10-23 17:54:14.578 UTC [1557] LOG:  listening on IPv4 address "127.0.0.1", port 5432
Oct 23 17:54:14 post postmaster[1557]: 2017-10-23 17:54:14.584 UTC [1557] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
Oct 23 17:54:14 post postmaster[1557]: 2017-10-23 17:54:14.587 UTC [1557] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
Oct 23 17:54:14 post postmaster[1557]: 2017-10-23 17:54:14.597 UTC [1557] LOG:  redirecting log output to logging collector process
Oct 23 17:54:14 post postmaster[1557]: 2017-10-23 17:54:14.597 UTC [1557] HINT:  Future log output will appear in directory "log".
Oct 23 17:54:14 post systemd[1]: Started PostgreSQL 10 database server.

Confirm the PostgreSQL listening on port 5432 using netstat command.

netstat -antup | grep 5432

Output:

tcp        0      0 0.0.0.0:5432            0.0.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

Output:

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

postgres=#

Set password for postgres (Database administrator) user.

postgres=# \password

That’s all!. You have successfully installed the PostgreSQL 10 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 10 on CentOS 7 / RHEL 7

6