How to install and setup PostgreSQL on RHEL 8
To install and set up PostgreSQL on RHEL 8, you can follow these steps:
- 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- Install the PostgreSQL server package by running:
sudo dnf install postgresql12-server- Initialize the database by running:
sudo /usr/pgsql-12/bin/postgresql-12-setup initdb- Start and enable the PostgreSQL service by running:
sudo systemctl start postgresql-12
sudo systemctl enable postgresql-12- Allow PostgreSQL to listen on all interfaces by editing the file /var/lib/pgsql/12/data/postgresql.conf and set listen_addresses = '*'
- Configure the firewall to allow PostgreSQL traffic by running
sudo firewall-cmd --permanent --add-service=postgresqlrnsudo firewall-cmd --reload- Create a PostgreSQL superuser by running:
sudo su - postgresrncreateuser --interactive- 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.
