How To Install PostgreSQL on RHEL 8


PostgreSQL is a free, open source object-relational database management system (ORDBMS) available for various platforms including Linux, Microsoft Windows, and Mac OS X.

PostgreSQL is developed by the PGDG (PostgreSQL Global Development Group) and released under the PostgreSQL License, a free and open source software.

In this post, we will see how to install PostgreSQL on RHEL 8.

PostgreSQL is now available for RHEL 8 from for Red Hat’s Application Stream (rhel-8-for-x86_64-appstream-rpms) repository. So, you won’t need to add any other repository.

Install PostgreSQL

Install PostgreSQL using yum command.

### PostgreSQL 10 ###

yum install -y @postgresql

### PostgreSQL 9.6 ###

yum install -y @postgresql:9.6

Initialize PostgreSQL Server

After installing PostgreSQL, initialize the database before using it for the first time.

postgresql-setup --initdb


 * Initializing database in '/var/lib/pgsql/data'
 * Initialized, logs are in /var/lib/pgsql/initdb_postgresql.log

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

Manage PostgreSQL Service

To start PostgreSQL service, run:

systemctl start postgresql

To enable PostgreSQL on system startup, run:

systemctl enable postgresql

To check the status of PostgreSQL service, run:

systemctl status postgresql


Install PostgreSQL On RHEL 8 - PostgreSQL Service Status
Install PostgreSQL On RHEL 8 – PostgreSQL Service Status

Configure PostgreSQL Server

By default, PostgreSQL listens on localhost. Only applications running on the server itself can connect to the database server by default and restricts external applications from connecting to the database.

To enable the database service access for external machines, edit the configuration file.

vi /var/lib/pgsql/data/postgresql.conf

Set the listen_addresses to *.

listen_addresses = '*'

Restart PostgreSQL service.

systemctl restart postgresql

Confirm the PostgreSQL listening on port 5432 on all network interface using the netstat command.

netstat -antup | grep 5432


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

Access PostgreSQL server

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

# su -l postgres

Access the database using the psql command.

$ psql


[[email protected] ~]$ psql
psql (10.6)
Type "help" for help.


Set password for postgres (Database administrator) user.

postgres=# \password


In this post, you have learned how to install PostgreSQL on RHEL 8. Please share your feedback in the comments section.

You might also like