Table of Contents [expand]
Last updated April 24, 2026
The PostGIS module adds support for geographic objects to the PostgreSQL object-relational database. In effect, PostGIS “spatially enables” the PostgreSQL server, allowing you to use it as a backend spatial database for geographic information systems (GIS). PostGIS is available on all Heroku Postgres plans. Heroku supports PostGIS v3 on Heroku Postgres databases.
Provisioning
To install PostGIS in an existing Heroku Postgres database, open a heroku pg:psql session, and run CREATE EXTENSION postgis;:
$ heroku pg:psql DATABASE_URL -a example-app
--> Connecting to ⛁ postgresql-octagonal-12345
psql (17.2 (Postgres.app), server 16.9 (Ubuntu 16.9-1.pgdg20.04+1))
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off, ALPN: none)
Type "help" for help.
example-app::DATABASE=> CREATE EXTENSION postgis;
CREATE EXTENSION
Run \dx in a psql session to check the extensions installed on your database and their current version:
=> \dx
List of installed extensions
Name | Version | Schema | Description
--------------------+---------+------------+------------------------------------------------------------------------
...
postgis | 3.5.3 | public | PostGIS geometry and geography spatial types and functions
Alternatively, run the following query to check the version of postgis you installed:
=> SELECT postgis_version();
postgis_version
---------------------------------------
3.5 USE_GEOS=1 USE_PROJ=1 USE_STATS=1
(1 row)
(1 row)
Setting Up PostGIS with Rails
To use PostgreSQL as your database in Ruby applications, include the activerecord-postgis-adapter gem in your Gemfile.
To fully take advantage of PostGIS with Rails on Heroku, configure your app with a custom buildpack, which includes the appropriate system dependencies. This classic buildpack for Cedar-generation apps include that support. For now, there is no Cloud Native Buildpack-equivalent for Fir-generation apps.
Be sure to deploy the buildpack before building any gems.
gem 'activerecord-postgis-adapter'
To download and resolve all dependencies, run bundle install. See the Ruby documentation for more information on getting set up with activerecord-postgis-adapter.
After you’ve installed the gem, change the adapter to postgis. See Rails Database Connection Behavior on how to modify your Rails connection adapter.