2: Install PostgreSQL 12

sudo yum update
sudo yum install rh-postgresql12-postgresql-server.x86_64 rh-postgresql12-postgresql.x86_64
sudo yum install rh-postgresql12-postgresql-contrib.x86_64 uuid.x86_64

3: Initialize and start database service

sudo /opt/rh/rh-postgresql12/root/usr/bin/postgresql-setup initdb
sudo systemctl enable --now rh-postgresql12-postgresql

systemctl status rh-postgresql12-postgresql

sudo firewall-cmd --add-service=postgresql --permanent
sudo firewall-cmd --reload
sudo firewall-cmd --list-all

4: Set PostgreSQL admin user’s password

sudo vi /etc/profile
export LD_LIBRARY_PATH=/opt/rh/rh-postgresql12/root/usr/lib64:$LD_LIBRARY_PATH
export PATH=/opt/rh/rh-postgresql12/root/usr/bin:$PATH

sudo su - postgres 
$ psql -c "alter user postgres with password 'pg'" 

5: Enable remote access (Optional)

vi /var/opt/rh/rh-postgresql12/lib/pgsql/data/postgresql.conf
listen_addresses = 'dbhome'

vi /var/lib/pgsql/12/data/pg_hba.conf
# Accept from anywhere
host all all 0.0.0.0/0 md5

# Accept from trusted subnet
# host all all 192.168.157.0/24 md5

sudo systemctl restart rh-postgresql12-postgresql

6: Connection testing

# connect to super user
$ psql -h dbhome -d postgres -U postgres -W
Password: 
psql (12.1)
Type "help" for help.
# create new user
postgres=# create user pg with password 'pg';

# create new db
postgres=# create database pgsq owner pg; 

# grant priv to user
postgres=# grant all privileges on database pgsq to pg; 

#re-connect with new user
$ psql -h dbhome -d pgsq -U pg -W
Password: 
psql (12.1)
Type "help" for help.

pgsq=> \conninfo
You are connected to database "pgsq" as user "pg" on host "dbhome" (address "192.168.157.77") at port "5432".
pgsq=>