Categories: CentOSLinuxShell

How to install PostgreSQL Database Server CentOS 8

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 CentOS 8. 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

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

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

# dnf install postgresql-server

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

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

The above screenshot show that the service is running.

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

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

listen_addresses = '*'

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

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.

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.

Karim Buzdar

About the Author: Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. You can reach Karim on LinkedIn

Recent Posts

How to Install Magento 2 on AlmaLinux

Magento is a free and open-source e-commerce platform written in PHP. It is simple, easy…

1 year ago

How to Install ISPConfig Hosting Control Panel with Apache Web Server on Ubuntu 24.04

ISPConfig is an open-source control panel that allows users to manage multiple servers from a…

1 year ago

How to Test your Email Server (SMTP) Using the Telnet Command

As a Linux administrator, you may find it necessary to troubleshoot or test your Simple…

1 year ago

Managing Network Interfaces and Settings on Ubuntu 24.04 with nmcli

Ubuntu 24.04, like many modern Linux distributions, relies on the NetworkManager for managing network connections.…

2 years ago

Using Restic Backup on Ubuntu 24.04

Restic is a modern, open-source backup program designed for efficiency, security, and simplicity. It enables…

2 years ago

Installing phpMyAdmin on Rocky Linux 9 and Securing it with Let’s Encrypt SSL

phpMyAdmin is a popular free tool written in PHP intended to administer MySQL and MariaDB…

2 years ago