How to Set Up the Latest Version of PostgreSQL on AWS Linux 2

Although AWS does provide their own RDS service for running PostgreSQL I recommend it only (1) if you frequently require restoring the database up to a particular minute’s snapshot and (2) if the CPU usage of the database server would be substantial. Otherwise, a daily backup of the database to an AWS S3 Bucket in an Infrequent Access Storage Class provides sufficient safety net.

While one can install in AWS Linux 2 PostgreSQL via “yum install”, the AWS provided versions are too old to be useful.

The PostgreSQL yum repo is which for AWS Linux 2 translates into Nevertheless, due to the changes in the yum packages, one cannot directly use the packages in AWS Linux 2.

The below steps are for PostgreSQL 11, but can be applied to PostgreSQL 10, 12, or 13. Just change the postgresql11 to postgresql10, or postgresql-11 to postgresql-10 etc.

1. Install PostgreSQL

sudo rpm -ivh --nodeps
sudo sed -i 's/\$releasever/7/g' /etc/yum.repos.d/pgdg-redhat-all.repo
sudo yum install -y postgresql11 postgresql11-server
PGSETUP_INITDB_OPTIONS='--encoding=UTF-8 --locale=C.UTF-8' sudo /usr/pgsql-11/bin/postgresql-11-setup initdb
sudo systemctl enable --now postgresql-11
systemctl status postgresql-11

2. Create a JIRA Database

sudo su - postgres
create user jirauser with password 'XXXXX';
grant all privileges on database jira to jirauser;
alter role jirauser login;

3. Set Up Outside Connection

Add this line to /var/lib/pgsql/11/data/postgresql.conf

listen_addresses = '*'

4. Set up Login Access

Edit /var/lib/pgsql/11/data/pg_hba.conf and disable the ident. The file should look like as follows

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
#host    all             all               ident
# IPv6 local connections:
#host    all             all             ::1/128                 ident
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     peer
#host    replication     all               ident
#host    replication     all             ::1/128                 ident

host    all             all               md5
host    all             all             ::1/128                 md5

local   all             all                                     trust
host    all             all               trust
host    all             all             ::1/128                 trust

5. Restart the Database Service

sudo systemctl reload postgresql-11
sudo systemctl restart postgresql-11


Related Posts