PostgreSQL, also known as Postgres, is an open-source relational database management system (RDBMS) that implements the Structural 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 the retrieval of information in a structural way. PostgreSQL has many advanced features like reliable transactions and high concurrency. In this tutorial, we will learn how to install PostgreSQL on CentOS8. So let’s get started.

PostgreSQL Installation on CentOS

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

# dnf module list postgresql

How to install PostgreSQL Database Server CentOS 8 centos linux shell

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

# dnf module enable postgresql:12

How to install PostgreSQL Database Server CentOS 8 centos linux shell

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

# dnf install postgresql-server

How to install PostgreSQL Database Server CentOS 8 centos linux shell

Now the Software is installed, needs to perform some initial steps to prepare and set up a new database cluster, for this use the following command:

# dnf install postgresql-initdb

How to install PostgreSQL Database Server CentOS 8 centos linux shell

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

# systemctl enable postgresql
# systemctl start postgresql

After enable and start the service, verify the status of the service by running the following command shown below:

# systemctl status postgresql

How to install PostgreSQL Database Server CentOS 8 centos linux shell

The above screenshot show that the service is running.Advertisement

Enable remote access to PostgreSQL server

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

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

How to install PostgreSQL Database Server CentOS 8 centos linux shell

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

listen_addresses = '*'

How to install PostgreSQL Database Server CentOS 8 centos linux shell

It will enable access for remote users as well. Save and close the configuration file and restart the PostgreSQL service by typing the following command:

# systemctl restart postgresql

You can also verify that PostgreSQL access is enabled for all user, use the following command:

# netstat –atnp | grep 5432

How to install PostgreSQL Database Server CentOS 8 centos linux shell

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

Configure Firewall for PostgreSQL

PostgreSQL uses port 5432 for its connection. To allow PostgreSQL from the firewall for remote access uses the following command:

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

# firewall-cmd –reload

The last steps is to allow the server to accept the remote connections for this edit “pg_hba.conf” configuration file. The file is located “/var/lib/pgsql/data/” directory.

How to install PostgreSQL Database Server CentOS 8 centos linux shell

Conclusion

In this tutorial, we have learned how to install PostgreSQL on CentOS 8. We also saw, how to allow PostgreSQL for remote access connection, how to add a Firewall rule to enable access for the remote. I hope this tutorial will help you in setting up PostgreSQL on Centos 8.