99

I have successfully launched new AWS RDS PostgreSQL v10 instance and need to install PostgreSQL v10 client on Amazon Linux EC2 instance.

I have tried to install it with yum, but it cant find the package for v10:

[ec2-user@ip-X-X-X-X ~]$ sudo yum install -y postgresql10
Loaded plugins: priorities, update-motd, upgrade-helper
amzn-main      | 2.1 kB  00:00:00
amzn-updates  | 2.5 kB  00:00:00
No package postgresql110 available.
Error: Nothing to do

Previously I managed to install PostgreSQL client v9.5 with:

[ec2-user@ip-X-X-X-X ~]$ sudo yum install -y postgresql95

I guess I need to add Postgres yum repository, as mentioned in https://www.postgresql.org/download/linux/redhat/. But what Platform should I choose for Amazon Linux? Red Hat?

Ismar Slomic
  • 5,315
  • 6
  • 44
  • 63

13 Answers13

243

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

sudo amazon-linux-extras install postgresql10
Eric
  • 2,636
  • 21
  • 25
johnthuss
  • 2,732
  • 2
  • 16
  • 7
59

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-release
Amazon 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 --version
psql (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.rpm
yum install -y https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-latest-x86_64/postgresql10-10.7-2PGDG.rhel7.x86_64.rpm
yum install -y https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-latest-x86_64/postgresql10-server-10.7-2PGDG.rhel7.x86_64.rpm
chobo
  • 4,830
  • 5
  • 23
  • 36
Haneef Mohammed
  • 1,094
  • 11
  • 11
19

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-devel
wget https://ftp.postgresql.org/pub/source/v10.4/postgresql-10.4.tar.gz
tar -xf postgresql-10.4.tar.gz
cd postgresql-10.4
./configure
make -C src/bin
sudo make -C src/bin install
make -C src/include
sudo make -C src/include install
make -C src/interfaces
sudo make -C src/interfaces install
make -C doc
sudo 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 --version
psql (PostgreSQL) 10.4
arudzinska
  • 3,152
  • 1
  • 16
  • 29
  • Based on postgres source install docs, I ended up tweaking the make steps to: `./configure && make`, `sudo make install`, `echo 'export PATH=$PATH:/usr/local/pgsql/bin' | sudo tee /etc/profile.d/postgres.sh` – jmwicks May 25 '19 at 14:22
  • Thanks a lot. This worked great for me. I did the same with postgresql-12.3 – roronoa Mar 02 '23 at 06:31
11

Adapting Haneef Mohammed's answer for Amazon Linux 1 (tested on 2018.03):

Go to the Postgres repositories page and grab the URL for 'Red Hat Enterprise Linux 6 - x86_64'. Install the PG repos and amend the entries, replacing '$releasever' with '6.9' (or newer?):

[ec2-user ~]$ sudo yum install -y  https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-6-x86_64/pgdg-redhat10-10-2.noarch.rpm

[ec2-user ~]$ sudo sed -i "s/rhel-\$releasever-\$basearch/rhel-6.9-x86_64/g" "/etc/yum.repos.d/pgdg-10-redhat.repo"

Second part is the same:

[ec2-user ~]$ sudo yum install -y postgresql10
[ec2-user ~]$ psql --version
psql (PostgreSQL) 10.3
steamer25
  • 9,278
  • 1
  • 33
  • 38
  • before 'yum install' you need to do > $yum clean all – Antônio Sérgio Ferraz Feb 19 '19 at 12:57
  • 3
    Error: Package: pgdg-redhat-repo-42.0-5.noarch (/pgdg-redhat-repo-latest.noarch) Requires: /etc/redhat-release – Tom Oct 14 '19 at 14:18
  • It seems the pgdg repo is no longer available, so this answer doesn't work: "Cannot open: https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-6-x86_64/pgdg-redhat10-10-2.noarch.rpm. Skipping." – Jeremy Apr 03 '23 at 13:57
11

PGDG repo is no longer available for Amazon Linux. So you can use amazon repo.

amazon-linux-extras install postgresql10 vim epel -y

Or follow this article

https://installvirtual.com/install-postgresql-10-on-amazon-ec2/

Chetan kapoor
  • 821
  • 12
  • 14
8

As of May 25th, 2019, the following direct RPM installation worked for me on Amazon Linux 1 2018.03 (latest Beanstalk platform version) to install PostgreSQL Client 10.7:

sudo rpm -ivh --force https://yum.postgresql.org/testing/10/redhat/rhel-6-x86_64/postgresql10-libs-10.7-2PGDG.rhel6.x86_64.rpm
sudo rpm -ivh --force https://yum.postgresql.org/testing/10/redhat/rhel-6-x86_64/postgresql10-10.7-2PGDG.rhel6.x86_64.rpm
jmwicks
  • 542
  • 5
  • 9
5

PSql10.7 installation (08/20/2019)

Remove all of the older version Psql client and perform the below steps:

wget https://yum.postgresql.org/10/redhat/rhel-6.9-x86_64/postgresql10-libs-10.7-1PGDG.rhel6.x86_64.rpm
wget https://yum.postgresql.org/10/redhat/rhel-6.9-x86_64/postgresql10-10.7-1PGDG.rhel6.x86_64.rpm
sudo rpm -ivh postgresql10-libs-10.7-1PGDG.rhel6.x86_64.rpm
sudo rpm -ivh postgresql10-10.7-1PGDG.rhel6.x86_64.rpm
karel
  • 5,489
  • 46
  • 45
  • 50
ANU MOHAN
  • 51
  • 1
  • 1
4

This my 2019 solution:

Just do

 sudo amazon-linux-extras install postgresql9.6

You should not have to download it from any outside source, since it is already given to you by default from Amazon, all you have to do is install it.

The other solutions didnt work for me and I spent a good amount time banging my head against the wall trying to figure out why.

And surprisingly even though you install psql9.6 you get version 10.

iqbal125
  • 1,331
  • 2
  • 11
  • 19
4

The following works for psql v11 on Amazon Linux (v1)

wget https://yum.postgresql.org/11/redhat/rhel-6.9-x86_64/postgresql11-libs-11.8-1PGDG.rhel6.x86_64.rpm
wget https://yum.postgresql.org/11/redhat/rhel-6.9-x86_64/postgresql11-11.8-1PGDG.rhel6.x86_64.rpm

sudo yum clean all
sudo rpm -ivh postgresql11-libs-11.8-1PGDG.rhel6.x86_64.rpm
sudo rpm -ivh postgresql11-11.8-1PGDG.rhel6.x86_64.rpm
Smith
  • 41
  • 3
4

Solution for Amazon Linux release 2023 (Amazon Linux) instances

If you receive errors like:

  • No match for argument: postgresql10
  • No match for argument: postgresql11
  • No match for argument: postgresql14

while running sudo yum install -y postgresql<your_version>

Just check what versions persist in repositories using sudo yum search "postgres". In my case there were neither postgresql10 nor postgresql14, but was postgresql15.

So I invoked sudo yum install postgresql15 and it worked.

HereAndBeyond
  • 794
  • 1
  • 8
  • 17
2

The way I resolved the issue was by running

yum clean all

before

yum install -y postgresql10 

on Amazon Linux

K.Dᴀᴠɪs
  • 9,945
  • 11
  • 33
  • 43
  • 1
    I would be very surprised if this was actually done on an Amazon Linux instance and not an Amazon Linux 2 instance. – MrCranky May 14 '19 at 15:26
0

for v11 on Amazon Linux 2 I had to do

yum -y install https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm
sed -i "s/rhel-\$releasever-\$basearch/rhel-7-x86_64/g" "/etc/yum.repos.d/pgdg-11-centos.repo"
0

For Amazon Linux 2 and AWS Cloud Shell instance you might use commands like this:

sudo amazon-linux-extras | grep postgre # To see the available versions
sudo amazon-linux-extras install postgresql14 # To perform installation