Eki Eqbal
Eki Eqbal

Reputation: 6057

Can't create extensions for Postgres

I'm using postgres (PostgreSQL) 9.3.5 with my Rails (4.0.1) app and Ruby (2.0.0-p451), and one of the migrations looks like:

class CreateExtensions< ActiveRecord::Migration
    def up
        connection = ActiveRecord::Base.connection
        extensions = %w(fuzzystrmatch hstore plpgsql postgis postgis_tiger_geocoder postgis_topology)
        ext_query = extensions.map {|e| "CREATE EXTENSION IF NOT EXISTS #{e};" }.join
        connection.execute(ext_query)
    end
end

Whenever I try to run the migration file I get the following error:

CREATE EXTENSION IF NOT EXISTS fuzzystrmatch;CREATE EXTENSION IF NOT EXISTS hstore;CREATE EXTENSION IF NOT EXISTS plpgsql;CREATE EXTENSION IF NOT EXISTS postgis;CREATE EXTENSION IF NOT EXISTS postgis_tiger_geocoder;CREATE EXTENSION IF NOT EXISTS postgis_topology;
PG::UndefinedFile: ERROR:  could not open extension control file "/usr/local/Cellar/postgresql/9.3.5_1/share/postgresql/extension/postgis.control": No such file or directory
: CREATE EXTENSION IF NOT EXISTS fuzzystrmatch;CREATE EXTENSION IF NOT EXISTS hstore;CREATE EXTENSION IF NOT EXISTS plpgsql;CREATE EXTENSION IF NOT EXISTS postgis;CREATE EXTENSION IF NOT EXISTS postgis_tiger_geocoder;CREATE EXTENSION IF NOT EXISTS postgis_topology;
ActiveRecord::StatementInvalid: PG::UndefinedFile: ERROR:  could not open extension control file "/usr/local/Cellar/postgresql/9.3.5_1/share/postgresql/extension/postgis.control": No such file or directory
: CREATE EXTENSION IF NOT EXISTS fuzzystrmatch;CREATE EXTENSION IF NOT EXISTS hstore;CREATE EXTENSION IF NOT EXISTS plpgsql;CREATE EXTENSION IF NOT EXISTS postgis;CREATE EXTENSION IF NOT EXISTS postgis_tiger_geocoder;CREATE EXTENSION IF NOT EXISTS postgis_topology;
    from /Users/info/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in `async_exec'
    from /Users/info/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in `block in execute'
    from /Users/info/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract_adapter.rb:435:in `block in log'
    from /Users/info/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.1/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
    from /Users/info/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract_adapter.rb:430:in `log'
    from /Users/info/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:127:in `execute'
    from (irb):14
    from /Users/info/.rvm/gems/ruby-2.0.0-p451/gems/railties-4.0.1/lib/rails/commands/console.rb:90:in `start'
    from /Users/info/.rvm/gems/ruby-2.0.0-p451/gems/railties-4.0.1/lib/rails/commands/console.rb:9:in `start'
    from /Users/info/.rvm/gems/ruby-2.0.0-p451/gems/railties-4.0.1/lib/rails/commands.rb:62:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

I installed Postgres using Homebrew, Any idea what am I doing wrong here?

Upvotes: 0

Views: 1752

Answers (1)

Nick Veys
Nick Veys

Reputation: 23949

Make sure you have PostgreSQL and PostGIS installed from the same sources and with compatible versions.

Upvotes: 1

Related Questions