In this article we will be looking at the installation of PostgreSQL 13 on Amazon Linux 2 server. PostgreSQL 13 was released officially on 2020-09-24 by PostgreSQL Global Development Group for general use. It is a release ready for running Production workloads.

PostgreSQL 13 comes with significant improvements to its indexing and lookup system that benefit large databases, including space savings and performance gains for indexes, faster response times for queries that use aggregates or partitions, better query planning when using enhanced statistics, and more.

Step 1: Enable EPEL repository

Since PostgreSQL YUM repository depends on the EPEL repository for some packages. We need to install the EPEL repo RPM along with PGDG repo RPMs to satisfy dependencies in our Amazon Linux 2 Server.

Run the command below to enable EPEL repository on Amazon Linux 2 server:

sudo amazon-linux-extras install epel

Accept installation by pressing the y key when asked.

Dependencies Resolved

================================================================================
 Package              Arch           Version      Repository               Size
================================================================================
Installing:
 epel-release         noarch         7-11         amzn2extra-epel          15 k

Transaction Summary
================================================================================
Install  1 Package

Total download size: 15 k
Installed size: 24 k
Is this ok [y/d/N]: y

Step 2: Install PostgreSQL 13 on Amazon Linux 2

Below are the minimum requirements for the installation in Production setup.

  • 2GB of RAM recommended
  • 1 virtual cpu core
  • 1GB of disk space for installation
  • You also need SSH access to the server as user with sudo privileges.

Run the following commands to ensure PGDG repository is added to your Amazon Linux 2 server.

sudo tee /etc/yum.repos.d/pgdg.repo<<EOF
[pgdg13]
name=PostgreSQL 13 for RHEL/CentOS 7 - x86_64
baseurl=https://download.postgresql.org/pub/repos/yum/13/redhat/rhel-7-x86_64
enabled=1
gpgcheck=0
EOF

After repository is added run the commands required to install PostgreSQL 13 on Amazon Linux 2:

sudo yum install postgresql13 postgresql13-server

Validate that correct software versions of PostgreSQL are being installed.

Dependencies Resolved

==================================================================================================================================================================
 Package                                       Arch                             Version                                    Repository                        Size
==================================================================================================================================================================
Installing:
 postgresql13                                  x86_64                           13.0-1PGDG.rhel7                           pgdg13                           1.4 M
 postgresql13-server                           x86_64                           13.0-1PGDG.rhel7                           pgdg13                           5.4 M
Installing for dependencies:
 postgresql13-libs                             x86_64                           13.0-1PGDG.rhel7                           pgdg13                           379 k

Transaction Summary
==================================================================================================================================================================
Install  2 Packages (+1 Dependent package)

Total download size: 7.1 M
Installed size: 30 M
Is this ok [y/d/N]: y

Step 3: Initialize and start database service

You need to generate initial database configurations file before starting the service.

$ sudo /usr/pgsql-13/bin/postgresql-13-setup initdb
Initializing database ... OK

The main configuration file for the database server is /var/lib/pgsql/12/data/postgresql.conf .

Service can be started and set to come up on system boot with the commands below.

$ sudo systemctl enable --now postgresql-13
Created symlink from /etc/systemd/system/multi-user.target.wants/postgresql-13.service to /usr/lib/systemd/system/postgresql-13.service.

Service should have been started without any errors.

$ $ systemctl status postgresql-13
● postgresql-13.service - PostgreSQL 13 database server
   Loaded: loaded (/usr/lib/systemd/system/postgresql-13.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2020-10-20 21:40:08 UTC; 43s ago
     Docs: https://www.postgresql.org/docs/13/static/
  Process: 21041 ExecStartPre=/usr/pgsql-13/bin/postgresql-13-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
 Main PID: 21046 (postmaster)
   CGroup: /system.slice/postgresql-13.service
           ├─21046 /usr/pgsql-13/bin/postmaster -D /var/lib/pgsql/13/data/
           ├─21049 postgres: logger
           ├─21051 postgres: checkpointer
           ├─21052 postgres: background writer
           ├─21053 postgres: walwriter
           ├─21054 postgres: autovacuum launcher
           ├─21055 postgres: stats collector
           └─21056 postgres: logical replication launcher

Oct 20 21:40:08 ip-172-31-39-10.eu-west-1.compute.internal systemd[1]: Starting PostgreSQL 13 database server...
Oct 20 21:40:08 ip-172-31-39-10.eu-west-1.compute.internal postmaster[21046]: 2020-10-20 21:40:08.746 UTC [21046] LOG:  redirecting log output to logging...rocess
Oct 20 21:40:08 ip-172-31-39-10.eu-west-1.compute.internal postmaster[21046]: 2020-10-20 21:40:08.746 UTC [21046] HINT:  Future log output will appear in..."log".
Oct 20 21:40:08 ip-172-31-39-10.eu-west-1.compute.internal systemd[1]: Started PostgreSQL 13 database server.
Hint: Some lines were ellipsized, use -l to show in full.

You should now be able to access PostgreSQL database server console and perform DB operations.

$ sudo su - postgres 
$ psql
psql (13.0)
Type "help" for help.

postgres=# CREATE DATABASE testdb;
CREATE DATABASE
postgres=# DROP DATABASE testdb;
DROP DATABASE

Enjoy!.

More guides on Amazon Linux:

Install Microsoft SQL Server 2019 on Amazon Linux 2

How To Install Tomcat 9 on Amazon Linux 2

Install GitLab CE on Amazon Linux 2 with Let’s Encrypt SSL

How To Install Grafana 7 on Amazon Linux 2

LEAVE A REPLY

Please enter your comment!
Please enter your name here

four + twenty =