Install Postgres on Cent OS.
Update System Packages:
sudo yum update
Install PostgreSQL:
sudo yum install postgresql-server
Initialize the Database:
sudo postgresql-setup initdb
Start and Enable PostgreSQL Service:
sudo systemctl start postgresql
sudo systemctl enable postgresql
Then finally setup according to the below description to enable publish access.
sudo nano /var/lib/pgsql/data/pg_hba.conf
Make sure the following line is uncommented or added:
host all all 0.0.0.0/0 md5
sudo nano /var/lib/pgsql/data/postgresql.conf
Find the line that starts with listen_addresses and change its value to '*':
listen_addresses = '*'
Restart PostgreSQL:
sudo systemctl restart postgresql
Configure Firewall:
If you have a firewall enabled, you need to allow incoming connections on the PostgreSQL port (default is 5432):
sudo firewall-cmd --zone=public --add-port=5432/tcp --permanent
sudo firewall-cmd --reload
Switch to the postgres user:
sudo su - postgres
Switch to the postgres System User
Peer authentication works if the system user matches the PostgreSQL role. Switch to the postgres system user and then connect:
sudo -i -u postgres
psql
ALTER USER postgres WITH PASSWORD 'postgres_password';
Exit the PostgreSQL prompt:
\q
Switch back to your regular user account:
exit
Now you are ready to login