Install PostgreSQL on EC2(Red Hat)

By Prashant Raghava

Follow below steps:

#  Install EPEL: Some time we face the error EPEL is not available. So we can install it as follows:

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm   

#Install the repository RPM:

sudo yum install https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-redhat96-9.6-3.noarch.rpm

# Set the locale:

export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
locale-gen en_US.UTF-8
dpkg-reconfigure locales

# download Postgres 9.6:

wget https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-redhat96-9.6-3.noarch.rpm

# Load rpm:

rpm -ivh pgdg-redhat96-9.6-3.noarch.rpm

#Install the client packages:

yum install postgresql96

#Install the server packages:

yum install postgresql96-server

#Optionally initialize the database and enable automatic start:

Path is : /usr/pgsql-9.6/bin/postgresql96-setup initdb

#Start/Stop Command

systemctl enable postgresql-9.6
systemctl start postgresql-9.6
systemctl status postgresql-9.6
systemctl stop postgresql-9.6

#Edit postgresql.conf

vi /var/lib/pgsql/9.6/data/postgresql.conf

#Edit below parameters in this file

wal_level = logical
listen_addresses = ‘*’
wal_buffers = 8MB
checkpoint_completion_target = 0.9
max_connections = 300
shared_buffers = 256MB

#Edit postgresql.conf file:

vi /var/lib/pgsql/9.6/data/pg_hba.conf

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# “local” is for Unix domain socket connections only

local   all             all                                    trust
host    all             all             0.0.0.0/0              md5
host    all             all             127.0.0.1/32            ident
# IPv6 local connections:
host    all             all             ::1/128                 ident
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local   replication     postgres                               peer
#host    replication     postgres        127.0.0.1/32           ident
#host    replication     postgres        ::1/128                ident

#Configure the PostgreSQL server to start at boot.

systemctl enable postgresql-9.6
sudo /sbin/chkconfig postgresql-9.6 on
systemctl list-dependencies postgresql-9.6
systemctl list-unit-files | grep postgresql-9.6.service
systemctl restart postgresql-9.6
systemctl status postgresql-9.6

Leave a Reply