How to Install PostgreSQL Database Server CentOS 8

PostgreSQL, also known as Postgres, is an open source relational database management system (RDBMS) that implements Structured Query Language (SQL). PostgreSQL is an enterprise-class SQL database server that allows you to build fault-tolerant and complex applications. It stores and organizes data and allows you to structurally retrieve information. PostgreSQL has many advanced features such as reliable transactions and high concurrency. In this tutorial, we will learn how to install PostgreSQL on CentOS8. So let’s get started.

Installing PostgreSQL on CentOS

There are different PostgreSQL versions in the CentOS 8 repository that you can install. To list the available streams for PostgreSQL, open a terminal and use the following command:

# dnf module list postgresql

PostgreSQL App Stream version 10 is enabled by default, to install the latest postgresql App Stream which is Stream12 you need to enable its repository using the following command, you can enable PostgreSQL Stream 12:

# dnf module enable postgresql:12

Enable postgresql stream 12

After enabling the latest version of PostgreSQL 12. Now we can install PostgreSQL using the following command:

# dnf install postgresql-server

Install PostgreSQL Server

With the software now installed, you need to complete some initial steps to prepare and configure your new database cluster by using the following command:

# dnf install postgresql-initdb

Initialize database

After initialization, start and enable the PostgreSQL service using the following command:

# systemctl enable postgresql
# systemctl start postgresql

After turn on and Start service, check the status of the service by running the following command shown below:

# systemctl status postgresql

Check postgres service status

The above screenshot shows the service is running.

Enable remote access to PostgreSQL server

By default the PostgreSQL server only listens on the local interface, to enable PostgreSQL for remote access, open the config file postgresql.conf by typing the following command:

# vim /var/lib/pgsql/data/postgresql.conf

PostgreSQL remote access

Scroll down to Connections and Authentication section and edit the following line by uncommenting:


Customize Listening Interface in PostgreSQL

This will also provide access for remote users. Save and close the configuration file and restart the PostgreSQL service by entering the following command:

# systemctl restart postgresql

You can also make sure PostgreSQL access is allowed for all users using the following command:

# netstat –atnp | grep 5432

PostgreSQL listens on all interfaces

The above output shows the PostgreSQL server is running on default ports on all interfaces.

Configure PostgreSQL Firewall

PostgreSQL uses port 5432 to connect. To allow PostgreSQL from the firewall for remote access, use the following command:

# firewall-cmd –add-port=5432/tcp –permanent

# firewall-cmd –reload

The final steps are to allow the server to accept remote connections for this edit “pg_hba.conf“configuration file. The file is located”/ var / library / pgsql / data /“Catalog.

PostgreSQL firewalld configuration


In this tutorial, we learned how to install PostgreSQL on CentOS 8. We also saw how to allow PostgreSQL for dial-up connections, how to add a firewall rule to allow remote access. I hope this tutorial helps you set up PostgreSQL on Centos 8.

How to Install PostgreSQL Database Server CentOS 8