Hero Image

Install PostgreSQL on AlmaLinux 9

Install PostgreSQL on AlmaLinux 9

Step 1 – Install PostgreSQL

dnf install -y postgresql-server postgresql-contrib
postgresql-setup --initdb
systemctl enable --now postgresql

Step 2 – Connect as the postgres superuser

sudo -u postgres psql

Step 3 – Create a database and user

CREATE USER appuser WITH PASSWORD 'StrongPass123!';
CREATE DATABASE appdb OWNER appuser;
GRANT ALL PRIVILEGES ON DATABASE appdb TO appuser;
\q

Step 4 – Key configuration files

File Purpose
/var/lib/pgsql/data/postgresql.conf Main server settings
/var/lib/pgsql/data/pg_hba.conf Client authentication rules
/var/lib/pgsql/data Data directory

Step 5 – Allow remote connections (optional)

Edit /var/lib/pgsql/data/postgresql.conf:

listen_addresses = '*'

Edit /var/lib/pgsql/data/pg_hba.conf and add:

host  appdb  appuser  0.0.0.0/0  scram-sha-256

Reload:

systemctl reload postgresql 2>/dev/null || \
rc-service postgresql-14 reload 2>/dev/null || \
rcctl reload postgresql