How to install and setup PostgreSQL on RHEL 8

To install and set up PostgreSQL on RHEL 8, you can follow these steps:

  1. Enable the PostgreSQL repository by running:
sudo dnf install https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
  1. Install the PostgreSQL server package by running:
sudo dnf install postgresql12-server
  1. Initialize the database by running:
sudo /usr/pgsql-12/bin/postgresql-12-setup initdb
  1. Start and enable the PostgreSQL service by running:
sudo systemctl start postgresql-12
sudo systemctl enable postgresql-12
  1. Allow PostgreSQL to listen on all interfaces by editing the file /var/lib/pgsql/12/data/postgresql.conf and set listen_addresses = ‘*’
  2. Configure the firewall to allow PostgreSQL traffic by running
sudo firewall-cmd --permanent --add-service=postgresql
sudo firewall-cmd --reload
  1. Create a PostgreSQL superuser by running:
sudo su - postgres
createuser --interactive
  1. Connect to the database and create a database by running:
psql -U <superuser_name>
CREATE DATABASE <database_name>;

Once you are done with the above steps, you should have a working installation of PostgreSQL on your RHEL 8 system.

You can also verify the installation by connecting to the database using the psql command :

psql -U <superuser_name> -d <database_name>

and check the version using the command

SELECT version();

You also need to create a new user and grant them access to the database if you want to use the database from an application.

Leave a Comment