To install and set up PostgreSQL on Red Hat Enterprise Linux (RHEL) 8, follow these steps:
dnf module enable postgresql:12
dnf install postgresql-server
/usr/pgsql-12/bin/postgresql-12-setup initdb
systemctl start postgresql-12 systemctl enable postgresql-12
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 '*'
.
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.
systemctl restart postgresql-12
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;