postgres hstore exists and doesn't exist at same time [duplicate]

人走茶凉 提交于 2019-12-10 12:30:58

问题


I set up a Rails app on a remote server and created an hstore extension

 sudo -u postgres psql
 CREATE EXTENSION hstore;

I then deployed an iteration of the app that uses hstore in one of the postgres tables, but when it ran the migrations it gave an error message

PG::UndefinedObject: ERROR:  type "hstore" does not exist

I then tried to do this again

 sudo -u postgres psql
 CREATE EXTENSION hstore;

but it told me hstore already exists

ERROR:  extension "hstore" already exists

and this circle continued on.

Any idea what might be causing this problem? I'm using postgres 9.1 on an Ubuntu 12.04 server

Update Note, wondering if this issue was related to permissions, I tried to check my permissions like this but got the following error

sudo -u postgres psql -U username
psql: FATAL:  Peer authentication failed for user "username"

Update Although hstore is installed, it's not an extension for the database I'm using. How to install it in a specific database?

psql -d db_production -c '\dx'
                 List of installed extensions
  Name   | Version |   Schema   |         Description          
---------+---------+------------+------------------------------
 plpgsql | 1.0     | pg_catalog | PL/pgSQL procedural language
(1 row)

回答1:


To create extension in your database, you have to explicitly connect to that database. So, if your database is my_app_development, you have to do :

sudo -u postgres psql my_app_development
create extension hstore;

Also, you do not tell which rails version you're on. If you're not on rails-4, you will have to use the postgres hstore gem.




回答2:


Using this SO answer How to create a new database with the hstore extension already installed?, I found out that I had to create the extension for the template1 database and then any other database I created thereafter would have it installed



来源:https://stackoverflow.com/questions/19467481/postgres-hstore-exists-and-doesnt-exist-at-same-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!