How to Install PostgreSQL with PostGIS on Amazon EC2 Linux

I recently ran into some problems running PostgreSQL with PostGIS on Amazon EC2 Linux when I tried to update the software. So I decided to write a little guide about how you can install PostgreSQL with PostGIS without any unexpected downtimes.

Note: If you plan to run PostgreSQL with PostGIS in the Amazon Cloud, I would preferably choose their managed database service RDS, for which they announced support of PostgreSQL and PostGIS just a couple of weeks ago. However, if you need to run the database with other software on the same machine or if you want to install your own server for other reasons, the following guide might help you.

When I first installed PostgreSQL on EC2, I just used the packages from the Amazon repos. They have postgresql available and all you need to do is sudo yum install postgresql-server  and then install PostGIS on top. I faced the following problem: When I updated the server software with sudo yum update later, it updated my postgresql version from 9.1.x to 9.2.x automatically. It did not update the PostGIS libraries though, so I wasn’t able to upgrade my database and the server wouldn’t start because PostGIS was compiled against the old postgresql version. So here is how to install it from the packages.

1. Create the Instance

First launch the desired instance type. I am using a 64 Bit version with Amazon Linux to be able to upgrade to bigger instance types later without reimporting the database. The same should work with a 32 Bit version. Just make sure to install the right packages. 

Login to the instance vie SSH, change to root user and exclude the default postgresql packages from the amazon respositories:

Add the following line to the block [amzn-main]:

Add the same line for the updates repository to the block [amzn-updates]

2. Install PostgreSQL Server

3. Create EBS-Volume and Initialize PostgreSQL-Server

I want to store the PostgreSQL data on an EBS-Volume to not loose my data on instance reset and to be able to easily attach the EBS-Volume to another instance.

Create an EBS-Volume with the desired size and IOPs and attach it to the instance. In my case I attach it to  /dev/sdf

Now delete the default postgresql data directory and create a symlink to the EBS drive instead. Initialize postgresql aufterwards.

You should now have a fully functioning postgresql database server running and all the postgresql data should be store in the directory  /vol/ on the EBS-Volume.

4. Install PostGIS Geospatial Support

To be able to install PostGIS geospatial support for PostgreSQL, we first need to install the required modules GEOS, Proj4, JSON-C, GDAL, and a couple others that are included in the Amazon repositories.

You should now have a PostgreSQL database server with PostGIS running on Amazon EC2 Linux


2 Responses to How to Install PostgreSQL with PostGIS on Amazon EC2 Linux
  1. Larry Reply

    While your instructions all result in a successful compilation and installation, they don’t result in a working system. PostGIS 1.5.8 is not compatible with Postgres 9.3. See compatibility matrix at

    After these steps, when I try to load postgis functions, I get:

    ERROR: could not load library “/usr/pgsql-9.3/lib/”: /usr/pgsql-9.3/lib/ undefined symbol: GETSTRUCT

    • Ivo Meißner Reply

      Thanks for pointing that out! On my production system I was running PostgreSQL 9.1. For the tutorial I decided to just use the latest postgres version and falsely assumed that it would work, when the installation did not raise any errors. Sorry for any inconveniences.
      I updated the post to also use the latest PostGIS version. Now it should also result in a running system. ;-)

Leave a Reply to Larry Cancel reply

Your email address will not be published. Please enter your name, email and a comment.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">