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.