Install PostgreSQL on RHEL, Rocky, or AlmaLinux via PGDG

Updated

PostgreSQL elephant logo

CentOS Linux is discontinued — install on Rocky Linux, AlmaLinux, or RHEL instead. Add the PGDG repo RPM for your EL major version, then sudo dnf install -y postgresql18-server, sudo /usr/pgsql-18/bin/postgresql-18-setup initdb, and sudo systemctl enable --now postgresql-18. As of 6 October 2026, current stable is PostgreSQL 18; version 13 is EOL upstream.

Do not add host all all 0.0.0.0/0 md5 to pg_hba.conf and set listen_addresses = '*'. That’s wrong: 0.0.0.0/0 means “accept a connection attempt from any IP address on the internet,” and pairing that with listen_addresses = '*' puts your database’s login prompt in front of every scanner and bot on the internet, with only a password standing between them and your data. If you need remote access, scope the pg_hba.conf line to the actual client subnet (e.g. 10.0.0.0/24) and keep the port closed at the firewall/security-group level to everything else. “Allow the world, rely on the password” is not a configuration step this page teaches.

Do not install on CentOS. CentOS Linux — the free, stable rebuild of RHEL you could install fresh — is discontinued. CentOS 8 reached end-of-life on 31 December 2021; CentOS 7 followed on 30 June 2024. Neither gets security patches now, so installing anything on either is installing onto an unpatched OS by definition. Red Hat redirected the CentOS project into CentOS Stream, a rolling release upstream of RHEL rather than a stable downstream rebuild — not a drop-in replacement for what CentOS Linux was. The distros that are: Rocky Linux (bug-for-bug compatible with RHEL) and AlmaLinux (binary compatible with RHEL since it dropped the 1:1 aim in July 2023), both built specifically to fill the gap CentOS left.

Pin neither PostgreSQL 13 nor an EL-7 repo URL. Per PostgreSQL’s own YUM repository (yum.postgresql.org, checked 2026-10-06), version 13 is listed as “EOLed by upstream as of Nov 2025,” current stable is 18, 19’s packages are “for beta testing only,” and 20 exists only as daily alpha builds; neither is meant for production. The repository RPM pattern is per EL major version, not EL-7:

sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sudo dnf install -y postgresql18-server postgresql18
sudo /usr/pgsql-18/bin/postgresql-18-setup initdb
sudo systemctl enable --now postgresql-18

Substitute EL-8 or EL-10 for your Rocky/AlmaLinux/RHEL major version (postgresql.org, Linux downloads (Red Hat family)). On EL-8 only, that page’s generated setup script (checked 2026-10-06) adds sudo dnf -qy module disable postgresql, labelled “Disable the built-in PostgreSQL module,” between the repository RPM and the server install; it adds no such step for EL-9 or EL-10. None of this was run — there’s no RHEL-family machine here — so it’s cited, not demonstrated.

What is demonstrated, on this machine’s own PostgreSQL 17.10, is the access-control behavior the warning at the top of this page is about, using a disposable cluster on port 55499 (not the running server), torn down on exit:

$ initdb -D "$PGDATA" -U postgres --auth=trust
$ grep -vE '^\s*#|^\s*$' "$PGDATA/pg_hba.conf"
local   all             all                                     trust
host    all             all             127.0.0.1/32            trust
host    all             all             ::1/128                 trust
local   replication     all                                     trust
host    replication     all             127.0.0.1/32            trust
host    replication     all             ::1/128                 trust

$ grep -E '^\s*#?\s*listen_addresses' "$PGDATA/postgresql.conf"
#listen_addresses = 'localhost'

A freshly initialized cluster trusts only the local Unix socket and loopback, and listen_addresses defaults to localhost, commented out. Both changes — the 0.0.0.0/0 line and listen_addresses = '*' — are opt-in actions you take, never the default:

$ echo "host    all             all             0.0.0.0/0               md5" >> "$PGDATA/pg_hba.conf"
$ grep -vE '^\s*#|^\s*$' "$PGDATA/pg_hba.conf"
local   all             all                                     trust
host    all             all             127.0.0.1/32            trust
host    all             all             ::1/128                 trust
local   replication     all                                     trust
host    replication     all             127.0.0.1/32            trust
host    replication     all             ::1/128                 trust
host    all             all             0.0.0.0/0               md5

That’s the exact line warned against above, sitting in the file after a real initdb run — the point being that it’s one appended line away from the safe default, which is exactly how easy it is to get wrong if the page you’re following doesn’t warn you. The access-control demonstration needs no RHEL-family host: install-postgresql-centos.sh reproduces the fresh-cluster defaults and the appended 0.0.0.0/0 line on any machine with PostgreSQL’s server tools and checks that yum.postgresql.org answers, while the package and repository steps stay unrun.

For version coexistence and uninstall questions, this site’s Pgpool-II on CentOS page covers the same CentOS-discontinuation ground in more depth; for exactly how and when a pg_hba.conf edit takes effect, see how to reload pg_hba.conf rather than restarting the service.

Photo of author
Sudhir P. founded HeatWare.com in 1999 and has built and operated it full-stack ever since; it is now used by more than 88,000 people. He writes here about the PostgreSQL, MySQL, Linux and DevOps work that keeps it running. Articles are rewritten only after the commands in them have actually been run, and the verification scripts are published alongside them so anyone can check the claims. Reach him at blog@heatware.net.