How to install and configure Postgresql on RHEL\Centos

Go to https://www.postgresql.org/download/ and choose your distribution (in my case RHEL family) and choose version of your OS and version of Postgresql

# yum install https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-redhat11-11-2.noarch.rpm
# yum install postgresql11
# yum install postgresql11-server
# /usr/pgsql-11/bin/postgresql-11-setup initdb

Set PostgreSQL Server to Listen Addresses and Set Port

$nano /var/lib/pgsql/11/data/postgresql.conf 

listen_addresses = ‘*’
port = 5432

Set PostgreSQL Permissions

$nano /var/lib/pgsql/11/data/pg_hba.conf

Local networks
host all all xx.xx.xx.xx/xx md5
IPv4 local connections:
host all all 127.0.0.1/32 md5

Enable to auto start after restart and run postgres, check the status of postgres

sudo systemctl enable postgresql-11
sudo systemctl start postgresql-11
sudo systemctl status postgresql-11

Set password „pass“ for user postgress

$sudo -u postgres psql
$ALTER USER postgres PASSWORD 'pass';
$ALTER ROLE
$\q

Checking for remote connection and give list of databases (My_IP = your addres)

$psql -h My_IP –p 5432 -U postgres
$\l
$\q

Check if firewall is disabled

$iptables -L

Should be something like this

Leave a Reply

Close Menu