How to install and setup PostgreSQL on RHEL 8

https‮//:‬www.lautturi.com
How to install and setup PostgreSQL on RHEL 8

To install and set up PostgreSQL on Red Hat Enterprise Linux (RHEL) 8, follow these steps:

  1. Enable the PostgreSQL module repository by running the following command:
dnf module enable postgresql:12
  1. Install the PostgreSQL server package using the following command:
dnf install postgresql-server
  1. Initialize the PostgreSQL database using the following command:
/usr/pgsql-12/bin/postgresql-12-setup initdb
  1. Start the PostgreSQL service and enable it to start at boot time using the following commands:
systemctl start postgresql-12
systemctl enable postgresql-12
  1. By default, PostgreSQL listens on a Unix socket located at /var/run/postgresql. To access the database from a remote machine, you will need to configure PostgreSQL to listen on a network interface. To do this, edit the /var/lib/pgsql/12/data/postgresql.conf file and set the listen_addresses parameter to '*'.

  2. You will also need to configure PostgreSQL to accept connections from remote clients. To do this, edit the /var/lib/pgsql/12/data/pg_hba.conf file and add the following line:

host    all             all             0.0.0.0/0               md5

This will allow any client to connect to the database using a password.

  1. Restart the PostgreSQL service to apply the changes:
systemctl restart postgresql-12
  1. To create a new PostgreSQL user and database, connect to the database using the psql command-line client:
sudo -u postgres psql

Then, use the CREATE USER and CREATE DATABASE commands to create the user and database, respectively:

CREATE USER username WITH PASSWORD 'password';
CREATE DATABASE database_name WITH OWNER username;
Created Time:2017-10-28 21:39:04  Author:lautturi