This question already has an answer here:
How to create a new database with the hstore extension already installed?
(1个答案)
5年前关闭。
我在远程服务器上设置了一个Rails应用程序,并创建了一个hstore扩展
 sudo -u postgres psql
 CREATE EXTENSION hstore;

然后我在一个postgres表中部署了一个使用hstore的应用程序迭代,但是当它运行迁移时,它给出了一个错误消息
PG::UndefinedObject: ERROR:  type "hstore" does not exist

然后我又试着做了一次
 sudo -u postgres psql
 CREATE EXTENSION hstore;

但它告诉我HStar已经存在
ERROR:  extension "hstore" already exists

这一圈还在继续。
知道是什么导致了这个问题吗?我在Ubuntu 12.04服务器上使用postgres 9.1
更新
注意,不知道这个问题是否与权限有关,我试图像这样检查我的权限,但得到以下错误
sudo -u postgres psql -U username
psql: FATAL:  Peer authentication failed for user "username"

更新
虽然已经安装了hstore,但它不是我正在使用的数据库的扩展。如何在特定的数据库中安装它?
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,则必须执行以下操作:

sudo -u postgres psql my_app_development
create extension hstore;

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

10-07 19:04
查看更多