Install PostgreSQL 9.4 on Fedora 23/22, CentOS/RHEL/SL 7.2/6.7/5.11

This is guide, howto install PostgreSQL 9.4 (currently 9.4.5) database server on Fedora 23/22/21/20/19, CentOS/Red Hat (RHEL)/Scientific Linux (SL) 7.2/6.7/5.11. This guide uses PostgreSQL own YUM repos, which are always up-to-date and stable releases are available instantly.

Note: If you are upgrading PostgresSQL (from earlier version), then make sure that you backup (dump and copy) your database and configs.

1. Install PostgreSQL 9.4.5 Database Server on Fedora 23/22/21/20/19, CentOS/Red Hat (RHEL)/Scientific Linux (SL) 7.2/6.7/5.11

1.1 Change root user

1.2 Exclude Fedora, CentOS, Red Hat (RHEL) and Scientific Linux (SL) own PostgreSQL Packages

This is important step to get PostgreSQL repository working properly. Exclude PostgreSQL packages from the repository of the distro.


Add exclude to /etc/yum.repos.d/fedora.repo file [fedora] section:

Add exclude to /etc/yum.repos.d/fedora-updates.repo file [updates] section:


Add exclude to /etc/yum.repos.d/CentOS-Base.repo file [base] and [updates] sections:

Red Hat (RHEL)

Add exclude to /etc/yum/pluginconf.d/rhnplugin.conf file [main] section:

Scientific Linux (SL)

Add exclude to /etc/yum.repos.d/sl.repo file [sl] and [sl-security] sections:

1.3 Install PostgreSQL 9.4 Repository


CentOS 7.2/6.7/5.11

Red Hat (RHEL) 7.2/6.7/5.11

Scientific Linux (SL) 7.2/6.7/5.11

1.4 Install PostgreSQL 9.4 with DNF/YUM

2. Configure PostgreSQL 9.4

2.1 Initialize Cluster with initdb Command

Here is multiple alternatives howto do this (like service postgresql-9.x initdb, /etc/init.d/postgresql-9.x initdb) and postgresql-setup initdb, so that’s why I use here universal PostgreSQL initdb method, which should work with Fedora 23/22/21/20/19, CentOS/Red Hat (RHEL)/Scientific Linux (SL) 7.2/6.7/5.11:

2.2 Set PostgreSQL Server to Listen Addresses and Set Port

Open /var/lib/pgsql/9.4/data/postgresql.conf file, and add/uncomment/modify following:

If you want just localhost setup, then use following:

Or if you want use specific ip, then use following:

2.3 Set PostgreSQL Permissions

Modify PostgreSQL /var/lib/pgsql/9.4/data/pg_hba.conf (host-based authentication) file:

You can find more examples and full guide from PostgreSQL pg_hba.conf manual.

2.4 Start PostgreSQL Server and Autostart PostgreSQL on Boot

Fedora 23/22/21/20/19 and CentOS/Red Hat (RHEL)/Scientific Linux (SL) 7.2

CentOS/Red Hat (RHEL)/Scientific Linux (SL) 6.7/5.11

2.5 Create Test Database and Create New User

Change to postgres user

Create test database (as postgres user)

Login test database (as postgres user)

Create New “testuser” Role with Superuser and Password

Test Connection from localhost (as Normal Linux User)

3. Enable Remote Connections to PostgreSQL Server –> Open PostgreSQL Port (5432) on Iptables Firewall

3.1. CentOS/Red Hat (RHEL) 6.7/5.11

3.1.1 Edit /etc/sysconfig/iptables file:

3.1.2 Add following INPUT rule:

3.1.3 Restart Iptables Firewall:

3.2. Fedora 23/22/21/20/19 and CentOS/Red Hat (RHEL) 7.2

3.2.1 List Your Active Firewalld Zones

Example output:

3.2.2 Add New Rule to Firewalld

You might have active zone like public, FedoraWorkstation, FedoraServer.

3.2.3 Restart firewalld.service

4. Test remote connection

Note: You have to allow remote connections on pg_hba.conf, check step 2.3 and PostgreSQL pg_hba.conf manual.

Share this post


  1. What are the ownership and permissions of /var/lib/pgsql supposed to be? I am following the install procedure for postgresql on and am at step 2.1 for fedora 24

    su – postgres -c /usr/pgsql-9.5/bin/initdb

    which fails with “authentication failure”

    Changing to

    su -c ‘/usr/pgsql-9.4/bin/initdb’ postgres

    fails with “su: failed to execute /var/lib/pgsql: Permission denied”

    the file permissions and ownership are

    sudo ls -alt /var/lib/pgsql
    drwx——. 4 postgres postgres 4096 Oct 5 11:08 .

    Do I have a file permissions/ownership problem or something else?


Submit a Comment

Your email address will not be published. Required fields are marked *