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. Dear all, when i installed and create user and database and also connect that database and user from my front end application. and when i create second user and database then postgres asking password. I never set password for postgres user and database. and why postgres asking for password?

    • Hi Ashwin,

      Could you post/check what you have in your pg_hba.conf file(s)?

      Maybe you use trust for other db and example md5 for other db?

  2. Problem has been resolved, I have replaced trust instead md5 for local, like
    local all all trust
    then postgres not asking for password…

    • Excellent! Nice to hear that you got it working!

  3. Great and complete tutorial! I did the install in 5 minutes. Thanks for that.
    I also like to create a user with createuser:
    As postgres user, do:

    Then as this testuser, you can create the db:

  4. great tutorial. thanks a lot

  5. Excellent as usual (Centos 6.5). Only suggestion would be a concrete example for pg_hba.conf:

    host all all trust

    For those on ‘safe’ networks and/or will worry about security later.

  6. … go to enterprise db site ,
    Download oss version , chmod to execute , execute … that ‘s all
    Wat else ?

    PS by the way , you have pgadmin installed

    fed 20 x 64

    PPS : i’m just switching from win7 to linux , happy to find at least a software that i can install just with a “click”

  7. oups… i mean : what else (sic)

  8. Note: using centos 6.6

    the command su - postgres -c /usr/pgsql-9.4/bin/initdb creates the data folder at the same level as 9.4 folder. And inside 9.4 exists a “data” folder but empty.
    To remedy this I moved the file inside 9.4 but afterwords doing a psql inside bash raised me this error: psql: symbol lookup error: psql: undefined symbol: PQconnectdbParams

  9. I had some troubles installing and enabling postgres service. And I got this error:
    sudo systemctl start postgresql-9.4.service
    sudo journalctl -xn
    “/var/lib/pgsql/9.4/data/” is missing or empty.

    Then I’ve runned the following command with the -D argument and simple quotes at whole command:
    # su – postgres -c ‘/usr/pgsql-9.4/bin/initdb -D /var/lib/pgsql/9.4/data/’

    Now that’s fine.

  10. Please the su at the beginning.

    Else you’ll get weird Authentication errors.

    • Hi crazywizard,

      Check step 1.1 Change root user.

  11. The command

    should be:firewall-cmd –permanent –zone=public –add-port=5432/tcp

    Also, changes to the firewall can be made active using:firewall-cmd –reload

    • Hi DK,

      Thanks. I updated this guide.

      Yes, reload works too. No problems.

  12. Very good guide, thanks!
    I’d suggest you to add a few things for completeness:

    2.2.2 Enable SSL with a self-signed certificate:

    sudo su – postgres
    cd /var/lib/pgsql/9.4/data/
    openssl req -newkey rsa:2048 -nodes -keyout server.key -x509 -days 365 -out server.crt

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

    ssl = on

    And to create a user, I’d suggest to use

    createuser -sePE

    instead of executing that long SQL sentence


  13. Can you also explain how to install postgis in a similar manner

  14. How to install postgresql on fedora 24?


Submit a Comment

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