Rails 4 + PostgreSQL hstore, can't execute "CREATE EXTENSION hstore"

kuatro picture kuatro · Jul 10, 2014 · Viewed 7.5k times · Source

I have RubyOnRails 4.1.4 and PostgreSQL installed on my MacOS X by:

brew install postgresql

When I'm trying to migrate this one:

CREATE EXTENSION hstore

It gives out me an error:

PG::UndefinedFile: ERROR:  could not open extension control file "/usr/share/postgresql/9.3/extension/hstore.control": No such file or directory

I tried to find "hstore.control" in filesystem using:

find / -name "hstore.control"

And found out that this file is located in the different path:

usr/local/Cellar/postgresql/9.3.4/share/postgresql/extension/hstore.control

So how can I redefine "PG" gem's configuration to correct the path of the hstore extension? I just tried to remove the gem and install it with:

rvm all do gem install pg -- --with-pg-config=/usr/local/Cellar/postgresql/9.3.4/bin/pg_config

But it didn't work. I still have the same error.

Thank you in advance.

UPDATE:

I just created symlink to correct path, but anyway it gives me out the same error.

Answer

ben picture ben · Jan 3, 2015

The solution is simple, just install postgresql-contrib in your OS and then run the migration as it is shown here Rails 4 PostgreSQL integration or any other way you using. For example if you are using ubuntu it will be:

sudo apt-get install postgresql-contrib-X.X

where X.X is the postgresql version that you are using. If it is version 9.3 it be:

sudo apt-get install postgresql-contrib-9.3

I also think for MAC Os is almost same, only that you will use brew.