SoFunction
Updated on 2025-03-09

Detailed explanation of CentOS7 PostgreSQL installation, configuration and use

CentOS7 PostgreSQL installation

Install

Install

Install using yum

yum install /9.4/redhat/rhel-6-x86_64/pgdg-redhat94-9.
yum install postgresql94-server postgresql94-contrib

Set up startup

systemctl enable postgresql-9.
systemctl start postgresql-9.

Initialize the database

/usr/pgsql-9.4/bin/postgresql94-setup initdb

Enable remote access

/var/lib/pgsql/9.4/data/

listen_addresses ='*'

/var/lib/pgsql/9.4/data/pg_hba.conf

# IPv4 local connections:
host  all       all       127.0.0.1/32      trust
host  all       all       192.168.117.1/32    trust
# IPv6 local connections:
host  all       all       ::1/128         trust

Modify user password

su postgres
psql -U postgres
ALTER USER postgres WITH PASSWORD 'P0stgres'
\q

Firewall

Create a new file /usr/lib/firewalld/services/

<?xml version="1.0" encoding="utf-8"?>
<service>
    <short>Postgres 9.4 Database service</short>
    <description>Postgres</description>
    <portprotocol="tcp"port="5432"/>
</service>

Modify firewall settings

firewall-cmd --permanent --add-service=postgres94
firewall-cmd --reload

Thank you for reading, I hope it can help you. Thank you for your support for this site!