Skip to content

Instantly share code, notes, and snippets.

@xvronny
Last active January 16, 2019 23:18
Show Gist options
  • Save xvronny/437dfcbb5e2f5751dc429f4e1c1c888d to your computer and use it in GitHub Desktop.
Save xvronny/437dfcbb5e2f5751dc429f4e1c1c888d to your computer and use it in GitHub Desktop.
Installing PostgreSQL 11 with PostGIS 2.4 on Amazon Linux 2018.03

Published note for installation instructions to make it easier for future installers.

PostgreSQL 11.0 Installation

Installation of PostgreSQL on Amazon Linux generally follows the same path as discussed in StackOverflow Question

  1. Copy the link from PostgreSQL repository list after selecting the appropriate options. For Amazon Linux 2018.xx we should select RedHat Enterprise Linux 6 as target OS.
  2. Add the repository link and replace versions placeholders in /etc/yum.repos.d/pgdg-11-redhat.repo using the following commands
sudo yum install -y https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-6-x86_64/pgdg-redhat11-11-2.noarch.rpm
sudo sed -i "s/rhel-\$releasever-\$basearch/rhel-6.9-x86_64/g" "/etc/yum.repos.d/pgdg-11-redhat.repo"
  1. Install PostgreSQL 11 and verify the results
sudo yum install -y postgresql11 postgresql11-server postgresql11-contrib

psql --version
# should result in string 'psql (PostgreSQL) 11.1'

PostGIS 2.4

Here's the fun part - mostly because PostGIS doesn't come prepackaged for RHEL distros. This section mostly follows an older installation script now updated for later versions.

  1. Install the appropriate EPEL / extra packages repository for the appropriate RHEL version (6.x)
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
sudo rpm -ivh epel-release-6-8.noarch.rpm
sudo yum repolist
  1. Prioritize previously installed Postgres repository first to make sure we use postgres' version whenever possible, though YMMV
sudo vi /etc/yum.repos.d/pgdg-11-redhat.repo
# add new line `priority=1`
  1. Run package installer and add any missing library manually as a new entry in the run script.
sudo yum --enablerepo=epel install postgis24_11 \
    https://rpmfind.net/linux/epel/6/x86_64/Packages/x/xerces-c-3.0.1-0.20.1.el6.x86_64.rpm \
    https://rpmfind.net/linux/epel/6/x86_64/Packages/l/libspatialite-2.4.0-0.6.RC4.el6.x86_64.rpm \
    https://rpmfind.net/linux/epel/6/x86_64/Packages/l/libdap-3.11.0-1.el6.x86_64.rpm \
    https://rpmfind.net/linux/epel/6/x86_64/Packages/n/netcdf-4.1.1-3.el6.5.x86_64.rpm \
    https://rpmfind.net/linux/epel/6/x86_64/Packages/c/cfitsio-3.240-3.el6.x86_64.rpm \
    https://rpmfind.net/linux/epel/6/x86_64/Packages/a/armadillo-4.550.2-1.el6.x86_64.rpm \
    https://rpmfind.net/linux/epel/6/x86_64/Packages/h/hdf5-1.8.5.patch1-10.el6.x86_64.rpm

You can search for the missing libraries in RPMFind, pkgs.org or just directly via Google. Try to match your target architecture x86_64 and OS as much as possible Amazon Linux 2018.xx -> RHEL 6 -> CentOS 6. If you know of a better way than this let me know :)

  1. Verify PostGIS installation.
sudo passwd postgres
sudo service postgresql-11 initdb
sudo service postgresql-11 start
sudo chkconfig postgresql-11 on

su postgres
/usr/pgsql-11/bin/psql -p 5432

# in psql
CREATE DATABASE gistest;
\connect gistest;
CREATE EXTENSION postgis;

postgres=# CREATE EXTENSION postgis;
CREATE EXTENSION
postgres=# SELECT postgis_full_version();
                                                                                postgis_full_version                                                                                
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 POSTGIS="2.4.5 r16765" PGSQL="110" GEOS="3.6.3-CAPI-1.10.3 80c13047" PROJ="Rel. 4.9.3, 15 August 2016" GDAL="GDAL 1.9.2, released 2012/10/08" LIBXML="2.7.6" LIBJSON="0.11" RASTER
(1 row)

Troubleshooting

a.k.a lessons I learned the hard way

  • Amazon Linux 2018.xx comes preconfigured with libraries that match well with EPEL release 6.x, and therefore should use packages for RHEL 6 and CentOS 6 in case a substitution is required. Amazon Linux 2, OTOH matches EPEL 7 as seen in this tutorial, and by inference should use RHEL 7 and CentOS 7 substitutes.
  • have you tried clearing your yum cache?
yum clean all

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment