Install Postgresql 11.1 on Fedora 29/28, CentOS/RHEL/SL 7.5/6.10

This is guide, howto install PostgreSQL 11.1 database server on Fedora 29/28/27, CentOS/Red Hat (RHEL)/Scientific Linux (SL) 7.5/6.10. This guide uses PostgreSQL own YUM repos, which are always up-to-date and stable releases are available instantly. You can use this guide to install any Postgresql versions, like 12, 11.1, 10.6, 9.6.11, 9.5.15, 9.4.20, and 9.3.25.

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 11.1 Database Server on Fedora 29/28/27, CentOS/Red Hat (RHEL)/Scientific Linux (SL) 7.5/6.10

1.1 Change root user


su -
## OR ##
sudo -i

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.

Fedora

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


[fedora]
...
exclude=postgresql*

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


[updates]
...
exclude=postgresql*

CentOS

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


[base]
...
exclude=postgresql*

[updates]
...
exclude=postgresql*

Red Hat (RHEL)

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


[main]
...
exclude=postgresql*

Scientific Linux (SL)

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


[sl]
...
exclude=postgresql*

[sl-security]
...
exclude=postgresql*

1.3 Install PostgreSQL 11.1 Repository

Fedora 29/28/27


## Fedora 29 ##
dnf install https://download.postgresql.org/pub/repos/yum/11/fedora/fedora-29-x86_64/pgdg-fedora11-11-2.noarch.rpm

## Fedora 28 ##
dnf install https://download.postgresql.org/pub/repos/yum/11/fedora/fedora-28-x86_64/pgdg-fedora11-11-2.noarch.rpm

## Fedora 27 ##
dnf install https://download.postgresql.org/pub/repos/yum/11/fedora/fedora-27-x86_64/pgdg-fedora11-11-2.noarch.rpm

CentOS 7.5/6.10

## CentOS 7 - x86_64 - 64-bit ##
yum install https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm

## CentOS 6 - x86_64 - 64-bit ##
yum install https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-6-x86_64/pgdg-centos11-11-2.noarch.rpm

Red Hat (RHEL) 7.5/6.10


## Red Hat (RHEL) 7 - x86_64 - 64-bit ##
yum install https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-redhat11-11-2.noarch.rpm

## Red Hat (RHEL) 6 - x86_64 - 64-bit ##
yum install https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-6-x86_64/pgdg-centos11-11-2.noarch.rpm

Scientific Linux (SL) 7.5/6.10


## Scientific Linux (SL) 7 - x86_64 - 64-bit ##
yum install https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-sl11-11-2.noarch.rpm

## Scientific Linux (SL) 6 - x86_64 - 64-bit ##
yum install https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-6-x86_64/pgdg-sl11-11-2.noarch.rpm

1.4 Install PostgreSQL 11.1 with DNF/YUM


## Fedora 29/28/27 ##
dnf install postgresql11 postgresql11-server

## Centos/RHEL/SL 7.5/6.10 ##
yum install postgresql11 postgresql11-server

2. Configure PostgreSQL 11.1

2.1 Initialize Cluster with initdb Command

Here is multiple alternatives howto do this (like service postgresql-10.x initdb, /etc/init.d/postgresql-9.x initdb) and postgresql-setup initdb:


## Fedora 29/28/27 and CentOS/RHEL/SL 7.5 ##
/usr/pgsql-11/bin/postgresql-11-setup initdb

## CentOS/RHEL/SL 6.10 ##
service postgresql-11 initdb

2.2 Set PostgreSQL Server to Listen Addresses and Set Port

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


listen_addresses = '*'
port = 5432

If you want just localhost setup, then use following:


listen_addresses = 'localhost'
port = 5432

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


listen_addresses = '192.1.2.33'
port = 5432

2.3 Set PostgreSQL Permissions

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


# Local networks
host	all	all	        xx.xx.xx.xx/xx	md5
# Example
host	all	all     	10.20.4.0/24	md5
# Example 2
host	test	testuser	127.0.0.1/32	md5

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 29/28/27 and CentOS/Red Hat (RHEL)/Scientific Linux (SL) 7.5


## Start PostgreSQL 11 ##
systemctl start postgresql-11.service

## Start PostgreSQL 11 on every boot ##
systemctl enable postgresql-11.service

CentOS/Red Hat (RHEL)/Scientific Linux (SL) 6.10


## Start PostgreSQL 11 ##
service postgresql-11 start
## OR ##
/etc/init.d/postgresql-11 start

## Start PostgreSQL 11 on every boot ##
chkconfig --levels 235 postgresql-11 on

2.5 Create Test Database and Create New User

Change to postgres user


su postgres

Create test database (as postgres user)


createdb test

Login test database (as postgres user)


psql test

Create New “testuser” Role with Superuser and Password


CREATE ROLE testuser WITH SUPERUSER LOGIN PASSWORD 'test';

Test Connection from localhost (as Normal Linux User)


psql -h localhost -U testuser test

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

3.1. CentOS/Red Hat (RHEL) 6.10

3.1.1 Edit /etc/sysconfig/iptables file:

nano -w /etc/sysconfig/iptables

3.1.2 Add following INPUT rule:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 5432 -j ACCEPT

3.1.3 Restart Iptables Firewall:


service iptables restart
## OR ##
/etc/init.d/iptables restart

3.2. Fedora 29/28/27 and CentOS/Red Hat (RHEL) 7.5

3.2.1 List Your Active Firewalld Zones


firewall-cmd --get-active-zones

Example output:

public
  interfaces: wlp1s0

3.2.2 Add New Rule to Firewalld

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


firewall-cmd --permanent --zone=public --add-service=postgresql

## OR ##

firewall-cmd --permanent --zone=public --add-port=5432/tcp

3.2.3 Restart firewalld.service


systemctl restart firewalld.service

4. Test remote connection


psql -h dbserver_name_or_ip_address -U testuser -W test

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

72 comments on “Install Postgresql 11.1 on Fedora 29/28, CentOS/RHEL/SL 7.5/6.10

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Close