Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#4613 closed defect (invalid)

Installing fresh openstreetmap database fails

Reported by: yurivict Owned by: rails-dev@…
Priority: minor Milestone:
Component: website Version:
Keywords: Cc:


Using PostgresSQL 9.2.1 on FreeBSD 9.1 amd64.

Command rake db:migrate always fails when it is run first, see log below. Second run though succeeds.

I am not an expert in PostgreSQL, but it seems strange that the second run succeeds when the first run fails. So is this an error or not an error?

This needs to be looked at.

Version is from Git @ Sun Oct 7 22:08:10 2012 +0000

--- log --- <...skipped...>

AddMoreChangesetIndexes?: migrating ======================================

-- add_index("changesets", created_at?, {:name=>"changesets_created_at_idx"})

-> 0.0116s

-- add_index("changesets", closed_at?, {:name=>"changesets_closed_at_idx"})

-> 0.0122s

-- add_index("changesets", ["min_lat", "max_lat", "min_lon", "max_lon"], {:method=>"GIST", :name=>"changesets_bbox_idx"}) rake aborted! An error has occurred, this and all later migrations canceled:

PG::Error: ERROR: data type integer has no default operator class for access method "gist" HINT: You must specify an operator class for the index or define a default operator class for the data type. : CREATE INDEX "changesets_bbox_idx" ON "changesets" USING GIST ("min_lat", "max_lat", "min_lon", "max_lon")

Tasks: TOP => db:migrate (See full trace by running task with --trace)

Change History (5)

comment:1 Changed 7 years ago by jfire

That particular error indicates you need to install the btree_gist extension. For Postgres > 9 the command is psql -d openstreetmap -c "CREATE EXTENSION btree_gist;".

In general you want to be running rake db:setup to initialize a new development database rather than rake db:migrate, which will create the database from db/schema.rb or db/structure.sql (the latter, in the case of the OSM Rails app). Unfortunately, our db/structure.sqlhas some hard-coded paths which need to be adjusted in order to run successfully. This took me a while to figure out when I was first getting going. It would make things easier for new contributors if we could customize the db:setup task such that it worked out of the box, perhaps by generating db/structure.sql from a db/structure.sql.erb file. However, that would also necessitate either manually editing db/structure.sql.erb when the schema changes, or also customizing the db:structure:dump task to write the .erb file.

comment:2 Changed 7 years ago by Tom Hughes

Resolution: invalid
Status: newclosed

It was never the intention that db:setup be used - the structure.sql is only committed because people asked for it as documentation and frankly committing it is a pain in the arse.

The correct procedure is to manually install btree_gist before running migrate, as I believe the instructions in the wiki tell you to do.

comment:3 Changed 7 years ago by Shaun McDonald

Is there a way to test if the btree_gist has been already installed, and if not we can tell the user and stop running the rake db:migrate. That way the user won't hit the problem of the getting part of the way through the migrations and then getting a strange error.

comment:4 Changed 7 years ago by Tom Hughes

Sure - doing this:

if not select_one("SELECT * FROM pg_opclass WHERE opcname = 'gist_int4_ops'")

throw "Please install the Postgres btree_gist extension in your database"


will, if btree_gist is not installed, abort the migrate with:

uncaught throw "Please install the Postgres btree_gist extension in your database"

comment:5 in reply to:  2 Changed 7 years ago by jfire

Replying to TomH:

It was never the intention that db:setup be used

Is that because of the hard-coded paths, or some other reason? db:setup is the recommended practice, and for good reason in my experience. Migrations, as a means of initializing a fresh database, are slower and more error-prone. Rails does not consider them to be the authoritative source for the schema; structure.sql is.

Note: See TracTickets for help on using tickets.