Install PostgreSQL on CentOS. PostgreSQL is used for a lot of business applications, and runs arguably much better on Linux than Windows (then again, what doesn’t?). This walkthrough is the original CentOS 6 install with the PGDG repository package, yum and SysV init scripts, with notes on what each step does and the current commands for RHEL, AlmaLinux and Rocky Linux 9 and 10 at the end.
Prerequisites
- A CentOS/RHEL 6 server with network access to yum.postgresql.org and the base repositories.
- Root access. Login as root.
- Disk space for your data under
/var/lib/pgsql.

1. Download the PGDG repository package
Download the repository RPM from the PostgreSQL yum site (the original link was the PostgreSQL YUM Installation page). This small noarch package does not contain PostgreSQL itself; it drops a .repo file into /etc/yum.repos.d/ that points yum at the PGDG builds.
curl -O http://yum.postgresql.org/9.1/redhat/rhel-6-i386/pgdg-centos91-9.1-4.noarch.rpm
ls


2. Install the repository RPM
Install with the following:
rpm -ivh pgdg-centos91-9.1-4.noarch.rpm


The NOKEY warning only means the PGDG signing key is not imported yet. It is safe to continue; yum will offer to import the key the first time it installs a package from the repository.
3. Find and install the packages
Search for postgres and find what you need to install:
yum list postgres*
yum install postgresql.x86_64 postgresql-server.x86_64


postgresql is the client (psql, pg_dump) and postgresql-server is the database server. Check the repository column in the yum list output: PGDG packages carry the version in their name (for example postgresql91-server, service postgresql-9.1), while the unversioned postgresql-server comes from the CentOS base repository (PostgreSQL 8.4 on CentOS 6). Install the versioned names if you want the release from PGDG.
4. Enable at boot, initialize and start
Start PostgreSQL on startup:
chkconfig postgresql on

When you try to start it you get an interesting error: the init script reports that the data directory /var/lib/pgsql/data is missing and tells you to run initdb first.

Do as it says. initdb creates the database cluster: the system catalogs, the default postgres database and the configuration files postgresql.conf and pg_hba.conf.
service postgresql initdb
service postgresql start

5. Verify
service postgresql status
su - postgres -c "psql -c 'select version();'"
The version query should return the PostgreSQL release you installed. That’s it!
Common errors
- Data directory is missing / not initialized: run
service postgresql initdb(orservice postgresql-9.1 initdbfor the PGDG package) before the first start. - FATAL: Ident authentication failed for user: the default
pg_hba.confon CentOS 6 uses ident authentication. Connect as the matching OS user (su - postgres) or change the method tomd5in/var/lib/pgsql/data/pg_hba.confand reload. - Remote clients cannot connect: set
listen_addressesinpostgresql.conf, add a host line topg_hba.conf, and open TCP 5432 in iptables.
Modern equivalent (RHEL, AlmaLinux, Rocky 9 and 10)
From the distribution AppStream repository:
dnf install postgresql-server
postgresql-setup --initdb
systemctl enable --now postgresql
From PGDG (example: PostgreSQL 17 on EL9; on EL8/EL9 disable the built-in module first):
dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm
dnf -qy module disable postgresql
dnf install -y postgresql17-server
/usr/pgsql-17/bin/postgresql-17-setup initdb
systemctl enable --now postgresql-17
For a full current walkthrough, see Install PostgreSQL on AlmaLinux 10: PGDG vs AppStream, pg_hba.conf and Remote Access and the rest of that series, including users, roles and privileges.
To get a hosted PostgreSQL/Linux Server visit www.zwiegnet.com/go to get signed up today!
Related guides: Connect CentOS to MySQL ODBC | MySQL Replication CentOS All Databases
