postgres hstore存在并且不同时存在 [英] postgres hstore exists and doesn't exist at same time

查看:171
本文介绍了postgres hstore存在并且不同时存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在远程服务器上设置了Rails应用并创建了一个hstore扩展

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

 sudo -u postgres psql
 CREATE EXTENSION hstore;

然后我在一个postgres表中部署了使用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

然后我尝试再次这样做

 sudo -u postgres psql
 CREATE EXTENSION hstore;

但是它告诉我hstore已经存在

but it told me hstore already exists

ERROR:  extension "hstore" already exists

继续。

任何想法都可能导致此问题吗?我在Ubuntu 12.04服务器上使用Postgres 9.1

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"

更新 $ b $的对等身份验证失败b尽管已安装hstore,但它不是我正在使用的数据库的扩展。

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)


推荐答案

要在数据库中创建扩展名,必须显式连接到该数据库。因此,如果您的数据库是 my_app_development ,则必须执行以下操作:

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;

此外,您不知道您使用的是哪个Rails版本。如果您不在Rails-4上,则必须使用 postgres hstore gem

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.

这篇关于postgres hstore存在并且不同时存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆