Heroku gotcha

Skip to first unread message

Sam Pierson

Jul 30, 2012, 11:16:07 AM7/30/12
to rgeo-...@googlegroups.com

Last night I setup a PostGIS app at Heroku using activerecord-postgis-adapter.   I thought I would share my experience in those hope that it saves someone the 3 hour detour I had.  Jump to the bold part for the gotcha that roadblocked me.

I'm using:
rails (3.2.7)
activerecord-postgis-adapter (0.4.3)
rgeo (0.3.14)
rgeo-activerecord (0.4.5)

I had an app functioning perfectly on my local machine, talking to PostgreSQL 9.1.4 / POSTGIS="2.0.0 r9605"

Then I got to Heroku...

I provisioned one of their "Ronin" DBs ($200/mo ouch) - the lowest level that supports PostGIS:

heroku addons:add heroku-postgresql:ronin --postgis=true version=9.0
heroku pg:wait
heroku pg:promote HEROKU_POSTGRESQL_CYAN
heroku pg:psql
SELECT PostGIS_Full_Version();
POSTGIS="1.5.2" GEOS="3.3.3-CAPI-1.7.4" PROJ="Rel. 4.7.1, 23 September 2009" LIBXML="2.7.6" USE_STATS

What I failed to notice was that Heroku sets its database adapter using the scheme:// part of it's DATABASE_URL, and the default set for its postgis enabled database is still "postgres".  You need to switch this from "postgres" to "postgis" by:

Run heroku config
Find the URL of your PostGIS enable databsae, e.g. for me it was HEROKU_POSTGRESQL_CYAN_URL
Then set DATABASE_URL to that URL, but with "postgis://" instead of "postgres://", e.g.:

Now I have fixed this everything is running flawlessly and identically locally and on Heroku.


Here are some of the error signatures I ran into while debugging, for those folks Googling error strings trying to solve this:

When I tried to migrate, my migration that created a spacial index failed with:

PG::Error: ERROR:  data type point has no default operator class for access method "btree"
HINT:  You must specify an operator class for the index or define a default operator class for the data type.
: CREATE  INDEX "index_user_feedback_on_latlon" ON "user_feedback" ("latlon")

I switched the migration to create the index using SQL instead, and got past that, only to have the app fail to boot with:

app/models/location.rb:7:in `<class:Location>': uninitialized constant Location::RGeo (NameError)

So I included rgeo, then got an error about set_rgeo_factory_for_column.
So I included rgeo-activerecord instead.
My point column was still being treated as just a string, however.
While debugging in the console I finally discovered that ActiveRecord::Base.connection was an ActiveRecord::ConnectionAdapters::PostgreSQLAdapter, which pointed me in the right direction.


Toby Rahilly

Aug 7, 2012, 3:23:42 AM8/7/12
to rgeo-...@googlegroups.com
Hi Sam,

Setting the schema to 'postgis' will break other heroku add-ons that also read the the DATABASE_URL config.

Most notably, it breaks the PGBackups addon, which was a show stopper for us.

Instead we left the the schema url as 'postgres', and monkey patched ActiveRecord::Base::ConnectionSpecification::Resolver::connection_url_to_hash to override the schema back to 'postgis'.


Daniel Docki

Aug 7, 2012, 9:56:34 PM8/7/12
to rgeo-...@googlegroups.com
Sorry Toby, but I did not understand how I pass the url of the database? and where do I put this line?

Daniel Docki
Skype: daniel.docki
MSN/Gtalk: daniel...@gmail.com
Twitter: http://twitter.com/danieldocki

Daniel Docki

Aug 9, 2012, 10:56:25 AM8/9/12
to rgeo-...@googlegroups.com
Hi There,

I followed the footsteps of Sam, data is being saved in the database, but when I try to use some method of RGEO gives me an error:

RGeo::Error::UnsupportedOperation (Method Geometry#within? not defined.)

Why? How I can solve that?

Daniel Docki
Skype: daniel.docki
MSN/Gtalk: daniel...@gmail.com
Twitter: http://twitter.com/danieldocki

Reply all
Reply to author
0 new messages