Installing PostgreSQL Client v10 on AWS Amazon Linux (EC2) AMI Installing PostgreSQL Client v10 on AWS Amazon Linux (EC2) AMI postgresql postgresql

Installing PostgreSQL Client v10 on AWS Amazon Linux (EC2) AMI


You can try to run the following command on your Linux server:

sudo amazon-linux-extras install postgresql10


Packages/Repos which is designed to work of RedHat will work on Amazon Linux also, Amazon Linux is a minimal-install version of RHEL. You may run into compatibility issues if you select old version of Amazon Linux (Amazon linux 1) for the below steps, otherwise it should work fine in the latest version Amazon Linux 2.

Check Amazon Linux version

[ec2-user ~]$ cat /etc/system-releaseAmazon Linux release 2.0 (2017.12) LTS Release Candidate

Install RHEL 7 yum repo for PostgreSQL

[ec2-user ~]$ sudo yum install -y  https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-redhat10-10-2.noarch.rpm[ec2-user ~]$ sudo sed -i "s/rhel-\$releasever-\$basearch/rhel-latest-x86_64/g" "/etc/yum.repos.d/pgdg-10-redhat.repo"

Install PostgreSQL Client v10

[ec2-user ~]$ sudo yum install -y postgresql10[ec2-user ~]$ psql --versionpsql (PostgreSQL) 10.3

Read more about Amazon Linux 2

Note! Amazon Linux 2 provides additional package installation through Amazon Linux Extras Repository (amazon-linux-extras) ((client only)). Since postgresql10 is not yet available, adding extra yum repo is the only solution per today.

UDATE 2019May

those who see

Error: Package: pgdg-redhat-repo-42.0-4.noarch (/pgdg-redhat-repo-latest.noarch)

Requires: /etc/redhat-release

may still install step by step all dependencies and the server with:

yum install -y https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-latest-x86_64/postgresql10-libs-10.7-2PGDG.rhel7.x86_64.rpmyum install -y https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-latest-x86_64/postgresql10-10.7-2PGDG.rhel7.x86_64.rpmyum install -y https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-latest-x86_64/postgresql10-server-10.7-2PGDG.rhel7.x86_64.rpm


Since none of the previous answers worked for me, I'm adding a solution that let me install the postgresql10 client. We're using VERSION="2018.03" of Amazon Linux AMI in our pipelines.

Building from source:

Note: The link below points to postgresql 10.4, you may want to check for newer subversions

sudo yum install -y gcc readline-devel zlib-develwget https://ftp.postgresql.org/pub/source/v10.4/postgresql-10.4.tar.gztar -xf postgresql-10.4.tar.gzcd postgresql-10.4./configuremake -C src/binsudo make -C src/bin installmake -C src/includesudo make -C src/include installmake -C src/interfacessudo make -C src/interfaces installmake -C docsudo make -C doc install

The new package should be installed with all its executables in here: /usr/local/pgsql/bin

Now, keep in mind that commands psql, pg_dump etc. still point to the old version of the psql client. You can run with the full executable paths (/usr/local/pgsql/bin/psql) or prepend the new directory at the beginning of your $PATH so that the system will look it up first:

Edit ~/.bash_profile adding this at the end:

export PATH="/usr/local/pgsql/bin:$PATH"

Then run:

source ~/.bash_profile

Now everything should be ready:

[ec2-user@ip-xx-x-x-xxx ~]$ psql --versionpsql (PostgreSQL) 10.4